diff options
author | Harald Becker <ralda@gmx.de> | 2010-09-22 14:50:15 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-22 18:03:29 +0200 |
commit | 361b1a6884bc9d4f5cece22d0eb9fe5eae17bda7 (patch) | |
tree | 7657b775df392a70b8dc1ea2bffddef112f71b0d | |
parent | 0e13b4019c3d05933ba8d37357023bfcd82e8106 (diff) | |
download | busybox-w32-361b1a6884bc9d4f5cece22d0eb9fe5eae17bda7.tar.gz busybox-w32-361b1a6884bc9d4f5cece22d0eb9fe5eae17bda7.tar.bz2 busybox-w32-361b1a6884bc9d4f5cece22d0eb9fe5eae17bda7.zip |
deluser: make it simpler, fix inability to delete user from group
Also makes menuconfig order more sensible
Signed-off-by: Harald Becker <ralda@gmx.de>
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r-- | loginutils/Config.src | 84 | ||||
-rw-r--r-- | loginutils/deluser.c | 54 |
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 | ||
96 | config ADDGROUP | 96 | config 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 | ||
102 | config FEATURE_ADDGROUP_LONG_OPTIONS | 102 | config 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 | |||
109 | config 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 | |||
118 | config DELGROUP | ||
119 | bool "delgroup" | ||
120 | default y | ||
121 | help | ||
122 | Utility for deleting a group account. | ||
123 | |||
124 | config 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 | ||
132 | config FEATURE_CHECK_NAMES | 109 | config 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 | ||
144 | config ADDUSER | ||
145 | bool "adduser" | ||
146 | default y | ||
147 | help | ||
148 | Utility for creating a new user account. | ||
149 | |||
150 | config 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 | |||
157 | config FIRST_SYSTEM_ID | 121 | config 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 | ||
137 | config ADDGROUP | ||
138 | bool "addgroup" | ||
139 | default y | ||
140 | help | ||
141 | Utility for creating a new group account. | ||
142 | |||
143 | config 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 | |||
150 | config 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 | |||
173 | config DELUSER | 159 | config 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 | ||
165 | config DELGROUP | ||
166 | bool "delgroup" | ||
167 | default y | ||
168 | help | ||
169 | Utility for deleting a group account. | ||
170 | |||
171 | config 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 | |||
179 | config GETTY | 179 | config 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 | ||
14 | static 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 | |||
22 | int deluser_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 14 | int deluser_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
23 | int deluser_main(int argc, char **argv) | 15 | int 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 | } |