diff --git a/usr.sbin/pwd_mkdb/pwd_mkdb.8 b/usr.sbin/pwd_mkdb/pwd_mkdb.8 index 6a55fcb01f96..20583eb5aede 100644 --- a/usr.sbin/pwd_mkdb/pwd_mkdb.8 +++ b/usr.sbin/pwd_mkdb/pwd_mkdb.8 @@ -39,6 +39,7 @@ .Nd "generate the password databases" .Sh SYNOPSIS .Nm pwd_mkdb +.Op Fl c .Op Fl p .Op Fl d Ar directory .Ar file @@ -61,6 +62,9 @@ different from the historic Version 7 style format. .Pp The options are as follows: .Bl -tag -width flag +.It Fl c +Check if the password file is in the correct format. Do not +change, add, or remove any files. .It Fl p Create a Version 7 style password file and install it into .Dq Pa /etc/passwd . diff --git a/usr.sbin/pwd_mkdb/pwd_mkdb.c b/usr.sbin/pwd_mkdb/pwd_mkdb.c index c4fa479fd0a6..03d24b977c44 100644 --- a/usr.sbin/pwd_mkdb/pwd_mkdb.c +++ b/usr.sbin/pwd_mkdb/pwd_mkdb.c @@ -101,12 +101,17 @@ main(argc, argv) char sbuf2[MAXPATHLEN]; char *username; u_int method, methoduid; + int cflag; + cflag = 0; strcpy(prefix, _PATH_PWD); makeold = 0; username = NULL; - while ((ch = getopt(argc, argv, "d:pu:v")) != EOF) + while ((ch = getopt(argc, argv, "cd:pu:v")) != EOF) switch(ch) { + case 'c': /* verify only */ + cflag = 1; + break; case 'd': strcpy(prefix, optarg); break; @@ -118,7 +123,6 @@ main(argc, argv) break; case 'v': /* backward compatible */ break; - case '?': default: usage(); } @@ -148,6 +152,12 @@ main(argc, argv) if (!(fp = fopen(pname, "r"))) error(pname); + /* check only if password database is valid */ + if (cflag) { + for (cnt = 1; scan(fp, &pwd); ++cnt); + exit(0); + } + /* Open the temporary insecure password database. */ (void)snprintf(buf, sizeof(buf), "%s/%s.tmp", prefix, _MP_DB); (void)snprintf(sbuf, sizeof(sbuf), "%s/%s.tmp", prefix, _SMP_DB); @@ -526,6 +536,6 @@ void usage() { - (void)fprintf(stderr, "usage: pwd_mkdb [-p] [-d ] [-u ] file\n"); + (void)fprintf(stderr, "usage: pwd_mkdb [-c] [-p] [-d ] [-u ] file\n"); exit(1); }