diff --git a/src/auth.rs b/src/auth.rs index a68fe48..08c5f34 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -25,7 +25,10 @@ pub fn handle_auth(ssh_host_username: &str, ssh_key: &str) -> Result<()> { //file name is pam_tty let file_name = pam_tty.replace("/", "_"); - fs::write("/opt/watchdog/ssh_env/file_name", data) + + let path = format!("/opt/watchdog/ssh_env/{}", file_name); + + fs::write(&path, data) .chain_err(|| "Cannot write temporary environment file. Please check if the watchdog `auth_keys_cmd` is run by the root user")?; println!("{}", ssh_key); diff --git a/src/ssh.rs b/src/ssh.rs index 9bf7f0f..51a10fe 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -27,12 +27,14 @@ pub fn handle_ssh() -> Result<()> { let file_name = pam_tty.replace("/", "_"); //dev_pts_0 - let env = read_temp_env("/opt/watchdog/ssh_env/file_name")?; //read appropriate env file + let path = format!("/opt/watchdog/ssh_env/{}", file_name); + + let env = read_temp_env(&path)?; //read appropriate env file let name = get_name(&config, &env.ssh_key)?; match fork() { Ok(ForkResult::Parent { .. }) => { - clear_file("/opt/watchdog/ssh_env/file_name")?; + clear_file(&path)?; } Ok(ForkResult::Child) => { notifier::post_ssh_summary(&config, true, name, pam_ruser)?;