diff options
author | wosch <wosch@FreeBSD.org> | 1997-03-08 14:09:24 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1997-03-08 14:09:24 +0000 |
commit | 9643ba6a4a9ff57f22c669d349ea529c0d7069e8 (patch) | |
tree | 5a77e12efbd6203d2ffa3b499312172f4bb6b9f4 /usr.sbin/pwd_mkdb | |
parent | e45d393547db1869e5f26eeceb0cc4d40799a228 (diff) | |
download | FreeBSD-src-9643ba6a4a9ff57f22c669d349ea529c0d7069e8.zip FreeBSD-src-9643ba6a4a9ff57f22c669d349ea529c0d7069e8.tar.gz |
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$'
Diffstat (limited to 'usr.sbin/pwd_mkdb')
-rw-r--r-- | usr.sbin/pwd_mkdb/Makefile | 1 | ||||
-rw-r--r-- | usr.sbin/pwd_mkdb/pwd_mkdb.c | 29 |
2 files changed, 26 insertions, 4 deletions
diff --git a/usr.sbin/pwd_mkdb/Makefile b/usr.sbin/pwd_mkdb/Makefile index 86116fec..25d001e 100644 --- a/usr.sbin/pwd_mkdb/Makefile +++ b/usr.sbin/pwd_mkdb/Makefile @@ -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> diff --git a/usr.sbin/pwd_mkdb/pwd_mkdb.c b/usr.sbin/pwd_mkdb/pwd_mkdb.c index 5b9fe28..eec546c 100644 --- a/usr.sbin/pwd_mkdb/pwd_mkdb.c +++ b/usr.sbin/pwd_mkdb/pwd_mkdb.c @@ -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 */ |