aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-03-12 15:30:46 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2015-03-12 15:30:46 +0100
commit936c8809caea5705e26e5d7e06ea3895c28fffd8 (patch)
tree2ac8561231d4d5da36213e7b2b25ce70319c9c75
parent748fb60f274b1ba40aa6ed4c4582185aae8f68f7 (diff)
downloadbusybox-w32-936c8809caea5705e26e5d7e06ea3895c28fffd8.tar.gz
busybox-w32-936c8809caea5705e26e5d7e06ea3895c28fffd8.tar.bz2
busybox-w32-936c8809caea5705e26e5d7e06ea3895c28fffd8.zip
deluser: also remove user from /etc/group
function old new delta update_passwd 1270 1470 +200 deluser_main 310 332 +22 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/update_passwd.c38
-rw-r--r--loginutils/deluser.c18
2 files changed, 48 insertions, 8 deletions
diff --git a/libbb/update_passwd.c b/libbb/update_passwd.c
index a30af6f72..dc26ebd1d 100644
--- a/libbb/update_passwd.c
+++ b/libbb/update_passwd.c
@@ -62,6 +62,8 @@ static void check_selinux_update_passwd(const char *username)
62 only if CONFIG_PASSWD=y and applet_name[0] == 'p' like in passwd 62 only if CONFIG_PASSWD=y and applet_name[0] == 'p' like in passwd
63 or if CONFIG_CHPASSWD=y and applet_name[0] == 'c' like in chpasswd 63 or if CONFIG_CHPASSWD=y and applet_name[0] == 'c' like in chpasswd
64 64
65 8) delete a user from all groups: update_passwd(FILE, NULL, NULL, MEMBER)
66
65 This function does not validate the arguments fed to it 67 This function does not validate the arguments fed to it
66 so the calling program should take care of that. 68 so the calling program should take care of that.
67 69
@@ -99,12 +101,13 @@ int FAST_FUNC update_passwd(const char *filename,
99 if (filename == NULL) 101 if (filename == NULL)
100 return ret; 102 return ret;
101 103
102 check_selinux_update_passwd(name); 104 if (name)
105 check_selinux_update_passwd(name);
103 106
104 /* New passwd file, "/etc/passwd+" for now */ 107 /* New passwd file, "/etc/passwd+" for now */
105 fnamesfx = xasprintf("%s+", filename); 108 fnamesfx = xasprintf("%s+", filename);
106 sfx_char = &fnamesfx[strlen(fnamesfx)-1]; 109 sfx_char = &fnamesfx[strlen(fnamesfx)-1];
107 name_colon = xasprintf("%s:", name); 110 name_colon = xasprintf("%s:", name ? name : "");
108 user_len = strlen(name_colon); 111 user_len = strlen(name_colon);
109 112
110 if (shadow) 113 if (shadow)
@@ -167,6 +170,37 @@ int FAST_FUNC update_passwd(const char *filename,
167 line = xmalloc_fgetline(old_fp); 170 line = xmalloc_fgetline(old_fp);
168 if (!line) /* EOF/error */ 171 if (!line) /* EOF/error */
169 break; 172 break;
173
174 if (!name && member) {
175 /* Delete member from all groups */
176 /* line is "GROUP:PASSWD:[member1[,member2]...]" */
177 unsigned member_len = strlen(member);
178 char *list = strrchr(line, ':');
179 while (list) {
180 list++;
181 next_list_element:
182 if (strncmp(list, member, member_len) == 0) {
183 char c;
184 changed_lines++;
185 c = list[member_len];
186 if (c == '\0') {
187 if (list[-1] == ',')
188 list--;
189 *list = '\0';
190 break;
191 }
192 if (c == ',') {
193 overlapping_strcpy(list, list + member_len + 1);
194 goto next_list_element;
195 }
196 changed_lines--;
197 }
198 list = strchr(list, ',');
199 }
200 fprintf(new_fp, "%s\n", line);
201 goto next;
202 }
203
170 if (strncmp(name_colon, line, user_len) != 0) { 204 if (strncmp(name_colon, line, user_len) != 0) {
171 fprintf(new_fp, "%s\n", line); 205 fprintf(new_fp, "%s\n", line);
172 goto next; 206 goto next;
diff --git a/loginutils/deluser.c b/loginutils/deluser.c
index 01a9386bc..110cd6310 100644
--- a/loginutils/deluser.c
+++ b/loginutils/deluser.c
@@ -114,16 +114,22 @@ int deluser_main(int argc, char **argv)
114 } 114 }
115 } while (ENABLE_FEATURE_SHADOWPASSWDS && pfile); 115 } while (ENABLE_FEATURE_SHADOWPASSWDS && pfile);
116 116
117 if (ENABLE_DELGROUP && do_deluser > 0) { 117 if (do_deluser > 0) {
118 /* "deluser USER" also should try to delete 118 /* Delete user from all groups */
119 * same-named group. IOW: do "delgroup USER" 119 if (update_passwd(bb_path_group_file, NULL, NULL, name) == -1)
120 */ 120 return EXIT_FAILURE;
121
122 if (ENABLE_DELGROUP) {
123 /* "deluser USER" also should try to delete
124 * same-named group. IOW: do "delgroup USER"
125 */
121// On debian deluser is a perl script that calls userdel. 126// On debian deluser is a perl script that calls userdel.
122// From man userdel: 127// From man userdel:
123// If USERGROUPS_ENAB is defined to yes in /etc/login.defs, userdel will 128// If USERGROUPS_ENAB is defined to yes in /etc/login.defs, userdel will
124// delete the group with the same name as the user. 129// delete the group with the same name as the user.
125 do_deluser = -1; 130 do_deluser = -1;
126 goto do_delgroup; 131 goto do_delgroup;
132 }
127 } 133 }
128 return EXIT_SUCCESS; 134 return EXIT_SUCCESS;
129 } 135 }