]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
The User directive in client.conf did not override the USER environment variable
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Mon, 9 Jun 2014 18:57:44 +0000 (18:57 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Mon, 9 Jun 2014 18:57:44 +0000 (18:57 +0000)
(STR #4426)

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11908 a1ca3aef-8c08-0410-bb20-df032aa958be

CHANGES-1.7.txt
cups/usersys.c

index 11663b9d289bbf56064c8503ed012f257bff8574..da982ef0ee7439dbea13fba437a6ed685b65f0ab 100644 (file)
@@ -6,6 +6,8 @@ CHANGES IN CUPS V1.7.4
        - CUPS did not compile when Avahi or mDNSResponder was not present
          (STR #4402, STR #4424)
        - The "snmp" option did not work with the network backends (STR #4422)
+       - The User directive in client.conf did not override the USER
+         environment variable (STR #4426)
 
 
 CHANGES IN CUPS V1.7.3
index 22d0f3464d6a6c91d25c057e033f6742c9e7fe5c..b6ef93e4dcac813a00559f5c9ac851291a6582ba 100644 (file)
@@ -850,29 +850,9 @@ _cupsSetDefaults(void)
 #endif /* HAVE_GSSAPI */
   cups_anyroot       = getenv("CUPS_ANYROOT");
   cups_expiredcerts   = getenv("CUPS_EXPIREDCERTS");
+  cups_user           = getenv("CUPS_USER");
   cups_validatecerts  = getenv("CUPS_VALIDATECERTS");
 
-  if ((cups_user = getenv("CUPS_USER")) == NULL)
-  {
-   /*
-    * Try the USER environment variable...
-    */
-
-    if ((cups_user = getenv("USER")) != NULL)
-    {
-     /*
-      * Validate USER matches the current UID, otherwise don't allow it to
-      * override things...  This makes sure that printing after doing su or
-      * sudo records the correct username.
-      */
-
-      struct passwd    *pw;            /* Account information */
-
-      if ((pw = getpwnam(cups_user)) == NULL || pw->pw_uid != getuid())
-        cups_user = NULL;
-    }
-  }
-
  /*
   * Then, if needed, read the ~/.cups/client.conf or /etc/cups/client.conf
   * files to get the default values...
@@ -1085,20 +1065,30 @@ cups_read_client_conf(
       if (!GetUserName(cg->user, &size))
 #else
      /*
-      * Get the user name corresponding to the current UID...
+      * Try the USER environment variable as the default username...
       */
 
-      struct passwd    *pwd;           /* User/password entry */
+      const char *envuser = getenv("USER");
+                                       /* Default username */
+      struct passwd    *pw = NULL;     /* Account information */
 
-      setpwent();
-      if ((pwd = getpwuid(getuid())) != NULL)
+      if (envuser)
       {
        /*
-       * Found a match!
+       * Validate USER matches the current UID, otherwise don't allow it to
+       * override things...  This makes sure that printing after doing su or
+       * sudo records the correct username.
        */
 
-       strlcpy(cg->user, pwd->pw_name, sizeof(cg->user));
+       if ((pw = getpwnam(envuser)) != NULL && pw->pw_uid != getuid())
+         pw = NULL;
       }
+
+      if (!pw)
+        pw = getpwuid(getuid());
+
+      if (pw)
+       strlcpy(cg->user, pw->pw_name, sizeof(cg->user));
       else
 #endif /* WIN32 */
       {