|
| 1 | +// This file is part of the uutils util-linux package. |
| 2 | +// |
| 3 | +// For the full copyright and license information, please view the LICENSE |
| 4 | +// file that was distributed with this source code. |
| 5 | + |
| 6 | +use clap::{crate_version, Arg, ArgAction, Command}; |
| 7 | +use std::fs; |
| 8 | +use uucore::{error::UResult, format_usage, help_about, help_usage}; |
| 9 | + |
| 10 | +const ABOUT: &str = help_about!("nologin.md"); |
| 11 | +const USAGE: &str = help_usage!("nologin.md"); |
| 12 | + |
| 13 | +#[uucore::main] |
| 14 | +pub fn uumain(args: impl uucore::Args) -> UResult<()> { |
| 15 | + let _matches = uu_app().try_get_matches_from(args)?; |
| 16 | + |
| 17 | + // Try to read custom message from /etc/nologin.txt |
| 18 | + let message = match fs::read_to_string("/etc/nologin.txt") { |
| 19 | + Ok(content) => content.trim().to_string(), |
| 20 | + Err(_) => "This account is currently not available.".to_string(), |
| 21 | + }; |
| 22 | + |
| 23 | + println!("{}", message); |
| 24 | + std::process::exit(1); |
| 25 | +} |
| 26 | + |
| 27 | +pub fn uu_app() -> Command { |
| 28 | + Command::new(uucore::util_name()) |
| 29 | + .version(crate_version!()) |
| 30 | + .about(ABOUT) |
| 31 | + .override_usage(format_usage(USAGE)) |
| 32 | + .infer_long_args(true) |
| 33 | + .arg( |
| 34 | + Arg::new("command") |
| 35 | + .short('c') |
| 36 | + .long("command") |
| 37 | + .value_name("command") |
| 38 | + .help("does nothing (for compatibility)"), |
| 39 | + ) |
| 40 | + .arg( |
| 41 | + Arg::new("init-file") |
| 42 | + .long("init-file") |
| 43 | + .value_name("file") |
| 44 | + .help("does nothing (for compatibility)"), |
| 45 | + ) |
| 46 | + .arg( |
| 47 | + Arg::new("interactive") |
| 48 | + .short('i') |
| 49 | + .long("interactive") |
| 50 | + .help("does nothing (for compatibility)") |
| 51 | + .action(ArgAction::SetTrue), |
| 52 | + ) |
| 53 | + .arg( |
| 54 | + Arg::new("login") |
| 55 | + .short('l') |
| 56 | + .long("login") |
| 57 | + .help("does nothing (for compatibility)") |
| 58 | + .action(ArgAction::SetTrue), |
| 59 | + ) |
| 60 | + .arg( |
| 61 | + Arg::new("noprofile") |
| 62 | + .long("noprofile") |
| 63 | + .help("does nothing (for compatibility)") |
| 64 | + .action(ArgAction::SetTrue), |
| 65 | + ) |
| 66 | + .arg( |
| 67 | + Arg::new("norc") |
| 68 | + .long("norc") |
| 69 | + .help("does nothing (for compatibility)") |
| 70 | + .action(ArgAction::SetTrue), |
| 71 | + ) |
| 72 | + .arg( |
| 73 | + Arg::new("posix") |
| 74 | + .long("posix") |
| 75 | + .help("does nothing (for compatibility)") |
| 76 | + .action(ArgAction::SetTrue), |
| 77 | + ) |
| 78 | + .arg( |
| 79 | + Arg::new("rcfile") |
| 80 | + .long("rcfile") |
| 81 | + .value_name("file") |
| 82 | + .help("does nothing (for compatibility)"), |
| 83 | + ) |
| 84 | + .arg( |
| 85 | + Arg::new("restricted") |
| 86 | + .short('r') |
| 87 | + .long("restricted") |
| 88 | + .help("does nothing (for compatibility)") |
| 89 | + .action(ArgAction::SetTrue), |
| 90 | + ) |
| 91 | +} |
0 commit comments