Solutions to Practice Problems

advertisement
Solutions to Practice Problems
Practice Problem 9.1
What is the output of the program shown below?
#include<stdio.h>
#include<string.h>
int main( int argc , char *argv[ ] )
{
char my_string[15] = "USNA Rules!" ;
printf( "The string is %s" , my_string ) ;
printf("The string's length is: %d\n" , strnlen( my_string )
);
strncat( my_string , "\n" , 1 ) ;
strncat( my_string , "\n" , 1 ) ;
printf( "The string is %s" , my_string ) ;
printf("The string's length is: %d\n" , strnlen( my_string )
}
Solution:
Practice Problem 9.2
What would happen if we did not have quotation marks in our command line arguments above?
Solution:
Only the first word of each string would be entered as argv[1].
Practice Problem 9.3
What are the access privileges for happytimes.exe after the command shown above is entered?
Solution:
rwxrwx--x
Practice Problem 9.4
What command would remove the ability for the public to execute happytimes.exe?
Solution:
chmod o-x
happytimes.exe
2
);
Practice Problem 9.5
What single command using the assign operator would assign the public the ability to read and execute
happytimes.exe?
Solution:
chmod o=rx happytimes.exe
Practice Problem 9.6
Who, besides the file's owner, can change a file's mode?
Solution:
root
Practice Problem 9.7
And just how does one get to be the owner of a file anyway?
Solution:
The creator of a file becomes the owner.
Practice Problem 9.8
You are viewing the access privileges of a file exam1.sh and they read: -r-xr-xr-- .
(a)
What privileges for this file are granted to the owner?
(b)
You give the command chmod g-x exam1.sh . What access privilege(s) did you change
and to whom do they apply?
Solution:
(a) read and execute
(b) The associated group may no longer execute the program
Practice Problem 9.9
The following is the output of ls –l for the shutdown command, which is a system administration program.
We can see that it is owned by the root user (administrator) and appears to be executable by everyone. That is,
in actuality, not the case, since the program requires further functionality that is only available to the user ID of
root. How can the root user modify the permissions to this program to allow anyone to shut down the
computer? (Give the command, then an explanation of how it solves this problem.)
Solution:
chmod u+s /sbin/shutdown
Any user running shutdown will have setuid permission of root for this process.
Practice Problem 9.10
What does the sudo command accomplish?
Solution:
Enables a user to perform a task as though they were the superuser (root).
Practice Problem 9.11
Who can execute the sudo command?
Solution:
Anyone who has explicitly been granted permission to do so by the root user in the
/etc/sudoers file.
3
Practice Problem 9.12
Consider the long listing for three files, shown below. The file note1.c is a C program that writes to the file
/tmp/notes. The file note1.exe is the compiled version of note1.c.
The system has four users: midshipman, smith, jones and, of course, root.
(a)
The user smith executes the file note1.exe and notices that his attempts to write to the file
/tmp/notes are not successful. Explain why.
(b)
Suppose it was necessary to grant users the ability to write to the file /tmp/notes, but only
when executing the program note1.exe. Your friend proposes two ways of accomplishing
this:
(i) Enter the command: chmod u+w /tmp/notes
OR
(ii) Enter the command: chmod u+s note1.exe
Which option do you select and why?
Solution:
(a)
/tmp/notes is owned by midshipman and he is the only user that would be allowed to
write to this file.
(b)
Option (ii). The user (owner) of /tmp/notes already has permission to write to it. We
need note1.exe to run as a process owned by midshipman, since he is the only one
who can write to it. Thus, note1.exe must have the setuid permission set during
execution.
4
Download