Handle -7 via gloval pwconf

This commit is contained in:
Baptiste Daroussin 2015-06-07 15:33:08 +00:00
parent bbe09b2e19
commit c86f7ad56d
3 changed files with 9 additions and 6 deletions

View File

@ -215,6 +215,9 @@ main(int argc, char *argv[])
case '?': case '?':
errx(EX_USAGE, "unknown switch"); errx(EX_USAGE, "unknown switch");
break; break;
case '7':
conf.v7 = true;
break;
case 'C': case 'C':
config = optarg; config = optarg;
break; break;

View File

@ -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 v7); static int print_user(struct passwd * pwd);
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,10 +316,9 @@ pw_user(int mode, struct cargs * args)
} }
if (mode == M_PRINT && getarg(args, 'a')) { if (mode == M_PRINT && getarg(args, 'a')) {
int v7 = getarg(args, '7') != NULL;
SETPWENT(); SETPWENT();
while ((pwd = GETPWENT()) != NULL) while ((pwd = GETPWENT()) != NULL)
print_user(pwd, v7); print_user(pwd);
ENDPWENT(); ENDPWENT();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -1161,15 +1160,15 @@ delete_user(struct userconf *cnf, struct passwd *pwd, struct carg *a_name,
} }
static int static int
print_user(struct passwd * pwd, int v7) print_user(struct passwd * pwd)
{ {
if (!conf.pretty) { if (!conf.pretty) {
char *buf; char *buf;
if (!v7) if (!conf.v7)
pwd->pw_passwd = (pwd->pw_passwd == NULL) ? "" : "*"; pwd->pw_passwd = (pwd->pw_passwd == NULL) ? "" : "*";
buf = v7 ? pw_make_v7(pwd) : pw_make(pwd); buf = conf.v7 ? pw_make_v7(pwd) : pw_make(pwd);
printf("%s\n", buf); printf("%s\n", buf);
free(buf); free(buf);
} else { } else {

View File

@ -85,6 +85,7 @@ struct pwconf {
char etcpath[MAXPATHLEN]; char etcpath[MAXPATHLEN];
bool dryrun; bool dryrun;
bool pretty; bool pretty;
bool v7;
struct userconf *userconf; struct userconf *userconf;
}; };