Add stream boilerplate and find if users have opted into the finger protocol.
This commit is contained in:
commit
0867c84825
4 changed files with 77 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
5
Cargo.lock
generated
Normal file
5
Cargo.lock
generated
Normal file
|
@ -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"
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "singer"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Celeste <colean@colean.cc>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
62
src/main.rs
Normal file
62
src/main.rs
Normal file
|
@ -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<u8>) -> 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(())
|
||||||
|
}
|
Reference in a new issue