aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--loginutils/Config.src84
-rw-r--r--loginutils/deluser.c54
2 files changed, 68 insertions, 70 deletions
diff --git a/loginutils/Config.src b/loginutils/Config.src
index 5d497c4dc..8158bce74 100644
--- a/loginutils/Config.src
+++ b/loginutils/Config.src
@@ -93,41 +93,18 @@ config USE_BB_CRYPT_SHA
93 With this option off, login will fail password check for any 93 With this option off, login will fail password check for any
94 user which has password encrypted with these algorithms. 94 user which has password encrypted with these algorithms.
95 95
96config ADDGROUP 96config ADDUSER
97 bool "addgroup" 97 bool "adduser"
98 default y 98 default y
99 help 99 help
100 Utility for creating a new group account. 100 Utility for creating a new user account.
101 101
102config FEATURE_ADDGROUP_LONG_OPTIONS 102config FEATURE_ADDUSER_LONG_OPTIONS
103 bool "Enable long options" 103 bool "Enable long options"
104 default y 104 default y
105 depends on ADDGROUP && LONG_OPTS 105 depends on ADDUSER && LONG_OPTS
106 help
107 Support long options for the addgroup applet.
108
109config FEATURE_ADDUSER_TO_GROUP
110 bool "Support for adding users to groups"
111 default y
112 depends on ADDGROUP
113 help
114 If called with two non-option arguments,
115 addgroup will add an existing user to an
116 existing group.
117
118config DELGROUP
119 bool "delgroup"
120 default y
121 help
122 Utility for deleting a group account.
123
124config FEATURE_DEL_USER_FROM_GROUP
125 bool "Support for removing users from groups"
126 default y
127 depends on DELGROUP
128 help 106 help
129 If called with two non-option arguments, deluser 107 Support long options for the adduser applet.
130 or delgroup will remove an user from a specified group.
131 108
132config FEATURE_CHECK_NAMES 109config FEATURE_CHECK_NAMES
133 bool "Enable sanity check on user/group names in adduser and addgroup" 110 bool "Enable sanity check on user/group names in adduser and addgroup"
@@ -141,19 +118,6 @@ config FEATURE_CHECK_NAMES
141 For compatibility with Samba machine accounts "$" is also supported 118 For compatibility with Samba machine accounts "$" is also supported
142 at the end of the user or group name. 119 at the end of the user or group name.
143 120
144config ADDUSER
145 bool "adduser"
146 default y
147 help
148 Utility for creating a new user account.
149
150config FEATURE_ADDUSER_LONG_OPTIONS
151 bool "Enable long options"
152 default y
153 depends on ADDUSER && LONG_OPTS
154 help
155 Support long options for the adduser applet.
156
157config FIRST_SYSTEM_ID 121config FIRST_SYSTEM_ID
158 int "First valid system uid or gid for adduser and addgroup" 122 int "First valid system uid or gid for adduser and addgroup"
159 depends on ADDUSER || ADDGROUP 123 depends on ADDUSER || ADDGROUP
@@ -170,12 +134,48 @@ config LAST_SYSTEM_ID
170 help 134 help
171 Last valid system uid or gid for adduser and addgroup 135 Last valid system uid or gid for adduser and addgroup
172 136
137config ADDGROUP
138 bool "addgroup"
139 default y
140 help
141 Utility for creating a new group account.
142
143config FEATURE_ADDGROUP_LONG_OPTIONS
144 bool "Enable long options"
145 default y
146 depends on ADDGROUP && LONG_OPTS
147 help
148 Support long options for the addgroup applet.
149
150config FEATURE_ADDUSER_TO_GROUP
151 bool "Support for adding users to groups"
152 default y
153 depends on ADDGROUP
154 help
155 If called with two non-option arguments,
156 addgroup will add an existing user to an
157 existing group.
158
173config DELUSER 159config DELUSER
174 bool "deluser" 160 bool "deluser"
175 default y 161 default y
176 help 162 help
177 Utility for deleting a user account. 163 Utility for deleting a user account.
178 164
165config DELGROUP
166 bool "delgroup"
167 default y
168 help
169 Utility for deleting a group account.
170
171config FEATURE_DEL_USER_FROM_GROUP
172 bool "Support for removing users from groups"
173 default y
174 depends on DELGROUP
175 help
176 If called with two non-option arguments, deluser
177 or delgroup will remove an user from a specified group.
178
179config GETTY 179config GETTY
180 bool "getty" 180 bool "getty"
181 default y 181 default y
diff --git a/loginutils/deluser.c b/loginutils/deluser.c
index e234d6678..65817b943 100644
--- a/loginutils/deluser.c
+++ b/loginutils/deluser.c
@@ -6,25 +6,18 @@
6 * Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org> 6 * Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org>
7 * Copyright (C) 2007 by Tito Ragusa <farmatito@tiscali.it> 7 * Copyright (C) 2007 by Tito Ragusa <farmatito@tiscali.it>
8 * 8 *
9 * Licensed under GPLv2, see file LICENSE in this source tree. 9 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
10 * 10 *
11 */ 11 */
12#include "libbb.h" 12#include "libbb.h"
13 13
14static int del_line_matching(char **args, const char *filename)
15{
16 if (ENABLE_FEATURE_DEL_USER_FROM_GROUP && args[2]) {
17 return update_passwd(filename, args[2], NULL, args[1]);
18 }
19 return update_passwd(filename, args[1], NULL, NULL);
20}
21
22int deluser_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 14int deluser_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
23int deluser_main(int argc, char **argv) 15int deluser_main(int argc, char **argv)
24{ 16{
25 if (argc != 2 17 if (argc != 2
26 && (!ENABLE_FEATURE_DEL_USER_FROM_GROUP 18 && (!ENABLE_FEATURE_DEL_USER_FROM_GROUP
27 || (applet_name[3] != 'g' || argc != 3)) 19 || applet_name[3] != 'g'
20 || argc != 3)
28 ) { 21 ) {
29 bb_show_usage(); 22 bb_show_usage();
30 } 23 }
@@ -32,25 +25,30 @@ int deluser_main(int argc, char **argv)
32 if (geteuid()) 25 if (geteuid())
33 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 26 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
34 27
35 if ((ENABLE_FEATURE_DEL_USER_FROM_GROUP && argc != 3) 28 if (ENABLE_DELUSER && applet_name[3] == 'u') {
36 || ENABLE_DELUSER 29 /* deluser USER */
37 || (ENABLE_DELGROUP && ENABLE_DESKTOP) 30 if (update_passwd(bb_path_passwd_file, argv[1], NULL, NULL) < 0)
38 ) { 31 return EXIT_FAILURE;
39 if (ENABLE_DELUSER 32 if (ENABLE_FEATURE_SHADOWPASSWDS)
40 && (!ENABLE_DELGROUP || applet_name[3] == 'u') 33 if (update_passwd(bb_path_shadow_file, argv[1], NULL, NULL) < 0)
41 ) {
42 if (del_line_matching(argv, bb_path_passwd_file) < 0)
43 return EXIT_FAILURE; 34 return EXIT_FAILURE;
44 if (ENABLE_FEATURE_SHADOWPASSWDS) { 35 } else if (ENABLE_DELGROUP) {
45 del_line_matching(argv, bb_path_shadow_file); 36 /* delgroup ... */
46 } 37 if (!ENABLE_FEATURE_DEL_USER_FROM_GROUP || argc != 3) {
47 } else if (ENABLE_DESKTOP && ENABLE_DELGROUP && getpwnam(argv[1])) 38 /* delgroup GROUP */
48 bb_error_msg_and_die("can't remove primary group of user %s", argv[1]); 39 if (update_passwd(bb_path_group_file, argv[1], NULL, NULL) < 0)
49 } 40 return EXIT_FAILURE;
50 if (del_line_matching(argv, bb_path_group_file) < 0) 41 if (ENABLE_FEATURE_SHADOWPASSWDS)
51 return EXIT_FAILURE; 42 if (update_passwd(bb_path_gshadow_file, argv[1], NULL, NULL) < 0)
52 if (ENABLE_FEATURE_SHADOWPASSWDS) { 43 return EXIT_FAILURE;
53 del_line_matching(argv, bb_path_gshadow_file); 44 } else {
45 /* delgroup USER GROUP */
46 if (update_passwd(bb_path_group_file, argv[2], NULL, argv[1]) < 0)
47 return EXIT_FAILURE;
48 if (ENABLE_FEATURE_SHADOWPASSWDS)
49 if (update_passwd(bb_path_gshadow_file, argv[2], NULL, argv[1]) < 0)
50 return EXIT_FAILURE;
51 }
54 } 52 }
55 return EXIT_SUCCESS; 53 return EXIT_SUCCESS;
56} 54}