xref: /DragonOS/user/apps/user-manage/src/cmd/usermod.rs (revision 79ad6e5ba4cf7fd624dfa91a1de35d7e60bdda43)
1 use crate::{
2     check::check::UModCheck,
3     error::error::{ErrorHandler, ExitStatus},
4     executor::executor::UModExecutor,
5     parser::parser::UserParser,
6 };
7 use libc::geteuid;
8 use std::process::exit;
9 
10 #[path = "../check/mod.rs"]
11 mod check;
12 #[path = "../error/mod.rs"]
13 mod error;
14 #[path = "../executor/mod.rs"]
15 mod executor;
16 #[path = "../parser/mod.rs"]
17 mod parser;
18 
19 #[allow(dead_code)]
20 fn main() {
21     let args = std::env::args().collect::<Vec<_>>();
22 
23     if unsafe { geteuid() } != 0 {
24         ErrorHandler::error_handle(
25             "permission denied (are you root?)".to_string(),
26             ExitStatus::PermissionDenied,
27         )
28     }
29 
30     if args.len() < 2 {
31         ErrorHandler::error_handle(
32             format!("usage: {} [options] username", args[0]),
33             ExitStatus::InvalidCmdSyntax,
34         );
35     }
36 
37     let cmd = UserParser::parse(args);
38     if !cmd.options.is_empty() {
39         let info = UModCheck::check(cmd);
40         let username = info.username.clone();
41         UModExecutor::execute(info);
42         println!("Modify user[{}] successfully!", username);
43     }
44 
45     exit(ExitStatus::Success as i32);
46 }
47