diff options
author | bapt <bapt@FreeBSD.org> | 2012-12-27 14:35:06 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2012-12-27 14:35:06 +0000 |
commit | e5fca3f7cb8b50d2f34c01c8e874df7aaa1f6ab3 (patch) | |
tree | 8d6fbf5724f9b3530df151be5830830187891170 /usr.sbin/pw | |
parent | b63557c001769d5ed1338eaa39730ba3ae77245b (diff) | |
download | FreeBSD-src-e5fca3f7cb8b50d2f34c01c8e874df7aaa1f6ab3.zip FreeBSD-src-e5fca3f7cb8b50d2f34c01c8e874df7aaa1f6ab3.tar.gz |
Simplify the code by using the new gr_add function
Diffstat (limited to 'usr.sbin/pw')
-rw-r--r-- | usr.sbin/pw/pw_user.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index 74c1ef9..5577511 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -745,25 +745,19 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) */ if (mode == M_ADD || getarg(args, 'G') != NULL) { - int i, j; + int i; for (i = 0; cnf->groups[i] != NULL; i++) { - char **members; grp = GETGRNAM(cnf->groups[i]); - for (j = 0; grp->gr_mem[j] != NULL; j++) { - if (!strcmp(grp->gr_mem[j], pwd->pw_name)) - break; - } - if (grp->gr_mem[j] != NULL) /* user already member of group */ + grp = gr_add(grp, pwd->pw_name); + /* + * grp can only be NULL in 2 cases: + * - the new member is already a member + * - a problem with memory occurs + * in both cases we want to skip now. + */ + if (grp == NULL) continue; - - members = malloc(sizeof(char *) * (j + 2)); - memcpy(members, grp->gr_mem, j * sizeof(*members)); - - members[j] = pwd->pw_name; - members[j+1] = NULL; - grp->gr_mem = members; chggrent(cnf->groups[i], grp); - free(members); } } |