commit 0867c8482555f910d4aae03aa66efd8fcb7b2109 Author: Celeste Date: Thu Dec 23 16:48:08 2021 +0000 Add stream boilerplate and find if users have opted into the finger protocol. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..a483b7a --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "singer" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..ce4d287 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "singer" +version = "0.1.0" +authors = ["Celeste "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..f227ffa --- /dev/null +++ b/src/main.rs @@ -0,0 +1,62 @@ +use std::io::{Write, BufReader, BufRead}; +use std::net::{TcpListener, TcpStream}; +use std::fs; +use std::string::{String}; + +fn path_exist(path: String) -> bool { + + let file = fs::metadata(path); + + match file { + Ok(_) => true, + Err(_) => false, + } + +} + + +fn process(request: Vec) -> String { + let mut input = String::from_utf8_lossy(&request).to_string(); + let output; + + input.pop(); + input.pop(); + + println!("/home/{}/.yes__finger", input); + + if path_exist(format!("/home/{}/.yes_finger", input)) { + // Todo: fingery stuff lmao + output = "User found!"; + } else { + output = "The requested user does not exist."; + } + + return output.to_string(); + +} + +fn serve(mut stream: TcpStream) { + let mut request = Vec::new(); + let mut reader = BufReader::new(&mut stream); + reader + .read_until(b'\n', &mut request) + .expect("Failed to read from stream!"); + + let finger = process(request); + let response = format!("{}\n", finger); + + stream.write(response.as_bytes()).unwrap(); + stream.flush().unwrap(); + +} + + +fn main() -> std::io::Result<()> { + let listen = TcpListener::bind("0.0.0.0:79")?; + + for stream in listen.incoming() { + println!("Serving incoming stream."); + serve(stream?); + } + Ok(()) +}