]> granicus.if.org Git - sudo/commitdiff
Reset HOME when env_reset is enabled unless it is in env_keep
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 19 Jul 2010 19:08:04 +0000 (15:08 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 19 Jul 2010 19:08:04 +0000 (15:08 -0400)
--HG--
branch : 1.7

UPGRADE
WHATSNEW
env.c
sudo.cat
sudo.man.in
sudo.pod

diff --git a/UPGRADE b/UPGRADE
index 3e049d22687a152c916dec61e05d1a9f4e41f5c8..cde28f2a892e1c5b392f0de48dd2e34de97aacdf 100644 (file)
--- a/UPGRADE
+++ b/UPGRADE
@@ -10,6 +10,15 @@ o Upgrading from a version prior to 1.7.4:
     system reboots.  Time stamp files older than the boot time are
     ignored on systems where it is possible to determine this.
 
+    The HOME and MAIL environment variables are now reset based on the
+    target user's password database entry when the env_reset sudoers option
+    is enabled (which is the case in the default configuration).  Users
+    wishing to preserve the original values should use a sudoers entry like:
+        Defaults env_keep += HOME
+    to preserve the old value of HOME and
+        Defaults env_keep += MAIL
+    to preserve the old value of MAIL.
+
 o Upgrading from a version prior to 1.7.0:
 
     Starting with sudo 1.7.0, comments in the sudoers file must not
index 2894f70eabd07d10814e365c610a1e69b81538d8..607b070d497163c87b9a304ff80f93442a05aa90 100644 (file)
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -34,9 +34,14 @@ What's new in Sudo 1.7.4?
    more than 32 descriptors on SuSE Linux, where sysconf(_SC_CHILD_MAX)
    will return -1 when RLIMIT_NPROC is set to RLIMIT_UNLIMITED (-1).
 
- * If env_reset is enabled in sudoers (the default), sudo will now set
-   the MAIL environment variable based on the target user unless MAIL is
-   explicitly preserved in sudoers.  Previously MAIL was passed unchanged.
+ * The HOME and MAIL environment variables are now reset based on the
+   target user's password database entry when the env_reset sudoers option
+   is enabled (which is the case in the default configuration).  Users
+   wishing to preserve the original values should use a sudoers entry like:
+       Defaults env_keep += HOME
+   to preserve the old value of HOME and
+       Defaults env_keep += MAIL
+   to preserve the old value of MAIL.
 
 What's new in Sudo 1.7.3?
 
diff --git a/env.c b/env.c
index 6ad32992f1e602a8451aa291dea6805246b459c8..c6e0a6b43fdfa144fb3f138a024a3e7c8162f2ae 100644 (file)
--- a/env.c
+++ b/env.c
@@ -196,7 +196,6 @@ static const char *initial_checkenv_table[] = {
 static const char *initial_keepenv_table[] = {
     "COLORS",
     "DISPLAY",
-    "HOME",
     "HOSTNAME",
     "KRB5CCNAME",
     "LS_COLORS",
@@ -595,6 +594,7 @@ rebuild_env(noexec)
     char **old_envp, **ep, *cp, *ps1;
     char idbuf[MAX_UID_T_LEN];
     unsigned int didvar;
+    int reset_home = FALSE;
 
     /*
      * Either clean out the environment or reset to a safe default.
@@ -609,6 +609,9 @@ rebuild_env(noexec)
     memset(env.envp, 0, env.env_size * sizeof(char *));
 #endif
     if (def_env_reset || ISSET(sudo_mode, MODE_LOGIN_SHELL)) {
+       /* Reset HOME based on target user unless keeping old value. */
+       reset_home = TRUE;
+
        /* Pull in vars we want to keep from the old environment. */
        for (ep = old_envp; *ep; ep++) {
            int keepit;
@@ -677,7 +680,6 @@ rebuild_env(noexec)
         * on sudoers options).
         */
        if (ISSET(sudo_mode, MODE_LOGIN_SHELL)) {
-           sudo_setenv("HOME", runas_pw->pw_dir, ISSET(didvar, DID_HOME));
            sudo_setenv("SHELL", runas_pw->pw_shell, ISSET(didvar, DID_SHELL));
            sudo_setenv("LOGNAME", runas_pw->pw_name,
                ISSET(didvar, DID_LOGNAME));
@@ -685,8 +687,6 @@ rebuild_env(noexec)
            sudo_setenv("USERNAME", runas_pw->pw_name,
                ISSET(didvar, DID_USERNAME));
        } else {
-           if (!ISSET(didvar, DID_HOME))
-               sudo_setenv("HOME", user_dir, FALSE);
            if (!ISSET(didvar, DID_SHELL))
                sudo_setenv("SHELL", sudo_user.pw->pw_shell, FALSE);
            if (!ISSET(didvar, DID_LOGNAME))
@@ -709,6 +709,13 @@ rebuild_env(noexec)
            sudo_putenv(cp, ISSET(didvar, DID_MAIL), TRUE);
        }
     } else {
+       /* Reset HOME based on target user if configured to. */
+       if (ISSET(sudo_mode, MODE_RUN)) {
+           if (def_always_set_home || ISSET(sudo_mode, MODE_RESET_HOME) || 
+               (ISSET(sudo_mode, MODE_SHELL) && def_set_home))
+               reset_home = TRUE;
+       }
+
        /*
         * Copy environ entries as long as they don't match env_delete or
         * env_check.
@@ -748,8 +755,7 @@ rebuild_env(noexec)
     }
 
     /* Set $USER, $LOGNAME and $USERNAME to target if "set_logname" is true. */
-    /* XXX - not needed for MODE_LOGIN_SHELL */
-    if (def_set_logname && runas_pw->pw_name) {
+    if (def_set_logname && !ISSET(sudo_mode, MODE_LOGIN_SHELL)) {
        if (!ISSET(didvar, KEPT_LOGNAME))
            sudo_setenv("LOGNAME", runas_pw->pw_name, TRUE);
        if (!ISSET(didvar, KEPT_USER))
@@ -758,14 +764,9 @@ rebuild_env(noexec)
            sudo_setenv("USERNAME", runas_pw->pw_name, TRUE);
     }
 
-    /* Set $HOME for `sudo -H'.  Only valid at PERM_FULL_RUNAS. */
-    /* XXX - not needed for MODE_LOGIN_SHELL */
-    if (runas_pw->pw_dir) {
-       if (ISSET(sudo_mode, MODE_RESET_HOME) ||
-           (ISSET(sudo_mode, MODE_RUN) && (def_always_set_home ||
-           (ISSET(sudo_mode, MODE_SHELL) && def_set_home))))
-           sudo_setenv("HOME", runas_pw->pw_dir, TRUE);
-    }
+    /* Set $HOME to target user if not preserving user's value. */
+    if (reset_home && !ISSET(didvar, KEPT_HOME))
+       sudo_setenv("HOME", runas_pw->pw_dir, ISSET(didvar, DID_HOME));
 
     /* Provide default values for $TERM and $PATH if they are not set. */
     if (!ISSET(didvar, DID_TERM))
index b9c6a0c884b2d07de8e6ccf3225fa87b5956faa4..97bc6b356b13e074b4bbda4a58356358aa515615 100644 (file)
--- a/sudo.cat
+++ b/sudo.cat
@@ -179,17 +179,17 @@ SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 
        -H          The -\b-H\bH (_\bH_\bO_\bM_\bE) option sets the HOME environment variable to
                    the homedir of the target user (root by default) as
-                   specified in _\bp_\ba_\bs_\bs_\bw_\bd(4).  By default, s\bsu\bud\bdo\bo does not modify
-                   HOME (see _\bs_\be_\bt_\b__\bh_\bo_\bm_\be and _\ba_\bl_\bw_\ba_\by_\bs_\b__\bs_\be_\bt_\b__\bh_\bo_\bm_\be in _\bs_\bu_\bd_\bo_\be_\br_\bs(4)).
+                   specified in _\bp_\ba_\bs_\bs_\bw_\bd(4).  The default handling of the HOME
+                   environment variable depends on _\bs_\bu_\bd_\bo_\be_\br_\bs(4) settings.  By
+                   default, s\bsu\bud\bdo\bo will set HOME if _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt or _\ba_\bl_\bw_\ba_\by_\bs_\b__\bs_\be_\bt_\b__\bh_\bo_\bm_\be
+                   are set, or if _\bs_\be_\bt_\b__\bh_\bo_\bm_\be is set and the -\b-s\bs option is
+                   specified on the command line.
 
        -h          The -\b-h\bh (_\bh_\be_\bl_\bp) option causes s\bsu\bud\bdo\bo to print a usage message
                    and exit.
 
        -i [command]
                    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 _\bp_\ba_\bs_\bs_\bw_\bd(4) entry of the target user as a
-                   login shell.  This means that login-specific resource files
-                   such as .profile or .login will be read by the shell.  If a
 
 
 
@@ -202,6 +202,9 @@ SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 
 
+                   specified in the _\bp_\ba_\bs_\bs_\bw_\bd(4) entry of the target user as a
+                   login shell.  This means that login-specific resource files
+                   such as .profile or .login will be read by the shell.  If a
                    command is specified, it is passed to the shell for
                    execution.  Otherwise, an interactive shell is executed.
                    s\bsu\bud\bdo\bo attempts to change to that user's home directory
@@ -253,9 +256,6 @@ SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 
        -P          The -\b-P\bP (_\bp_\br_\be_\bs_\be_\br_\bv_\be _\bg_\br_\bo_\bu_\bp _\bv_\be_\bc_\bt_\bo_\br) option causes s\bsu\bud\bdo\bo to
                    preserve the invoking user's group vector unaltered.  By
-                   default, s\bsu\bud\bdo\bo will initialize the group vector to the list
-                   of groups the target user is in.  The real and effective
-                   group IDs, however, are still set to match the target user.
 
 
 
@@ -268,6 +268,10 @@ SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 
 
+                   default, s\bsu\bud\bdo\bo will initialize the group vector to the list
+                   of groups the target user is in.  The real and effective
+                   group IDs, however, are still set to match the target user.
+
        -p _\bp_\br_\bo_\bm_\bp_\bt   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 following
                    percent (`%') escapes are supported:
@@ -318,10 +322,6 @@ SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
                    listed.  Only root or a user with s\bsu\bud\bdo\bo ALL on the current
                    host may use this option.
 
-       -u _\bu_\bs_\be_\br     The -\b-u\bu (_\bu_\bs_\be_\br) option causes s\bsu\bud\bdo\bo to run the specified
-                   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.  When running commands as
-                   a _\bu_\bi_\bd, many shells require that the '#' be escaped with a
 
 
 
@@ -334,6 +334,10 @@ SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 
 
+       -u _\bu_\bs_\be_\br     The -\b-u\bu (_\bu_\bs_\be_\br) option causes s\bsu\bud\bdo\bo to run the specified
+                   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.  When running commands as
+                   a _\bu_\bi_\bd, many shells require that the '#' be escaped with a
                    backslash ('\').  Note that if the _\bt_\ba_\br_\bg_\be_\bt_\bp_\bw Defaults option
                    is set (see _\bs_\bu_\bd_\bo_\be_\br_\bs(4)) it is not possible to run commands
                    with a uid not listed in the password database.
@@ -384,10 +388,6 @@ S\bSE\bEC\bCU\bUR\bRI\bIT\bTY\bY N\bNO\bOT\bTE\bES\bS
        default, the _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt _\bs_\bu_\bd_\bo_\be_\br_\bs option is enabled.  This causes commands
        to be executed with a minimal environment containing TERM, PATH, HOME,
        SHELL, LOGNAME, USER and USERNAME in addition to variables from the
-       invoking process permitted by the _\be_\bn_\bv_\b__\bc_\bh_\be_\bc_\bk and _\be_\bn_\bv_\b__\bk_\be_\be_\bp _\bs_\bu_\bd_\bo_\be_\br_\bs
-       options.  There is effectively a whitelist for environment variables.
-
-       If, however, the _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt option is disabled in _\bs_\bu_\bd_\bo_\be_\br_\bs, any variables
 
 
 
@@ -400,6 +400,10 @@ S\bSE\bEC\bCU\bUR\bRI\bIT\bTY\bY N\bNO\bOT\bTE\bES\bS
 SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 
 
+       invoking process permitted by the _\be_\bn_\bv_\b__\bc_\bh_\be_\bc_\bk and _\be_\bn_\bv_\b__\bk_\be_\be_\bp _\bs_\bu_\bd_\bo_\be_\br_\bs
+       options.  There is effectively a whitelist for environment variables.
+
+       If, however, the _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt option is disabled in _\bs_\bu_\bd_\bo_\be_\br_\bs, any variables
        not explicitly denied by the _\be_\bn_\bv_\b__\bc_\bh_\be_\bc_\bk and _\be_\bn_\bv_\b__\bd_\be_\bl_\be_\bt_\be options are
        inherited from the invoking process.  In this case, _\be_\bn_\bv_\b__\bc_\bh_\be_\bc_\bk and
        _\be_\bn_\bv_\b__\bd_\be_\bl_\be_\bt_\be behave like a blacklist.  Since it is not possible to
@@ -451,10 +455,6 @@ SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
        On systems where the boot time is available, s\bsu\bud\bdo\bo will also not honor
        time stamps from before the machine booted.
 
-       Since time stamp files live in the file system, they can outlive a
-       user's login session.  As a result, a user may be able to login, run a
-       command with s\bsu\bud\bdo\bo after authenticating, logout, login again, and run
-
 
 
 1.7.4                     July 19, 2010                         7
@@ -466,6 +466,9 @@ SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 
 
+       Since time stamp files live in the file system, they can outlive a
+       user's login session.  As a result, a user may be able to login, run a
+       command with s\bsu\bud\bdo\bo after authenticating, logout, login again, and run
        s\bsu\bud\bdo\bo without authenticating so long as the time stamp file's
        modification time is within 5 minutes (or whatever the timeout is set
        to in _\bs_\bu_\bd_\bo_\be_\br_\bs).  When the _\bt_\bt_\by_\b__\bt_\bi_\bc_\bk_\be_\bt_\bs option is enabled in _\bs_\bu_\bd_\bo_\be_\br_\bs, the
@@ -497,9 +500,10 @@ E\bEN\bNV\bVI\bIR\bRO\bON\bNM\bME\bEN\bNT\bT
        MAIL            In -\b-i\bi mode or when _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt is enabled in _\bs_\bu_\bd_\bo_\be_\br_\bs, set
                        to the mail spool of the target user
 
-       HOME            In -\b-s\bs or -\b-H\bH mode (or if sudo was configured with the
-                       --enable-shell-sets-home option), set to homedir of the
-                       target user
+       HOME            Set to the home directory of the target user if -\b-i\bi or
+                       -\b-H\bH are specified, _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt or _\ba_\bl_\bw_\ba_\by_\bs_\b__\bs_\be_\bt_\b__\bh_\bo_\bm_\be are set
+                       in _\bs_\bu_\bd_\bo_\be_\br_\bs, or when the -\b-s\bs optino is specified and
+                       _\bs_\be_\bt_\b__\bh_\bo_\bm_\be is set in _\bs_\bu_\bd_\bo_\be_\br_\bs
 
        PATH            Set to a sane value if the _\bs_\be_\bc_\bu_\br_\be_\b__\bp_\ba_\bt_\bh sudoers option
                        is set.
@@ -516,10 +520,6 @@ E\bEN\bNV\bVI\bIR\bRO\bON\bNM\bME\bEN\bNT\bT
 
        SUDO_GID        Set to the group ID of the user who invoked sudo
 
-       SUDO_PROMPT     Used as the default password prompt
-
-       SUDO_PS1        If set, PS1 will be set to its value for the program
-                       being run
 
 
 
@@ -532,6 +532,11 @@ E\bEN\bNV\bVI\bIR\bRO\bON\bNM\bME\bEN\bNT\bT
 SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 
 
+       SUDO_PROMPT     Used as the default password prompt
+
+       SUDO_PS1        If set, PS1 will be set to its value for the program
+                       being run
+
        SUDO_UID        Set to the user ID of the user who invoked sudo
 
        SUDO_USER       Set to the login of the user who invoked sudo
@@ -582,11 +587,6 @@ E\bEX\bXA\bAM\bMP\bPL\bLE\bES\bS
        Note that this runs the commands in a sub-shell to make the cd and file
        redirection work.
 
-        $ sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"
-
-S\bSE\bEE\bE A\bAL\bLS\bSO\bO
-       _\bg_\br_\be_\bp(1), _\bs_\bu(1), _\bs_\bt_\ba_\bt(2), _\bl_\bo_\bg_\bi_\bn_\b__\bc_\ba_\bp(3), _\bp_\ba_\bs_\bs_\bw_\bd(4), _\bs_\bu_\bd_\bo_\be_\br_\bs(5),
-
 
 
 1.7.4                     July 19, 2010                         9
@@ -598,6 +598,10 @@ S\bSE\bEE\bE A\bAL\bLS\bSO\bO
 SUDO(1m)               MAINTENANCE COMMANDS              SUDO(1m)
 
 
+        $ sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"
+
+S\bSE\bEE\bE A\bAL\bLS\bSO\bO
+       _\bg_\br_\be_\bp(1), _\bs_\bu(1), _\bs_\bt_\ba_\bt(2), _\bl_\bo_\bg_\bi_\bn_\b__\bc_\ba_\bp(3), _\bp_\ba_\bs_\bs_\bw_\bd(4), _\bs_\bu_\bd_\bo_\be_\br_\bs(5),
        _\bv_\bi_\bs_\bu_\bd_\bo(1m)
 
 A\bAU\bUT\bTH\bHO\bOR\bRS\bS
@@ -651,10 +655,6 @@ D\bDI\bIS\bSC\bCL\bLA\bAI\bIM\bME\bER\bR
 
 
 
-
-
-
-
 1.7.4                     July 19, 2010                        10
 
 
index 1ffea70e013dcc2b3d458bdd58a8d8d595ac9f99..65a79d5b226d6a05336c2b3a87057472acabfca5 100644 (file)
@@ -332,8 +332,11 @@ case, the primary group will be set to \fIgroup\fR.
 .IX Item "-H"
 The \fB\-H\fR (\fI\s-1HOME\s0\fR) option sets the \f(CW\*(C`HOME\*(C'\fR environment variable
 to the homedir of the target user (root by default) as specified
-in \fIpasswd\fR\|(@mansectform@).  By default, \fBsudo\fR does not modify \f(CW\*(C`HOME\*(C'\fR
-(see \fIset_home\fR and \fIalways_set_home\fR in \fIsudoers\fR\|(@mansectform@)).
+in \fIpasswd\fR\|(@mansectform@).  The default handling of the \f(CW\*(C`HOME\*(C'\fR environment
+variable depends on \fIsudoers\fR\|(@mansectform@) settings.  By default, \fBsudo\fR
+will set \f(CW\*(C`HOME\*(C'\fR if \fIenv_reset\fR or \fIalways_set_home\fR are set, or
+if \fIset_home\fR is set and the \fB\-s\fR option is specified on the
+command line.
 .IP "\-h" 12
 .IX Item "-h"
 The \fB\-h\fR (\fIhelp\fR) option causes \fBsudo\fR to print a usage message and exit.
@@ -623,8 +626,10 @@ to the mail spool of the target user
 .ie n .IP "\*(C`HOME\*(C'" 16
 .el .IP "\f(CW\*(C`HOME\*(C'\fR" 16
 .IX Item "HOME"
-In \fB\-s\fR or \fB\-H\fR mode (or if sudo was configured with the
-\&\-\-enable\-shell\-sets\-home option), set to homedir of the target user
+Set to the home directory of the target user if \fB\-i\fR or \fB\-H\fR are
+specified, \fIenv_reset\fR or \fIalways_set_home\fR are set in \fIsudoers\fR,
+or when the \fB\-s\fR optino is specified and \fIset_home\fR is set in
+\&\fIsudoers\fR
 .ie n .IP "\*(C`PATH\*(C'" 16
 .el .IP "\f(CW\*(C`PATH\*(C'\fR" 16
 .IX Item "PATH"
index c2426a0d8ee0d1f834a1de28646456bab12be8bc..39c8cd9cc936d429ea80f98451b278557c483897 100644 (file)
--- a/sudo.pod
+++ b/sudo.pod
@@ -213,8 +213,11 @@ case, the primary group will be set to I<group>.
 
 The B<-H> (I<HOME>) option sets the C<HOME> environment variable
 to the homedir of the target user (root by default) as specified
-in passwd(5).  By default, B<sudo> does not modify C<HOME>
-(see I<set_home> and I<always_set_home> in L<sudoers(5)>).
+in passwd(5).  The default handling of the C<HOME> environment
+variable depends on L<sudoers(5)> settings.  By default, B<sudo>
+will set C<HOME> if I<env_reset> or I<always_set_home> are set, or
+if I<set_home> is set and the B<-s> option is specified on the
+command line.
 
 =item -h
 
@@ -526,8 +529,10 @@ to the mail spool of the target user
 
 =item C<HOME>
 
-In B<-s> or B<-H> mode (or if sudo was configured with the
---enable-shell-sets-home option), set to homedir of the target user
+Set to the home directory of the target user if B<-i> or B<-H> are
+specified, I<env_reset> or I<always_set_home> are set in I<sudoers>,
+or when the B<-s> optino is specified and I<set_home> is set in
+I<sudoers>
 
 =item C<PATH>