xref: /DragonOS/user/apps/user-manage/src/check/info.rs (revision a8753f8fffb992e4d3bbd21eda431081b395af6b)
1 #[derive(Debug, Default, Clone)]
2 /// useradd的信息
3 pub struct UAddInfo {
4     /// 用户名
5     pub username: String,
6     pub uid: String,
7     pub gid: String,
8     /// 所在组的组名
9     pub group: String,
10     /// 用户描述信息
11     pub comment: String,
12     /// 主目录
13     pub home_dir: String,
14     /// 终端程序名
15     pub shell: String,
16 }
17 
18 impl From<UAddInfo> for String {
19     fn from(info: UAddInfo) -> Self {
20         format!(
21             "{}::{}:{}:{}:{}:{}\n",
22             info.username, info.uid, info.gid, info.comment, info.home_dir, info.shell
23         )
24     }
25 }
26 
27 #[derive(Debug, Default, Clone)]
28 /// userdel的信息
29 pub struct UDelInfo {
30     pub username: String,
31     pub home: Option<String>,
32 }
33 
34 #[derive(Debug, Default, Clone)]
35 /// usermod的信息
36 pub struct UModInfo {
37     pub username: String,
38     pub groups: Option<Vec<String>>,
39     pub new_comment: Option<String>,
40     pub new_home: Option<String>,
41     pub new_gid: Option<String>,
42     pub new_group: Option<String>,
43     pub new_name: Option<String>,
44     pub new_shell: Option<String>,
45     pub new_uid: Option<String>,
46 }
47 
48 #[derive(Debug, Default, Clone)]
49 /// passwd的信息
50 pub struct PasswdInfo {
51     pub username: String,
52     pub new_password: String,
53 }
54 
55 #[derive(Debug, Default, Clone)]
56 /// groupadd的信息
57 pub struct GAddInfo {
58     pub groupname: String,
59     pub gid: String,
60     pub passwd: Option<String>,
61 }
62 
63 impl GAddInfo {
64     pub fn to_string_group(&self) -> String {
65         let mut passwd = String::from("");
66         if self.passwd.is_some() {
67             passwd = "x".to_string();
68         }
69         format!("{}:{}:{}:\n", self.groupname, passwd, self.gid)
70     }
71 
72     pub fn to_string_gshadow(&self) -> String {
73         let mut passwd = String::from("!");
74         if let Some(gpasswd) = &self.passwd {
75             passwd = gpasswd.clone();
76         }
77 
78         format!("{}:{}::\n", self.groupname, passwd)
79     }
80 }
81 
82 #[derive(Debug, Default, Clone)]
83 /// groupdel的信息
84 pub struct GDelInfo {
85     pub groupname: String,
86 }
87 
88 #[derive(Debug, Default, Clone)]
89 /// groupmod的信息
90 pub struct GModInfo {
91     pub groupname: String,
92     pub gid: String,
93     pub new_groupname: Option<String>,
94     pub new_gid: Option<String>,
95 }
96