summaryrefslogtreecommitdiffstats
path: root/pw/pw_user.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-07-11 16:58:47 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-07-11 16:58:47 +0000
commit5809c6a767c19d9ce6cca88efbcd54a6f19b5ce8 (patch)
treecb39d1446d4c98deea9d8fcbfee11bd28219e569 /pw/pw_user.c
parent6b05c812aab670bc774bcc5dcc38cfc87a401ab6 (diff)
downloadpw-darwin-5809c6a767c19d9ce6cca88efbcd54a6f19b5ce8.tar.gz
pw-darwin-5809c6a767c19d9ce6cca88efbcd54a6f19b5ce8.tar.zst
pw-darwin-5809c6a767c19d9ce6cca88efbcd54a6f19b5ce8.zip
Separate usernext/groupnext from the main functions
Diffstat (limited to 'pw/pw_user.c')
-rw-r--r--pw/pw_user.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c
index e123786..298aeab 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -148,6 +148,20 @@ set_passwd(struct passwd *pwd, bool update)
return (1);
}
+int
+pw_usernext(struct userconf *cnf, bool quiet)
+{
+ uid_t next = pw_uidpolicy(cnf, -1);
+
+ if (quiet)
+ return (next);
+
+ printf("%u:", next);
+ pw_groupnext(cnf, quiet);
+
+ return (EXIT_SUCCESS);
+}
+
/*-
* -C config configuration file
* -q quiet operation
@@ -216,19 +230,8 @@ pw_user(int mode, char *name, long id, struct cargs * args)
cnf = conf.userconf;
- /*
- * With M_NEXT, we only need to return the
- * next uid to stdout
- */
if (mode == M_NEXT)
- {
- uid_t next = pw_uidpolicy(cnf, id);
- if (getarg(args, 'q'))
- return next;
- printf("%u:", next);
- pw_group(mode, name, -1, args);
- return EXIT_SUCCESS;
- }
+ return (pw_usernext(cnf, getarg(args, 'q') != NULL));
/*
* We can do all of the common legwork here
@@ -845,11 +848,8 @@ pw_gidpolicy(struct cargs * args, char *nam, gid_t prefer)
addarg(&grpargs, 'g', tmp);
}
if (conf.dryrun) {
- addarg(&grpargs, 'q', NULL);
- gid = pw_group(M_NEXT, nam, -1, &grpargs);
- }
- else
- {
+ gid = pw_groupnext(cnf, true);
+ } else {
pw_group(M_ADD, nam, -1, &grpargs);
if ((grp = GETGRNAM(nam)) != NULL)
gid = grp->gr_gid;