From: msweet Date: Mon, 9 Jun 2014 18:57:44 +0000 (+0000) Subject: The User directive in client.conf did not override the USER environment variable X-Git-Tag: v2.2b1~618 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=93e3d3f5aa301250fbc50cea1490c77eb58397ab;p=thirdparty%2Fcups.git The User directive in client.conf did not override the USER environment variable (STR #4426) git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11908 a1ca3aef-8c08-0410-bb20-df032aa958be --- diff --git a/CHANGES-1.7.txt b/CHANGES-1.7.txt index 11663b9d2..da982ef0e 100644 --- a/CHANGES-1.7.txt +++ b/CHANGES-1.7.txt @@ -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 diff --git a/cups/usersys.c b/cups/usersys.c index 22d0f3464..b6ef93e4d 100644 --- a/cups/usersys.c +++ b/cups/usersys.c @@ -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 */ {