proto: Simply Login by removing VT field
There are currently use-cases for this functionality, so remove feature in order to simplify the protocol.
This commit is contained in:
@@ -8,7 +8,7 @@ use rpassword::prompt_password_stderr;
|
||||
use clap::{crate_authors, crate_version, App, Arg};
|
||||
use nix::sys::utsname::uname;
|
||||
|
||||
use greet_proto::{Header, Request, Response, VtSelection};
|
||||
use greet_proto::{Header, Request, Response};
|
||||
|
||||
fn prompt_stderr(prompt: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let stdin = io::stdin();
|
||||
@@ -17,7 +17,7 @@ fn prompt_stderr(prompt: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
Ok(stdin_iter.next().unwrap()?)
|
||||
}
|
||||
|
||||
fn login(node: &str, cmd: Option<&str>, vt: VtSelection) -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn login(node: &str, cmd: Option<&str>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let username = prompt_stderr(&format!("{} login: ", node)).unwrap();
|
||||
let password = prompt_password_stderr("Password: ").unwrap();
|
||||
let command = match cmd {
|
||||
@@ -34,7 +34,6 @@ fn login(node: &str, cmd: Option<&str>, vt: VtSelection) -> Result<(), Box<dyn s
|
||||
password,
|
||||
command: vec![command],
|
||||
env,
|
||||
vt,
|
||||
};
|
||||
|
||||
// Write request
|
||||
@@ -111,13 +110,13 @@ fn main() {
|
||||
};
|
||||
|
||||
let vntr: usize = env::var("XDG_VTNR").unwrap_or("0".to_string()).parse().expect("unable to parse VTNR");
|
||||
let (vt_text, target_vt) = match matches.value_of("vt") {
|
||||
None => (format!("tty{}; next VT", vntr), VtSelection::Next),
|
||||
Some("next") => (format!("tty{}; next VT", vntr), VtSelection::Next),
|
||||
Some("current") => (format!("tty{}", vntr), VtSelection::Current),
|
||||
Some(n) => match n.parse() {
|
||||
Ok(v) if v == vntr => (format!("tty{}", v), VtSelection::Specific(v)),
|
||||
Ok(v) => (format!("tty{}; tty{}", vntr, v), VtSelection::Specific(v)),
|
||||
let vt_text = match matches.value_of("vt") {
|
||||
None => format!("tty{}; next VT", vntr),
|
||||
Some("next") => format!("tty{}; next VT", vntr),
|
||||
Some("current") => format!("tty{}", vntr),
|
||||
Some(n) => match n.parse::<usize>() {
|
||||
Ok(v) if v == vntr => format!("tty{}", v),
|
||||
Ok(v) => format!("tty{}; tty{}", vntr, v),
|
||||
Err(e) => {
|
||||
eprintln!("unable to parse VT number: {}", e);
|
||||
std::process::exit(1)
|
||||
@@ -134,7 +133,7 @@ fn main() {
|
||||
println!("");
|
||||
|
||||
for _ in 0..max_failures {
|
||||
match login(uts.nodename(), cmd, target_vt) {
|
||||
match login(uts.nodename(), cmd) {
|
||||
Ok(()) => {
|
||||
break;
|
||||
}
|
||||
|
@@ -60,20 +60,6 @@ impl Header {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum VtSelection {
|
||||
Current,
|
||||
Next,
|
||||
Specific(usize),
|
||||
}
|
||||
|
||||
impl Default for VtSelection {
|
||||
fn default() -> Self {
|
||||
VtSelection::Current
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, Copy)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ShutdownAction {
|
||||
@@ -91,9 +77,6 @@ pub enum Request {
|
||||
password: String,
|
||||
command: Vec<String>,
|
||||
env: HashMap<String, String>,
|
||||
|
||||
#[serde(default)]
|
||||
vt: VtSelection,
|
||||
},
|
||||
Shutdown {
|
||||
action: ShutdownAction,
|
||||
|
@@ -3,7 +3,7 @@ use std::env;
|
||||
use std::io::{self, BufRead, Read, Write};
|
||||
use std::os::unix::net::UnixStream;
|
||||
|
||||
use greet_proto::{Header, Request, Response, VtSelection};
|
||||
use greet_proto::{Header, Request, Response};
|
||||
|
||||
use rpassword::prompt_password_stderr;
|
||||
|
||||
@@ -24,7 +24,6 @@ fn login() -> Result<(), Box<dyn std::error::Error>> {
|
||||
password,
|
||||
command: vec![command],
|
||||
env: HashMap::new(),
|
||||
vt: VtSelection::Next,
|
||||
};
|
||||
|
||||
// Write request
|
||||
|
@@ -103,8 +103,7 @@ impl Pollable for Client {
|
||||
password,
|
||||
command,
|
||||
env,
|
||||
vt,
|
||||
} => match ctx.login(username, password, command, env, vt) {
|
||||
} => match ctx.login(username, password, command, env) {
|
||||
Ok(_) => Response::Success,
|
||||
Err(e) => Response::Failure(Failure::LoginError {
|
||||
description: format!("{}", e),
|
||||
|
@@ -4,8 +4,6 @@ use std::fs::read_to_string;
|
||||
use clap::{crate_authors, crate_version, App, Arg};
|
||||
use serde::Deserialize;
|
||||
|
||||
use greet_proto::VtSelection;
|
||||
|
||||
fn default_vt() -> toml::Value {
|
||||
toml::Value::String("next".to_string())
|
||||
}
|
||||
@@ -25,6 +23,12 @@ pub struct Config {
|
||||
pub socket_path: String,
|
||||
}
|
||||
|
||||
pub enum VtSelection {
|
||||
Next,
|
||||
Current,
|
||||
Specific(usize)
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn vt(&self) -> VtSelection {
|
||||
match &self.vt {
|
||||
|
@@ -9,8 +9,7 @@ use nix::unistd::{alarm, execv, fork, ForkResult};
|
||||
|
||||
use crate::scrambler::Scrambler;
|
||||
use crate::session::{Session, SessionChild};
|
||||
use crate::terminal;
|
||||
use greet_proto::{ShutdownAction, VtSelection};
|
||||
use greet_proto::ShutdownAction;
|
||||
|
||||
/// Context keeps track of running sessions and start new ones.
|
||||
pub struct Context<'a> {
|
||||
@@ -87,7 +86,6 @@ impl<'a> Context<'a> {
|
||||
mut password: String,
|
||||
cmd: Vec<String>,
|
||||
provided_env: HashMap<String, String>,
|
||||
vt: VtSelection,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
if !self.greeter.is_some() {
|
||||
eprintln!("login request not valid when greeter is not active");
|
||||
@@ -98,14 +96,8 @@ impl<'a> Context<'a> {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "session already active").into());
|
||||
}
|
||||
|
||||
let vt = match vt {
|
||||
VtSelection::Current => self.vt,
|
||||
VtSelection::Specific(vt) => vt,
|
||||
VtSelection::Next => terminal::Terminal::open(0)?.vt_get_next()?,
|
||||
};
|
||||
|
||||
let pending_session =
|
||||
Session::new("login", "user", &username, &password, cmd, provided_env, vt)?;
|
||||
Session::new("login", "user", &username, &password, cmd, provided_env, self.vt)?;
|
||||
password.scramble();
|
||||
self.pending_session = Some(pending_session);
|
||||
|
||||
|
@@ -4,8 +4,6 @@ use std::fs::remove_file;
|
||||
use nix::poll::{poll, PollFd};
|
||||
use nix::unistd::chown;
|
||||
|
||||
use greet_proto::VtSelection;
|
||||
|
||||
mod config;
|
||||
mod client;
|
||||
mod context;
|
||||
@@ -38,9 +36,9 @@ fn main() {
|
||||
let term = terminal::Terminal::open(0)
|
||||
.expect("unable to open controlling terminal");
|
||||
let vt = match config.vt() {
|
||||
VtSelection::Current => term.vt_get_current().expect("unable to get current VT"),
|
||||
VtSelection::Next => term.vt_get_next().expect("unable to get next VT"),
|
||||
VtSelection::Specific(v) => v
|
||||
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::Specific(v) => v
|
||||
};
|
||||
drop(term);
|
||||
|
||||
@@ -73,7 +71,6 @@ fn main() {
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
|
||||
let mut idx_compensation: isize = 0;
|
||||
for (idx, fd) in fds.iter().enumerate() {
|
||||
if let Some(revents) = fd.revents() {
|
||||
|
Reference in New Issue
Block a user