summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-06-07 15:09:53 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-06-07 15:09:53 +0000
commit577824cadb88a52417c8a551d1aa6b70b2224b22 (patch)
treec4dd39aa75f88d08e399e7e8126280b83657e59f
parente6c20d74e9c630e7116f84d3712c178369b10c96 (diff)
downloadpw-darwin-577824cadb88a52417c8a551d1aa6b70b2224b22.tar.gz
pw-darwin-577824cadb88a52417c8a551d1aa6b70b2224b22.tar.zst
pw-darwin-577824cadb88a52417c8a551d1aa6b70b2224b22.zip
Handle dryrun (-N) via global pwconf
-rw-r--r--pw/pw.c6
-rw-r--r--pw/pw_group.c2
-rw-r--r--pw/pw_user.c8
-rw-r--r--pw/pwupd.h2
4 files changed, 11 insertions, 7 deletions
diff --git a/pw/pw.c b/pw/pw.c
index 991019d..7a86680 100644
--- a/pw/pw.c
+++ b/pw/pw.c
@@ -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");
/*
diff --git a/pw/pw_group.c b/pw/pw_group.c
index b57eab3..302d44e 100644
--- a/pw/pw_group.c
+++ b/pw/pw_group.c
@@ -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) {
diff --git a/pw/pw_user.c b/pw/pw_user.c
index d69f56b..fac4d25 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -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 *nam, gid_t prefer)
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, struct cargs * args, char const * user)
* 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);
diff --git a/pw/pwupd.h b/pw/pwupd.h
index a5d6c27..ec9ac30 100644
--- a/pw/pwupd.h
+++ b/pw/pwupd.h
@@ -35,6 +35,7 @@
#include <pwd.h>
#include <grp.h>
+#include <stdbool.h>
#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;
};