- if ((passwd = bb_wfopen(filename, "r"))) {
- // Remove pointless const.
- xstat((char *)filename, &statbuf);
- buffer = (char *) xmalloc(statbuf.st_size * sizeof(char));
- fread(buffer, statbuf.st_size, sizeof(char), passwd);
- fclose(passwd);
- /* find the user to remove */
- b = boundary(buffer, login);
- if (b.stop != 0) {
- /* write the file w/o the user */
- if ((passwd = bb_wfopen(filename, "w"))) {
- fwrite(buffer, (b.start - 1), sizeof(char), passwd);
- fwrite(&buffer[b.stop], (statbuf.st_size - b.stop), sizeof(char), passwd);
- fclose(passwd);
+ if (geteuid())
+ bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
+
+ if ((ENABLE_FEATURE_DEL_USER_FROM_GROUP && argc != 3)
+ || ENABLE_DELUSER
+ || (ENABLE_DELGROUP && ENABLE_DESKTOP)
+ ) {
+ if (ENABLE_DELUSER
+ && (!ENABLE_DELGROUP || applet_name[3] == 'u')
+ ) {
+ if (del_line_matching(argv, bb_path_passwd_file) < 0)
+ return EXIT_FAILURE;
+ if (ENABLE_FEATURE_SHADOWPASSWDS) {
+ del_line_matching(argv, bb_path_shadow_file);