The Linux Programming Interface

(nextflipdebug5) #1

796 Chapter 38


38.13 Exercises


38-1. Log in as a normal, unprivileged user, create an executable file (or copy an existing
file such as /bin/sleep), and enable the set-user-ID permission bit on that file (chmod
u+s). Try modifying the file (e.g., cat >> file). What happens to the file permissions
as a result (ls –l)? Why does this happen?
38-2. Write a set-user-ID-root program similar to the sudo(8) program. This program
should take command-line options and arguments as follows:

$ ./douser [-u user ] program-file arg1 arg2 ...

The douser program executes program-file, with the given arguments, as though it
was run by user. (If the –u option is omitted, then user should default to root.) Before
executing program-file, douser should request the password for user, authenticate it
against the standard password file (see Listing 8-2, on page 164), and then set all of
the process user and group IDs to the correct values for that user.
Free download pdf