Files
saslauthd_yaml/server/src/handler.rs
T

38 lines
964 B
Rust
Raw Normal View History

use crate::repository::PasswordDirectory;
use common::request::Request;
use std::io::{Error, Write};
use std::os::unix::net::UnixStream;
pub const RESPONSE_NO: [u8; 4] = [0x0, 0x2, b'N', b'O'];
pub const RESPONSE_OK: [u8; 4] = [0x0, 0x2, b'O', b'K'];
pub struct Handler {
stream: UnixStream,
handler: PasswordDirectory,
}
impl Handler {
pub fn new(stream: UnixStream, handler: PasswordDirectory) -> Handler {
Handler { stream, handler }
}
fn communicate(&mut self) -> Result<(), Error> {
let request = Request::from_stream(&mut self.stream)?;
println!("userid: {}", request.userid);
if self.handler.check_auth(&request) {
self.stream.write_all(&RESPONSE_OK)?
} else {
self.stream.write_all(&RESPONSE_NO)?
}
Ok(())
}
pub fn handle_client(&mut self) {
if let Err(error) = self.communicate() {
eprint!("{error}");
}
}
}