]> granicus.if.org Git - sudo/commitdiff
Remove special handling of the USERNAME environment variable. It
authorTodd C. Miller <Todd.Miller@sudo.ws>
Mon, 24 Sep 2018 11:30:03 +0000 (05:30 -0600)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Mon, 24 Sep 2018 11:30:03 +0000 (05:30 -0600)
used to be set on old versions of Fedora but that hasn't been the
case for some time.  It's worth noting that ssh doesn't set USERNAME
either.

doc/sudo.cat
doc/sudo.man.in
doc/sudo.mdoc.in
doc/sudoers.cat
doc/sudoers.man.in
doc/sudoers.mdoc.in
plugins/sudoers/env.c
plugins/sudoers/logging.c
plugins/sudoers/regress/visudo/test6.sh

index 2ab3cd91e3dbead3b72c23d827f1d48fc63916da..58714ad3705eff5db7007362ad22ede8cffe2b88 100644 (file)
@@ -566,8 +566,6 @@ E\bEN\bNV\bVI\bIR\bRO\bON\bNM\bME\bEN\bNT\bT
 
      USER             Set to the same value as LOGNAME, described above.
 
-     USERNAME         Same as USER.
-
      VISUAL           Default editor to use in -\b-e\be (sudoedit) mode if
                       SUDO_EDITOR is not set.
 
index c9b2f490e90aee61fe1c592db9a4945303d4b9cb..5dc8e2f1a603e033b732ed0f91a0b3f86d2b7ce4 100644 (file)
@@ -1123,10 +1123,6 @@ Set to the same value as
 \fRLOGNAME\fR,
 described above.
 .TP 17n
-\fRUSERNAME\fR
-Same as
-\fRUSER\fR.
-.TP 17n
 \fRVISUAL\fR
 Default editor to use in
 \fB\-e\fR
index f96081a0f10d689bf965e0aa4aa0a55de7ea24b1..5d2a84fe06e812b1d4a5c2786da285148d4289c6 100644 (file)
@@ -1035,9 +1035,6 @@ Set to the login name of the user who invoked sudo.
 Set to the same value as
 .Ev LOGNAME ,
 described above.
-.It Ev USERNAME
-Same as
-.Ev USER .
 .It Ev VISUAL
 Default editor to use in
 .Fl e
index 8f79b99ef408f940459093809e8531aebb79c2b1..b2c9327e673bbd737f3e7851bd21488ea07cb172 100644 (file)
@@ -126,16 +126,14 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      _\b/_\be_\bt_\bc_\b/_\be_\bn_\bv_\bi_\br_\bo_\bn_\bm_\be_\bn_\bt file.  On BSD systems, if the _\bu_\bs_\be_\b__\bl_\bo_\bg_\bi_\bn_\bc_\bl_\ba_\bs_\bs option is
      enabled, the environment is initialized based on the _\bp_\ba_\bt_\bh and _\bs_\be_\bt_\be_\bn_\bv
      settings in _\b/_\be_\bt_\bc_\b/_\bl_\bo_\bg_\bi_\bn_\b._\bc_\bo_\bn_\bf.  The new environment contains the TERM,
-     PATH, HOME, MAIL, SHELL, LOGNAME, USER, USERNAME and SUDO_* variables 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 options.  This is effectively a whitelist for
-     environment variables.  The environment variables LOGNAME, USER and
-     USERNAME are treated specially.  If one or more variables are preserved
-     from the invoking process, any of the three remaining variables (that
-     were not explicitly preserved) will be set to the same value as the first
-     one in the list that was preserved.  This avoids an inconsistent
-     environment where some of the variables describing the user name are set
-     to the invoking user and some are set to the target user.  () are removed
+     PATH, HOME, MAIL, SHELL, LOGNAME, USER and SUDO_* variables 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 options.  This is effectively a whitelist for environment
+     variables.  The environment variables LOGNAME and USER are treated
+     specially.  If only one of them is preserved from user's environment, the
+     other will be set to the same value.  This avoids an inconsistent
+     environment where one of the variables describing the user name is set to
+     the invoking user and one is set to the target user.  () are removed
      unless both the name and value parts are matched by _\be_\bn_\bv_\b__\bk_\be_\be_\bp or
      _\be_\bn_\bv_\b__\bc_\bh_\be_\bc_\bk, as they may be interpreted as functions by the b\bba\bas\bsh\bh shell.
      Prior to version 1.8.11, such variables were always removed.
@@ -1043,10 +1041,10 @@ S\bSU\bUD\bDO\bOE\bER\bRS\bS O\bOP\bPT\bTI\bIO\bON\bNS\bS
 
      env_reset         If set, s\bsu\bud\bdo\bo will run the command in a minimal
                        environment containing the TERM, PATH, HOME, MAIL,
-                       SHELL, LOGNAME, USER, USERNAME and SUDO_* variables.
-                       Any variables in the caller's environment or in the
-                       file specified by the _\br_\be_\bs_\bt_\br_\bi_\bc_\bt_\be_\bd_\b__\be_\bn_\bv_\b__\bf_\bi_\bl_\be option that
-                       match the env_keep and env_check lists are then added,
+                       SHELL, LOGNAME, USER and SUDO_* variables.  Any
+                       variables in the caller's environment or in the file
+                       specified by the _\br_\be_\bs_\bt_\br_\bi_\bc_\bt_\be_\bd_\b__\be_\bn_\bv_\b__\bf_\bi_\bl_\be option that match
+                       the env_keep and env_check lists are then added,
                        followed by any variables present in the file specified
                        by the _\be_\bn_\bv_\b__\bf_\bi_\bl_\be option (if any).  The contents of the
                        env_keep and env_check lists, as modified by global
@@ -1382,7 +1380,7 @@ S\bSU\bUD\bDO\bOE\bER\bRS\bS O\bOP\bPT\bTI\bIO\bON\bNS\bS
                        disabled or HOME is present in the _\be_\bn_\bv_\b__\bk_\be_\be_\bp list.  This
                        flag is _\bo_\bf_\bf by default.
 
-     set_logname       Normally, s\bsu\bud\bdo\bo will set the LOGNAME, USER and USERNAME
+     set_logname       Normally, s\bsu\bud\bdo\bo will set the LOGNAME and USER
                        environment variables to the name of the target user
                        (usually root unless the -\b-u\bu option is given).  However,
                        since some programs (including the RCS revision control
@@ -1391,8 +1389,8 @@ S\bSU\bUD\bDO\bOE\bER\bRS\bS O\bOP\bPT\bTI\bIO\bON\bNS\bS
                        This can be done by negating the set_logname option.
                        Note that _\bs_\be_\bt_\b__\bl_\bo_\bg_\bn_\ba_\bm_\be will have no effect if the
                        _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt option has not been disabled and the _\be_\bn_\bv_\b__\bk_\be_\be_\bp
-                       list contains LOGNAME, USER or USERNAME.  This flag is
-                       _\bo_\bn by default.
+                       list contains LOGNAME or USER.  This flag is _\bo_\bn by
+                       default.
 
      set_utmp          When enabled, s\bsu\bud\bdo\bo will create an entry in the utmp (or
                        utmpx) file when a pseudo-tty is allocated.  A pseudo-
@@ -2506,7 +2504,7 @@ E\bEX\bXA\bAM\bMP\bPL\bLE\bES\bS
      Here we override some of the compiled in default values.  We want s\bsu\bud\bdo\bo to
      log via syslog(3) using the _\ba_\bu_\bt_\bh facility in all cases.  We don't want to
      subject the full time staff to the s\bsu\bud\bdo\bo lecture, user m\bmi\bil\bll\ble\ber\brt\bt need not
-     give a password, and we don't want to reset the LOGNAME, USER or USERNAME
+     give a password, and we don't want to reset the LOGNAME or USER
      environment variables when running commands as root.  Additionally, on
      the machines in the _\bS_\bE_\bR_\bV_\bE_\bR_\bS Host_Alias, we keep an additional local log
      file and make sure we log the year in each log line since the log entries
@@ -2927,4 +2925,4 @@ D\bDI\bIS\bSC\bCL\bLA\bAI\bIM\bME\bER\bR
      file distributed with s\bsu\bud\bdo\bo or https://www.sudo.ws/license.html for
      complete details.
 
-Sudo 1.8.25                     August 7, 2018                     Sudo 1.8.25
+Sudo 1.8.26                     August 7, 2018                     Sudo 1.8.26
index bc2061215443511eb37c1771f954171386c546a7..c9f75eba43ef37bc7c2e4938f963545902b76cd3 100644 (file)
@@ -309,8 +309,7 @@ The new environment contains the
 \fRMAIL\fR,
 \fRSHELL\fR,
 \fRLOGNAME\fR,
-\fRUSER\fR,
-\fRUSERNAME\fR
+\fRUSER\fR
 and
 \fRSUDO_*\fR
 variables
@@ -322,17 +321,14 @@ options.
 This is effectively a whitelist
 for environment variables.
 The environment variables
-\fRLOGNAME\fR,
-\fRUSER\fR
+\fRLOGNAME\fR
 and
-\fRUSERNAME\fR
+\fRUSER\fR
 are treated specially.
-If one or more variables are preserved from the invoking process,
-any of the three remaining variables (that were not explicitly
-preserved) will be set to the same value as the first one in the
-list that was preserved.
-This avoids an inconsistent environment where some of the variables
-describing the user name are set to the invoking user and some are
+If only one of them is preserved from user's environment, the other
+will be set to the same value.
+This avoids an inconsistent environment where one of the variables
+describing the user name is set to the invoking user and one is
 set to the target user.
 \fR()\fR
 are removed unless both the name and value parts are matched by
@@ -2217,8 +2213,7 @@ will run the command in a minimal environment containing the
 \fRMAIL\fR,
 \fRSHELL\fR,
 \fRLOGNAME\fR,
-\fRUSER\fR,
-\fRUSERNAME\fR
+\fRUSER\fR
 and
 \fRSUDO_*\fR
 variables.
@@ -2884,10 +2879,9 @@ set_logname
 Normally,
 \fBsudo\fR
 will set the
-\fRLOGNAME\fR,
-\fRUSER\fR
+\fRLOGNAME\fR
 and
-\fRUSERNAME\fR
+\fRUSER\fR
 environment variables to the name of the target user (usually root unless the
 \fB\-u\fR
 option is given).
@@ -2904,10 +2898,9 @@ if the
 option has not been disabled and the
 \fIenv_keep\fR
 list contains
-\fRLOGNAME\fR,
-\fRUSER\fR
+\fRLOGNAME\fR
 or
-\fRUSERNAME\fR.
+\fRUSER\fR.
 This flag is
 \fIon\fR
 by default.
@@ -4899,10 +4892,9 @@ We don't want to subject the full time staff to the
 lecture, user
 \fBmillert\fR
 need not give a password, and we don't want to reset the
-\fRLOGNAME\fR,
-\fRUSER\fR
+\fRLOGNAME\fR
 or
-\fRUSERNAME\fR
+\fRUSER\fR
 environment variables when running commands as root.
 Additionally, on the machines in the
 \fISERVERS\fR
index 7f568413765ca6827d830acd29525a7f6f48202c..d9214ae4838c23ff2061ab8f8605cbe9adc86082 100644 (file)
@@ -299,8 +299,7 @@ The new environment contains the
 .Ev MAIL ,
 .Ev SHELL ,
 .Ev LOGNAME ,
-.Ev USER ,
-.Ev USERNAME
+.Ev USER
 and
 .Ev SUDO_*
 variables
@@ -312,17 +311,14 @@ options.
 This is effectively a whitelist
 for environment variables.
 The environment variables
-.Ev LOGNAME ,
-.Ev USER
+.Ev LOGNAME
 and
-.Ev USERNAME
+.Ev USER
 are treated specially.
-If one or more variables are preserved from the invoking process,
-any of the three remaining variables (that were not explicitly
-preserved) will be set to the same value as the first one in the
-list that was preserved.
-This avoids an inconsistent environment where some of the variables
-describing the user name are set to the invoking user and some are
+If only one of them is preserved from user's environment, the other
+will be set to the same value.
+This avoids an inconsistent environment where one of the variables
+describing the user name is set to the invoking user and one is
 set to the target user.
 .Li ()
 are removed unless both the name and value parts are matched by
@@ -2081,8 +2077,7 @@ will run the command in a minimal environment containing the
 .Ev MAIL ,
 .Ev SHELL ,
 .Ev LOGNAME ,
-.Ev USER ,
-.Ev USERNAME
+.Ev USER
 and
 .Ev SUDO_*
 variables.
@@ -2711,10 +2706,9 @@ by default.
 Normally,
 .Nm sudo
 will set the
-.Ev LOGNAME ,
-.Ev USER
+.Ev LOGNAME
 and
-.Ev USERNAME
+.Ev USER
 environment variables to the name of the target user (usually root unless the
 .Fl u
 option is given).
@@ -2731,10 +2725,9 @@ if the
 option has not been disabled and the
 .Em env_keep
 list contains
-.Ev LOGNAME ,
-.Ev USER
+.Ev LOGNAME
 or
-.Ev USERNAME .
+.Ev USER .
 This flag is
 .Em on
 by default.
@@ -4560,10 +4553,9 @@ We don't want to subject the full time staff to the
 lecture, user
 .Sy millert
 need not give a password, and we don't want to reset the
-.Ev LOGNAME ,
-.Ev USER
+.Ev LOGNAME
 or
-.Ev USERNAME
+.Ev USER
 environment variables when running commands as root.
 Additionally, on the machines in the
 .Em SERVERS
index 9112ef51e71cda70534aa1bdbd1170c7d757d8ed..f2a3b274f7fe580822b9ed6f35f0f4ef41597ab0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2005, 2007-2016
+ * Copyright (c) 2000-2005, 2007-2018
  *     Todd C. Miller <Todd.Miller@sudo.ws>
  *
  * Permission to use, copy, modify, and distribute this software for any
 #define DID_LOGNAME    0x00000010
 #undef DID_USER
 #define DID_USER       0x00000020
-#undef DID_USERNAME
-#define DID_USERNAME           0x00000040
 #undef DID_LOGIN
-#define DID_LOGIN      0x00000080
+#define DID_LOGIN      0x00000040
 #undef DID_MAIL
-#define DID_MAIL       0x00000100
+#define DID_MAIL       0x00000080
 #undef DID_MAX
 #define DID_MAX        0x0000ffff
 
 #define KEPT_LOGNAME   0x00100000
 #undef KEPT_USER
 #define KEPT_USER      0x00200000
-#undef KEPT_USERNAME
-#define KEPT_USERNAME  0x00400000
 #undef KEPT_LOGIN
-#define KEPT_LOGIN     0x00800000
+#define KEPT_LOGIN     0x00400000
 #undef KEPT_MAIL
-#define KEPT_MAIL      0x01000000
+#define KEPT_MAIL      0x00800000
 #undef KEPT_MAX
 #define KEPT_MAX       0xffff0000
 
@@ -99,9 +95,9 @@
  * AIX sets the LOGIN environment variable too.
  */
 #ifdef _AIX
-# define KEPT_USER_VARIABLES (KEPT_LOGIN|KEPT_LOGNAME|KEPT_USER|KEPT_USERNAME)
+# define KEPT_USER_VARIABLES (KEPT_LOGIN|KEPT_LOGNAME|KEPT_USER)
 #else
-# define KEPT_USER_VARIABLES (KEPT_LOGNAME|KEPT_USER|KEPT_USERNAME)
+# define KEPT_USER_VARIABLES (KEPT_LOGNAME|KEPT_USER)
 #endif
 
 struct environment {
@@ -807,8 +803,6 @@ env_update_didvar(const char *ep, unsigned int *didvar)
        case 'U':
            if (strncmp(ep, "USER=", 5) == 0)
                SET(*didvar, DID_USER);
-           if (strncmp(ep, "USERNAME=", 9) == 0)
-               SET(*didvar, DID_USERNAME);
            break;
     }
 }
@@ -935,8 +929,6 @@ rebuild_env(void)
                ISSET(didvar, DID_LOGNAME), true);
            CHECK_SETENV2("USER", runas_pw->pw_name,
                ISSET(didvar, DID_USER), true);
-           CHECK_SETENV2("USERNAME", runas_pw->pw_name,
-               ISSET(didvar, DID_USERNAME), true);
        } else {
            /* We will set LOGNAME later in the def_set_logname case. */
            if (!def_set_logname) {
@@ -948,8 +940,6 @@ rebuild_env(void)
                    CHECK_SETENV2("LOGNAME", user_name, false, true);
                if (!ISSET(didvar, DID_USER))
                    CHECK_SETENV2("USER", user_name, false, true);
-               if (!ISSET(didvar, DID_USERNAME))
-                   CHECK_SETENV2("USERNAME", user_name, false, true);
            }
        }
 
@@ -1002,7 +992,7 @@ rebuild_env(void)
     }
 
     /*
-     * Set LOGIN, LOGNAME, USER and USERNAME to target if "set_logname" is not
+     * Set LOGIN, LOGNAME, and USER to target if "set_logname" is not
      * disabled.  We skip this if we are running a login shell (because
      * they have already been set).
      */
@@ -1014,10 +1004,9 @@ rebuild_env(void)
 #endif
            CHECK_SETENV2("LOGNAME", runas_pw->pw_name, true, true);
            CHECK_SETENV2("USER", runas_pw->pw_name, true, true);
-           CHECK_SETENV2("USERNAME", runas_pw->pw_name, true, true);
        } else if ((didvar & KEPT_USER_VARIABLES) != KEPT_USER_VARIABLES) {
            /*
-            * Preserved some of LOGIN, LOGNAME, USER, USERNAME but not all.
+            * Preserved some of LOGIN, LOGNAME, USER but not all.
             * Make the unset ones match so we don't end up with some
             * set to the invoking user and others set to the runas user.
             */
@@ -1029,8 +1018,6 @@ rebuild_env(void)
 #endif
            else if (ISSET(didvar, KEPT_USER))
                cp = sudo_getenv("USER");
-           else if (ISSET(didvar, KEPT_USERNAME))
-               cp = sudo_getenv("USERNAME");
            else
                cp = NULL;
            if (cp != NULL) {
@@ -1042,8 +1029,6 @@ rebuild_env(void)
                    CHECK_SETENV2("LOGNAME", cp, true, true);
                if (!ISSET(didvar, KEPT_USER))
                    CHECK_SETENV2("USER", cp, true, true);
-               if (!ISSET(didvar, KEPT_USERNAME))
-                   CHECK_SETENV2("USERNAME", cp, true, true);
            }
        }
     }
index ef62736a59bafbe316b7d5cfd5e35d63c4563f94..f16a546cea5625a509091df9a6b402f91486d6f6 100644 (file)
@@ -637,8 +637,10 @@ send_mail(const char *fmt, ...)
        "HOME=/",
        "PATH=/usr/bin:/bin:/usr/sbin:/sbin",
        "LOGNAME=root",
-       "USERNAME=root",
        "USER=root",
+# ifdef _AIX
+       "LOGIN=root",
+# endif
        NULL
     };
 #endif /* NO_ROOT_MAILER */
index 876196520473a11492f3728fe3d9e1c6f8bd429d..596f5a184523d06a801ec7ed653e4a2a5f9f7540 100755 (executable)
@@ -13,7 +13,7 @@ Defaults!PAGERS               noexec
 
 Defaults               env_keep -= "HOME"
 Defaults               env_keep =  "COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS"
-Defaults               env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
+Defaults               env_keep += "MAIL PS1 PS2 QTDIR LANG LC_ADDRESS LC_CTYPE"
 
 User_Alias             FULLTIMERS = millert, mikef, dowdy