A generic greeter daemon
0

Configure Feed

Select the types of activity you want to include in your feed.

agretty: allow restricting a username

authored by

Hugo Osvaldo Barrera and committed by
Kenny Levinsen
(Mar 21, 2025, 1:52 PM +0100) cda1e567 e74e2bfc

+27 -10
+23 -9
agreety/src/main.rs
··· 57 57 Failure, 58 58 } 59 59 60 - fn login(node: &str, cmd: &mut Option<String>) -> Result<LoginResult, Box<dyn std::error::Error>> { 61 - let username = loop { 62 - let username = prompt_stderr(&format!("{} login: ", node))?; 63 - if let Some(u) = username.strip_prefix('!') { 64 - *cmd = Some(u.to_string()); 65 - eprintln!("Login command changed to: {u}"); 66 - continue; 60 + fn login( 61 + node: &str, 62 + cmd: &mut Option<String>, 63 + user: Option<&str>, 64 + ) -> Result<LoginResult, Box<dyn std::error::Error>> { 65 + let username = if let Some(u) = user { 66 + println!("{node} login: {u}"); 67 + u.to_string() 68 + } else { 69 + loop { 70 + let username = prompt_stderr(&format!("{node} login: "))?; 71 + if let Some(u) = username.strip_prefix('!') { 72 + *cmd = Some(u.to_string()); 73 + eprintln!("Login command changed to: {u}"); 74 + continue; 75 + } 76 + break username; 67 77 } 68 - break username; 69 78 }; 70 79 71 80 let mut stream = UnixStream::connect(env::var("GREETD_SOCK")?)?; ··· 143 152 "maximum number of accepted failures", 144 153 "FAILURES", 145 154 ); 155 + opts.optopt("u", "user", "restrict login to a specific user", "USER"); 146 156 let matches = match opts.parse(&args[1..]) { 147 157 Ok(m) => m, 148 158 Err(f) => { ··· 164 174 std::process::exit(1) 165 175 } 166 176 }; 177 + let user: Option<String> = match matches.opt_get("user") { 178 + Ok(s) => s, 179 + Err(_) => None, 180 + }; 167 181 168 182 if let Ok(issue) = get_issue() { 169 183 print!("{}", issue); ··· 171 185 172 186 let uts = uname().unwrap(); 173 187 for _ in 0..max_failures { 174 - match login(uts.nodename().to_str().unwrap(), &mut cmd) { 188 + match login(uts.nodename().to_str().unwrap(), &mut cmd, user.as_deref()) { 175 189 Ok(LoginResult::Success) => break, 176 190 Ok(LoginResult::Failure) => eprintln!("Login incorrect\n"), 177 191 Err(e) => {
+4 -1
man/agreety-1.scd
··· 21 21 Specifies the maximum number of login failures to accept before terminating. 22 22 Defaults to 5. 23 23 24 + *-u, --user <user>* 25 + Restrict login to *user*. 26 + 24 27 # DESCRIPTION 25 28 26 29 agreety is a very simple text-based greeter, with an appearance similar to ··· 34 37 greetd development, see https://git.sr.ht/~kennylevinsen/greetd. 35 38 36 39 # SEE ALSO 37 - *greetd*(1) *greetd*(5) 40 + *greetd*(1) *greetd*(5)