- print(fp, pw);
- (void)fflush(fp);
-
- (void)fstat(fd, &begin);
- rval = edit(tfile);
- (void)unlink(tfile);
-
- if (rval) {
- fprintf(stderr, "chpass: edit failed");
- return(0);
- }
- (void)fstat(fd, &end);
- if (begin.st_mtime == end.st_mtime) {
- fprintf(stderr, "chpass: no changes made");
- return(0);
- }
- (void)rewind(fp);
- while (fgets(buf, sizeof(buf), fp)) {
- if (!buf[0])
- continue;
- if (!(p = index(buf, '\n'))) {
- fprintf(stderr, "chpass: line too long");
- return(0);
- }
- *p = '\0';
- for (ep = list; ep->prompt; ++ep)
- if (!strncasecmp(buf, ep->prompt, ep->len)) {
- if (ep->restricted && euid)
- continue;
- if (!(p = index(buf, ':'))) {
- fprintf(stderr,
- "chpass: line corrupted");
- return(0);
- }
- while (isspace(*++p));
- if (ep->except && strpbrk(p, ep->except)) {
- fprintf(stderr,
- "chpass: illegal character in the \"%s\" field",
- ep->prompt);
- return(0);
- }
- if ((ep->func)(p, pw, ep))
- return(0);
- break;
- }
- }
- (void)fclose(fp);
- return(1);
-}
-
-copy(pw, fp)
- struct passwd *pw;
- FILE *fp;
-{
- 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, "chpass: line too long");
- return(0);
- }
- if (done) {
- fprintf(fp, "%s", buf);
- continue;
- }
- if (!(p = index(buf, ':'))) {
- fprintf(stderr, "chpass: corrupted entry");
- return(0);
- }
- *p = '\0';
- if (strcmp(buf, pw->pw_name)) {
- *p = ':';
- fprintf(fp, "%s", buf);
- continue;
- }
- fprintf(fp, "%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);
- done = 1;
- }
- if (!done)
- fprintf(fp, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
- pw->pw_name, "NOLOGIN", pw->pw_uid, pw->pw_gid,
- pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
- pw->pw_dir, pw->pw_shell);
- return(1);