diff --git a/src/nss.rs b/src/nss.rs index 21fa3b400ef9167858ed39259fb7bfdb0b0ccbc2..e972146443066ade6c507622e23e98fa30c63e51 100644 --- a/src/nss.rs +++ b/src/nss.rs @@ -50,6 +50,13 @@ fn nss_hook_prepare() -> Config { } setup_log(log_level); + // Set the context user to the current user, but only if not already set + // When doing PAM, we might get called back into by libc to do some NSS + // lookup, and we want to keep the PAM login user context in that case + if !get_cache().context_user.is_initialized() { + get_cache().context_user.set_current_user(); + } + return conf; } @@ -59,13 +66,6 @@ impl PasswdHooks for OidcPasswd { fn get_all_entries() -> Response<Vec<Passwd>> { let conf = nss_hook_prepare(); - // Set the context user to the current user, but only if not already set - // When doing PAM, we might get called back into by libc to do some NSS - // lookup, and we want to keep the PAM login user context in that case - if !get_cache().context_user.is_initialized() { - get_cache().context_user.set_current_user(); - } - let mut cache = get_cache(); let user_token_res = cache.context_user.get_access_token(); // FIXME Implement caching of system token @@ -98,10 +98,6 @@ impl PasswdHooks for OidcPasswd { fn get_entry_by_uid(uid: libc::uid_t) -> Response<Passwd> { let conf = nss_hook_prepare(); - if !get_cache().context_user.is_initialized() { - get_cache().context_user.set_current_user(); - } - let mut cache = get_cache(); let user_token_res = cache.context_user.get_access_token(); // FIXME Implement caching of system token @@ -133,9 +129,6 @@ impl PasswdHooks for OidcPasswd { fn get_entry_by_name(name: String) -> Response<Passwd> { let conf = nss_hook_prepare(); - if !get_cache().context_user.is_initialized() { - get_cache().context_user.set_current_user(); - } let mut cache = get_cache(); let user_token_res = cache.context_user.get_access_token();