~kennylevinsen/greetd-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH] agretty: allow restricting a username

Details
Message ID
<20240612203728.30770-2-hugo@whynothugo.nl>
DKIM signature
pass
Download raw message
Patch: +24 -9
---
 agreety/src/main.rs | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/agreety/src/main.rs b/agreety/src/main.rs
index 5ab294d..b709b81 100644
--- a/agreety/src/main.rs
+++ b/agreety/src/main.rs
@@ -57,15 +57,25 @@ enum LoginResult {
    Failure,
}

fn login(node: &str, cmd: &mut Option<String>) -> Result<LoginResult, Box<dyn std::error::Error>> {
    let username = loop {
        let username = prompt_stderr(&format!("{} login: ", node))?;
        if let Some(u) = username.strip_prefix('!') {
            *cmd = Some(u.to_string());
            eprintln!("Login command changed to: {u}");
            continue;
fn login(
    node: &str,
    cmd: &mut Option<String>,
    user: &Option<String>,
) -> Result<LoginResult, Box<dyn std::error::Error>> {
    let username = match user {
        Some(u) => {
            print!("{} login: {}\n", node, u);
            u.clone()
        }
        break username;
        None => loop {
            let username = prompt_stderr(&format!("{} login: ", node))?;
            if let Some(u) = username.strip_prefix('!') {
                *cmd = Some(u.to_string());
                eprintln!("Login command changed to: {u}");
                continue;
            }
            break username;
        },
    };

    let mut stream = UnixStream::connect(env::var("GREETD_SOCK")?)?;
@@ -143,6 +153,7 @@ fn main() {
        "maximum number of accepted failures",
        "FAILURES",
    );
    opts.optopt("u", "user", "restrict login to  asingle user", "USER");
    let matches = match opts.parse(&args[1..]) {
        Ok(m) => m,
        Err(f) => {
@@ -164,6 +175,10 @@ fn main() {
            std::process::exit(1)
        }
    };
    let user: Option<String> = match matches.opt_get("user") {
        Ok(s) => s,
        Err(_) => None,
    };

    if let Ok(issue) = get_issue() {
        print!("{}", issue);
@@ -171,7 +186,7 @@ fn main() {

    let uts = uname().unwrap();
    for _ in 0..max_failures {
        match login(uts.nodename().to_str().unwrap(), &mut cmd) {
        match login(uts.nodename().to_str().unwrap(), &mut cmd, &user) {
            Ok(LoginResult::Success) => break,
            Ok(LoginResult::Failure) => eprintln!("Login incorrect\n"),
            Err(e) => {
-- 
2.45.2
Reply to thread Export thread (mbox)