]> granicus.if.org Git - sudo/commitdiff
Treat USERNAME environemnt variable like LOGNAME/USER
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 18 Jun 2007 21:23:48 +0000 (21:23 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 18 Jun 2007 21:23:48 +0000 (21:23 +0000)
env.c
logging.c

diff --git a/env.c b/env.c
index 885d0054e929d24569de66679d652683480b2c07..ab9391457d9b8b042fb50cd74881fd552b8caf06 100644 (file)
--- a/env.c
+++ b/env.c
@@ -65,6 +65,8 @@ __unused static const char rcsid[] = "$Sudo$";
 #define DID_LOGNAME    0x0010
 #undef DID_USER
 #define DID_USER       0x0020
+#undef DID_USERNAME
+#define DID_USERNAME           0x0040
 #undef DID_MAX
 #define DID_MAX        0x00ff
 
@@ -80,6 +82,8 @@ __unused static const char rcsid[] = "$Sudo$";
 #define KEPT_LOGNAME   0x1000
 #undef KEPT_USER
 #define KEPT_USER      0x2000
+#undef KEPT_USERNAME
+#define KEPT_USERNAME  0x4000
 #undef KEPT_MAX
 #define KEPT_MAX       0xff00
 
@@ -372,6 +376,8 @@ rebuild_env(envp, sudo_mode, noexec)
                    case 'U':
                        if (strncmp(*ep, "USER=", 5) == 0)
                            SET(didvar, DID_USER);
+                       if (strncmp(*ep, "USERNAME=", 5) == 0)
+                           SET(didvar, DID_USERNAME);
                        break;
                }
                insert_env(*ep, &env, 0);
@@ -393,6 +399,8 @@ rebuild_env(envp, sudo_mode, noexec)
                ISSET(didvar, DID_LOGNAME));
            insert_env(format_env("USER", runas_pw->pw_name, VNULL), &env,
                ISSET(didvar, DID_USER));
+           insert_env(format_env("USERNAME", runas_pw->pw_name, VNULL), &env,
+               ISSET(didvar, DID_USERNAME));
        } else {
            if (!ISSET(didvar, DID_HOME))
                insert_env(format_env("HOME", user_dir, VNULL), &env, 0);
@@ -403,6 +411,8 @@ rebuild_env(envp, sudo_mode, noexec)
                insert_env(format_env("LOGNAME", user_name, VNULL), &env, 0);
            if (!ISSET(didvar, DID_USER))
                insert_env(format_env("USER", user_name, VNULL), &env, 0);
+           if (!ISSET(didvar, DID_USERNAME))
+               insert_env(format_env("USERNAME", user_name, VNULL), &env, 0);
        }
     } else {
        /*
@@ -466,12 +476,14 @@ rebuild_env(envp, sudo_mode, noexec)
        SET(didvar, DID_PATH);
     }
 
-    /* Set $USER and $LOGNAME to target if "set_logname" is true. */
+    /* Set $USER, $LOGNAME and $USERNAME to target if "set_logname" is true. */
     if (def_set_logname && runas_pw->pw_name) {
        if (!ISSET(didvar, KEPT_LOGNAME))
            insert_env(format_env("LOGNAME", runas_pw->pw_name, VNULL), &env, 1);
        if (!ISSET(didvar, KEPT_USER))
            insert_env(format_env("USER", runas_pw->pw_name, VNULL), &env, 1);
+       if (!ISSET(didvar, KEPT_USERNAME))
+           insert_env(format_env("USERNAME", runas_pw->pw_name, VNULL), &env, 1);
     }
 
     /* Set $HOME for `sudo -H'.  Only valid at PERM_FULL_RUNAS. */
index 07c83d37251758ad5757e122eb40ea6ce152efdb..29514c98af9dc9d3807b8bb9a8f5c28f45d7018f 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -436,6 +436,7 @@ send_mail(line)
        "HOME=/",
        "PATH=/usr/bin:/bin",
        "LOGNAME=root",
+       "USERNAME=root",
        "USER=root",
        NULL
     };