summaryrefslogtreecommitdiffstats
path: root/pw/pw_group.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-06-07 19:59:01 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-06-07 19:59:01 +0000
commit068c2f64c08c71d084c16d066a0fb3802e26b7a9 (patch)
tree34933cae6046bdcfaa9e44dee7b5e562a6ff9d03 /pw/pw_group.c
parente3bd6749869f3f1649662b39609bbea8d2141354 (diff)
downloadpw-darwin-068c2f64c08c71d084c16d066a0fb3802e26b7a9.tar.gz
pw-darwin-068c2f64c08c71d084c16d066a0fb3802e26b7a9.tar.zst
pw-darwin-068c2f64c08c71d084c16d066a0fb3802e26b7a9.zip
Fix duplicate checking
Diffstat (limited to 'pw/pw_group.c')
-rw-r--r--pw/pw_group.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/pw/pw_group.c b/pw/pw_group.c
index f95d263..b9cce0d 100644
--- a/pw/pw_group.c
+++ b/pw/pw_group.c
@@ -45,7 +45,7 @@ static struct passwd *lookup_pwent(const char *user);
static void delete_members(char ***members, int *grmembers, int *i,
struct carg *arg, struct group *grp);
static int print_group(struct group * grp);
-static gid_t gr_gidpolicy(struct userconf * cnf, struct cargs * args);
+static gid_t gr_gidpolicy(struct userconf * cnf, long id);
int
pw_group(int mode, char *name, long id, struct cargs * args)
@@ -73,7 +73,7 @@ pw_group(int mode, char *name, long id, struct cargs * args)
* next gid to stdout
*/
if (mode == M_NEXT) {
- gid_t next = gr_gidpolicy(cnf, args);
+ gid_t next = gr_gidpolicy(cnf, id);
if (getarg(args, 'q'))
return next;
printf("%u\n", next);
@@ -145,7 +145,7 @@ pw_group(int mode, char *name, long id, struct cargs * args)
grp = &fakegroup;
grp->gr_name = pw_checkname(name, 0);
grp->gr_passwd = "*";
- grp->gr_gid = gr_gidpolicy(cnf, args);
+ grp->gr_gid = gr_gidpolicy(cnf, id);
grp->gr_mem = members;
}
@@ -336,19 +336,18 @@ delete_members(char ***members, int *grmembers, int *i, struct carg *arg,
static gid_t
-gr_gidpolicy(struct userconf * cnf, struct cargs * args)
+gr_gidpolicy(struct userconf * cnf, long id)
{
struct group *grp;
gid_t gid = (gid_t) - 1;
- struct carg *a_gid = getarg(args, 'g');
/*
* Check the given gid, if any
*/
- if (a_gid != NULL) {
- gid = (gid_t) atol(a_gid->val);
+ if (id > 0) {
+ gid = (gid_t) id;
- if ((grp = GETGRGID(gid)) != NULL && getarg(args, 'o') == NULL)
+ if ((grp = GETGRGID(gid)) != NULL && conf.checkduplicate)
errx(EX_DATAERR, "gid `%u' has already been allocated", grp->gr_gid);
} else {
struct bitmap bm;