From bc539790827cbc69585a6ec393f04705e5825eff Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sat, 11 Jul 2015 16:58:47 +0000 Subject: Separate usernext/groupnext from the main functions --- pw/pw_group.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'pw/pw_group.c') diff --git a/pw/pw_group.c b/pw/pw_group.c index c664ef5..28a7c94 100644 --- a/pw/pw_group.c +++ b/pw/pw_group.c @@ -91,6 +91,18 @@ set_passwd(struct group *grp, bool update) grp->gr_passwd = pw_pwcrypt(line); } +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) { @@ -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) -- cgit v1.2.3