diff options
author | bapt <bapt@FreeBSD.org> | 2015-07-11 16:58:47 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-07-11 16:58:47 +0000 |
commit | 032c1600ece5fbb82f126701974fc66146ebbf24 (patch) | |
tree | aded7ed05a9bcc807780c877d3ba659f17dc1d0d | |
parent | b9cbaea559a53c209d303c50a378ded9f2c3d1b8 (diff) | |
download | FreeBSD-src-032c1600ece5fbb82f126701974fc66146ebbf24.zip FreeBSD-src-032c1600ece5fbb82f126701974fc66146ebbf24.tar.gz |
Separate usernext/groupnext from the main functions
-rw-r--r-- | usr.sbin/pw/pw.h | 2 | ||||
-rw-r--r-- | usr.sbin/pw/pw_group.c | 27 | ||||
-rw-r--r-- | usr.sbin/pw/pw_user.c | 34 |
3 files changed, 34 insertions, 29 deletions
diff --git a/usr.sbin/pw/pw.h b/usr.sbin/pw/pw.h index 6239004..ed3b715 100644 --- a/usr.sbin/pw/pw.h +++ b/usr.sbin/pw/pw.h @@ -83,7 +83,9 @@ struct carg *addarg(struct cargs * _args, int ch, char *argstr); struct carg *getarg(struct cargs * _args, int ch); int pw_user(int mode, char *name, long id, struct cargs * _args); +int pw_usernext(struct userconf *cnf, bool quiet); int pw_group(int mode, char *name, long id, struct cargs * _args); +int pw_groupnext(struct userconf *cnf, bool quiet); char *pw_checkname(char *name, int gecos); int addnispwent(const char *path, struct passwd *pwd); diff --git a/usr.sbin/pw/pw_group.c b/usr.sbin/pw/pw_group.c index c664ef5..28a7c94 100644 --- a/usr.sbin/pw/pw_group.c +++ b/usr.sbin/pw/pw_group.c @@ -92,6 +92,18 @@ set_passwd(struct group *grp, bool update) } int +pw_groupnext(struct userconf *cnf, bool quiet) +{ + gid_t next = gr_gidpolicy(cnf, -1); + + if (quiet) + return (next); + printf("%u\n", next); + + return (EXIT_SUCCESS); +} + +int pw_group(int mode, char *name, long id, struct cargs * args) { int rc; @@ -109,21 +121,12 @@ pw_group(int mode, char *name, long id, struct cargs * args) NULL }; + if (mode == M_NEXT) + return (pw_groupnext(cnf, getarg(args, 'q') != NULL)); + if (mode == M_LOCK || mode == M_UNLOCK) errx(EX_USAGE, "'lock' command is not available for groups"); - /* - * With M_NEXT, we only need to return the - * next gid to stdout - */ - if (mode == M_NEXT) { - gid_t next = gr_gidpolicy(cnf, id); - if (getarg(args, 'q')) - return next; - printf("%u\n", next); - return EXIT_SUCCESS; - } - if (mode == M_PRINT && getarg(args, 'a')) { SETGRENT(); while ((grp = GETGRENT()) != NULL) diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index e123786..298aeab 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/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; |