Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NSS): Fix should_pre_check logic to identify sshd #419

Merged
merged 1 commit into from
Jul 5, 2024
Merged
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
13 changes: 7 additions & 6 deletions nss/src/passwd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{info, REQUEST_TIMEOUT};
use libc::uid_t;
use libnss::interop::Response;
use libnss::passwd::{Passwd, PasswdHooks};
use std::path::PathBuf;
use tokio::runtime::Builder;
use tonic::Request;

Expand Down Expand Up @@ -140,23 +141,23 @@ fn passwd_entries_to_passwds(entries: Vec<PasswdEntry>) -> Vec<Passwd> {
entries.into_iter().map(passwd_entry_to_passwd).collect()
}

static SSHD_BINARY_PATH: &str = "/usr/sbin/sshd";
3v1n0 marked this conversation as resolved.
Show resolved Hide resolved

/// should_pre_check returns true if the current process is a child of sshd.
#[allow(unreachable_code)] // This function body is overridden in integration tests, so we need to ignore the warning.
fn should_pre_check() -> bool {
#[cfg(feature = "integration_tests")]
return std::env::var("AUTHD_NSS_SHOULD_PRE_CHECK").is_ok();

let ppid = std::os::unix::process::parent_id();
let parent = procfs::process::Process::new(ppid as i32);
let parent = procfs::process::Process::new(std::os::unix::process::parent_id() as i32);
if parent.is_err() {
return false;
}

let cmds = parent.unwrap().cmdline();
if cmds.is_err() {
let executable_path = parent.unwrap().exe();
if executable_path.is_err() {
return false;
}

let cmds = cmds.unwrap();
matches!(&cmds[0], s if s == "sshd")
PathBuf::from(SSHD_BINARY_PATH) == executable_path.unwrap()
}
Loading