SETUID(8)

NAME
setuid - run setuid shell scripts safely

SYNOPSIS
#! /bin/setuid

DESCRIPTION
setuid is never normally executed from a shell. Instead it can be used as the interpreter for shell scripts that need to be run setuid to someone else: this is done by making the first line of the script

#! /bin/setuid

rather than the usual

#! /bin/sh

setuid tries to open the script for reading. If successful it discards the first line (containing the #! /bin/setuid) and tries to read a line formatted as follows:

#? absolute-path-of-interpreter arguments

Example:

#? /bin/csh -bf /usr/etc/setuid_script

To avoid `linking tricks' for obtaining all privileges of the owner of the file, 2 measures have been taken:

1) the script must contain its own safe invocation, that is the `#?' line;
2) just before the final execv(2) setuid checks if the owner and mode of the script are still what they are supposed to be; if there is a discrepancy, setuid will abort with an error message.

setuid will only exec a pathname beginning with a '/', to improve security. Of course setuid can be `fooled' by supplying dubious arguments to the interpreter, like relative pathnames. Furthermore it is a mistake to let the last directory component of the ultimate path be writable by others. In our example /usr/etc should not be writable for ordinary users.

In addition, for the sake of security, setuid sets the PATH environment variable back to a simple default, and deletes the IFS environment variable.

AUTHOR
Maarten Litmaath @ VU Informatika Amsterdam (maart@cs.vu.nl)

SEE ALSO
sh(1),csh(1)

BUGS
The maintenance of setuid scripts is a bit annoying: if a script is moved, one must not forget to change the path mentioned in the script. Possibly the editing causes the setuid bit to get turned off.