Handle pretty print (-P) via global pwconf
This commit is contained in:
parent
363cefdbb1
commit
2166b4d190
@ -133,6 +133,7 @@ main(int argc, char *argv[])
|
|||||||
relocated = nis = false;
|
relocated = nis = false;
|
||||||
conf.rootdir[0] = '\0';
|
conf.rootdir[0] = '\0';
|
||||||
conf.dryrun = false;
|
conf.dryrun = false;
|
||||||
|
conf.pretty = false;
|
||||||
strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath));
|
strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath));
|
||||||
|
|
||||||
LIST_INIT(&arglist);
|
LIST_INIT(&arglist);
|
||||||
@ -222,6 +223,9 @@ main(int argc, char *argv[])
|
|||||||
case 'N':
|
case 'N':
|
||||||
conf.dryrun = true;
|
conf.dryrun = true;
|
||||||
break;
|
break;
|
||||||
|
case 'P':
|
||||||
|
conf.pretty = true;
|
||||||
|
break;
|
||||||
case 'Y':
|
case 'Y':
|
||||||
nis = true;
|
nis = true;
|
||||||
break;
|
break;
|
||||||
|
@ -44,7 +44,7 @@ static const char rcsid[] =
|
|||||||
static struct passwd *lookup_pwent(const char *user);
|
static struct passwd *lookup_pwent(const char *user);
|
||||||
static void delete_members(char ***members, int *grmembers, int *i,
|
static void delete_members(char ***members, int *grmembers, int *i,
|
||||||
struct carg *arg, struct group *grp);
|
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);
|
static gid_t gr_gidpolicy(struct userconf * cnf, struct cargs * args);
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -89,11 +89,9 @@ pw_group(int mode, struct cargs * args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mode == M_PRINT && getarg(args, 'a')) {
|
if (mode == M_PRINT && getarg(args, 'a')) {
|
||||||
int pretty = getarg(args, 'P') != NULL;
|
|
||||||
|
|
||||||
SETGRENT();
|
SETGRENT();
|
||||||
while ((grp = GETGRENT()) != NULL)
|
while ((grp = GETGRENT()) != NULL)
|
||||||
print_group(grp, pretty);
|
print_group(grp);
|
||||||
ENDGRENT();
|
ENDGRENT();
|
||||||
return EXIT_SUCCESS;
|
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_name = a_name ? a_name->val : "nogroup";
|
||||||
fakegroup.gr_gid = a_gid ? (gid_t) atol(a_gid->val) : (gid_t)-1;
|
fakegroup.gr_gid = a_gid ? (gid_t) atol(a_gid->val) : (gid_t)-1;
|
||||||
fakegroup.gr_mem = fmems;
|
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);
|
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);
|
pw_log(cnf, mode, W_GROUP, "%s(%u) removed", a_name->val, gid);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} else if (mode == M_PRINT)
|
} else if (mode == M_PRINT)
|
||||||
return print_group(grp, getarg(args, 'P') != NULL);
|
return print_group(grp);
|
||||||
|
|
||||||
if (a_gid)
|
if (a_gid)
|
||||||
grp->gr_gid = (gid_t) atoi(a_gid->val);
|
grp->gr_gid = (gid_t) atoi(a_gid->val);
|
||||||
@ -259,7 +257,7 @@ pw_group(int mode, struct cargs * args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (conf.dryrun)
|
if (conf.dryrun)
|
||||||
return print_group(grp, getarg(args, 'P') != NULL);
|
return print_group(grp);
|
||||||
|
|
||||||
if (mode == M_ADD && (rc = addgrent(grp)) != 0) {
|
if (mode == M_ADD && (rc = addgrent(grp)) != 0) {
|
||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
@ -412,9 +410,9 @@ gr_gidpolicy(struct userconf * cnf, struct cargs * args)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
print_group(struct group * grp, int pretty)
|
print_group(struct group * grp)
|
||||||
{
|
{
|
||||||
if (!pretty) {
|
if (!conf.pretty) {
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
|
||||||
buf = gr_make(grp);
|
buf = gr_make(grp);
|
||||||
|
@ -53,7 +53,7 @@ static char locked_str[] = "*LOCKED*";
|
|||||||
|
|
||||||
static int delete_user(struct userconf *cnf, struct passwd *pwd,
|
static int delete_user(struct userconf *cnf, struct passwd *pwd,
|
||||||
struct carg *a_name, int delete, int mode);
|
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_uidpolicy(struct userconf * cnf, struct cargs * args);
|
||||||
static uid_t pw_gidpolicy(struct cargs * args, char *nam, gid_t prefer);
|
static uid_t pw_gidpolicy(struct cargs * args, char *nam, gid_t prefer);
|
||||||
static time_t pw_pwdpolicy(struct userconf * cnf, struct cargs * args);
|
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')) {
|
if (mode == M_PRINT && getarg(args, 'a')) {
|
||||||
int pretty = getarg(args, 'P') != NULL;
|
|
||||||
int v7 = getarg(args, '7') != NULL;
|
int v7 = getarg(args, '7') != NULL;
|
||||||
SETPWENT();
|
SETPWENT();
|
||||||
while ((pwd = GETPWENT()) != NULL)
|
while ((pwd = GETPWENT()) != NULL)
|
||||||
print_user(pwd, pretty, v7);
|
print_user(pwd, v7);
|
||||||
ENDPWENT();
|
ENDPWENT();
|
||||||
return EXIT_SUCCESS;
|
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_name = a_name ? a_name->val : "nouser";
|
||||||
fakeuser.pw_uid = a_uid ? (uid_t) atol(a_uid->val) : (uid_t) -1;
|
fakeuser.pw_uid = a_uid ? (uid_t) atol(a_uid->val) : (uid_t) -1;
|
||||||
return print_user(&fakeuser,
|
return print_user(&fakeuser,
|
||||||
getarg(args, 'P') != NULL,
|
|
||||||
getarg(args, '7') != NULL);
|
getarg(args, '7') != NULL);
|
||||||
}
|
}
|
||||||
if (a_name == NULL)
|
if (a_name == NULL)
|
||||||
@ -401,9 +399,7 @@ pw_user(int mode, struct cargs * args)
|
|||||||
return (delete_user(cnf, pwd, a_name,
|
return (delete_user(cnf, pwd, a_name,
|
||||||
getarg(args, 'r') != NULL, mode));
|
getarg(args, 'r') != NULL, mode));
|
||||||
else if (mode == M_PRINT)
|
else if (mode == M_PRINT)
|
||||||
return print_user(pwd,
|
return print_user(pwd, getarg(args, '7') != NULL);
|
||||||
getarg(args, 'P') != NULL,
|
|
||||||
getarg(args, '7') != NULL);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The rest is edit code
|
* The rest is edit code
|
||||||
@ -621,9 +617,7 @@ pw_user(int mode, struct cargs * args)
|
|||||||
* Special case: -N only displays & exits
|
* Special case: -N only displays & exits
|
||||||
*/
|
*/
|
||||||
if (conf.dryrun)
|
if (conf.dryrun)
|
||||||
return print_user(pwd,
|
return print_user(pwd, getarg(args, '7') != NULL);
|
||||||
getarg(args, 'P') != NULL,
|
|
||||||
getarg(args, '7') != NULL);
|
|
||||||
|
|
||||||
if (mode == M_ADD) {
|
if (mode == M_ADD) {
|
||||||
edited = 1; /* Always */
|
edited = 1; /* Always */
|
||||||
@ -1167,9 +1161,9 @@ delete_user(struct userconf *cnf, struct passwd *pwd, struct carg *a_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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;
|
char *buf;
|
||||||
|
|
||||||
if (!v7)
|
if (!v7)
|
||||||
|
@ -84,6 +84,7 @@ struct pwconf {
|
|||||||
char rootdir[MAXPATHLEN];
|
char rootdir[MAXPATHLEN];
|
||||||
char etcpath[MAXPATHLEN];
|
char etcpath[MAXPATHLEN];
|
||||||
bool dryrun;
|
bool dryrun;
|
||||||
|
bool pretty;
|
||||||
struct userconf *userconf;
|
struct userconf *userconf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user