user_cmnd = "list";
pwflag = I_LISTPW;
break;
+ case MODE_CHECK:
+ pwflag = I_LISTPW;
+ break;
}
/* Must have a command to run... */
log_auth(validated, 1);
if (sudo_mode == MODE_VALIDATE)
exit(0);
+ else if (sudo_mode == MODE_CHECK)
+ exit(display_cmnd(list_pw ? list_pw : sudo_user.pw));
else if (sudo_mode == MODE_LIST) {
display_privs(list_pw ? list_pw : sudo_user.pw);
#ifdef HAVE_LDAP
/* It is now safe to use log_error() and set_perms() */
#ifdef HAVE_GETGROUPS
- if ((user_ngroups = getgroups(0, NULL)) > 0) {
+ if (list_pw == NULL && (user_ngroups = getgroups(0, NULL)) > 0) {
user_groups = emalloc2(user_ngroups, sizeof(gid_t));
if (getgroups(user_ngroups, user_groups) < 0)
log_error(USE_ERRNO|MSG_ONLY, "can't get group vector");
/* Resolve the path and return. */
rval = FOUND;
user_stat = emalloc(sizeof(struct stat));
- if (sudo_mode & (MODE_RUN | MODE_EDIT)) {
- if (ISSET(sudo_mode, MODE_RUN)) {
+ if (sudo_mode & (MODE_RUN | MODE_EDIT | MODE_CHECK)) {
+ if (ISSET(sudo_mode, MODE_RUN | MODE_CHECK)) {
set_perms(PERM_RUNAS);
rval = find_path(NewArgv[0], &user_cmnd, user_stat, user_path);
set_perms(PERM_ROOT);
case 'S':
SET(tgetpass_flags, TGP_STDIN);
break;
+ case 'U':
+ /* Must have an associated list user. */
+ if (NewArgv[1] == NULL)
+ usage(1);
+ if ((list_pw = sudo_getpwnam(NewArgv[1])) == NULL)
+ errorx(1, "unknown user %s", NewArgv[1]);
+ NewArgc--;
+ NewArgv++;
+ break;
case '-':
NewArgc--;
NewArgv++;
NewArgc--;
NewArgv++;
}
+ if (NewArgc > 0 && rval == MODE_LIST)
+ rval = MODE_CHECK;
- if (user_runas != NULL) {
- if (rval == MODE_LIST) {
- if ((list_pw = sudo_getpwnam(*user_runas)) == NULL)
- errorx(1, "unknown user %s", *user_runas);
- user_runas = NULL;
- } else if (!ISSET(rval, (MODE_EDIT|MODE_RUN))) {
- warningx("the `-u' and '-%c' options may not be used together", excl);
- usage(1);
- }
+ if (user_runas != NULL && !ISSET(rval, (MODE_EDIT|MODE_RUN|MODE_CHECK))) {
+ if (excl != '\0')
+ warningx("the `-u' and '-%c' options may not be used together",
+ excl);
+ usage(1);
+ }
+ if (list_pw != NULL && rval != MODE_LIST && rval != MODE_CHECK) {
+ if (excl != '\0')
+ warningx("the `-U' and '-%c' options may not be used together",
+ excl);
+ usage(1);
}
if ((NewArgc == 0 && (rval & MODE_EDIT)) ||
- (NewArgc > 0 && !(rval & (MODE_RUN | MODE_EDIT))))
+ (NewArgc > 0 && !(rval & (MODE_RUN | MODE_EDIT | MODE_CHECK))))
usage(1);
return(rval);
continue;
*p = " file [...]";
} else {
- fprintf(stderr, "usage: %s -K | -L | -V | -h | -k | -l | -v\n",
+ fprintf(stderr, "usage: %s -K | -L | -V | -h | -k | -v\n",
+ getprogname());
+ fprintf(stderr,
+ "usage: %s [-U username] [-u username|#uid] -l [command]\n",
getprogname());
}
sudo, sudoedit - execute a command as another user
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
- s\bsu\bud\bdo\bo -\b-K\bK | -\b-L\bL | -\b-V\bV | -\b-h\bh | -\b-k\bk | -\b-l\bl | -\b-v\bv
+ s\bsu\bud\bdo\bo -\b-K\bK | -\b-L\bL | -\b-V\bV | -\b-h\bh | -\b-k\bk | -\b-v\bv
+
+ s\bsu\bud\bdo\bo [-\b-U\bU _\bu_\bs_\be_\br_\bn_\ba_\bm_\be] [-\b-u\bu _\bu_\bs_\be_\br_\bn_\ba_\bm_\be|_\b#_\bu_\bi_\bd] -\b-l\bl [_\bc_\bo_\bm_\bm_\ba_\bn_\bd]
s\bsu\bud\bdo\bo [-\b-H\bHP\bPS\bSb\bb] [-\b-a\ba _\ba_\bu_\bt_\bh_\b__\bt_\by_\bp_\be] [-\b-c\bc _\bc_\bl_\ba_\bs_\bs|_\b-] [-\b-p\bp _\bp_\br_\bo_\bm_\bp_\bt]
[-\b-u\bu _\bu_\bs_\be_\br_\bn_\ba_\bm_\be|_\b#_\bu_\bi_\bd] {-\b-e\be file [...] | -\b-i\bi | -\b-s\bs | _\bc_\bo_\bm_\bm_\ba_\bn_\bd}
mands through sudo even when a root shell has been
invoked. It also allows the -\b-e\be flag to remain useful even
when being run via a sudo-run script or program. Note
- however, that the sudoers lookup is still done for root,
- not the user specified by SUDO_USER.
-1.6.9 November 11, 2004 1
+1.6.9 November 24, 2004 1
SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
+ however, that the sudoers lookup is still done for root,
+ not the user specified by SUDO_USER.
+
s\bsu\bud\bdo\bo can log both successful and unsuccessful attempts (as
well as errors) to _\bs_\by_\bs_\bl_\bo_\bg(3), a log file, or both. By
default s\bsu\bud\bdo\bo will log via _\bs_\by_\bs_\bl_\bo_\bg(3) but this is changeable
from the standard input instead of the terminal
device.
+ -U The -\b-U\bU (_\bo_\bt_\bh_\be_\br _\bu_\bs_\be_\br) option is used in conjunction with
+ the -\b-l\bl option to specify the user whose privileges
+ should be listed. Only root or a user with s\bsu\bud\bdo\bo ALL
+ on the current host may use this option.
+
-V The -\b-V\bV (_\bv_\be_\br_\bs_\bi_\bo_\bn) option causes s\bsu\bud\bdo\bo to print the ver
sion number and exit. If the invoking user is already
root the -\b-V\bV option will print out a list of the
administrator may specify a list of sudo-specific
authentication methods by adding an "auth-sudo" entry
in /etc/login.conf. This option is only available on
- systems that support BSD authentication where s\bsu\bud\bdo\bo has
- been configured with the --with-bsdauth option.
- -b The -\b-b\bb (_\bb_\ba_\bc_\bk_\bg_\br_\bo_\bu_\bn_\bd) option tells s\bsu\bud\bdo\bo to run the given
- command in the background. Note that if you use the
- -\b-b\bb option you cannot use shell job control to manipu
- late the process.
+1.6.9 November 24, 2004 2
-1.6.9 November 11, 2004 2
+SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
-SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
+ systems that support BSD authentication where s\bsu\bud\bdo\bo has
+ been configured with the --with-bsdauth option.
+ -b The -\b-b\bb (_\bb_\ba_\bc_\bk_\bg_\br_\bo_\bu_\bn_\bd) option tells s\bsu\bud\bdo\bo to run the given
+ command in the background. Note that if you use the
+ -\b-b\bb option you cannot use shell job control to manipu
+ late the process.
-c The -\b-c\bc (_\bc_\bl_\ba_\bs_\bs) option causes s\bsu\bud\bdo\bo to run the specified
command with resources limited by the specified login
sage and exit.
-i The -\b-i\bi (_\bs_\bi_\bm_\bu_\bl_\ba_\bt_\be _\bi_\bn_\bi_\bt_\bi_\ba_\bl _\bl_\bo_\bg_\bi_\bn) option runs the shell
- specified in the passwd(4) entry of the user that the
- command is being run as. The command name argument
- given to the shell begins with a `-' to tell the shell
- to run as a login shell. s\bsu\bud\bdo\bo attempts to change to
- that user's home directory before running the shell.
- It also initializes the environment, leaving _\bT_\bE_\bR_\bM
- unchanged, setting _\bH_\bO_\bM_\bE, _\bS_\bH_\bE_\bL_\bL, _\bU_\bS_\bE_\bR, _\bL_\bO_\bG_\bN_\bA_\bM_\bE, and
- _\bP_\bA_\bT_\bH, and unsetting all other environment variables.
-1.6.9 November 11, 2004 3
+1.6.9 November 24, 2004 3
SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
+ specified in the passwd(4) entry of the user that the
+ command is being run as. The command name argument
+ given to the shell begins with a `-' to tell the shell
+ to run as a login shell. s\bsu\bud\bdo\bo attempts to change to
+ that user's home directory before running the shell.
+ It also initializes the environment, leaving _\bT_\bE_\bR_\bM
+ unchanged, setting _\bH_\bO_\bM_\bE, _\bS_\bH_\bE_\bL_\bL, _\bU_\bS_\bE_\bR, _\bL_\bO_\bG_\bN_\bA_\bM_\bE, and
+ _\bP_\bA_\bT_\bH, and unsetting all other environment variables.
+
-k The -\b-k\bk (_\bk_\bi_\bl_\bl) option to s\bsu\bud\bdo\bo invalidates the user's
timestamp by setting the time on it to the epoch. The
next time s\bsu\bud\bdo\bo is run a password will be required.
to allow a user to revoke s\bsu\bud\bdo\bo permissions from a
.logout file.
- -l The -\b-l\bl (_\bl_\bi_\bs_\bt) option will list out the allowed (and
- forbidden) commands for the user on the current host.
- If the -\b-u\bu flag is specified and the invoking user has
- s\bsu\bud\bdo\bo ALL on the current host, the information listed
- will be for the user specified by the -\b-u\bu flag.
+ -l [_\bc_\bo_\bm_\bm_\ba_\bn_\bd]
+ If no _\bc_\bo_\bm_\bm_\ba_\bn_\bd is specified, the -\b-l\bl (_\bl_\bi_\bs_\bt) option will
+ list the allowed (and forbidden) commands for the
+ invoking user (or the user specified by the -\b-U\bU option)
+ on the current host. If a _\bc_\bo_\bm_\bm_\ba_\bn_\bd is specified and is
+ permitted by _\bs_\bu_\bd_\bo_\be_\br_\bs, the fully-qualified path to the
+ command is displayed along with any command line argu
+ ments. If _\bc_\bo_\bm_\bm_\ba_\bn_\bd is not allowed, s\bsu\bud\bdo\bo will exit with
+ a return value of 1.
-p The -\b-p\bp (_\bp_\br_\bo_\bm_\bp_\bt) option allows you to override the
default password prompt and use a custom one. The
command as a user other than _\br_\bo_\bo_\bt. To specify a _\bu_\bi_\bd
instead of a _\bu_\bs_\be_\br_\bn_\ba_\bm_\be, use _\b#_\bu_\bi_\bd. Note that if the
_\bt_\ba_\br_\bg_\be_\bt_\bp_\bw Defaults option is set (see sudoers(4)) it is
- not possible to run commands with a uid not listed in
- the password database.
- -v If given the -\b-v\bv (_\bv_\ba_\bl_\bi_\bd_\ba_\bt_\be) option, s\bsu\bud\bdo\bo will update
- the user's timestamp, prompting for the user's pass
- word if necessary. This extends the s\bsu\bud\bdo\bo timeout for
- another 5 minutes (or whatever the timeout is set to
- in _\bs_\bu_\bd_\bo_\be_\br_\bs) but does not run a command.
- -- The -\b--\b- flag indicates that s\bsu\bud\bdo\bo should stop processing
- command line arguments. It is most useful in conjunc
- tion with the -\b-s\bs flag.
+1.6.9 November 24, 2004 4
-1.6.9 November 11, 2004 4
+SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
+ not possible to run commands with a uid not listed in
+ the password database.
-SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
+ -v If given the -\b-v\bv (_\bv_\ba_\bl_\bi_\bd_\ba_\bt_\be) option, s\bsu\bud\bdo\bo will update
+ the user's timestamp, prompting for the user's pass
+ word if necessary. This extends the s\bsu\bud\bdo\bo timeout for
+ another 5 minutes (or whatever the timeout is set to
+ in _\bs_\bu_\bd_\bo_\be_\br_\bs) but does not run a command.
+ -- The -\b--\b- flag indicates that s\bsu\bud\bdo\bo should stop processing
+ command line arguments. It is most useful in conjunc
+ tion with the -\b-s\bs flag.
R\bRE\bET\bTU\bUR\bRN\bN V\bVA\bAL\bLU\bUE\bES\bS
Upon successful execution of a program, the return value
as root.
To prevent command spoofing, s\bsu\bud\bdo\bo checks "." and "" (both
+
+
+
+1.6.9 November 24, 2004 5
+
+
+
+
+
+SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
+
+
denoting current directory) last when searching for a com
mand in the user's PATH (if one or both are in the PATH).
Note, however, that the actual PATH environment variable
cally.
s\bsu\bud\bdo\bo will check the ownership of its timestamp directory
-
-
-
-1.6.9 November 11, 2004 5
-
-
-
-
-
-SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
-
-
(_\b/_\bv_\ba_\br_\b/_\br_\bu_\bn_\b/_\bs_\bu_\bd_\bo by default) and ignore the directory's con
tents if it is not owned by root and only writable by
root. On systems that allow non-root users to give away
E\bEN\bNV\bVI\bIR\bRO\bON\bNM\bME\bEN\bNT\bT
s\bsu\bud\bdo\bo utilizes the following environment variables:
- EDITOR Default editor to use in -e (sudoedit) mode if
- VISUAL is not set
- HOME In -s or -H mode (or if sudo was configured with
- the --enable-shell-sets-home option), set to
- homedir of the target user
- PATH Set to a sane value if sudo was configured with
- the --with-secure-path option
- SHELL Used to determine shell to run with -s option
- SUDO_PROMPT Used as the default password prompt
+1.6.9 November 24, 2004 6
-1.6.9 November 11, 2004 6
+SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
+ EDITOR Default editor to use in -e (sudoedit) mode if
+ VISUAL is not set
+
+ HOME In -s or -H mode (or if sudo was configured with
+ the --enable-shell-sets-home option), set to
+ homedir of the target user
+ PATH Set to a sane value if sudo was configured with
+ the --with-secure-path option
-SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
+ SHELL Used to determine shell to run with -s option
+ SUDO_PROMPT Used as the default password prompt
SUDO_COMMAND Set to the command run by sudo
$ sudo shutdown -r +15 "quick reboot"
+
+
+1.6.9 November 24, 2004 7
+
+
+
+
+
+SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
+
+
To make a usage listing of the directories in the /home
partition. Note that this runs the commands in a sub-
shell to make the cd and file redirection work.
Many people have worked on s\bsu\bud\bdo\bo over the years; this ver
sion consists of code written primarily by:
-
-
-1.6.9 November 11, 2004 7
-
-
-
-
-
-SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
-
-
Todd Miller
Chris Jepeway
If you feel you have found a bug in s\bsu\bud\bdo\bo, please submit a
bug report at http://www.sudo.ws/sudo/bugs/
-S\bSU\bUP\bPP\bPO\bOR\bRT\bT
- Commercial support is available for s\bsu\bud\bdo\bo, see
- http://www.sudo.ws/sudo/support.html for details.
-
- Limited free support is available via the sudo-users mail
- ing list, see http://www.sudo.ws/mail
- man/listinfo/sudo-users to subscribe or search the
- archives.
-D\bDI\bIS\bSC\bCL\bLA\bAI\bIM\bME\bER\bR
- S\bSu\bud\bdo\bo is provided ``AS IS'' and any express or implied war
- ranties, including, but not limited to, the implied war
- ranties of merchantability and fitness for a particular
- purpose are disclaimed. See the LICENSE file distributed
- with s\bsu\bud\bdo\bo or http://www.sudo.ws/sudo/license.html for
-1.6.9 November 11, 2004 8
+1.6.9 November 24, 2004 8
SUDO(1m) MAINTENANCE COMMANDS SUDO(1m)
- complete details.
-
-
-
-
-
-
-
-
-
-
-
-
-
+S\bSU\bUP\bPP\bPO\bOR\bRT\bT
+ Commercial support is available for s\bsu\bud\bdo\bo, see
+ http://www.sudo.ws/sudo/support.html for details.
+ Limited free support is available via the sudo-users mail
+ ing list, see http://www.sudo.ws/mail
+ man/listinfo/sudo-users to subscribe or search the
+ archives.
+D\bDI\bIS\bSC\bCL\bLA\bAI\bIM\bME\bER\bR
+ S\bSu\bud\bdo\bo is provided ``AS IS'' and any express or implied war
+ ranties, including, but not limited to, the implied war
+ ranties of merchantability and fitness for a particular
+ purpose are disclaimed. See the LICENSE file distributed
+ with s\bsu\bud\bdo\bo or http://www.sudo.ws/sudo/license.html for com
+ plete details.
-1.6.9 November 11, 2004 9
+1.6.9 November 24, 2004 9