WIP cargo fmt
This commit is contained in:
@@ -5,16 +5,9 @@ mod scrambler;
|
|||||||
mod session;
|
mod session;
|
||||||
mod terminal;
|
mod terminal;
|
||||||
|
|
||||||
use std::{
|
use std::{cell::RefCell, error::Error, io, rc::Rc};
|
||||||
cell::RefCell,
|
|
||||||
error::Error,
|
|
||||||
io,
|
|
||||||
rc::Rc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use nix::{
|
use nix::unistd::{chown, Gid, Uid};
|
||||||
unistd::{chown, Gid, Uid},
|
|
||||||
};
|
|
||||||
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
net::{UnixListener, UnixStream},
|
net::{UnixListener, UnixStream},
|
||||||
@@ -26,12 +19,7 @@ use tokio::{
|
|||||||
|
|
||||||
use greet_proto::{Failure, Header, Request, Response};
|
use greet_proto::{Failure, Header, Request, Response};
|
||||||
|
|
||||||
use crate::{
|
use crate::{config::VtSelection, context::Context, scrambler::Scrambler, terminal::Terminal};
|
||||||
scrambler::Scrambler,
|
|
||||||
config::VtSelection,
|
|
||||||
context::Context,
|
|
||||||
terminal::Terminal,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn reset_vt(vt: usize) -> Result<(), Box<dyn Error>> {
|
fn reset_vt(vt: usize) -> Result<(), Box<dyn Error>> {
|
||||||
let term = Terminal::open(vt)?;
|
let term = Terminal::open(vt)?;
|
||||||
@@ -79,10 +67,12 @@ async fn client(ctx: Rc<RefCell<Context<'_>>>, mut s: UnixStream) -> Result<(),
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let resp_bytes = resp.to_bytes()
|
let resp_bytes = resp
|
||||||
|
.to_bytes()
|
||||||
.map_err(|e| format!("unable to serialize response: {}", e))?;
|
.map_err(|e| format!("unable to serialize response: {}", e))?;
|
||||||
let header = Header::new(resp_bytes.len() as u32);
|
let header = Header::new(resp_bytes.len() as u32);
|
||||||
let header_bytes = header.to_bytes()
|
let header_bytes = header
|
||||||
|
.to_bytes()
|
||||||
.map_err(|e| format!("unable to serialize header: {}", e))?;
|
.map_err(|e| format!("unable to serialize header: {}", e))?;
|
||||||
|
|
||||||
s.write_all(&header_bytes).await?;
|
s.write_all(&header_bytes).await?;
|
||||||
@@ -136,7 +126,8 @@ async fn main() {
|
|||||||
alarm.recv().await;
|
alarm.recv().await;
|
||||||
alarm_ctx
|
alarm_ctx
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.alarm().await
|
.alarm()
|
||||||
|
.await
|
||||||
.expect("unable to read alarm");
|
.expect("unable to read alarm");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -148,7 +139,8 @@ async fn main() {
|
|||||||
child.recv().await;
|
child.recv().await;
|
||||||
child_ctx
|
child_ctx
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.check_children().await
|
.check_children()
|
||||||
|
.await
|
||||||
.expect("unable to check children");
|
.expect("unable to check children");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -6,7 +6,7 @@ use std::{
|
|||||||
fs,
|
fs,
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{BufRead, BufReader, Write},
|
io::{BufRead, BufReader, Write},
|
||||||
os::unix::io::{FromRawFd, AsRawFd, RawFd},
|
os::unix::io::{AsRawFd, FromRawFd, RawFd},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
@@ -17,22 +17,13 @@ use nix::{
|
|||||||
signal::{SigSet, Signal},
|
signal::{SigSet, Signal},
|
||||||
wait::{waitpid, WaitPidFlag, WaitStatus},
|
wait::{waitpid, WaitPidFlag, WaitStatus},
|
||||||
},
|
},
|
||||||
unistd::{
|
unistd::{close, execve, fork, initgroups, setgid, setsid, setuid, ForkResult, Gid, Pid, Uid},
|
||||||
close, execve, fork, initgroups, setgid, setsid, setuid, ForkResult, Gid, Pid, Uid,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use users::{
|
|
||||||
os::unix::UserExt,
|
|
||||||
User,
|
|
||||||
};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use pam_sys::{PamFlag, PamItemType};
|
use pam_sys::{PamFlag, PamItemType};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use users::{os::unix::UserExt, User};
|
||||||
|
|
||||||
use crate::{
|
use crate::{pam::converse::PasswordConv, pam::session::PamSession, terminal};
|
||||||
pam::converse::PasswordConv,
|
|
||||||
pam::session::PamSession,
|
|
||||||
terminal,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
enum PamQuestionStyle {
|
enum PamQuestionStyle {
|
||||||
@@ -44,13 +35,8 @@ enum PamQuestionStyle {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
enum ParentToSessionChild {
|
enum ParentToSessionChild {
|
||||||
InitiateLogin {
|
InitiateLogin { username: String },
|
||||||
username: String,
|
PamResponse { resp: String, code: i32 },
|
||||||
},
|
|
||||||
PamResponse {
|
|
||||||
resp: String,
|
|
||||||
code: i32,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@@ -63,7 +49,7 @@ enum SessionChildToParent {
|
|||||||
LoginFinalized {
|
LoginFinalized {
|
||||||
success: bool,
|
success: bool,
|
||||||
error_msg: String,
|
error_msg: String,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a set containing the signals we want to block in the main process.
|
/// Returns a set containing the signals we want to block in the main process.
|
||||||
@@ -286,7 +272,10 @@ impl<'a> Session<'a> {
|
|||||||
/// The entry point for the session worker process. The session worker is
|
/// The entry point for the session worker process. The session worker is
|
||||||
/// responsible for the entirety of the session setup and execution. It is
|
/// responsible for the entirety of the session setup and execution. It is
|
||||||
/// started by Session::start.
|
/// started by Session::start.
|
||||||
fn session_worker(&mut self, childfd: std::os::unix::net::UnixDatagram) -> Result<(), Box<dyn Error>> {
|
fn session_worker(
|
||||||
|
&mut self,
|
||||||
|
childfd: std::os::unix::net::UnixDatagram,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
// Clear the signal masking that was inherited from the parent.
|
// Clear the signal masking that was inherited from the parent.
|
||||||
blocked_sigset()
|
blocked_sigset()
|
||||||
.thread_unblock()
|
.thread_unblock()
|
||||||
@@ -451,8 +440,9 @@ impl<'a> Session<'a> {
|
|||||||
let msg = SessionChildToParent::FinalChildPid(child.as_raw() as u64);
|
let msg = SessionChildToParent::FinalChildPid(child.as_raw() as u64);
|
||||||
let data = serde_json::to_vec(&msg)?;
|
let data = serde_json::to_vec(&msg)?;
|
||||||
eprintln!("sending: {:?}\n", data);
|
eprintln!("sending: {:?}\n", data);
|
||||||
childfd.send(&data)
|
childfd
|
||||||
.map_err(|e| format!("unable to send message: {}", e))?;
|
.send(&data)
|
||||||
|
.map_err(|e| format!("unable to send message: {}", e))?;
|
||||||
// close(childfd.as_raw_fd())
|
// close(childfd.as_raw_fd())
|
||||||
// .map_err(|e| format!("unable to close pipe: {}", e))?;
|
// .map_err(|e| format!("unable to close pipe: {}", e))?;
|
||||||
|
|
||||||
@@ -488,7 +478,8 @@ impl<'a> Session<'a> {
|
|||||||
///
|
///
|
||||||
pub async fn start(&mut self) -> Result<SessionChild, Box<dyn Error>> {
|
pub async fn start(&mut self) -> Result<SessionChild, Box<dyn Error>> {
|
||||||
// Pipe used to communicate the true PID of the final child.
|
// Pipe used to communicate the true PID of the final child.
|
||||||
let (parentfd, childfd) = std::os::unix::net::UnixDatagram::pair().map_err(|e| format!("could not create pipe: {}", e))?;
|
let (parentfd, childfd) = std::os::unix::net::UnixDatagram::pair()
|
||||||
|
.map_err(|e| format!("could not create pipe: {}", e))?;
|
||||||
|
|
||||||
// PAM requires for unfathmoable reasons that we run this in a
|
// PAM requires for unfathmoable reasons that we run this in a
|
||||||
// subprocess. Things seem to fail otherwise.
|
// subprocess. Things seem to fail otherwise.
|
||||||
|
Reference in New Issue
Block a user