diff options
author | Neel Natu <neel@FreeBSD.org> | 2013-01-04 19:28:32 +0000 |
---|---|---|
committer | Neel Natu <neel@FreeBSD.org> | 2013-01-04 19:28:32 +0000 |
commit | 5946fff02d2b2e5d1fd3b8fa3634c3f5fbaf7e0b (patch) | |
tree | 505256c5f6496f779a54c7842e16886f87803e08 /pw/pw_user.c | |
parent | ea570e4ea7dc6c03c87457846a4509c32a8aa689 (diff) | |
parent | f5d6684c8d9c572b686c5274162e3b17ae77091f (diff) | |
download | pw-darwin-5946fff02d2b2e5d1fd3b8fa3634c3f5fbaf7e0b.tar.gz pw-darwin-5946fff02d2b2e5d1fd3b8fa3634c3f5fbaf7e0b.tar.zst pw-darwin-5946fff02d2b2e5d1fd3b8fa3634c3f5fbaf7e0b.zip |
IFC @ r244983.
Diffstat (limited to 'pw/pw_user.c')
-rw-r--r-- | pw/pw_user.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c index abf1c35..5577511 100644 --- a/pw/pw_user.c +++ b/pw/pw_user.c @@ -394,7 +394,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) /* * Remove crontabs */ - sprintf(file, "/var/cron/tabs/%s", pwd->pw_name); + snprintf(file, sizeof(file), "/var/cron/tabs/%s", pwd->pw_name); if (access(file, F_OK) == 0) { sprintf(file, "crontab -u %s -r", pwd->pw_name); system(file); @@ -745,24 +745,18 @@ 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++) { 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; - - if (j == 0) - grp->gr_mem = NULL; - - grp->gr_mem = reallocf(grp->gr_mem, sizeof(*grp->gr_mem) * - (j + 2)); - - grp->gr_mem[j] = pwd->pw_name; - grp->gr_mem[j+1] = NULL; chggrent(cnf->groups[i], grp); } } |