Fetch some user information and send it to the client.
This commit is contained in:
parent
0867c84825
commit
d801ab8dc5
2 changed files with 28 additions and 6 deletions
|
@ -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"
|
||||||
|
|
||||||
|
|
32
src/main.rs
32
src/main.rs
|
@ -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();
|
||||||
|
|
Reference in a new issue