- /*
- * possible race; have to rename four files, and someone could slip
- * in between them. LOCK_EX and rename the ``passwd.dir'' file first
- * so that getpwent(3) can't slip in; the lock should never fail and
- * it's unclear what to do if it does. Rename ``ptmp'' last so that
- * passwd/vipw/chpass can't slip in.
- */
- (void)setpriority(PRIO_PROCESS, 0, -20);
- fend = strcpy(from, temp) + strlen(temp);
- tend = strcpy(to, _PATH_PASSWD) + strlen(_PATH_PASSWD);
- bcopy(".dir", fend, 5);
- bcopy(".dir", tend, 5);
- if ((fd = open(from, O_RDONLY, 0)) >= 0)
- (void)flock(fd, LOCK_EX);
- /* here we go... */
- (void)rename(from, to);
- bcopy(".pag", fend, 5);
- bcopy(".pag", tend, 5);
- (void)rename(from, to);
- bcopy(".orig", fend, 6);
- (void)rename(from, _PATH_PASSWD);
- (void)rename(temp, passwd);
- /* done! */
- exit(0);
-}
-
-copy(name, np, fp, pw)
- char *name, *np;
- FILE *fp;
- struct passwd *pw;
-{
- register int done;
- register char *p;
- char buf[1024];
-
- for (done = 0; fgets(buf, sizeof(buf), stdin);) {
- /* skip lines that are too big */
- if (!index(buf, '\n')) {
- fprintf(stderr, "passwd: line too long.\n");
- return(0);
- }
- if (done) {
- fprintf(fp, "%s", buf);
- continue;
- }
- if (!(p = index(buf, ':'))) {
- fprintf(stderr, "passwd: corrupted entry.\n");
- return(0);
- }
- *p = '\0';
- if (strcmp(buf, name)) {
- *p = ':';
- fprintf(fp, "%s", buf);
- continue;
- }
- if (!(p = index(++p, ':'))) {
- fprintf(stderr, "passwd: corrupted entry.\n");
- return(0);
- }
- /*
- * reset change time to zero; when classes are implemented,
- * go and get the "offset" value for this class and reset
- * the timer.
- */
- fprintf(fp, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
- pw->pw_name, np, pw->pw_uid, pw->pw_gid,
- pw->pw_class, 0L, pw->pw_expire, pw->pw_gecos,
- pw->pw_dir, pw->pw_shell);
- done = 1;
- }
- return(1);