From owner-svn-src-head@FreeBSD.ORG Sun Jun 7 15:09:55 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 39E46F5B; Sun, 7 Jun 2015 15:09:55 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from svn.freebsd.org (svn.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 280941FC8; Sun, 7 Jun 2015 15:09:55 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t57F9t9k011653; Sun, 7 Jun 2015 15:09:55 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t57F9s86011647; Sun, 7 Jun 2015 15:09:54 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201506071509.t57F9s86011647@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Sun, 7 Jun 2015 15:09:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284121 - 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-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jun 2015 15:09:55 -0000 Author: bapt Date: Sun Jun 7 15:09:53 2015 New Revision: 284121 URL: https://svnweb.freebsd.org/changeset/base/284121 Log: Handle dryrun (-N) via global pwconf Modified: head/usr.sbin/pw/pw.c head/usr.sbin/pw/pw_group.c head/usr.sbin/pw/pw_user.c head/usr.sbin/pw/pwupd.h Modified: head/usr.sbin/pw/pw.c ============================================================================== --- head/usr.sbin/pw/pw.c Sun Jun 7 14:57:16 2015 (r284120) +++ head/usr.sbin/pw/pw.c Sun Jun 7 15:09:53 2015 (r284121) @@ -132,6 +132,7 @@ main(int argc, char *argv[]) relocated = nis = false; conf.rootdir[0] = '\0'; + conf.dryrun = false; strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath)); LIST_INIT(&arglist); @@ -218,6 +219,9 @@ main(int argc, char *argv[]) case 'C': config = optarg; break; + case 'N': + conf.dryrun = true; + break; case 'Y': nis = true; break; @@ -231,7 +235,7 @@ main(int argc, char *argv[]) /* * Must be root to attempt an update */ - if (geteuid() != 0 && mode != M_PRINT && mode != M_NEXT && getarg(&arglist, 'N')==NULL) + if (geteuid() != 0 && mode != M_PRINT && mode != M_NEXT && !conf.dryrun) errx(EX_NOPERM, "you must be root to run this program"); /* Modified: head/usr.sbin/pw/pw_group.c ============================================================================== --- head/usr.sbin/pw/pw_group.c Sun Jun 7 14:57:16 2015 (r284120) +++ head/usr.sbin/pw/pw_group.c Sun Jun 7 15:09:53 2015 (r284121) @@ -258,7 +258,7 @@ pw_group(int mode, struct cargs * args) grp->gr_mem = members; } - if (getarg(args, 'N') != NULL) + if (conf.dryrun) return print_group(grp, getarg(args, 'P') != NULL); if (mode == M_ADD && (rc = addgrent(grp)) != 0) { Modified: head/usr.sbin/pw/pw_user.c ============================================================================== --- head/usr.sbin/pw/pw_user.c Sun Jun 7 14:57:16 2015 (r284120) +++ head/usr.sbin/pw/pw_user.c Sun Jun 7 15:09:53 2015 (r284121) @@ -620,7 +620,7 @@ pw_user(int mode, struct cargs * args) /* * Special case: -N only displays & exits */ - if (getarg(args, 'N') != NULL) + if (conf.dryrun) return print_user(pwd, getarg(args, 'P') != NULL, getarg(args, '7') != NULL); @@ -872,9 +872,7 @@ pw_gidpolicy(struct cargs * args, char * snprintf(tmp, sizeof(tmp), "%u", prefer); addarg(&grpargs, 'g', tmp); } - if (getarg(args, 'N')) - { - addarg(&grpargs, 'N', NULL); + if (conf.dryrun) { addarg(&grpargs, 'q', NULL); gid = pw_group(M_NEXT, &grpargs); } @@ -1035,7 +1033,7 @@ pw_password(struct userconf * cnf, struc * We give this information back to the user */ if (getarg(args, 'h') == NULL && getarg(args, 'H') == NULL && - getarg(args, 'N') == NULL) { + !conf.dryrun) { if (isatty(STDOUT_FILENO)) printf("Password for '%s' is: ", user); printf("%s\n", pwbuf); Modified: head/usr.sbin/pw/pwupd.h ============================================================================== --- head/usr.sbin/pw/pwupd.h Sun Jun 7 14:57:16 2015 (r284120) +++ head/usr.sbin/pw/pwupd.h Sun Jun 7 15:09:53 2015 (r284121) @@ -35,6 +35,7 @@ #include #include +#include #if defined(__FreeBSD__) #define RET_SETGRENT int @@ -82,6 +83,7 @@ struct userconf { struct pwconf { char rootdir[MAXPATHLEN]; char etcpath[MAXPATHLEN]; + bool dryrun; struct userconf *userconf; };