Add shell_login_flag option in config (#129)

* Add  option in config
* fmt
This commit is contained in:
Gijs Burghoorn 2023-03-03 23:03:31 +01:00 committed by GitHub
parent c64f69ccf8
commit d84deacb2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 37 deletions

2
Cargo.lock generated
View file

@ -113,7 +113,7 @@ dependencies = [
[[package]]
name = "lemurs"
version = "0.4.0"
version = "0.3.1"
dependencies = [
"crossterm 0.22.1",
"env_logger",

View file

@ -44,6 +44,13 @@ tty = 2
# The PAM service that should be used to login
pam_service = "lemurs"
# The type flag that will be appended to the shell that calls the session
# environment. This may depend on your shell. Options:
# - 'none'. Disables calling a login shell
# - 'short'. Produces the `-l` flag. Supported by most shells.
# - 'long'. This produces the `--login` flag and is suited for bash and zsh.
shell_login_flag = "short"
# Focus behaviour of fields when Lemurs is initially started
#
# Possible values:

View file

@ -155,6 +155,8 @@ toml_config_struct! { Config, PartialConfig,
pam_service => String,
shell_login_flag => ShellLoginFlag,
focus_behaviour => FocusBehaviour,
power_controls => PowerControlConfig [PartialPowerControlConfig],
@ -267,6 +269,16 @@ pub enum FocusBehaviour {
Password,
}
#[derive(Debug, Clone, Deserialize)]
pub enum ShellLoginFlag {
#[serde(rename = "none")]
None,
#[serde(rename = "short")]
Short,
#[serde(rename = "long")]
Long,
}
impl Default for Config {
fn default() -> Config {
toml::from_str(include_str!("../extra/config.toml")).unwrap_or_else(|_| {

View file

@ -9,7 +9,7 @@ use std::os::unix::process::CommandExt;
use std::process::{Child, Command, Stdio};
use crate::auth::AuthUserInfo;
use crate::config::Config;
use crate::config::{Config, ShellLoginFlag};
use crate::env_container::EnvironmentContainer;
use crate::post_login::x::setup_x;
@ -160,48 +160,57 @@ impl PostLoginEnvironment {
&self,
user_info: &AuthUserInfo<'_>,
process_env: &mut EnvironmentContainer,
_config: &Config,
config: &Config,
) -> Result<SpawnedEnvironment, EnvironmentStartError> {
let shell_login_flag = match config.shell_login_flag {
ShellLoginFlag::None => None,
ShellLoginFlag::Short => Some("-l"),
ShellLoginFlag::Long => Some("--login"),
};
let mut client = lower_command_permissions_to_user(Command::new(SYSTEM_SHELL), user_info);
if let Some(shell_login_flag) = shell_login_flag {
client.arg(shell_login_flag);
}
client.arg("-c");
match self {
PostLoginEnvironment::X { xinitrc_path } => {
info!("Starting X11 session");
let server =
setup_x(process_env, user_info).map_err(EnvironmentStartError::XSetup)?;
let client =
match lower_command_permissions_to_user(Command::new(SYSTEM_SHELL), user_info)
.arg("--login")
.arg("-c")
.arg(format!("{} {}", "/etc/lemurs/xsetup.sh", xinitrc_path))
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
{
Ok(child) => child,
Err(err) => {
error!("Failed to start X11 environment. Reason '{}'", err);
return Err(EnvironmentStartError::XStartEnv);
}
};
let client = match client
.arg(format!("{} {}", "/etc/lemurs/xsetup.sh", xinitrc_path))
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
{
Ok(child) => child,
Err(err) => {
error!("Failed to start X11 environment. Reason '{}'", err);
return Err(EnvironmentStartError::XStartEnv);
}
};
Ok(SpawnedEnvironment::X11 { server, client })
}
PostLoginEnvironment::Wayland { script_path } => {
info!("Starting Wayland session");
let child =
match lower_command_permissions_to_user(Command::new(SYSTEM_SHELL), user_info)
.arg("--login")
.arg("-c")
.arg(script_path)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
{
Ok(child) => child,
Err(err) => {
error!("Failed to start Wayland Compositor. Reason '{err}'");
return Err(EnvironmentStartError::WaylandStart);
}
};
let child = match client
.arg(script_path)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
{
Ok(child) => child,
Err(err) => {
error!("Failed to start Wayland Compositor. Reason '{err}'");
return Err(EnvironmentStartError::WaylandStart);
}
};
Ok(SpawnedEnvironment::Wayland(child))
}
@ -209,10 +218,8 @@ impl PostLoginEnvironment {
info!("Starting TTY shell");
let shell = &user_info.shell;
// TODO: Instead of calling the shell directly we should be calling it through
// `/bin/bash --login`
let child = match lower_command_permissions_to_user(Command::new(shell), user_info)
.arg("--login")
let child = match client
.arg(shell)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.stdin(Stdio::inherit())