aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/pwd_mkdb
diff options
context:
space:
mode:
authorWolfram Schneider <wosch@FreeBSD.org>1997-03-08 14:09:24 +0000
committerWolfram Schneider <wosch@FreeBSD.org>1997-03-08 14:09:24 +0000
commiteb0abfcc1885bf48fc8b8e32317c6750af1787b8 (patch)
tree406c1e3f82e5d812d3cf2498944b662743de4590 /usr.sbin/pwd_mkdb
parentc29c9ac4183813385caa1bb5bddf514353887b8a (diff)
downloadsrc-eb0abfcc1885bf48fc8b8e32317c6750af1787b8.tar.gz
src-eb0abfcc1885bf48fc8b8e32317c6750af1787b8.zip
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$'
Notes
Notes: svn path=/head/; revision=23517
Diffstat (limited to 'usr.sbin/pwd_mkdb')
-rw-r--r--usr.sbin/pwd_mkdb/Makefile1
-rw-r--r--usr.sbin/pwd_mkdb/pwd_mkdb.c29
2 files changed, 26 insertions, 4 deletions
diff --git a/usr.sbin/pwd_mkdb/Makefile b/usr.sbin/pwd_mkdb/Makefile
index 86116fecce74..25d001efb1e2 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 5b9fe280f44a..eec546c97c9c 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 */