Skip to content

Commit

Permalink
Use the correct PAM service name on FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Nov 19, 2024
1 parent 6aaa6eb commit 380bddd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/su/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ fn authenticate(
user: &str,
login: bool,
) -> Result<PamContext<CLIConverser>, Error> {
let context = if login { "su-l" } else { "su" };
// FIXME make it configurable by the packager
let context = if login && cfg!(target_os = "linux") {
"su-l"
} else {
"su"
};
let use_stdin = true;
let mut pam = PamContext::builder_cli("su", use_stdin, false)
.target_user(user)
Expand Down
7 changes: 6 additions & 1 deletion src/sudo/pam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ pub fn init_pam(
auth_user: &str,
requesting_user: &str,
) -> PamResult<PamContext<CLIConverser>> {
let service_name = if is_login_shell { "sudo-i" } else { "sudo" };
// FIXME make it configurable by the packager
let service_name = if is_login_shell && cfg!(target_os = "linux") {
"sudo-i"
} else {
"sudo"
};
let mut pam = PamContext::builder_cli("sudo", use_stdin, non_interactive)
.service_name(service_name)
.build()?;
Expand Down
1 change: 1 addition & 0 deletions test-framework/sudo-compliance-tests/src/sudo/pam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ fn sudo_uses_correct_service_file() -> Result<()> {
}

#[test]
#[cfg_attr(target_os = "freebsd", ignore = "FreeBSD doesn't use sudo-i PAM context")]
fn sudo_dash_i_uses_correct_service_file() -> Result<()> {
let env = Env("ALL ALL=(ALL:ALL) ALL")
.file("/etc/pam.d/sudo-i", "auth sufficient pam_permit.so")
Expand Down

0 comments on commit 380bddd

Please sign in to comment.