Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Unix Programming (preferred in Oracle VirtualBox) Log into the Linux system as a common user (say, bob ) and open a shell window. Create a

Unix Programming (preferred in Oracle VirtualBox)

  1. Log into the Linux system as a common user (say, bob) and open a shell window.
  2. Create a directory named, say, proj. (using command "mkdir proj "). Then execute the command "chmod 755 proj " to set the permission string of the proj directory to be rwxr-x-r-x. Next, enter the proj directory (using command "cd proj ").
  3. Edit a C program consisting of the following source codes. Name the file log2.c and save the file into the proj directory, which was created in the previous step. Then compile the program to get an executable file named log2. Command to compile the program is
     gcc -o log2 log2.c
    Question: What is the file permission string of the executable file log2?
    /* C program: log2.c */ /* To do: append the current time to the log file */ #include #include #include #include #include #include #define LOG_FILE "./log_file" int main(void) { char *username; time_t t; int fd; char s[1000]; char *time_string; username = getenv("USER"); /* Get user account info. */ t = time(0); /* Get current time */ /* Open file "./log_file" * Create a new file if the file does not exit */ fd = open(LOG_FILE, O_APPEND | O_SYNC | O_CREAT | O_WRONLY, 0666); if (fd < 0) { fprintf(stderr, "Can't write log file %s ", LOG_FILE); return -1; } time_string = asctime(localtime(&t)); /* Convert time to string */ /* Write to the file */ sprintf(s, "%-10s %s", username, time_string); write(fd, s, strlen(s)); close(fd); /* Close the file */ return 0; }
  4. Run the executable log2. Command to run the executable is " ./log2 ". List the current directory to check the existence of the log file log_file. Check the content of the file log_file. One command to display the file content is " cat log_file ".
  5. Set up the permissions of the file log_file so that it can be written only by the owner.
  6. Set up the permissions of the executable log2 so that it can be executed by everyone.
  7. Log into the system as a different user (say, alice), run the executable log2.
  8. Log into the system as the first user (say, bob). Set the SetUID bit of the executable file log2. What is the file permission string of log2 after the execution of the command?
  9. Log into the system as the second user (say, alice), run the executable log2. Question: What is the output? Check the content of the file log_file, is there any difference from step 4.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions