fixes in setproctitle to avoid problems with titles longer than
[unix-history] / usr / src / usr.sbin / vipw / vipw.c
index 88ba9af..0d082b5 100644 (file)
@@ -1,6 +1,18 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)vipw.c     4.3 (Berkeley) %G%";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)vipw.c     5.1 (Berkeley) %G%";
+#endif not lint
 
 #include <sys/types.h>
 #include <sys/stat.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -13,8 +25,12 @@ static char sccsid[] = "@(#)vipw.c   4.3 (Berkeley) %G%";
 /*
  * Password file editor with locking.
  */
 /*
  * Password file editor with locking.
  */
-char   *temp = "/etc/ptmp";
-char   *passwd = "/etc/passwd";
+char   temp[] = "/etc/ptmp";
+char   temp_pag[] = "/etc/ptmp.pag";
+char   temp_dir[] = "/etc/ptmp.dir";
+char   passwd[] = "/etc/passwd";
+char   passwd_pag[] = "/etc/passwd.pag";
+char   passwd_dir[] = "/etc/passwd.dir";
 char   buf[BUFSIZ];
 char   *getenv();
 char   *index();
 char   buf[BUFSIZ];
 char   *getenv();
 char   *index();
@@ -27,9 +43,9 @@ main(argc, argv)
        FILE *ft, *fp;
        char *editor;
 
        FILE *ft, *fp;
        char *editor;
 
+       signal(SIGHUP, SIG_IGN);
        signal(SIGINT, SIG_IGN);
        signal(SIGQUIT, SIG_IGN);
        signal(SIGINT, SIG_IGN);
        signal(SIGQUIT, SIG_IGN);
-       signal(SIGHUP, SIG_IGN);
        setbuf(stderr, NULL);
        umask(0);
        fd = open(temp, O_WRONLY|O_CREAT|O_EXCL, 0644);
        setbuf(stderr, NULL);
        umask(0);
        fd = open(temp, O_WRONLY|O_CREAT|O_EXCL, 0644);
@@ -114,7 +130,7 @@ main(argc, argv)
                        if (cp == 0)
                                break;
                        /* login directory */
                        if (cp == 0)
                                break;
                        /* login directory */
-                       if (strncmp(++cp, "/:"))
+                       if (strncmp(++cp, "/:", 2))
                                break;
                        cp += 2;
                        if (*cp && strcmp(cp, "/bin/sh") &&
                                break;
                        cp += 2;
                        if (*cp && strcmp(cp, "/bin/sh") &&
@@ -124,7 +140,13 @@ main(argc, argv)
                }
                fclose(ft);
                if (ok) {
                }
                fclose(ft);
                if (ok) {
-                       if (rename(temp, passwd) < 0)
+                       if (makedb(temp) < 0)
+                               fprintf(stderr, "vipw: mkpasswd failed\n");
+                       else if (rename(temp_pag, passwd_pag) < 0)
+                               fprintf(stderr, "vipw: "), perror(temp_pag);
+                       else if (rename(temp_dir, passwd_dir) < 0)
+                               fprintf(stderr, "vipw: "), perror(temp_dir);
+                       else if (rename(temp, passwd) < 0)
                                fprintf(stderr, "vipw: "), perror("rename");
                        else
                                exit(0);
                                fprintf(stderr, "vipw: "), perror("rename");
                        else
                                exit(0);
@@ -134,6 +156,24 @@ main(argc, argv)
                            passwd);
        }
 bad:
                            passwd);
        }
 bad:
+       unlink(temp_pag);
+       unlink(temp_dir);
        unlink(temp);
        exit(1);
 }
        unlink(temp);
        exit(1);
 }
+
+makedb(file)
+       char *file;
+{
+       int status, pid, w;
+
+       if ((pid = vfork()) == 0) {
+               execl("/etc/mkpasswd", "mkpasswd", file, 0);
+               _exit(127);
+       }
+       while ((w = wait(&status)) != pid && w != -1)
+               ;
+       if (w == -1 || status != 0)
+               status = -1;
+       return(status);
+}