summaryrefslogtreecommitdiff
path: root/usr.bin/chpass/pw_copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/chpass/pw_copy.c')
-rw-r--r--usr.bin/chpass/pw_copy.c81
1 files changed, 72 insertions, 9 deletions
diff --git a/usr.bin/chpass/pw_copy.c b/usr.bin/chpass/pw_copy.c
index 9b7ab9025d5c..6bfcc6b6b851 100644
--- a/usr.bin/chpass/pw_copy.c
+++ b/usr.bin/chpass/pw_copy.c
@@ -46,21 +46,36 @@ static char sccsid[] = "@(#)pw_copy.c 5.3 (Berkeley) 5/2/91";
extern char *progname, *tempname;
-pw_copy(ffd, tfd, pw)
+int globcnt;
+
+/*
+ * NB: Use of pw_copy() to update the insecure passwd file
+ * necessitates that this routine be wrapperized
+ * so that it can handle the formats used by both
+ * /etc/master.passwd and /etc/passwd
+ *
+ * pw_copy() and pw_copy_insecure() both call pw_copy_drv(), which
+ * does the work.
+ */
+static pw_copy_drv(ffd, tfd, pw, secure_format)
int ffd, tfd;
struct passwd *pw;
+ int secure_format;
{
register FILE *from, *to;
register int done;
register char *p;
char buf[8192];
+ int tmpcnt;
if (!(from = fdopen(ffd, "r")))
pw_error(_PATH_MASTERPASSWD, 1, 1);
if (!(to = fdopen(tfd, "w")))
pw_error(tempname, 1, 1);
+ tmpcnt=0;
for (done = 0; fgets(buf, sizeof(buf), from);) {
+ tmpcnt++;
if (!index(buf, '\n')) {
(void)fprintf(stderr, "%s: %s: line too long\n",
progname, _PATH_MASTERPASSWD);
@@ -85,21 +100,69 @@ pw_copy(ffd, tfd, pw)
goto err;
continue;
}
- (void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
- pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
- pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
- pw->pw_dir, pw->pw_shell);
+ globcnt = tmpcnt;
+ /*
+ * NB: /etc/passwd: insecure format does not have
+ * class, change and expire fields !
+ */
+ if(secure_format)
+ (void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
+ pw->pw_name, pw->pw_passwd, pw->pw_uid,
+ pw->pw_gid, pw->pw_class, pw->pw_change,
+ pw->pw_expire, pw->pw_gecos, pw->pw_dir,
+ pw->pw_shell);
+ else
+ (void)fprintf(to, "%s:%s:%d:%d:%s:%s:%s\n",
+ pw->pw_name, pw->pw_passwd, pw->pw_uid,
+ pw->pw_gid, pw->pw_gecos, pw->pw_dir,
+ pw->pw_shell);
done = 1;
if (ferror(to))
goto err;
}
if (!done)
- (void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
- pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
- pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
- pw->pw_dir, pw->pw_shell);
+ {
+ globcnt = tmpcnt+1;
+ /*
+ * NB: /etc/passwd: insecure format does not have
+ * class, change and expire fields !
+ */
+ if(secure_format)
+ (void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
+ pw->pw_name, pw->pw_passwd, pw->pw_uid,
+ pw->pw_gid, pw->pw_class, pw->pw_change,
+ pw->pw_expire, pw->pw_gecos, pw->pw_dir,
+ pw->pw_shell);
+ else
+ (void)fprintf(to, "%s:%s:%d:%d:%s:%s:%s\n",
+ pw->pw_name, pw->pw_passwd, pw->pw_uid,
+ pw->pw_gid, pw->pw_gecos, pw->pw_dir,
+ pw->pw_shell);
+ }
if (ferror(to))
err: pw_error(NULL, 1, 1);
(void)fclose(to);
}
+
+
+/*
+ * Standard pw_copy routine - used to update master.passwd
+ */
+pw_copy(ffd, tfd, pw)
+ int ffd, tfd;
+ struct passwd *pw;
+{
+ pw_copy_drv(ffd, tfd, pw, 1);
+}
+
+
+/*
+ * Special pw_copy routine used to update insecure passwd file
+ */
+pw_copy_insecure(ffd, tfd, pw)
+ int ffd, tfd;
+ struct passwd *pw;
+{
+ pw_copy_drv(ffd, tfd, pw, 0);
+}