Allow comments in password database. The comments are copied from

the password file into /etc/master.passwd and optional (-p) into
/etc/passwd. Enable this feature with the compile
option -DPASSWD_IGNORE_COMMENTS.

The character `#' introduces a comment. Leading spaces and tabs are
ignored: '^[ \t]*#.*\n$'

Count an empty line - only spaces, tabs or newline - also as a comment.
An empty line at the bottom of /etc/master.passwd is a common
novice error and increased my mail load: '^[ \t]*\n$'
This commit is contained in:
Wolfram Schneider 1997-03-08 14:09:24 +00:00
parent c29c9ac418
commit eb0abfcc18
2 changed files with 26 additions and 4 deletions

View File

@ -3,5 +3,6 @@
PROG= pwd_mkdb
SRCS= pw_scan.c pwd_mkdb.c
MAN8= pwd_mkdb.8
CFLAGS+= -DPASSWD_IGNORE_COMMENTS
.include <bsd.prog.mk>

View File

@ -77,6 +77,9 @@ static struct passwd pwd; /* password structure */
static char *pname; /* password file name */
static char prefix[MAXPATHLEN];
static int Cflag; /* flag for comments */
static char line[LINE_MAX];
void cleanup __P((void));
void error __P((char *));
void cp __P((char *, char *, mode_t mode));
@ -272,10 +275,12 @@ main(argc, argv)
sdata.data = (u_char *)sbuf;
key.data = (u_char *)tbuf;
for (cnt = 1; scan(fp, &pwd); ++cnt) {
if (pwd.pw_name[0] == '+' || pwd.pw_name[0] == '-')
if (!Cflag &&
(pwd.pw_name[0] == '+' || pwd.pw_name[0] == '-'))
yp_enabled = 1;
#define COMPACT(e) t = e; while (*p++ = *t++);
if (!username || (strcmp(username, pwd.pw_name) == 0)) {
if (!Cflag &&
(!username || (strcmp(username, pwd.pw_name) == 0))) {
/* Create insecure data. */
p = buf;
COMPACT(pwd.pw_name);
@ -373,7 +378,9 @@ main(argc, argv)
}
}
/* Create original format password file entry */
if (makeold) {
if (Cflag && makeold) /* copy comments */
(void)fprintf(oldfp, "%s\n", line);
else if (makeold) {
char uidstr[20];
char gidstr[20];
@ -438,7 +445,6 @@ scan(fp, pw)
struct passwd *pw;
{
static int lcnt;
static char line[LINE_MAX];
char *p;
if (!fgets(line, sizeof(line), fp))
@ -455,6 +461,21 @@ scan(fp, pw)
}
*p = '\0';
#ifdef PASSWD_IGNORE_COMMENTS
/*
* Ignore comments: ^[ \t]*#
*/
for (p = line; *p != '\0'; p++)
if (*p != ' ' && *p != '\t')
break;
if (*p == '#' || *p == '\0') {
Cflag = 1;
return(1);
} else
Cflag = 0;
#endif
if (!pw_scan(line, pw)) {
warnx("at line #%d", lcnt);
fmt: errno = EFTYPE; /* XXX */