~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 v2] agretty: allow restricting a username

Details
Message ID
<20240626074756.15855-1-hugo@whynothugo.nl>
DKIM signature
pass
Download raw message
Patch: +28 -10
---
v2: updated man page
 agreety/src/main.rs | 33 ++++++++++++++++++++++++---------
 man/agreety-1.scd   |  5 ++++-
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/agreety/src/main.rs b/agreety/src/main.rs
index 5ab294d..e829ddb 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 a specific 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) => {
diff --git a/man/agreety-1.scd b/man/agreety-1.scd
index 5043c00..fa1259c 100644
--- a/man/agreety-1.scd
+++ b/man/agreety-1.scd
@@ -21,6 +21,9 @@ agreety - A text-based greeter for greetd
	Specifies the maximum number of login failures to accept before terminating.
	Defaults to 5.

*-u, --user <user>*
	Restrict login to *user*.

# DESCRIPTION

agreety is a very simple text-based greeter, with an appearance similar to
@@ -34,4 +37,4 @@ Maintained by Kenny Levinsen <contact@kl.wtf>. For more information about
greetd development, see https://git.sr.ht/~kennylevinsen/greetd.

# SEE ALSO
*greetd*(1) *greetd*(5)
\ No newline at end of file
*greetd*(1) *greetd*(5)
-- 
2.45.2
Reply to thread Export thread (mbox)