Skip to content

Commit

Permalink
fix log implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Arshdeep54 committed Dec 20, 2024
1 parent 1772f4f commit 6dd0690
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 49 deletions.
15 changes: 3 additions & 12 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,12 @@ pub fn handle_auth(ssh_host_username: &str, ssh_key: &str) -> Result<()> {

Ok(false) => {
let name = get_name(&config, ssh_key)?;

if let Err(e) = logger::log(AUTH_LOG_PATH, "SUCCESS", &format!("User: {}", name)) {
println!("Failed to log: {}", e);
}
match fork() {
Ok(ForkResult::Parent { .. }) => {}
Ok(ForkResult::Child) => {
match fork() {
Ok(ForkResult::Parent { .. }) => {}
Ok(ForkResult::Child) => {
if let Err(e) = logger::log(AUTH_LOG_PATH, "SUCCESS", &format!("User: {}", name)) {
println!("Failed to log: {}", e);
}
std::process::exit(0);
}
Err(_) => println!("Fork failed"),
}

notifier::post_ssh_summary(
&config,
false,
Expand Down
20 changes: 5 additions & 15 deletions src/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use lib::errors::*;
use lib::init::init;
use lib::keyhouse::get_name;
use lib::notifier;
use lib::utils::clear_file;
//use lib::utils::clear_file;
use lib::logger;
use lib::utils::SSH_LOG_PATH;

Expand All @@ -23,22 +23,12 @@ pub fn handle_ssh() -> Result<()> {

let env = read_temp_env("/opt/watchdog/ssh_env")?;
let name = get_name(&config, &env.ssh_key)?;

if let Err(e) = logger::log(SSH_LOG_PATH, "SUCCESS", &format!("User: {}", name)) {
println!("Failed to log: {}", e);
}
match fork() {
Ok(ForkResult::Parent { .. }) => {
clear_file("/opt/watchdog/ssh_env")?;
}
Ok(ForkResult::Parent { .. }) => {}
Ok(ForkResult::Child) => {
match fork() {
Ok(ForkResult::Parent { .. }) => {}
Ok(ForkResult::Child) => {
if let Err(e) = logger::log(SSH_LOG_PATH, "SUCCESS", &format!("User: {}", name)) {
println!("Failed to log: {}", e);
}
}
Err(_) => println!("Fork failed"),
}

notifier::post_ssh_summary(&config, true, name, env.ssh_host_username)?;
}
Err(_) => println!("Fork failed"),
Expand Down
14 changes: 3 additions & 11 deletions src/su.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ pub fn handle_su() -> Result<()> {
if pam_type == "open_session" {
let config = read_config()?;
init(&config)?;

if let Err(e) = logger::log(SU_LOG_PATH, "SUCCESS", &format!("User: {}", pam_user)) {
println!("Failed to log: {}", e);
}
match fork() {
Ok(ForkResult::Parent { .. }) => {}
Ok(ForkResult::Child) => {
match fork() {
Ok(ForkResult::Parent { .. }) => {}
Ok(ForkResult::Child) => {
if let Err(e) = logger::log(SU_LOG_PATH, "SUCCESS", &format!("User: {}", pam_user)) {
println!("Failed to log: {}", e);
}
}
Err(_) => println!("Fork failed"),
}

notifier::post_su_summary(&config, pam_ruser, pam_user)?;
}
Err(_) => println!("Fork failed"),
Expand Down
14 changes: 3 additions & 11 deletions src/sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,12 @@ pub fn handle_sudo() -> Result<()> {
if pam_type == "open_session" {
let config = read_config()?;
init(&config)?;

if let Err(e) = logger::log(SUDO_LOG_PATH, "SUCCESS", &format!("User: {}", pam_ruser)) {
println!("Failed to log: {}", e);
}
match fork() {
Ok(ForkResult::Parent { .. }) => {}
Ok(ForkResult::Child) => {
match fork() {
Ok(ForkResult::Parent { .. }) => {}
Ok(ForkResult::Child) => {
if let Err(e) = logger::log(SUDO_LOG_PATH, "SUCCESS", &format!("User: {}", pam_ruser)) {
println!("Failed to log: {}", e);
}
}
Err(_) => println!("Fork failed"),
}

notifier::post_sudo_summary(&config, pam_ruser)?;
}
Err(_) => println!("Fork failed"),
Expand Down

0 comments on commit 6dd0690

Please sign in to comment.