Fetch some user information and send it to the client.

This commit is contained in:
abbie 2021-12-23 17:27:37 +00:00
parent 0867c84825
commit d801ab8dc5
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87
2 changed files with 28 additions and 6 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "singer" name = "singer"
version = "0.1.0" version = "0.1.1"
authors = ["Celeste <colean@colean.cc>"] authors = ["Celeste <colean@colean.cc>"]
edition = "2018" edition = "2018"

View file

@ -2,6 +2,7 @@ use std::io::{Write, BufReader, BufRead};
use std::net::{TcpListener, TcpStream}; use std::net::{TcpListener, TcpStream};
use std::fs; use std::fs;
use std::string::{String}; use std::string::{String};
use std::process::Command;
fn path_exist(path: String) -> bool { fn path_exist(path: String) -> bool {
@ -21,14 +22,35 @@ fn process(request: Vec<u8>) -> String {
input.pop(); input.pop();
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)) { if path_exist(format!("{}/.yes_finger", homedir1)) {
// Todo: fingery stuff lmao let foutput = Command::new("sh")
output = "User found!"; .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 { } else {
output = "The requested user does not exist."; output = "The requested user does not exist.".to_string();
} }
return output.to_string(); return output.to_string();