From owner-svn-src-all@freebsd.org Sat Jul 11 16:58:49 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 93A8F999839; Sat, 11 Jul 2015 16:58:49 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 848071026; Sat, 11 Jul 2015 16:58:49 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6BGwnTX089546; Sat, 11 Jul 2015 16:58:49 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6BGwmX9089543; Sat, 11 Jul 2015 16:58:48 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201507111658.t6BGwmX9089543@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Sat, 11 Jul 2015 16:58:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285395 - head/usr.sbin/pw X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Jul 2015 16:58:49 -0000 Author: bapt Date: Sat Jul 11 16:58:47 2015 New Revision: 285395 URL: https://svnweb.freebsd.org/changeset/base/285395 Log: Separate usernext/groupnext from the main functions Modified: head/usr.sbin/pw/pw.h head/usr.sbin/pw/pw_group.c head/usr.sbin/pw/pw_user.c Modified: head/usr.sbin/pw/pw.h ============================================================================== --- head/usr.sbin/pw/pw.h Sat Jul 11 16:44:28 2015 (r285394) +++ head/usr.sbin/pw/pw.h Sat Jul 11 16:58:47 2015 (r285395) @@ -83,7 +83,9 @@ struct carg *addarg(struct cargs * _args 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); Modified: head/usr.sbin/pw/pw_group.c ============================================================================== --- head/usr.sbin/pw/pw_group.c Sat Jul 11 16:44:28 2015 (r285394) +++ head/usr.sbin/pw/pw_group.c Sat Jul 11 16:58:47 2015 (r285395) @@ -92,6 +92,18 @@ set_passwd(struct group *grp, bool updat } 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, 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) Modified: head/usr.sbin/pw/pw_user.c ============================================================================== --- head/usr.sbin/pw/pw_user.c Sat Jul 11 16:44:28 2015 (r285394) +++ head/usr.sbin/pw/pw_user.c Sat Jul 11 16:58:47 2015 (r285395) @@ -148,6 +148,20 @@ set_passwd(struct passwd *pwd, bool upda 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, s 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 * 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;