Homework 3 (Program)

Points: 100
Due Date: Friday, November 18, 1999 at 11:59PM

  1. (100 points) Write a program called xsu that takes a command as an argument. Your program is to authenticate the user running the program by requesting the password and validating it, then change the UID to the user's UID and the GID to the user's primary GID and execute the command. The program is described further in the attached manual page.As always, your program must be robust.

Extra Credit

  1. (15 points) Modify your program in problem 1 so that is the user flag is given as user.group, the GID is changed to that of group when user is a member of the group. If user is not a member of the group, and the real UID is root, allow the change; otherwise, deny it.


NAME

xsu - run a command as another user

SYNOPSIS

xsu [ -d ] [ -u user ] command

DESCRIPTION

The command xsu executes the given command with the UID of the named user. If no user is named, the UID of root is used.

The command may be in quotes (one argument) or may be multiple arguments. The command is run in a pristine environment. Specifically, the PATH is set to search /usr/bin, /bin, /usr/sbin, /sbin, and /etc in that order; the HOME is set to the home of user (again, to that of root if no user is named on the command line); SHELL is set to the user's login shell; IFS is set to tab, newline, and blank; and TZ is set to PDT8PST. No other environment variables are set. All files except for standard input, output, and error are closed.All signals are reset to their default value.

OPTIONS

-d Ignore failure of the change to the requested UID (or root, if none). This flag is used for debugging, when the programmer is not running as root.
-u user The real and effective UIDs and GIDs are to be set to those of user rather than root. If user is an integer, it is handled as follows. If a user exists with that integer UID, the command acts as though the name of the user had been typed. If no user exists with that UID, and the user executing xsu has the real UID of root, the password requested is that of root and the given UID is used. If no user exists with that UID and the user executing xsu does not have the real UID of root, the command is refused.

EXIT CODE

If command cannot be executed, xsu exits with a code of -127. If command is executed, the program returns with the return code of command.

EXAMPLES

xsu -u bishop more /home/bishop/private
This executes the command "more /home/bishop/private" with bishop's privileges.

xsu -u nobody ed /tmp/plugh
This allows the user to edit the file "/tmp/plugh" with the privileges of the nobody user.

SEE ALSO

su(1)


Send email to cs153@csif.cs.ucdavis.edu.

Department of Computer Science
University of California at Davis
Davis, CA 95616-8562



Page last modified on 11/17/99