Minor fmt
This commit is contained in:
@@ -26,7 +26,7 @@ pub struct Config {
|
|||||||
pub enum VtSelection {
|
pub enum VtSelection {
|
||||||
Next,
|
Next,
|
||||||
Current,
|
Current,
|
||||||
Specific(usize)
|
Specific(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@@ -36,8 +36,7 @@ impl Config {
|
|||||||
"next" => VtSelection::Next,
|
"next" => VtSelection::Next,
|
||||||
"current" => VtSelection::Current,
|
"current" => VtSelection::Current,
|
||||||
_ => panic!("unknown value of vt, expect next, current, or vt number"),
|
_ => panic!("unknown value of vt, expect next, current, or vt number"),
|
||||||
|
},
|
||||||
}
|
|
||||||
toml::Value::Integer(u) => VtSelection::Specific(*u as usize),
|
toml::Value::Integer(u) => VtSelection::Specific(*u as usize),
|
||||||
_ => panic!("unknown value of vt, expect next, current, or vt number"),
|
_ => panic!("unknown value of vt, expect next, current, or vt number"),
|
||||||
}
|
}
|
||||||
|
@@ -96,8 +96,15 @@ impl<'a> Context<'a> {
|
|||||||
return Err(io::Error::new(io::ErrorKind::Other, "session already active").into());
|
return Err(io::Error::new(io::ErrorKind::Other, "session already active").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let pending_session =
|
let pending_session = Session::new(
|
||||||
Session::new("login", "user", &username, &password, cmd, provided_env, self.vt)?;
|
"login",
|
||||||
|
"user",
|
||||||
|
&username,
|
||||||
|
&password,
|
||||||
|
cmd,
|
||||||
|
provided_env,
|
||||||
|
self.vt,
|
||||||
|
)?;
|
||||||
password.scramble();
|
password.scramble();
|
||||||
self.pending_session = Some(pending_session);
|
self.pending_session = Some(pending_session);
|
||||||
|
|
||||||
|
@@ -42,8 +42,6 @@ impl Pollable for Listener {
|
|||||||
Err(_) => return Ok(PollRunResult::Uneventful),
|
Err(_) => return Ok(PollRunResult::Uneventful),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(PollRunResult::NewPollable(Box::new(
|
Ok(PollRunResult::NewPollable(Box::new(Client::new(stream)?)))
|
||||||
Client::new(stream)?,
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,8 +4,8 @@ use std::fs::remove_file;
|
|||||||
use nix::poll::{poll, PollFd};
|
use nix::poll::{poll, PollFd};
|
||||||
use nix::unistd::chown;
|
use nix::unistd::chown;
|
||||||
|
|
||||||
mod config;
|
|
||||||
mod client;
|
mod client;
|
||||||
|
mod config;
|
||||||
mod context;
|
mod context;
|
||||||
mod listener;
|
mod listener;
|
||||||
mod pam;
|
mod pam;
|
||||||
@@ -33,12 +33,11 @@ fn main() {
|
|||||||
|
|
||||||
let signals = signals::Signals::new().expect("unable to create signalfd");
|
let signals = signals::Signals::new().expect("unable to create signalfd");
|
||||||
|
|
||||||
let term = terminal::Terminal::open(0)
|
let term = terminal::Terminal::open(0).expect("unable to open controlling terminal");
|
||||||
.expect("unable to open controlling terminal");
|
|
||||||
let vt = match config.vt() {
|
let vt = match config.vt() {
|
||||||
config::VtSelection::Current => term.vt_get_current().expect("unable to get current VT"),
|
config::VtSelection::Current => term.vt_get_current().expect("unable to get current VT"),
|
||||||
config::VtSelection::Next => term.vt_get_next().expect("unable to get next VT"),
|
config::VtSelection::Next => term.vt_get_next().expect("unable to get next VT"),
|
||||||
config::VtSelection::Specific(v) => v
|
config::VtSelection::Specific(v) => v,
|
||||||
};
|
};
|
||||||
drop(term);
|
drop(term);
|
||||||
|
|
||||||
@@ -48,10 +47,8 @@ fn main() {
|
|||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut pollables: Vec<Box<dyn pollable::Pollable>> = vec![
|
let mut pollables: Vec<Box<dyn pollable::Pollable>> =
|
||||||
Box::new(listener),
|
vec![Box::new(listener), Box::new(signals)];
|
||||||
Box::new(signals),
|
|
||||||
];
|
|
||||||
|
|
||||||
let mut fds: Vec<PollFd> = Vec::new();
|
let mut fds: Vec<PollFd> = Vec::new();
|
||||||
let mut fds_changed = true;
|
let mut fds_changed = true;
|
||||||
@@ -83,14 +80,14 @@ fn main() {
|
|||||||
// not require index compensation.
|
// not require index compensation.
|
||||||
pollables.push(p);
|
pollables.push(p);
|
||||||
fds_changed = true;
|
fds_changed = true;
|
||||||
},
|
}
|
||||||
Ok(pollable::PollRunResult::Dead) => {
|
Ok(pollable::PollRunResult::Dead) => {
|
||||||
// We remove a pollable at the current index, so
|
// We remove a pollable at the current index, so
|
||||||
// compensate the index of future accesses.
|
// compensate the index of future accesses.
|
||||||
idx_compensation -= 1;
|
idx_compensation -= 1;
|
||||||
pollables.remove(idx);
|
pollables.remove(idx);
|
||||||
fds_changed = true;
|
fds_changed = true;
|
||||||
},
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("task failed: {}", e);
|
eprintln!("task failed: {}", e);
|
||||||
terminal::restore(vt).expect("unable to reset vt");
|
terminal::restore(vt).expect("unable to reset vt");
|
||||||
|
@@ -24,9 +24,9 @@ impl<'a> PamSession<'a> {
|
|||||||
|
|
||||||
match pam_sys::start(service, None, &conv, &mut pam_handle) {
|
match pam_sys::start(service, None, &conv, &mut pam_handle) {
|
||||||
PamReturnCode::SUCCESS => Ok(PamSession {
|
PamReturnCode::SUCCESS => Ok(PamSession {
|
||||||
handle: unsafe { &mut *pam_handle },
|
handle: unsafe { &mut *pam_handle },
|
||||||
converse: pam_conv,
|
converse: pam_conv,
|
||||||
last_code: PamReturnCode::SUCCESS,
|
last_code: PamReturnCode::SUCCESS,
|
||||||
}),
|
}),
|
||||||
_ => Err(io::Error::new(io::ErrorKind::Other, "unable to start pam session").into()),
|
_ => Err(io::Error::new(io::ErrorKind::Other, "unable to start pam session").into()),
|
||||||
}
|
}
|
||||||
|
@@ -149,7 +149,6 @@ impl<'a> Session<'a> {
|
|||||||
/// 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: RawFd) -> Result<(), Box<dyn Error>> {
|
fn session_worker(&mut self, childfd: RawFd) -> 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()
|
||||||
@@ -371,8 +370,7 @@ impl<'a> Session<'a> {
|
|||||||
|
|
||||||
// Run the child entrypoint.
|
// Run the child entrypoint.
|
||||||
if let Err(e) = self.session_worker(childfd) {
|
if let Err(e) = self.session_worker(childfd) {
|
||||||
writeln!(stderr, "session worker: {}", e)
|
writeln!(stderr, "session worker: {}", e).expect("could not write log output");
|
||||||
.expect("could not write log output");
|
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
|
Reference in New Issue
Block a user