config: Add general.source_profile
This adds a system-wide toggle for whether the system profile should be sourced by /bin/sh before running the command. Note that the command will still be run with /bin/sh, regardless of profile sourcing. The option defaults to true for now. Example usage: [general] source_profile = false
This commit is contained in:
@@ -35,9 +35,15 @@ pub struct ConfigTerminal {
|
|||||||
pub vt: VtSelection,
|
pub vt: VtSelection,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Default)]
|
||||||
|
pub struct ConfigGeneral {
|
||||||
|
pub source_profile: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Default)]
|
#[derive(Debug, Eq, PartialEq, Default)]
|
||||||
pub struct ConfigFile {
|
pub struct ConfigFile {
|
||||||
pub terminal: ConfigTerminal,
|
pub terminal: ConfigTerminal,
|
||||||
|
pub general: ConfigGeneral,
|
||||||
pub default_session: ConfigSession,
|
pub default_session: ConfigSession,
|
||||||
pub initial_session: Option<ConfigSession>,
|
pub initial_session: Option<ConfigSession>,
|
||||||
}
|
}
|
||||||
@@ -91,6 +97,9 @@ fn parse_old_config(config: &HashMap<&str, HashMap<&str, &str>>) -> Result<Confi
|
|||||||
user: greeter_user,
|
user: greeter_user,
|
||||||
command: greeter,
|
command: greeter,
|
||||||
},
|
},
|
||||||
|
general: ConfigGeneral {
|
||||||
|
source_profile: true,
|
||||||
|
},
|
||||||
initial_session: None,
|
initial_session: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -150,9 +159,23 @@ fn parse_new_config(config: &HashMap<&str, HashMap<&str, &str>>) -> Result<Confi
|
|||||||
None => Err("no terminal specified"),
|
None => Err("no terminal specified"),
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
|
let general = match config.get("general") {
|
||||||
|
Some(section) => ConfigGeneral {
|
||||||
|
source_profile: section
|
||||||
|
.get("source_profile")
|
||||||
|
.unwrap_or(&"true")
|
||||||
|
.parse()
|
||||||
|
.map_err(|e| format!("could not parse source_profile: {}", e))?,
|
||||||
|
},
|
||||||
|
None => ConfigGeneral {
|
||||||
|
source_profile: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
Ok(ConfigFile {
|
Ok(ConfigFile {
|
||||||
initial_session,
|
initial_session,
|
||||||
default_session,
|
default_session,
|
||||||
|
general,
|
||||||
terminal,
|
terminal,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -40,6 +40,7 @@ pub struct Context {
|
|||||||
greeter_service: String,
|
greeter_service: String,
|
||||||
pam_service: String,
|
pam_service: String,
|
||||||
term_mode: TerminalMode,
|
term_mode: TerminalMode,
|
||||||
|
source_profile: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
@@ -49,6 +50,7 @@ impl Context {
|
|||||||
greeter_service: String,
|
greeter_service: String,
|
||||||
pam_service: String,
|
pam_service: String,
|
||||||
term_mode: TerminalMode,
|
term_mode: TerminalMode,
|
||||||
|
source_profile: bool,
|
||||||
) -> Context {
|
) -> Context {
|
||||||
Context {
|
Context {
|
||||||
inner: RwLock::new(ContextInner {
|
inner: RwLock::new(ContextInner {
|
||||||
@@ -61,6 +63,7 @@ impl Context {
|
|||||||
greeter_service,
|
greeter_service,
|
||||||
pam_service,
|
pam_service,
|
||||||
term_mode,
|
term_mode,
|
||||||
|
source_profile,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +79,14 @@ impl Context {
|
|||||||
) -> Result<SessionChild, Error> {
|
) -> Result<SessionChild, Error> {
|
||||||
let mut scheduled_session = Session::new_external()?;
|
let mut scheduled_session = Session::new_external()?;
|
||||||
scheduled_session
|
scheduled_session
|
||||||
.initiate(&service, class, user, false, &self.term_mode)
|
.initiate(
|
||||||
|
&service,
|
||||||
|
class,
|
||||||
|
user,
|
||||||
|
false,
|
||||||
|
&self.term_mode,
|
||||||
|
self.source_profile,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
loop {
|
loop {
|
||||||
match scheduled_session.get_state().await {
|
match scheduled_session.get_state().await {
|
||||||
@@ -162,7 +172,14 @@ impl Context {
|
|||||||
};
|
};
|
||||||
session_set
|
session_set
|
||||||
.session
|
.session
|
||||||
.initiate(&self.pam_service, "user", &username, true, &self.term_mode)
|
.initiate(
|
||||||
|
&self.pam_service,
|
||||||
|
"user",
|
||||||
|
&username,
|
||||||
|
true,
|
||||||
|
&self.term_mode,
|
||||||
|
self.source_profile,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut session = Some(session_set);
|
let mut session = Some(session_set);
|
||||||
|
@@ -221,6 +221,7 @@ pub async fn main(config: Config) -> Result<(), Error> {
|
|||||||
greeter_service.to_string(),
|
greeter_service.to_string(),
|
||||||
service.to_string(),
|
service.to_string(),
|
||||||
term_mode.clone(),
|
term_mode.clone(),
|
||||||
|
config.file.general.source_profile,
|
||||||
));
|
));
|
||||||
|
|
||||||
if let Some(s) = config.file.initial_session {
|
if let Some(s) = config.file.initial_session {
|
||||||
|
@@ -137,6 +137,7 @@ impl Session {
|
|||||||
user: &str,
|
user: &str,
|
||||||
authenticate: bool,
|
authenticate: bool,
|
||||||
term_mode: &TerminalMode,
|
term_mode: &TerminalMode,
|
||||||
|
source_profile: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let msg = ParentToSessionChild::InitiateLogin {
|
let msg = ParentToSessionChild::InitiateLogin {
|
||||||
service: service.to_string(),
|
service: service.to_string(),
|
||||||
@@ -144,6 +145,7 @@ impl Session {
|
|||||||
user: user.to_string(),
|
user: user.to_string(),
|
||||||
authenticate,
|
authenticate,
|
||||||
tty: term_mode.clone(),
|
tty: term_mode.clone(),
|
||||||
|
source_profile,
|
||||||
};
|
};
|
||||||
msg.send(&mut self.sock).await?;
|
msg.send(&mut self.sock).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@@ -40,6 +40,7 @@ pub enum ParentToSessionChild {
|
|||||||
user: String,
|
user: String,
|
||||||
authenticate: bool,
|
authenticate: bool,
|
||||||
tty: TerminalMode,
|
tty: TerminalMode,
|
||||||
|
source_profile: bool,
|
||||||
},
|
},
|
||||||
PamResponse {
|
PamResponse {
|
||||||
resp: Option<String>,
|
resp: Option<String>,
|
||||||
@@ -80,17 +81,19 @@ impl SessionChildToParent {
|
|||||||
/// responsible for the entirety of the session setup and execution. It is
|
/// responsible for the entirety of the session setup and execution. It is
|
||||||
/// started by Session::start.
|
/// started by Session::start.
|
||||||
fn worker(sock: &UnixDatagram) -> Result<(), Error> {
|
fn worker(sock: &UnixDatagram) -> Result<(), Error> {
|
||||||
let (service, class, user, authenticate, tty) = match ParentToSessionChild::recv(sock)? {
|
let (service, class, user, authenticate, tty, source_profile) =
|
||||||
ParentToSessionChild::InitiateLogin {
|
match ParentToSessionChild::recv(sock)? {
|
||||||
service,
|
ParentToSessionChild::InitiateLogin {
|
||||||
class,
|
service,
|
||||||
user,
|
class,
|
||||||
authenticate,
|
user,
|
||||||
tty,
|
authenticate,
|
||||||
} => (service, class, user, authenticate, tty),
|
tty,
|
||||||
ParentToSessionChild::Cancel => return Err("cancelled".into()),
|
source_profile,
|
||||||
msg => return Err(format!("expected InitiateLogin or Cancel, got: {:?}", msg).into()),
|
} => (service, class, user, authenticate, tty, source_profile),
|
||||||
};
|
ParentToSessionChild::Cancel => return Err("cancelled".into()),
|
||||||
|
msg => return Err(format!("expected InitiateLogin or Cancel, got: {:?}", msg).into()),
|
||||||
|
};
|
||||||
|
|
||||||
let conv = Box::pin(SessionConv::new(sock));
|
let conv = Box::pin(SessionConv::new(sock));
|
||||||
let mut pam = PamSession::start(&service, &user, conv)?;
|
let mut pam = PamSession::start(&service, &user, conv)?;
|
||||||
@@ -206,10 +209,14 @@ fn worker(sock: &UnixDatagram) -> Result<(), Error> {
|
|||||||
|
|
||||||
// Prepare some strings in C format that we'll need.
|
// Prepare some strings in C format that we'll need.
|
||||||
let cusername = CString::new(username)?;
|
let cusername = CString::new(username)?;
|
||||||
let command = format!(
|
let command = if source_profile {
|
||||||
"[ -f /etc/profile ] && . /etc/profile; [ -f $HOME/.profile ] && . $HOME/.profile; exec {}",
|
format!(
|
||||||
cmd.join(" ")
|
"[ -f /etc/profile ] && . /etc/profile; [ -f $HOME/.profile ] && . $HOME/.profile; exec {}",
|
||||||
);
|
cmd.join(" ")
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
format!("exec {}", cmd.join(" "))
|
||||||
|
};
|
||||||
|
|
||||||
// Extract PAM environment for use with execve below.
|
// Extract PAM environment for use with execve below.
|
||||||
let pamenvlist = pam.getenvlist()?;
|
let pamenvlist = pam.getenvlist()?;
|
||||||
|
Reference in New Issue
Block a user