* Verify that the current cupsUser() matches the current UID...
*/
- struct passwd *pwd; /* Password information */
+ struct passwd pwd; /* Password information */
+ struct passwd *result; /* Auxiliary pointer */
const char *username; /* Current username */
username = cupsUser();
- if ((pwd = getpwnam(username)) != NULL && pwd->pw_uid == getuid())
+ getpwnam_r(username, &pwd, cg->pw_buf, PW_BUF_SIZE, &result);
+ if (result && pwd.pw_uid == getuid())
{
httpSetAuthString(http, "PeerCred", username);
*cups_statedir, /* CUPS_STATEDIR environment var */
*home, /* HOME environment var */
*localedir; /* LOCALDIR environment var */
+#ifndef _WIN32
+#define PW_BUF_SIZE 16384 /* As per glibc manual page */
+ char pw_buf[PW_BUF_SIZE];
+ /* Big buffer for struct passwd buffers */
+#endif
/* adminutil.c */
time_t cupsd_update; /* Last time we got or set cupsd.conf */
if (!cg->home)
{
- struct passwd *pw; /* User info */
+ struct passwd pw; /* User info */
+ struct passwd *result; /* Auxiliary pointer */
- if ((pw = getpwuid(getuid())) != NULL)
- cg->home = _cupsStrAlloc(pw->pw_dir);
+ getpwuid_r(getuid(), &pw, cg->pw_buf, PW_BUF_SIZE, &result);
+ if (result)
+ cg->home = _cupsStrAlloc(pw.pw_dir);
}
#endif /* _WIN32 */
* Try the USER environment variable as the default username...
*/
- const char *envuser = getenv("USER");
- /* Default username */
- struct passwd *pw = NULL; /* Account information */
+ const char *envuser = getenv("USER"); /* Default username */
+ struct passwd pw; /* Account information */
+ struct passwd *result = NULL; /* Auxiliary pointer */
+ _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
if (envuser)
{
* override things... This makes sure that printing after doing su
* or sudo records the correct username.
*/
-
- if ((pw = getpwnam(envuser)) != NULL && pw->pw_uid != getuid())
- pw = NULL;
+ getpwnam_r(envuser, &pw, cg->pw_buf, PW_BUF_SIZE, &result);
+ if (result && pw.pw_uid != getuid())
+ result = NULL;
}
- if (!pw)
- pw = getpwuid(getuid());
+ if (!result)
+ getpwuid_r(getuid(), &pw, cg->pw_buf, PW_BUF_SIZE, &result);
- if (pw)
- strlcpy(cc->user, pw->pw_name, sizeof(cc->user));
+ if (result)
+ strlcpy(cc->user, pw.pw_name, sizeof(cc->user));
else
#endif /* _WIN32 */
{