Merge with 4.4-Lite version.
This commit is contained in:
parent
91d8b1d405
commit
2303fc40d7
|
@ -1,5 +1,5 @@
|
||||||
# from: @(#)Makefile 5.4 (Berkeley) 2/12/91
|
# $NetBSD: Makefile,v 1.4 1995/01/20 19:19:53 mycroft Exp $
|
||||||
# $Id: Makefile,v 1.3 1994/12/22 11:45:27 cgd Exp $
|
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||||
|
|
||||||
PROG= vipw
|
PROG= vipw
|
||||||
SRCS= pw_util.c vipw.c
|
SRCS= pw_util.c vipw.c
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
/* $NetBSD: pw_util.c,v 1.5 1995/01/20 19:19:54 mycroft Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1990 The Regents of the University of California.
|
* Copyright (c) 1990, 1993, 1994
|
||||||
* All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -32,8 +34,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
/*static char sccsid[] = "from: @(#)pw_util.c 5.4 (Berkeley) 5/21/91";*/
|
static char sccsid[] = "@(#)pw_util.c 8.3 (Berkeley) 4/2/94";
|
||||||
static char rcsid[] = "$Id: pw_util.c,v 1.4 1994/03/29 02:21:11 jtc Exp $";
|
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -42,24 +43,25 @@ static char rcsid[] = "$Id: pw_util.c,v 1.4 1994/03/29 02:21:11 jtc Exp $";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <signal.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <sys/wait.h>
|
||||||
#include <pwd.h>
|
|
||||||
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <fcntl.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <string.h>
|
#include <pwd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern char *progname;
|
#include "pw_util.h"
|
||||||
extern char *tempname;
|
|
||||||
|
|
||||||
void pw_error __P((char *, int, int));
|
extern char *tempname;
|
||||||
|
|
||||||
void
|
void
|
||||||
pw_init()
|
pw_init()
|
||||||
|
@ -92,11 +94,11 @@ pw_init()
|
||||||
(void)umask(0);
|
(void)umask(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int lockfd;
|
||||||
|
|
||||||
int
|
int
|
||||||
pw_lock()
|
pw_lock()
|
||||||
{
|
{
|
||||||
int lockfd;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the master password file doesn't exist, the system is hosed.
|
* If the master password file doesn't exist, the system is hosed.
|
||||||
* Might as well try to build one. Set the close-on-exec bit so
|
* Might as well try to build one. Set the close-on-exec bit so
|
||||||
|
@ -104,17 +106,11 @@ pw_lock()
|
||||||
* Open should allow flock'ing the file; see 4.4BSD. XXX
|
* Open should allow flock'ing the file; see 4.4BSD. XXX
|
||||||
*/
|
*/
|
||||||
lockfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
|
lockfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
|
||||||
if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1) {
|
if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1)
|
||||||
(void)fprintf(stderr, "%s: %s: %s\n",
|
err(1, "%s", _PATH_MASTERPASSWD);
|
||||||
progname, _PATH_MASTERPASSWD, strerror(errno));
|
if (flock(lockfd, LOCK_EX|LOCK_NB))
|
||||||
exit(1);
|
errx(1, "the password db file is busy");
|
||||||
}
|
return (lockfd);
|
||||||
if (flock(lockfd, LOCK_EX|LOCK_NB)) {
|
|
||||||
(void)fprintf(stderr,
|
|
||||||
"%s: the password db is busy.\n", progname);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return(lockfd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -124,18 +120,15 @@ pw_tmp()
|
||||||
int fd;
|
int fd;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if ((p = strrchr(path, '/')) != NULL)
|
if (p = strrchr(path, '/'))
|
||||||
++p;
|
++p;
|
||||||
else
|
else
|
||||||
p = path;
|
p = path;
|
||||||
(void)snprintf(p, sizeof(path), "%s.XXXXXX", progname);
|
strcpy(p, "pw.XXXXXX");
|
||||||
if ((fd = mkstemp(path)) == -1) {
|
if ((fd = mkstemp(path)) == -1)
|
||||||
(void)fprintf(stderr,
|
err(1, "%s", path);
|
||||||
"%s: %s: %s\n", progname, path, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
tempname = path;
|
tempname = path;
|
||||||
return(fd);
|
return (fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -144,17 +137,17 @@ pw_mkdb()
|
||||||
int pstat;
|
int pstat;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
(void)printf("%s: rebuilding the database...\n", progname);
|
warnx("rebuilding the database...");
|
||||||
(void)fflush(stdout);
|
(void)fflush(stderr);
|
||||||
if (!(pid = vfork())) {
|
if (!(pid = vfork())) {
|
||||||
execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", tempname, NULL);
|
execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", tempname, NULL);
|
||||||
pw_error(_PATH_PWD_MKDB, 1, 1);
|
pw_error(_PATH_PWD_MKDB, 1, 1);
|
||||||
}
|
}
|
||||||
pid = waitpid(pid, &pstat, 0);
|
pid = waitpid(pid, &pstat, 0);
|
||||||
if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0)
|
if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0)
|
||||||
return(0);
|
return (0);
|
||||||
(void)printf("%s: done\n", progname);
|
warnx("done");
|
||||||
return(1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -167,7 +160,7 @@ pw_edit(notsetuid)
|
||||||
|
|
||||||
if (!(editor = getenv("EDITOR")))
|
if (!(editor = getenv("EDITOR")))
|
||||||
editor = _PATH_VI;
|
editor = _PATH_VI;
|
||||||
if ((p = strrchr(editor, '/')) != NULL)
|
if (p = strrchr(editor, '/'))
|
||||||
++p;
|
++p;
|
||||||
else
|
else
|
||||||
p = editor;
|
p = editor;
|
||||||
|
@ -180,7 +173,7 @@ pw_edit(notsetuid)
|
||||||
execlp(editor, p, tempname, NULL);
|
execlp(editor, p, tempname, NULL);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
pid = waitpid(pid, &pstat, 0);
|
pid = waitpid(pid, (int *)&pstat, 0);
|
||||||
if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0)
|
if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0)
|
||||||
pw_error(editor, 1, 1);
|
pw_error(editor, 1, 1);
|
||||||
}
|
}
|
||||||
|
@ -188,18 +181,15 @@ pw_edit(notsetuid)
|
||||||
void
|
void
|
||||||
pw_prompt()
|
pw_prompt()
|
||||||
{
|
{
|
||||||
register int c;
|
int c;
|
||||||
|
|
||||||
for (;;) {
|
(void)printf("re-edit the password file? [y]: ");
|
||||||
(void)printf("re-edit the password file? [y]: ");
|
(void)fflush(stdout);
|
||||||
(void)fflush(stdout);
|
c = getchar();
|
||||||
c = getchar();
|
if (c != EOF && c != '\n')
|
||||||
if (c != EOF && c != (int)'\n')
|
while (getchar() != '\n');
|
||||||
while (getchar() != (int)'\n');
|
if (c == 'n')
|
||||||
if (c == (int)'n')
|
pw_error(NULL, 0, 0);
|
||||||
pw_error((char *)NULL, 0, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -207,17 +197,10 @@ pw_error(name, err, eval)
|
||||||
char *name;
|
char *name;
|
||||||
int err, eval;
|
int err, eval;
|
||||||
{
|
{
|
||||||
int sverrno;
|
if (err)
|
||||||
|
warn(name);
|
||||||
|
|
||||||
if (err) {
|
warnx("%s: unchanged", _PATH_MASTERPASSWD);
|
||||||
sverrno = errno;
|
|
||||||
(void)fprintf(stderr, "%s: ", progname);
|
|
||||||
if (name)
|
|
||||||
(void)fprintf(stderr, "%s: ", name);
|
|
||||||
(void)fprintf(stderr, "%s\n", strerror(sverrno));
|
|
||||||
}
|
|
||||||
(void)fprintf(stderr,
|
|
||||||
"%s: %s unchanged\n", progname, _PATH_MASTERPASSWD);
|
|
||||||
(void)unlink(tempname);
|
(void)unlink(tempname);
|
||||||
exit(eval);
|
exit(eval);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $NetBSD: pw_util.h,v 1.2 1995/01/20 19:19:55 mycroft Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1994
|
* Copyright (c) 1994
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
|
.\" $NetBSD: vipw.8,v 1.4 1995/01/20 19:19:56 mycroft Exp $
|
||||||
.\" All rights reserved.
|
.\"
|
||||||
|
.\" Copyright (c) 1983, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
.\" modification, are permitted provided that the following conditions
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
@ -29,10 +31,9 @@
|
||||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" from: @(#)vipw.8 6.7 (Berkeley) 3/16/91
|
.\" @(#)vipw.8 8.1 (Berkeley) 6/6/93
|
||||||
.\" $Id: vipw.8,v 1.3 1993/08/01 07:23:03 mycroft Exp $
|
|
||||||
.\"
|
.\"
|
||||||
.Dd March 16, 1991
|
.Dd June 6, 1993
|
||||||
.Dt VIPW 8
|
.Dt VIPW 8
|
||||||
.Os BSD 4
|
.Os BSD 4
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
/* $NetBSD: vipw.c,v 1.3 1995/01/20 19:19:57 mycroft Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1987 Regents of the University of California.
|
* Copyright (c) 1987, 1993, 1994
|
||||||
* All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -32,30 +34,53 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
char copyright[] =
|
static char copyright[] =
|
||||||
"@(#) Copyright (c) 1987 Regents of the University of California.\n\
|
"@(#) Copyright (c) 1987, 1993, 1994\n\
|
||||||
All rights reserved.\n";
|
The Regents of the University of California. All rights reserved.\n";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
/*static char sccsid[] = "from: @(#)vipw.c 5.16 (Berkeley) 3/3/91";*/
|
static char sccsid[] = "@(#)vipw.c 8.3 (Berkeley) 4/2/94";
|
||||||
static char rcsid[] = "$Id: vipw.c,v 1.2 1993/08/01 17:54:45 mycroft Exp $";
|
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "pw_util.h"
|
||||||
|
|
||||||
char *progname = "vipw";
|
|
||||||
char *tempname;
|
char *tempname;
|
||||||
|
|
||||||
main()
|
void copyfile __P((int, int));
|
||||||
|
void usage __P((void));
|
||||||
|
|
||||||
|
int
|
||||||
|
main(argc, argv)
|
||||||
|
int argc;
|
||||||
|
char *argv[];
|
||||||
{
|
{
|
||||||
register int pfd, tfd;
|
int pfd, tfd;
|
||||||
struct stat begin, end;
|
struct stat begin, end;
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
while ((ch = getopt(argc, argv, "")) != EOF) {
|
||||||
|
switch (ch) {
|
||||||
|
case '?':
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (argc != 0)
|
||||||
|
usage();
|
||||||
|
|
||||||
pw_init();
|
pw_init();
|
||||||
pfd = pw_lock();
|
pfd = pw_lock();
|
||||||
|
@ -70,7 +95,7 @@ main()
|
||||||
if (stat(tempname, &end))
|
if (stat(tempname, &end))
|
||||||
pw_error(tempname, 1, 1);
|
pw_error(tempname, 1, 1);
|
||||||
if (begin.st_mtime == end.st_mtime) {
|
if (begin.st_mtime == end.st_mtime) {
|
||||||
(void)fprintf(stderr, "vipw: no changes made\n");
|
warnx("no changes made");
|
||||||
pw_error((char *)NULL, 0, 0);
|
pw_error((char *)NULL, 0, 0);
|
||||||
}
|
}
|
||||||
if (pw_mkdb())
|
if (pw_mkdb())
|
||||||
|
@ -80,10 +105,11 @@ main()
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
copyfile(from, to)
|
copyfile(from, to)
|
||||||
register int from, to;
|
int from, to;
|
||||||
{
|
{
|
||||||
register int nr, nw, off;
|
int nr, nw, off;
|
||||||
char buf[8*1024];
|
char buf[8*1024];
|
||||||
|
|
||||||
while ((nr = read(from, buf, sizeof(buf))) > 0)
|
while ((nr = read(from, buf, sizeof(buf))) > 0)
|
||||||
|
@ -93,3 +119,11 @@ copyfile(from, to)
|
||||||
if (nr < 0)
|
if (nr < 0)
|
||||||
pw_error(_PATH_MASTERPASSWD, 1, 1);
|
pw_error(_PATH_MASTERPASSWD, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
|
||||||
|
(void)fprintf(stderr, "usage: vipw\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue