Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/loginutils/deluser.c

    r3232 r3621  
    88 *
    99 * Licensed under GPLv2, see file LICENSE in this source tree.
    10  *
    1110 */
     11//config:config DELUSER
     12//config:   bool "deluser"
     13//config:   default y
     14//config:   help
     15//config:     Utility for deleting a user account.
     16//config:
     17//config:config DELGROUP
     18//config:   bool "delgroup"
     19//config:   default y
     20//config:   help
     21//config:     Utility for deleting a group account.
     22//config:
     23//config:config FEATURE_DEL_USER_FROM_GROUP
     24//config:   bool "Support for removing users from groups"
     25//config:   default y
     26//config:   depends on DELGROUP
     27//config:   help
     28//config:     If called with two non-option arguments, deluser
     29//config:     or delgroup will remove an user from a specified group.
     30
     31//applet:IF_DELUSER(APPLET(deluser, BB_DIR_USR_SBIN, BB_SUID_DROP))
     32//applet:IF_DELGROUP(APPLET_ODDNAME(delgroup, deluser, BB_DIR_USR_SBIN, BB_SUID_DROP, delgroup))
     33
     34//kbuild:lib-$(CONFIG_DELUSER) += deluser.o
     35//kbuild:lib-$(CONFIG_DELGROUP) += deluser.o
    1236
    1337//usage:#define deluser_trivial_usage
    14 //usage:       "USER"
     38//usage:       IF_LONG_OPTS("[--remove-home] ") "USER"
    1539//usage:#define deluser_full_usage "\n\n"
    1640//usage:       "Delete USER from the system"
     41//  --remove-home is self-explanatory enough to put it in --help
    1742
    1843//usage:#define delgroup_trivial_usage
     
    3863    int do_deluser = (ENABLE_DELUSER && (!ENABLE_DELGROUP || applet_name[3] == 'u'));
    3964
     65#if !ENABLE_LONG_OPTS
     66    const int opt_delhome = 0;
     67#else
     68    int opt_delhome = 0;
     69    if (do_deluser) {
     70        applet_long_options =
     71            "remove-home\0" No_argument "\xff";
     72        opt_delhome = getopt32(argv, "");
     73        argv += opt_delhome;
     74        argc -= opt_delhome;
     75    }
     76#endif
     77
    4078    if (geteuid() != 0)
    4179        bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
     
    5694        if (do_deluser) {
    5795            /* "deluser USER" */
    58             xgetpwnam(name); /* bail out if USER is wrong */
     96            struct passwd *pw;
     97
     98            pw = xgetpwnam(name); /* bail out if USER is wrong */
    5999            pfile = bb_path_passwd_file;
    60100            if (ENABLE_FEATURE_SHADOWPASSWDS)
    61101                sfile = bb_path_shadow_file;
     102            if (opt_delhome)
     103                remove_file(pw->pw_dir, FILEUTILS_RECUR);
    62104        } else {
    63105            struct group *gr;
     
    74116                /* "delgroup GROUP" */
    75117                struct passwd *pw;
    76                 struct passwd pwent;
    77118                /* Check if the group is in use */
    78 #define passwd_buf bb_common_bufsiz1
    79                 while (!getpwent_r(&pwent, passwd_buf, sizeof(passwd_buf), &pw)) {
    80                     if (pwent.pw_gid == gr->gr_gid)
    81                         bb_error_msg_and_die("'%s' still has '%s' as their primary group!", pwent.pw_name, name);
     119                while ((pw = getpwent()) != NULL) {
     120                    if (pw->pw_gid == gr->gr_gid)
     121                        bb_error_msg_and_die("'%s' still has '%s' as their primary group!",
     122                            pw->pw_name, name);
    82123                }
    83124                //endpwent();
     
    98139        } while (ENABLE_FEATURE_SHADOWPASSWDS && pfile);
    99140
    100         if (ENABLE_DELGROUP && do_deluser > 0) {
    101             /* "deluser USER" also should try to delete
    102              * same-named group. IOW: do "delgroup USER"
    103              */
     141        if (do_deluser > 0) {
     142            /* Delete user from all groups */
     143            if (update_passwd(bb_path_group_file, NULL, NULL, name) == -1)
     144                return EXIT_FAILURE;
     145
     146            if (ENABLE_DELGROUP) {
     147                /* "deluser USER" also should try to delete
     148                 * same-named group. IOW: do "delgroup USER"
     149                 */
    104150// On debian deluser is a perl script that calls userdel.
    105151// From man userdel:
    106152//  If USERGROUPS_ENAB is defined to yes in /etc/login.defs, userdel will
    107153//  delete the group with the same name as the user.
    108             do_deluser = -1;
    109             goto do_delgroup;
     154                do_deluser = -1;
     155                goto do_delgroup;
     156            }
    110157        }
    111158        return EXIT_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.