* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)vipw.c 5.1 (Berkeley) %G%";
* Password file editor with locking.
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";
signal(SIGQUIT
, SIG_IGN
);
fd
= open(temp
, O_WRONLY
|O_CREAT
|O_EXCL
, 0644);
fprintf(stderr
, "vipw: password file busy\n");
fprintf(stderr
, "vipw: "); perror(temp
);
fprintf(stderr
, "vipw: "); perror(temp
);
fprintf(stderr
, "vipw: "); perror(passwd
);
while (fgets(buf
, sizeof (buf
) - 1, fp
) != NULL
)
editor
= getenv("EDITOR");
sprintf(buf
, "%s %s", editor
, temp
);
if (stat(temp
, &sbuf
) < 0) {
"vipw: can't stat temp file, %s unchanged\n",
fprintf(stderr
, "vipw: bad temp file, %s unchanged\n",
"vipw: can't reopen temp file, %s unchanged\n",
while (fgets(buf
, sizeof (buf
) - 1, ft
) != NULL
) {
if (strncmp(++cp
, "/:", 2))
if (*cp
&& strcmp(cp
, "/bin/sh") &&
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");
"vipw: you mangled the temp file, %s unchanged\n",
if ((pid
= vfork()) == 0) {
execl("/etc/mkpasswd", "mkpasswd", file
, 0);
while ((w
= wait(&status
)) != pid
&& w
!= -1)
if (w
== -1 || status
!= 0)