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.
This commit is contained in:
Bill Paul 1996-10-22 03:18:11 +00:00
parent b9ab560398
commit 8839484b47
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=19085

View File

@ -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) {