From 8839484b4789d681c1c19109135a27ce8a68bd6b Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Tue, 22 Oct 1996 03:18:11 +0000 Subject: [PATCH] Begin closing out PR #1519 (this requires a change to chpass too, and both changes need to be pulled into the stable branch). The problem here is that when pwd_mkdb creates /etc/passwd, it turns empty UID and GID fields into zeroes. To fix this, we check the _PWF_UID and _PWF_GID bits in the pw_fields flag: if the bits are not set, we print an empty field instead of a zero. This way, you don't get zeroes in the UID or GID fields unless you explicit want them. --- usr.sbin/pwd_mkdb/pwd_mkdb.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/usr.sbin/pwd_mkdb/pwd_mkdb.c b/usr.sbin/pwd_mkdb/pwd_mkdb.c index 03d24b977c44..5b9fe280f44a 100644 --- a/usr.sbin/pwd_mkdb/pwd_mkdb.c +++ b/usr.sbin/pwd_mkdb/pwd_mkdb.c @@ -373,10 +373,18 @@ main(argc, argv) } } /* Create original format password file entry */ - if (makeold) - (void)fprintf(oldfp, "%s:*:%d:%d:%s:%s:%s\n", - pwd.pw_name, pwd.pw_uid, pwd.pw_gid, pwd.pw_gecos, - pwd.pw_dir, pwd.pw_shell); + if (makeold) { + char uidstr[20]; + char gidstr[20]; + + snprintf(uidstr, sizeof(uidstr), "%d", pwd.pw_uid); + snprintf(gidstr, sizeof(gidstr), "%d", pwd.pw_gid); + + (void)fprintf(oldfp, "%s:*:%s:%s:%s:%s:%s\n", + pwd.pw_name, pwd.pw_fields & _PWF_UID ? uidstr : "", + pwd.pw_fields & _PWF_GID ? gidstr : "", + pwd.pw_gecos, pwd.pw_dir, pwd.pw_shell); + } } /* If YP enabled, set flag. */ if (yp_enabled) {