]> granicus.if.org Git - sudo/commitdiff
Treat LOGIN, LOGNAME and USER specially. If one is preserved
authorTodd C. Miller <Todd.Miller@sudo.ws>
Mon, 24 Sep 2018 11:30:28 +0000 (05:30 -0600)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Mon, 24 Sep 2018 11:30:28 +0000 (05:30 -0600)
or deleted we want to preserve or delete all of them.

doc/sudoers.cat
doc/sudoers.man.in
doc/sudoers.mdoc.in
plugins/sudoers/env.c

index b2c9327e673bbd737f3e7851bd21488ea07cb172..eb11d148506466be569bf76166db2477bc57ac7b 100644 (file)
@@ -130,7 +130,9 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      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
+     specially.  If one of them is preserved (or removed) from user's
+     environment, the other will be as well.  If LOGNAME and USER are to be
+     preserved but only one of them is present in the 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
@@ -2925,4 +2927,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.26                     August 7, 2018                     Sudo 1.8.26
+Sudo 1.8.26                   September 24, 2018                   Sudo 1.8.26
index c9f75eba43ef37bc7c2e4938f963545902b76cd3..ca37eb3348c62cbf5c1f835ed180dc5b75bd90ef 100644 (file)
@@ -20,7 +20,7 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.TH "SUDOERS" "5" "August 7, 2018" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
+.TH "SUDOERS" "5" "September 24, 2018" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
 .nh
 .if n .ad l
 .SH "NAME"
@@ -325,8 +325,14 @@ The environment variables
 and
 \fRUSER\fR
 are treated specially.
-If only one of them is preserved from user's environment, the other
-will be set to the same value.
+If one of them is preserved (or removed) from user's environment, the other
+will be as well.
+If
+\fRLOGNAME\fR
+and
+\fRUSER\fR
+are to be preserved but only one of them is present in the 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.
index d9214ae4838c23ff2061ab8f8605cbe9adc86082..c7e3fb0d269348ce83203cbacf2465f3ae4b3079 100644 (file)
@@ -19,7 +19,7 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.Dd August 7, 2018
+.Dd September 24, 2018
 .Dt SUDOERS @mansectform@
 .Os Sudo @PACKAGE_VERSION@
 .Sh NAME
@@ -315,8 +315,14 @@ The environment variables
 and
 .Ev USER
 are treated specially.
-If only one of them is preserved from user's environment, the other
-will be set to the same value.
+If one of them is preserved (or removed) from user's environment, the other
+will be as well.
+If
+.Ev LOGNAME
+and
+.Ev USER
+are to be preserved but only one of them is present in the 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.
index f2a3b274f7fe580822b9ed6f35f0f4ef41597ab0..b708761b40396ffdb3915db4893ceb2ecc6631bb 100644 (file)
@@ -578,11 +578,42 @@ static bool
 matches_env_list(const char *var, struct list_members *list, bool *full_match)
 {
     struct list_member *cur;
+    bool is_logname = false;
     debug_decl(matches_env_list, SUDOERS_DEBUG_ENV)
 
-    SLIST_FOREACH(cur, list, entries) {
-       if (matches_env_pattern(cur->value, var, full_match))
-           debug_return_bool(true);
+    switch (*var) {
+    case 'L':
+       if (strncmp(var, "LOGNAME=", 8) == 0)
+           is_logname = true;
+#ifdef _AIX
+       else if (strncmp(var, "LOGIN=", 6) == 0)
+           is_logname = true;
+#endif
+       break;
+    case 'U':
+       if (strncmp(var, "USER=", 5) == 0)
+           is_logname = true;
+       break;
+    }
+
+    if (is_logname) {
+       /*
+        * We treat LOGIN, LOGNAME and USER specially.
+        * If one is preserved/deleted we want to preserve/delete them all.
+        */
+       SLIST_FOREACH(cur, list, entries) {
+           if (matches_env_pattern(cur->value, "LOGNAME", full_match) ||
+#ifdef _AIX
+               matches_env_pattern(cur->value, "LOGIN", full_match) ||
+#endif
+               matches_env_pattern(cur->value, "USER", full_match))
+               debug_return_bool(true);
+       }
+    } else {
+       SLIST_FOREACH(cur, list, entries) {
+           if (matches_env_pattern(cur->value, var, full_match))
+               debug_return_bool(true);
+       }
     }
     debug_return_bool(false);
 }