WIP cargo fmt
This commit is contained in:
@@ -5,16 +5,9 @@ mod scrambler;
|
||||
mod session;
|
||||
mod terminal;
|
||||
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
error::Error,
|
||||
io,
|
||||
rc::Rc,
|
||||
};
|
||||
use std::{cell::RefCell, error::Error, io, rc::Rc};
|
||||
|
||||
use nix::{
|
||||
unistd::{chown, Gid, Uid},
|
||||
};
|
||||
use nix::unistd::{chown, Gid, Uid};
|
||||
|
||||
use tokio::{
|
||||
net::{UnixListener, UnixStream},
|
||||
@@ -26,12 +19,7 @@ use tokio::{
|
||||
|
||||
use greet_proto::{Failure, Header, Request, Response};
|
||||
|
||||
use crate::{
|
||||
scrambler::Scrambler,
|
||||
config::VtSelection,
|
||||
context::Context,
|
||||
terminal::Terminal,
|
||||
};
|
||||
use crate::{config::VtSelection, context::Context, scrambler::Scrambler, terminal::Terminal};
|
||||
|
||||
fn reset_vt(vt: usize) -> Result<(), Box<dyn Error>> {
|
||||
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))?;
|
||||
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))?;
|
||||
|
||||
s.write_all(&header_bytes).await?;
|
||||
@@ -136,7 +126,8 @@ async fn main() {
|
||||
alarm.recv().await;
|
||||
alarm_ctx
|
||||
.borrow_mut()
|
||||
.alarm().await
|
||||
.alarm()
|
||||
.await
|
||||
.expect("unable to read alarm");
|
||||
}
|
||||
});
|
||||
@@ -148,7 +139,8 @@ async fn main() {
|
||||
child.recv().await;
|
||||
child_ctx
|
||||
.borrow_mut()
|
||||
.check_children().await
|
||||
.check_children()
|
||||
.await
|
||||
.expect("unable to check children");
|
||||
}
|
||||
});
|
||||
|
@@ -6,7 +6,7 @@ use std::{
|
||||
fs,
|
||||
fs::File,
|
||||
io::{BufRead, BufReader, Write},
|
||||
os::unix::io::{FromRawFd, AsRawFd, RawFd},
|
||||
os::unix::io::{AsRawFd, FromRawFd, RawFd},
|
||||
path::PathBuf,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
@@ -17,22 +17,13 @@ use nix::{
|
||||
signal::{SigSet, Signal},
|
||||
wait::{waitpid, WaitPidFlag, WaitStatus},
|
||||
},
|
||||
unistd::{
|
||||
close, execve, fork, initgroups, setgid, setsid, setuid, ForkResult, Gid, Pid, Uid,
|
||||
},
|
||||
unistd::{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 serde::{Deserialize, Serialize};
|
||||
use users::{os::unix::UserExt, User};
|
||||
|
||||
use crate::{
|
||||
pam::converse::PasswordConv,
|
||||
pam::session::PamSession,
|
||||
terminal,
|
||||
};
|
||||
use crate::{pam::converse::PasswordConv, pam::session::PamSession, terminal};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
enum PamQuestionStyle {
|
||||
@@ -44,13 +35,8 @@ enum PamQuestionStyle {
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
enum ParentToSessionChild {
|
||||
InitiateLogin {
|
||||
username: String,
|
||||
},
|
||||
PamResponse {
|
||||
resp: String,
|
||||
code: i32,
|
||||
},
|
||||
InitiateLogin { username: String },
|
||||
PamResponse { resp: String, code: i32 },
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@@ -63,7 +49,7 @@ enum SessionChildToParent {
|
||||
LoginFinalized {
|
||||
success: bool,
|
||||
error_msg: String,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// responsible for the entirety of the session setup and execution. It is
|
||||
/// 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.
|
||||
blocked_sigset()
|
||||
.thread_unblock()
|
||||
@@ -451,8 +440,9 @@ impl<'a> Session<'a> {
|
||||
let msg = SessionChildToParent::FinalChildPid(child.as_raw() as u64);
|
||||
let data = serde_json::to_vec(&msg)?;
|
||||
eprintln!("sending: {:?}\n", data);
|
||||
childfd.send(&data)
|
||||
.map_err(|e| format!("unable to send message: {}", e))?;
|
||||
childfd
|
||||
.send(&data)
|
||||
.map_err(|e| format!("unable to send message: {}", e))?;
|
||||
// close(childfd.as_raw_fd())
|
||||
// .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>> {
|
||||
// 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
|
||||
// subprocess. Things seem to fail otherwise.
|
||||
|
Reference in New Issue
Block a user