Skip to content
Snippets Groups Projects
Verified Commit 2327a57f authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

[PAM] Resolve authenticating user using getpwnam outside the UserInfo struct

Necessary because in order t oresolve the home directory to store the access token,
the try_resolve method would have to be called, which can not resolve using
getpwnam while the PAM module holds the lock to the structure.
parent e3ad91e2
No related branches found
No related tags found
No related merge requests found
......@@ -182,6 +182,13 @@ impl UserInfo {
};
}
/// Set the full passwd struct from outside
pub fn set_passwd(&mut self, passwd: Passwd) {
self.passwd = Some(passwd.clone());
self.username = Some(passwd.pw_name);
self.uid = Some(passwd.pw_uid);
}
/// Return the home directory from the passwd slot,
/// attempting NSS resolution before doing so
pub fn get_home_directory(&mut self) -> Result<String, io::Error> {
......
......@@ -26,6 +26,8 @@ use crate::logging::setup_log;
use crate::cache::{get_context_user, set_is_getpwnam_safe};
use crate::unix::getpwnam_safe;
use pamsm::{PamServiceModule, Pam, PamFlag, PamError, PamLibExt};
fn pam_sm_prepare(argv: &Vec<String>) -> Config {
......@@ -91,7 +93,10 @@ impl PamServiceModule for PamOidc {
Ok(t) => {
info!("Authenticated {} using Resource Owner Password Grant", username);
set_is_getpwnam_safe(false);
get_context_user().set_username(username.to_string());
let passwd = getpwnam_safe(username.to_string());
if passwd.is_ok() {
get_context_user().set_passwd(passwd.unwrap());
}
get_context_user().set_access_token(t);
set_is_getpwnam_safe(true);
return PamError::SUCCESS;
......
......@@ -20,6 +20,7 @@ use std::io;
use std::mem::uninitialized;
use std::ptr::null_mut;
#[derive(Clone)]
pub struct Passwd {
pub pw_name: String,
pub pw_passwd: String,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment