···5757 Failure,
5858}
59596060-fn login(node: &str, cmd: &mut Option<String>) -> Result<LoginResult, Box<dyn std::error::Error>> {
6161- let username = loop {
6262- let username = prompt_stderr(&format!("{} login: ", node))?;
6363- if let Some(u) = username.strip_prefix('!') {
6464- *cmd = Some(u.to_string());
6565- eprintln!("Login command changed to: {u}");
6666- continue;
6060+fn login(
6161+ node: &str,
6262+ cmd: &mut Option<String>,
6363+ user: Option<&str>,
6464+) -> Result<LoginResult, Box<dyn std::error::Error>> {
6565+ let username = if let Some(u) = user {
6666+ println!("{node} login: {u}");
6767+ u.to_string()
6868+ } else {
6969+ loop {
7070+ let username = prompt_stderr(&format!("{node} login: "))?;
7171+ if let Some(u) = username.strip_prefix('!') {
7272+ *cmd = Some(u.to_string());
7373+ eprintln!("Login command changed to: {u}");
7474+ continue;
7575+ }
7676+ break username;
6777 }
6868- break username;
6978 };
70797180 let mut stream = UnixStream::connect(env::var("GREETD_SOCK")?)?;
···143152 "maximum number of accepted failures",
144153 "FAILURES",
145154 );
155155+ opts.optopt("u", "user", "restrict login to a specific user", "USER");
146156 let matches = match opts.parse(&args[1..]) {
147157 Ok(m) => m,
148158 Err(f) => {
···164174 std::process::exit(1)
165175 }
166176 };
177177+ let user: Option<String> = match matches.opt_get("user") {
178178+ Ok(s) => s,
179179+ Err(_) => None,
180180+ };
167181168182 if let Ok(issue) = get_issue() {
169183 print!("{}", issue);
···171185172186 let uts = uname().unwrap();
173187 for _ in 0..max_failures {
174174- match login(uts.nodename().to_str().unwrap(), &mut cmd) {
188188+ match login(uts.nodename().to_str().unwrap(), &mut cmd, user.as_deref()) {
175189 Ok(LoginResult::Success) => break,
176190 Ok(LoginResult::Failure) => eprintln!("Login incorrect\n"),
177191 Err(e) => {
+4-1
man/agreety-1.scd
···2121 Specifies the maximum number of login failures to accept before terminating.
2222 Defaults to 5.
23232424+*-u, --user <user>*
2525+ Restrict login to *user*.
2626+2427# DESCRIPTION
25282629agreety is a very simple text-based greeter, with an appearance similar to
···3437greetd development, see https://git.sr.ht/~kennylevinsen/greetd.
35383639# SEE ALSO
3737-*greetd*(1) *greetd*(5)4040+*greetd*(1) *greetd*(5)