Use roken_get_*() instead of getpwuuid()
Using non-reentrant getpwuid() (or getpwnam(), or getspnam()) can be dangerous. We had a report of a login application / PAM that calls those, and Heimdal, by calling them too, clobbered the cached struct passwd used by the login app / PAM.
This commit is contained in:

committed by
Nico Williams

parent
95eb83c424
commit
620862049e
@@ -819,45 +819,25 @@ static char *
|
||||
get_config_file_for_user(void)
|
||||
{
|
||||
char *fn;
|
||||
|
||||
#ifndef _WIN32
|
||||
char *home;
|
||||
int ret;
|
||||
|
||||
fn = secure_getenv("SOFTPKCS11RC");
|
||||
if (fn)
|
||||
fn = strdup(fn);
|
||||
home = secure_getenv("HOME");
|
||||
if (fn == NULL && home == NULL) {
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
if(pw != NULL)
|
||||
home = pw->pw_dir;
|
||||
}
|
||||
if (fn == NULL) {
|
||||
char homebuf[MAX_PATH];
|
||||
const char *home = roken_get_appdatadir(homebuf, sizeof(homebuf));
|
||||
|
||||
if (home) {
|
||||
ret = asprintf(&fn, "%s/.soft-token.rc", home);
|
||||
if (ret == -1)
|
||||
fn = NULL;
|
||||
} else
|
||||
} else {
|
||||
#ifndef WIN32
|
||||
fn = strdup("/etc/soft-token.rc");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#else /* Windows */
|
||||
|
||||
char appdatafolder[MAX_PATH];
|
||||
|
||||
fn = getenv("SOFTPKCS11RC");
|
||||
|
||||
/* Retrieve the roaming AppData folder for the current user. The
|
||||
current user is the user account represented by the current
|
||||
thread token. */
|
||||
|
||||
if (fn == NULL &&
|
||||
SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdatafolder))) {
|
||||
|
||||
asprintf(&fn, "%s\\.soft-token.rc", appdatafolder);
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
Reference in New Issue
Block a user