intial commit

This commit is contained in:
2026-02-25 22:53:25 +01:00
commit 054c3ff1f8
12 changed files with 1164 additions and 0 deletions

40
src/auth/pamsock.rs Normal file
View File

@@ -0,0 +1,40 @@
//! Horrible error handling here btw
use std::fmt::{Debug, Display};
use pamsock::prot::ServerResponse;
use super::AuthenticateResponse;
#[allow(clippy::from_over_into)]
impl Into<AuthenticateResponse<&'static str>> for ServerResponse {
fn into(self) -> AuthenticateResponse<&'static str> {
use AuthenticateResponse as AR;
match self {
Self::ServerError => AR::Failed("unknown server error"),
Self::Locked => AR::Failed("account locked, too many login attempts"),
Self::Failed => AR::Failed("wrong credentials"),
Self::Succeeded => AR::Success,
}
}
}
pub async fn authenticate(
cfg: &crate::args::Args,
user: &str,
passwd: &str,
) -> Option<AuthenticateResponse<impl Display + Debug>> {
use std::os::unix::net::UnixStream;
use tokio::net::UnixStream as AsyncUnixStream;
let std_sock = UnixStream::connect_addr(&cfg.pamsock_abstract_name).ok()?;
std_sock.set_nonblocking(true).ok();
let async_sock = AsyncUnixStream::from_std(std_sock).ok()?;
Some(
pamsock::prot::attempt_login_async(async_sock, user, passwd)
.await?
.into(),
)
}