summaryrefslogtreecommitdiffstats
path: root/pw
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2012-12-27 14:35:06 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2012-12-27 14:35:06 +0000
commita76b46580eef36f7765bae26ec8a9a9f0fea4408 (patch)
tree3280841450cabb1e8d0bc858bcc7eedc451fe16a /pw
parentac1681ea5c7980246ca789137e852441e10207d5 (diff)
downloadpw-darwin-a76b46580eef36f7765bae26ec8a9a9f0fea4408.tar.gz
pw-darwin-a76b46580eef36f7765bae26ec8a9a9f0fea4408.tar.zst
pw-darwin-a76b46580eef36f7765bae26ec8a9a9f0fea4408.zip
Simplify the code by using the new gr_add function
Diffstat (limited to 'pw')
-rw-r--r--pw/pw_user.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c
index 74c1ef9..5577511 100644
--- a/pw/pw_user.c
+++ b/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);
}
}