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/libbb/update_passwd.c

    r2725 r3621  
    6363    or if CONFIG_CHPASSWD=y and applet_name[0] == 'c' like in chpasswd
    6464
     65 8) delete a user from all groups: update_passwd(FILE, NULL, NULL, MEMBER)
     66
    6567 This function does not validate the arguments fed to it
    6668 so the calling program should take care of that.
     
    8385    char *sfx_char;
    8486    char *name_colon;
    85     unsigned user_len;
    8687    int old_fd;
    8788    int new_fd;
     
    100101        return ret;
    101102
    102     check_selinux_update_passwd(name);
     103    if (name)
     104        check_selinux_update_passwd(name);
    103105
    104106    /* New passwd file, "/etc/passwd+" for now */
    105107    fnamesfx = xasprintf("%s+", filename);
    106108    sfx_char = &fnamesfx[strlen(fnamesfx)-1];
    107     name_colon = xasprintf("%s:", name);
    108     user_len = strlen(name_colon);
     109    name_colon = xasprintf("%s:", name ? name : "");
    109110
    110111    if (shadow)
     
    168169        if (!line) /* EOF/error */
    169170            break;
    170         if (strncmp(name_colon, line, user_len) != 0) {
     171
     172        if (!name && member) {
     173            /* Delete member from all groups */
     174            /* line is "GROUP:PASSWD:[member1[,member2]...]" */
     175            unsigned member_len = strlen(member);
     176            char *list = strrchr(line, ':');
     177            while (list) {
     178                list++;
     179 next_list_element:
     180                if (is_prefixed_with(list, member)) {
     181                    char c;
     182                    changed_lines++;
     183                    c = list[member_len];
     184                    if (c == '\0') {
     185                        if (list[-1] == ',')
     186                            list--;
     187                        *list = '\0';
     188                        break;
     189                    }
     190                    if (c == ',') {
     191                        overlapping_strcpy(list, list + member_len + 1);
     192                        goto next_list_element;
     193                    }
     194                    changed_lines--;
     195                }
     196                list = strchr(list, ',');
     197            }
    171198            fprintf(new_fp, "%s\n", line);
    172199            goto next;
    173200        }
    174201
     202        cp = is_prefixed_with(line, name_colon);
     203        if (!cp) {
     204            fprintf(new_fp, "%s\n", line);
     205            goto next;
     206        }
     207
    175208        /* We have a match with "name:"... */
    176         cp = line + user_len; /* move past name: */
     209        /* cp points past "name:" */
    177210
    178211#if ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP
Note: See TracChangeset for help on using the changeset viewer.