summaryrefslogtreecommitdiffstats
path: root/pw/pw_user.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-07-11 23:56:55 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-07-11 23:56:55 +0000
commit53d815d2b67ba1daf3d088e6049c75e9134228d2 (patch)
tree0e926a827ac73dfae7ddec14112afaebd49a2b18 /pw/pw_user.c
parenta715bff28feb804ba62f2da0e310734d377e6f78 (diff)
downloadpw-darwin-53d815d2b67ba1daf3d088e6049c75e9134228d2.tar.gz
pw-darwin-53d815d2b67ba1daf3d088e6049c75e9134228d2.tar.zst
pw-darwin-53d815d2b67ba1daf3d088e6049c75e9134228d2.zip
Fix regression: ensure when try to create the group and the user with the same
id if possible and nothing in particular was specified
Diffstat (limited to 'pw/pw_user.c')
-rw-r--r--pw/pw_user.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c
index f1dae74..315af39 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -875,7 +875,7 @@ pw_gidpolicy(struct cargs * args, char *nam, gid_t prefer)
gid = grp->gr_gid; /* Already created? Use it anyway... */
} else {
struct cargs grpargs;
- char tmp[32];
+ gid_t grid = -1;
LIST_INIT(&grpargs);
@@ -888,23 +888,15 @@ pw_gidpolicy(struct cargs * args, char *nam, gid_t prefer)
* user's name dups an existing group, then the group add
* function will happily handle that case for us and exit.
*/
- if (GETGRGID(prefer) == NULL) {
- snprintf(tmp, sizeof(tmp), "%u", prefer);
- addarg(&grpargs, 'g', tmp);
- }
+ if (GETGRGID(prefer) == NULL)
+ grid = prefer;
if (conf.dryrun) {
gid = pw_groupnext(cnf, true);
} else {
- pw_group(M_ADD, nam, -1, &grpargs);
+ pw_group(M_ADD, nam, grid, &grpargs);
if ((grp = GETGRNAM(nam)) != NULL)
gid = grp->gr_gid;
}
- a_gid = LIST_FIRST(&grpargs);
- while (a_gid != NULL) {
- struct carg *t = LIST_NEXT(a_gid, list);
- LIST_REMOVE(a_gid, list);
- a_gid = t;
- }
}
ENDGRENT();
return gid;