From d801ab8dc5f579c6893710c2cefecdf406341695 Mon Sep 17 00:00:00 2001 From: Celeste Date: Thu, 23 Dec 2021 17:27:37 +0000 Subject: [PATCH] Fetch some user information and send it to the client. --- Cargo.toml | 2 +- src/main.rs | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ce4d287..39ff6d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "singer" -version = "0.1.0" +version = "0.1.1" authors = ["Celeste "] edition = "2018" diff --git a/src/main.rs b/src/main.rs index f227ffa..9927275 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::io::{Write, BufReader, BufRead}; use std::net::{TcpListener, TcpStream}; use std::fs; use std::string::{String}; +use std::process::Command; fn path_exist(path: String) -> bool { @@ -21,14 +22,35 @@ fn process(request: Vec) -> String { input.pop(); input.pop(); + let homedir = Command::new("sh") + .arg("-c") + .arg(format!("getent passwd {} | cut -d: -f6", input)) + .output() + .expect("Command failed"); - println!("/home/{}/.yes__finger", input); + let mut homedir1 = String::from_utf8_lossy(&homedir.stdout).to_string(); + homedir1.pop(); - if path_exist(format!("/home/{}/.yes_finger", input)) { - // Todo: fingery stuff lmao - output = "User found!"; + if path_exist(format!("{}/.yes_finger", homedir1)) { + let foutput = Command::new("sh") + .arg("-c") + .arg(format!("getent passwd {} | cut -d: -f7", input)) + .output() + .expect("Command failed"); + let name = Command::new("sh") + .arg("-c") + .arg(format!("getent passwd {} | cut -d: -f5", input)) + .output() + .expect("Command failed"); + + let mut gecos = String::from_utf8_lossy(&name.stdout).to_string(); + let mut shell = String::from_utf8_lossy(&foutput.stdout).to_string(); + gecos.pop(); + shell.pop(); + + output = format!("Login: {}\nName: {}\nDirectory: {}\nShell: {}", input, gecos, homedir1, shell); } else { - output = "The requested user does not exist."; + output = "The requested user does not exist.".to_string(); } return output.to_string();