Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -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::*};

Expand Down Expand Up @@ -105,7 +105,7 @@ impl<'a, C: conv::Conversation> Client<'a, C> {
pub fn get_user(&mut self) -> PamResult<String> {
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)),
Expand Down Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down