summaryrefslogtreecommitdiffstats
path: root/pw
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-06-07 15:27:17 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-06-07 15:27:17 +0000
commitfec3dfc01be2e26eb5df5998a06066e2064e0a4b (patch)
treea1ac5d4a11b6514b940db0a3450ccfd22b618ea6 /pw
parent577824cadb88a52417c8a551d1aa6b70b2224b22 (diff)
downloadpw-darwin-fec3dfc01be2e26eb5df5998a06066e2064e0a4b.tar.gz
pw-darwin-fec3dfc01be2e26eb5df5998a06066e2064e0a4b.tar.zst
pw-darwin-fec3dfc01be2e26eb5df5998a06066e2064e0a4b.zip
Handle pretty print (-P) via global pwconf
Diffstat (limited to 'pw')
-rw-r--r--pw/pw.c4
-rw-r--r--pw/pw_group.c16
-rw-r--r--pw/pw_user.c18
-rw-r--r--pw/pwupd.h1
4 files changed, 18 insertions, 21 deletions
diff --git a/pw/pw.c b/pw/pw.c
index 7a86680..22665e9 100644
--- a/pw/pw.c
+++ b/pw/pw.c
@@ -133,6 +133,7 @@ main(int argc, char *argv[])
relocated = nis = false;
conf.rootdir[0] = '\0';
conf.dryrun = false;
+ conf.pretty = false;
strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath));
LIST_INIT(&arglist);
@@ -222,6 +223,9 @@ main(int argc, char *argv[])
case 'N':
conf.dryrun = true;
break;
+ case 'P':
+ conf.pretty = true;
+ break;
case 'Y':
nis = true;
break;
diff --git a/pw/pw_group.c b/pw/pw_group.c
index 302d44e..d5d7d52 100644
--- a/pw/pw_group.c
+++ b/pw/pw_group.c
@@ -44,7 +44,7 @@ static const char rcsid[] =
static struct passwd *lookup_pwent(const char *user);
static void delete_members(char ***members, int *grmembers, int *i,
struct carg *arg, struct group *grp);
-static int print_group(struct group * grp, int pretty);
+static int print_group(struct group * grp);
static gid_t gr_gidpolicy(struct userconf * cnf, struct cargs * args);
int
@@ -89,11 +89,9 @@ pw_group(int mode, struct cargs * args)
}
if (mode == M_PRINT && getarg(args, 'a')) {
- int pretty = getarg(args, 'P') != NULL;
-
SETGRENT();
while ((grp = GETGRENT()) != NULL)
- print_group(grp, pretty);
+ print_group(grp);
ENDGRENT();
return EXIT_SUCCESS;
}
@@ -119,7 +117,7 @@ pw_group(int mode, struct cargs * args)
fakegroup.gr_name = a_name ? a_name->val : "nogroup";
fakegroup.gr_gid = a_gid ? (gid_t) atol(a_gid->val) : (gid_t)-1;
fakegroup.gr_mem = fmems;
- return print_group(&fakegroup, getarg(args, 'P') != NULL);
+ return print_group(&fakegroup);
}
errx(EX_DATAERR, "unknown group `%s'", a_name ? a_name->val : a_gid->val);
}
@@ -141,7 +139,7 @@ pw_group(int mode, struct cargs * args)
pw_log(cnf, mode, W_GROUP, "%s(%u) removed", a_name->val, gid);
return EXIT_SUCCESS;
} else if (mode == M_PRINT)
- return print_group(grp, getarg(args, 'P') != NULL);
+ return print_group(grp);
if (a_gid)
grp->gr_gid = (gid_t) atoi(a_gid->val);
@@ -259,7 +257,7 @@ pw_group(int mode, struct cargs * args)
}
if (conf.dryrun)
- return print_group(grp, getarg(args, 'P') != NULL);
+ return print_group(grp);
if (mode == M_ADD && (rc = addgrent(grp)) != 0) {
if (rc == -1)
@@ -412,9 +410,9 @@ gr_gidpolicy(struct userconf * cnf, struct cargs * args)
static int
-print_group(struct group * grp, int pretty)
+print_group(struct group * grp)
{
- if (!pretty) {
+ if (!conf.pretty) {
char *buf = NULL;
buf = gr_make(grp);
diff --git a/pw/pw_user.c b/pw/pw_user.c
index fac4d25..bfbde78 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -53,7 +53,7 @@ static char locked_str[] = "*LOCKED*";
static int delete_user(struct userconf *cnf, struct passwd *pwd,
struct carg *a_name, int delete, int mode);
-static int print_user(struct passwd * pwd, int pretty, int v7);
+static int print_user(struct passwd * pwd, int v7);
static uid_t pw_uidpolicy(struct userconf * cnf, struct cargs * args);
static uid_t pw_gidpolicy(struct cargs * args, char *nam, gid_t prefer);
static time_t pw_pwdpolicy(struct userconf * cnf, struct cargs * args);
@@ -316,11 +316,10 @@ pw_user(int mode, struct cargs * args)
}
if (mode == M_PRINT && getarg(args, 'a')) {
- int pretty = getarg(args, 'P') != NULL;
int v7 = getarg(args, '7') != NULL;
SETPWENT();
while ((pwd = GETPWENT()) != NULL)
- print_user(pwd, pretty, v7);
+ print_user(pwd, v7);
ENDPWENT();
return EXIT_SUCCESS;
}
@@ -363,7 +362,6 @@ pw_user(int mode, struct cargs * args)
fakeuser.pw_name = a_name ? a_name->val : "nouser";
fakeuser.pw_uid = a_uid ? (uid_t) atol(a_uid->val) : (uid_t) -1;
return print_user(&fakeuser,
- getarg(args, 'P') != NULL,
getarg(args, '7') != NULL);
}
if (a_name == NULL)
@@ -401,9 +399,7 @@ pw_user(int mode, struct cargs * args)
return (delete_user(cnf, pwd, a_name,
getarg(args, 'r') != NULL, mode));
else if (mode == M_PRINT)
- return print_user(pwd,
- getarg(args, 'P') != NULL,
- getarg(args, '7') != NULL);
+ return print_user(pwd, getarg(args, '7') != NULL);
/*
* The rest is edit code
@@ -621,9 +617,7 @@ pw_user(int mode, struct cargs * args)
* Special case: -N only displays & exits
*/
if (conf.dryrun)
- return print_user(pwd,
- getarg(args, 'P') != NULL,
- getarg(args, '7') != NULL);
+ return print_user(pwd, getarg(args, '7') != NULL);
if (mode == M_ADD) {
edited = 1; /* Always */
@@ -1167,9 +1161,9 @@ delete_user(struct userconf *cnf, struct passwd *pwd, struct carg *a_name,
}
static int
-print_user(struct passwd * pwd, int pretty, int v7)
+print_user(struct passwd * pwd, int v7)
{
- if (!pretty) {
+ if (!conf.pretty) {
char *buf;
if (!v7)
diff --git a/pw/pwupd.h b/pw/pwupd.h
index ec9ac30..63aaa64 100644
--- a/pw/pwupd.h
+++ b/pw/pwupd.h
@@ -84,6 +84,7 @@ struct pwconf {
char rootdir[MAXPATHLEN];
char etcpath[MAXPATHLEN];
bool dryrun;
+ bool pretty;
struct userconf *userconf;
};