diff --git a/src/client.rs b/src/client.rs index 237bac9..781988d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,5 +1,5 @@ //! Authentication related structure and functions -use std::{env, ffi::CStr}; +use std::{env, ffi::CStr, os::raw::c_char}; use crate::{conv, enums::*, functions::*, types::*}; @@ -105,7 +105,7 @@ impl<'a, C: conv::Conversation> Client<'a, C> { pub fn get_user(&mut self) -> PamResult { get_item(self.handle, PamItemType::User).and_then(|result| { // Pam user is a char * - let ptr: *const i8 = unsafe { std::mem::transmute(result) }; + let ptr: *const c_char = unsafe { std::mem::transmute(result) }; let username = unsafe { CStr::from_ptr(ptr) }; match username.to_str() { Err(_) => Err(PamError(PamReturnCode::System_Err)), @@ -142,6 +142,16 @@ impl<'a, C: conv::Conversation> Client<'a, C> { self.initialize_environment() } + /// Retreive environement variable set by pam + pub fn get_env_list(&mut self) -> Vec<(String, String)> { + let pam_env = getenvlist(self.handle); + let mut env = vec![]; + for (name, value) in pam_env { + env.push((name, value)); + } + env + } + // Initialize the client environment with common variables. // Currently always called from Client.open_session() fn initialize_environment(&mut self) -> PamResult<()> { @@ -172,6 +182,11 @@ impl<'a, C: conv::Conversation> Client<'a, C> { self.set_env("SHELL", user.shell().to_str().unwrap())?; // Note: We don't set PATH here, as this should be the job of `pam_env.so` + // Set env variable returned by pam module + for (name, value) in self.get_env_list() { + self.set_env(&name, &value)?; + } + Ok(()) } diff --git a/src/env.rs b/src/env.rs index d72b2fd..b34751e 100644 --- a/src/env.rs +++ b/src/env.rs @@ -51,7 +51,7 @@ fn parse_env_line(input: &[u8]) -> Option<(OsString, OsString)> { if input.is_empty() { return None; } - let pos = memchr(b'=', input).map(|p| p + 1); + let pos = memchr(b'=', input); pos.map(|p| { ( OsStringExt::from_vec(input[..p].to_vec()),