Update to 4.4-Lite version.
This commit is contained in:
parent
13c12b62f7
commit
9839fe449e
@ -1,5 +1,5 @@
|
||||
# from: @(#)Makefile 5.1 (Berkeley) 3/8/91
|
||||
# $Id: Makefile,v 1.3 1993/07/30 21:41:16 mycroft Exp $
|
||||
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# $Id: Makefile,v 1.4 1994/08/28 23:32:47 mycroft Exp $
|
||||
|
||||
PROG= pwd_mkdb
|
||||
SRCS= pw_scan.c pwd_mkdb.c getpwent.c
|
||||
@ -10,4 +10,4 @@ MAN8= pwd_mkdb.0
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
getpwent.o: getpwent.c
|
||||
${CC} ${CFLAGS} -UYP -c ${.IMPSRC}
|
||||
${CC} ${CFLAGS} ${CPPFLAGS} -UYP -c ${.IMPSRC}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -32,8 +32,8 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)pw_scan.c 5.1 (Berkeley) 2/12/91";*/
|
||||
static char rcsid[] = "$Id: pw_scan.c,v 1.2 1993/08/01 17:57:14 mycroft Exp $";
|
||||
/*static char sccsid[] = "from: @(#)pw_scan.c 8.3 (Berkeley) 4/2/94";*/
|
||||
static char *rcsid = "$Id: pw_scan.c,v 1.3 1994/08/28 23:32:49 mycroft Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -42,23 +42,26 @@ static char rcsid[] = "$Id: pw_scan.c,v 1.2 1993/08/01 17:57:14 mycroft Exp $";
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern char *progname;
|
||||
#include "pw_scan.h"
|
||||
|
||||
int
|
||||
pw_scan(bp, pw)
|
||||
char *bp;
|
||||
struct passwd *pw;
|
||||
{
|
||||
register long id;
|
||||
register int root;
|
||||
register char *p, *sh;
|
||||
char *getusershell();
|
||||
long id;
|
||||
int root;
|
||||
char *p, *sh;
|
||||
|
||||
if (!(pw->pw_name = strsep(&bp, ":"))) /* login */
|
||||
goto fmt;
|
||||
@ -71,13 +74,12 @@ pw_scan(bp, pw)
|
||||
goto fmt;
|
||||
id = atol(p);
|
||||
if (root && id) {
|
||||
(void)fprintf(stderr, "%s: root uid should be 0", progname);
|
||||
return(0);
|
||||
warnx("root uid should be 0");
|
||||
return (0);
|
||||
}
|
||||
if (id > USHRT_MAX) {
|
||||
(void)fprintf(stderr,
|
||||
"%s: %s > max uid value (%d)", progname, p, USHRT_MAX);
|
||||
return(0);
|
||||
warnx("%s > max uid value (%d)", p, USHRT_MAX);
|
||||
return (0);
|
||||
}
|
||||
pw->pw_uid = id;
|
||||
|
||||
@ -85,9 +87,8 @@ pw_scan(bp, pw)
|
||||
goto fmt;
|
||||
id = atol(p);
|
||||
if (id > USHRT_MAX) {
|
||||
(void)fprintf(stderr,
|
||||
"%s: %s > max gid value (%d)", progname, p, USHRT_MAX);
|
||||
return(0);
|
||||
warnx("%s > max gid value (%d)", p, USHRT_MAX);
|
||||
return (0);
|
||||
}
|
||||
pw->pw_gid = id;
|
||||
|
||||
@ -107,9 +108,7 @@ pw_scan(bp, pw)
|
||||
if (root && *p) /* empty == /bin/sh */
|
||||
for (setusershell();;) {
|
||||
if (!(sh = getusershell())) {
|
||||
(void)fprintf(stderr,
|
||||
"%s: warning, unknown root shell\n",
|
||||
progname);
|
||||
warnx("warning, unknown root shell");
|
||||
break;
|
||||
}
|
||||
if (!strcmp(p, sh))
|
||||
@ -117,8 +116,8 @@ pw_scan(bp, pw)
|
||||
}
|
||||
|
||||
if (p = strsep(&bp, ":")) { /* too many */
|
||||
fmt: (void)fprintf(stderr, "%s: corrupted entry\n", progname);
|
||||
return(0);
|
||||
fmt: warnx("corrupted entry");
|
||||
return (0);
|
||||
}
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" Copyright (c) 1991 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\" Copyright (c) 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
@ -29,65 +29,65 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)pwd_mkdb.8 5.3 (Berkeley) 6/29/91
|
||||
.\" $Id: pwd_mkdb.8,v 1.3 1993/10/06 19:07:02 jtc Exp $
|
||||
.\" from: @(#)pwd_mkdb.8 8.1 (Berkeley) 6/6/93
|
||||
.\" $Id: pwd_mkdb.8,v 1.4 1994/08/28 23:32:52 mycroft Exp $
|
||||
.\"
|
||||
.Dd June 29, 1991
|
||||
.Dt PWD_MKDB 8
|
||||
.Dd June 6, 1993
|
||||
.Dt PWD_MKDB 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm pwd_mkdb
|
||||
.Nd generate the password databases
|
||||
.Nm pwd_mkdb
|
||||
.Nd "generate the password databases"
|
||||
.Sh SYNOPSIS
|
||||
.Nm pwd_mkdb
|
||||
.Op Fl p
|
||||
.Nm pwd_mkdb
|
||||
.Op Fl p
|
||||
.Ar file
|
||||
.Sh DESCRIPTION
|
||||
.Nm Pwd_mkdb
|
||||
creates
|
||||
.Xr db 3
|
||||
style secure and insecure databases for the specified file.
|
||||
These databases are then installed into
|
||||
.Pa /etc/spwd.db
|
||||
These databases are then installed into
|
||||
.Dq Pa /etc/spwd.db
|
||||
and
|
||||
.Pa /etc/pwd.db
|
||||
.Dq Pa /etc/pwd.db
|
||||
respectively.
|
||||
The file is installed into
|
||||
.Pa /etc/master.passwd .
|
||||
The file is installed into
|
||||
.Dq Pa /etc/master.passwd .
|
||||
The file must be in the correct format (see
|
||||
.Xr passwd 5 ).
|
||||
.Xr passwd 5 ) .
|
||||
It is important to note that the format used in this system is
|
||||
different from the historic Version 7 style format.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width indent
|
||||
.Bl -tag -width flag
|
||||
.It Fl p
|
||||
Create a Version 7 style password file and install it into
|
||||
.Pa /etc/password .
|
||||
Create a Version 7 style password file and install it into
|
||||
.Dq Pa /etc/passwd .
|
||||
.El
|
||||
.Pp
|
||||
The two databases differ in that the secure version contains the user's
|
||||
encrypted password and the insecure version has an asterisk (``*'')
|
||||
.Pp
|
||||
The databases are used by the C library password routines (see
|
||||
.Xr getpwent 3 ).
|
||||
.Xr getpwent 3 ) .
|
||||
.Pp
|
||||
.Nm Pwd_mkdb
|
||||
exits zero on success, non-zero on failure.
|
||||
.Sh FILES
|
||||
.Bl -tag -width 24n -compact
|
||||
.Bl -tag -width Pa -compact
|
||||
.It Pa /var/db/pwd.db
|
||||
The insecure password database file
|
||||
The insecure password database file.
|
||||
.It Pa /var/db/pwd.db.tmp
|
||||
A temporary file
|
||||
A temporary file.
|
||||
.It Pa /var/db/spwd.db
|
||||
The secure password database file
|
||||
The secure password database file.
|
||||
.It Pa /var/db/spwd.db.tmp
|
||||
A temporary file
|
||||
A temporary file.
|
||||
.It Pa /etc/master.passwd
|
||||
The current password file
|
||||
The current password file.
|
||||
.It Pa /etc/passwd
|
||||
A Version 7 format password file
|
||||
A Version 7 format password file.
|
||||
.El
|
||||
.Sh BUGS
|
||||
Because of the necessity for atomic update of the password files,
|
||||
@ -96,8 +96,8 @@ uses
|
||||
.Xr rename 2
|
||||
to install them.
|
||||
This, however, requires that the file specified on the command line live
|
||||
on the same file system as the
|
||||
.Pa /etc
|
||||
on the same file system as the
|
||||
.Dq Pa /etc
|
||||
directory.
|
||||
.Pp
|
||||
There are the obvious races with multiple people running
|
||||
@ -112,7 +112,7 @@ and
|
||||
handle the locking necessary to avoid this problem.
|
||||
.Sh COMPATIBILITY
|
||||
Previous versions of the system had a program similar to
|
||||
.Nm pwd_mkdb,
|
||||
.Nm pwd_mkdb ,
|
||||
.Xr mkpasswd 8 ,
|
||||
which built
|
||||
.Xr dbm 3
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*-
|
||||
* Copyright (c) 1991 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -32,50 +32,68 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
char copyright[] =
|
||||
"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1991, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)pwd_mkdb.c 5.5 (Berkeley) 5/6/91";*/
|
||||
static char rcsid[] = "$Id: pwd_mkdb.c,v 1.4 1994/04/10 07:05:59 cgd Exp $";
|
||||
/*static char sccsid[] = "from: @(#)pwd_mkdb.c 8.5 (Berkeley) 4/20/94";*/
|
||||
static char *rcsid = "$Id: pwd_mkdb.c,v 1.5 1994/08/28 23:32:54 mycroft Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <db.h>
|
||||
#include <pwd.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pw_scan.h"
|
||||
|
||||
#define INSECURE 1
|
||||
#define SECURE 2
|
||||
#define PERM_INSECURE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
|
||||
#define PERM_SECURE (S_IRUSR|S_IWUSR)
|
||||
|
||||
char *progname = "pwd_mkdb";
|
||||
HASHINFO openinfo = {
|
||||
4096, /* bsize */
|
||||
32, /* ffactor */
|
||||
256, /* nelem */
|
||||
2048 * 1024, /* cachesize */
|
||||
NULL, /* hash() */
|
||||
0 /* lorder */
|
||||
};
|
||||
|
||||
static enum state { FILE_INSECURE, FILE_SECURE, FILE_ORIG } clean;
|
||||
static struct passwd pwd; /* password structure */
|
||||
static char *pname; /* password file name */
|
||||
|
||||
void cleanup __P((void));
|
||||
void error __P((char *));
|
||||
void mv __P((char *, char *));
|
||||
int scan __P((FILE *, struct passwd *));
|
||||
void usage __P((void));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
char *argv[];
|
||||
{
|
||||
extern int optind;
|
||||
register int len, makeold;
|
||||
register char *p, *t;
|
||||
FILE *fp, *oldfp;
|
||||
DB *dp, *edp;
|
||||
sigset_t set;
|
||||
DBT data, key;
|
||||
int ch, cnt, tfd;
|
||||
FILE *fp, *oldfp;
|
||||
sigset_t set;
|
||||
int ch, cnt, len, makeold, tfd;
|
||||
char *p, *t;
|
||||
char buf[MAX(MAXPATHLEN, LINE_MAX * 2)], tbuf[1024];
|
||||
|
||||
makeold = 0;
|
||||
@ -96,12 +114,9 @@ main(argc, argv)
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
/* set umask explicitly, so that 077 doesn't mess up /etc/passwd */
|
||||
umask(S_IWGRP|S_IWOTH);
|
||||
|
||||
/*
|
||||
* This could be done to allow the user to interrupt. Probably
|
||||
* not worth the effort.
|
||||
* This could be changed to allow the user to interrupt.
|
||||
* Probably not worth the effort.
|
||||
*/
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGTSTP);
|
||||
@ -111,37 +126,35 @@ main(argc, argv)
|
||||
sigaddset(&set, SIGTERM);
|
||||
(void)sigprocmask(SIG_BLOCK, &set, (sigset_t *)NULL);
|
||||
|
||||
/* We don't care what the user wants. */
|
||||
(void)umask(0);
|
||||
|
||||
pname = *argv;
|
||||
/* Open the original password file */
|
||||
if (!(fp = fopen(pname, "r")))
|
||||
error(pname);
|
||||
|
||||
/* Open the temporary insecure password database. */
|
||||
(void)sprintf(buf, "%s.tmp", _PATH_MP_DB);
|
||||
dp = dbopen(buf, O_RDWR|O_CREAT|O_EXCL, PERM_INSECURE, DB_HASH, NULL);
|
||||
if (!dp)
|
||||
(void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_MP_DB);
|
||||
dp = dbopen(buf,
|
||||
O_RDWR|O_CREAT|O_EXCL, PERM_INSECURE, DB_HASH, &openinfo);
|
||||
if (dp == NULL)
|
||||
error(buf);
|
||||
clean = FILE_INSECURE;
|
||||
|
||||
/* Open the temporary encrypted password database. */
|
||||
(void)sprintf(buf, "%s.tmp", _PATH_SMP_DB);
|
||||
edp = dbopen(buf, O_RDWR|O_CREAT|O_EXCL, PERM_SECURE, DB_HASH, NULL);
|
||||
if (!edp)
|
||||
error(buf);
|
||||
clean = FILE_SECURE;
|
||||
|
||||
/*
|
||||
* Open file for old password file. Minor trickiness -- don't want to
|
||||
* chance the file already existing, since someone (stupidly) might
|
||||
* still be using this for permission checking. So, open it first and
|
||||
* fdopen the resulting fd. Don't really care who reads it.
|
||||
* fdopen the resulting fd. The resulting file should be readable by
|
||||
* everyone.
|
||||
*/
|
||||
if (makeold) {
|
||||
(void)sprintf(buf, "%s.orig", pname);
|
||||
(void)snprintf(buf, sizeof(buf), "%s.orig", pname);
|
||||
if ((tfd = open(buf,
|
||||
O_WRONLY|O_CREAT|O_EXCL, PERM_INSECURE)) < 0)
|
||||
error(buf);
|
||||
if (!(oldfp = fdopen(tfd, "w")))
|
||||
if ((oldfp = fdopen(tfd, "w")) == NULL)
|
||||
error(buf);
|
||||
clean = FILE_ORIG;
|
||||
}
|
||||
@ -165,82 +178,42 @@ main(argc, argv)
|
||||
p = buf;
|
||||
COMPACT(pwd.pw_name);
|
||||
COMPACT("*");
|
||||
bcopy((char *)&pwd.pw_uid, p, sizeof(int));
|
||||
memmove(p, &pwd.pw_uid, sizeof(int));
|
||||
p += sizeof(int);
|
||||
bcopy((char *)&pwd.pw_gid, p, sizeof(int));
|
||||
memmove(p, &pwd.pw_gid, sizeof(int));
|
||||
p += sizeof(int);
|
||||
bcopy((char *)&pwd.pw_change, p, sizeof(time_t));
|
||||
memmove(p, &pwd.pw_change, sizeof(time_t));
|
||||
p += sizeof(time_t);
|
||||
COMPACT(pwd.pw_class);
|
||||
COMPACT(pwd.pw_gecos);
|
||||
COMPACT(pwd.pw_dir);
|
||||
COMPACT(pwd.pw_shell);
|
||||
bcopy((char *)&pwd.pw_expire, p, sizeof(time_t));
|
||||
memmove(p, &pwd.pw_expire, sizeof(time_t));
|
||||
p += sizeof(time_t);
|
||||
data.size = p - buf;
|
||||
|
||||
/* Store insecure by name. */
|
||||
tbuf[0] = _PW_KEYBYNAME;
|
||||
len = strlen(pwd.pw_name);
|
||||
bcopy(pwd.pw_name, tbuf + 1, len);
|
||||
memmove(tbuf + 1, pwd.pw_name, len);
|
||||
key.size = len + 1;
|
||||
if ((dp->put)(dp, &key, &data, R_NOOVERWRITE) == -1)
|
||||
error("put");
|
||||
|
||||
/* Store insecure by number. */
|
||||
tbuf[0] = _PW_KEYBYNUM;
|
||||
bcopy((char *)&cnt, tbuf + 1, sizeof(cnt));
|
||||
memmove(tbuf + 1, &cnt, sizeof(cnt));
|
||||
key.size = sizeof(cnt) + 1;
|
||||
if ((dp->put)(dp, &key, &data, R_NOOVERWRITE) == -1)
|
||||
error("put");
|
||||
|
||||
/* Store insecure by uid. */
|
||||
tbuf[0] = _PW_KEYBYUID;
|
||||
bcopy((char *)&pwd.pw_uid, tbuf + 1, sizeof(pwd.pw_uid));
|
||||
memmove(tbuf + 1, &pwd.pw_uid, sizeof(pwd.pw_uid));
|
||||
key.size = sizeof(pwd.pw_uid) + 1;
|
||||
if ((dp->put)(dp, &key, &data, R_NOOVERWRITE) == -1)
|
||||
error("put");
|
||||
|
||||
/* Create secure data. */
|
||||
p = buf;
|
||||
COMPACT(pwd.pw_name);
|
||||
COMPACT(pwd.pw_passwd);
|
||||
bcopy((char *)&pwd.pw_uid, p, sizeof(int));
|
||||
p += sizeof(int);
|
||||
bcopy((char *)&pwd.pw_gid, p, sizeof(int));
|
||||
p += sizeof(int);
|
||||
bcopy((char *)&pwd.pw_change, p, sizeof(time_t));
|
||||
p += sizeof(time_t);
|
||||
COMPACT(pwd.pw_class);
|
||||
COMPACT(pwd.pw_gecos);
|
||||
COMPACT(pwd.pw_dir);
|
||||
COMPACT(pwd.pw_shell);
|
||||
bcopy((char *)&pwd.pw_expire, p, sizeof(time_t));
|
||||
p += sizeof(time_t);
|
||||
data.size = p - buf;
|
||||
|
||||
/* Store secure by name. */
|
||||
tbuf[0] = _PW_KEYBYNAME;
|
||||
len = strlen(pwd.pw_name);
|
||||
bcopy(pwd.pw_name, tbuf + 1, len);
|
||||
key.size = len + 1;
|
||||
if ((dp->put)(edp, &key, &data, R_NOOVERWRITE) == -1)
|
||||
error("put");
|
||||
|
||||
/* Store secure by number. */
|
||||
tbuf[0] = _PW_KEYBYNUM;
|
||||
bcopy((char *)&cnt, tbuf + 1, sizeof(cnt));
|
||||
key.size = sizeof(cnt) + 1;
|
||||
if ((dp->put)(edp, &key, &data, R_NOOVERWRITE) == -1)
|
||||
error("put");
|
||||
|
||||
/* Store secure by uid. */
|
||||
tbuf[0] = _PW_KEYBYUID;
|
||||
bcopy((char *)&pwd.pw_uid, tbuf + 1, sizeof(pwd.pw_uid));
|
||||
key.size = sizeof(pwd.pw_uid) + 1;
|
||||
if ((dp->put)(edp, &key, &data, R_NOOVERWRITE) == -1)
|
||||
error("put");
|
||||
|
||||
/* Create original format password file entry */
|
||||
if (makeold)
|
||||
(void)fprintf(oldfp, "%s:*:%d:%d:%s:%s:%s\n",
|
||||
@ -248,23 +221,76 @@ main(argc, argv)
|
||||
pwd.pw_dir, pwd.pw_shell);
|
||||
}
|
||||
(void)(dp->close)(dp);
|
||||
(void)(edp->close)(edp);
|
||||
if (makeold) {
|
||||
(void)fsync(oldfp);
|
||||
(void)fflush(oldfp);
|
||||
(void)fclose(oldfp);
|
||||
}
|
||||
|
||||
/* Open the temporary encrypted password database. */
|
||||
(void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_SMP_DB);
|
||||
edp = dbopen(buf,
|
||||
O_RDWR|O_CREAT|O_EXCL, PERM_SECURE, DB_HASH, &openinfo);
|
||||
if (!edp)
|
||||
error(buf);
|
||||
clean = FILE_SECURE;
|
||||
|
||||
rewind(fp);
|
||||
for (cnt = 1; scan(fp, &pwd); ++cnt) {
|
||||
|
||||
/* Create secure data. */
|
||||
p = buf;
|
||||
COMPACT(pwd.pw_name);
|
||||
COMPACT(pwd.pw_passwd);
|
||||
memmove(p, &pwd.pw_uid, sizeof(int));
|
||||
p += sizeof(int);
|
||||
memmove(p, &pwd.pw_gid, sizeof(int));
|
||||
p += sizeof(int);
|
||||
memmove(p, &pwd.pw_change, sizeof(time_t));
|
||||
p += sizeof(time_t);
|
||||
COMPACT(pwd.pw_class);
|
||||
COMPACT(pwd.pw_gecos);
|
||||
COMPACT(pwd.pw_dir);
|
||||
COMPACT(pwd.pw_shell);
|
||||
memmove(p, &pwd.pw_expire, sizeof(time_t));
|
||||
p += sizeof(time_t);
|
||||
data.size = p - buf;
|
||||
|
||||
/* Store secure by name. */
|
||||
tbuf[0] = _PW_KEYBYNAME;
|
||||
len = strlen(pwd.pw_name);
|
||||
memmove(tbuf + 1, pwd.pw_name, len);
|
||||
key.size = len + 1;
|
||||
if ((dp->put)(edp, &key, &data, R_NOOVERWRITE) == -1)
|
||||
error("put");
|
||||
|
||||
/* Store secure by number. */
|
||||
tbuf[0] = _PW_KEYBYNUM;
|
||||
memmove(tbuf + 1, &cnt, sizeof(cnt));
|
||||
key.size = sizeof(cnt) + 1;
|
||||
if ((dp->put)(edp, &key, &data, R_NOOVERWRITE) == -1)
|
||||
error("put");
|
||||
|
||||
/* Store secure by uid. */
|
||||
tbuf[0] = _PW_KEYBYUID;
|
||||
memmove(tbuf + 1, &pwd.pw_uid, sizeof(pwd.pw_uid));
|
||||
key.size = sizeof(pwd.pw_uid) + 1;
|
||||
if ((dp->put)(edp, &key, &data, R_NOOVERWRITE) == -1)
|
||||
error("put");
|
||||
}
|
||||
|
||||
(void)(edp->close)(edp);
|
||||
|
||||
/* Set master.passwd permissions, in case caller forgot. */
|
||||
(void)fchmod(fileno(fp), S_IRUSR|S_IWUSR);
|
||||
(void)fclose(fp);
|
||||
|
||||
/* Install as the real password files. */
|
||||
(void)sprintf(buf, "%s.tmp", _PATH_MP_DB);
|
||||
(void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_MP_DB);
|
||||
mv(buf, _PATH_MP_DB);
|
||||
(void)sprintf(buf, "%s.tmp", _PATH_SMP_DB);
|
||||
(void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_SMP_DB);
|
||||
mv(buf, _PATH_SMP_DB);
|
||||
if (makeold) {
|
||||
(void)sprintf(buf, "%s.orig", pname);
|
||||
(void)snprintf(buf, sizeof(buf), "%s.orig", pname);
|
||||
mv(buf, _PATH_PASSWD);
|
||||
}
|
||||
/*
|
||||
@ -277,6 +303,7 @@ main(argc, argv)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
scan(fp, pw)
|
||||
FILE *fp;
|
||||
struct passwd *pw;
|
||||
@ -286,70 +313,76 @@ scan(fp, pw)
|
||||
char *p;
|
||||
|
||||
if (!fgets(line, sizeof(line), fp))
|
||||
return(0);
|
||||
return (0);
|
||||
++lcnt;
|
||||
/*
|
||||
* ``... if I swallow anything evil, put your fingers down my
|
||||
* throat...''
|
||||
* -- The Who
|
||||
*/
|
||||
if (!(p = index(line, '\n'))) {
|
||||
(void)fprintf(stderr, "pwd_mkdb: line too long\n");
|
||||
if (!(p = strchr(line, '\n'))) {
|
||||
warnx("line too long");
|
||||
goto fmt;
|
||||
|
||||
}
|
||||
*p = '\0';
|
||||
if (!pw_scan(line, pw)) {
|
||||
(void)fprintf(stderr, "pwd_mkdb: at line #%d.\n", lcnt);
|
||||
fmt: errno = EFTYPE;
|
||||
warnx("at line #%d", lcnt);
|
||||
fmt: errno = EFTYPE; /* XXX */
|
||||
error(pname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
mv(from, to)
|
||||
char *from, *to;
|
||||
{
|
||||
int sverrno;
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
if (rename(from, to)) {
|
||||
sverrno = errno;
|
||||
(void)sprintf(buf, "%s to %s", from, to);
|
||||
int sverrno = errno;
|
||||
(void)snprintf(buf, sizeof(buf), "%s to %s", from, to);
|
||||
errno = sverrno;
|
||||
error(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
error(name)
|
||||
char *name;
|
||||
{
|
||||
(void)fprintf(stderr, "pwd_mkdb: %s: %s\n", name, strerror(errno));
|
||||
|
||||
warn(name);
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
cleanup()
|
||||
{
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
switch(clean) {
|
||||
case FILE_ORIG:
|
||||
(void)sprintf(buf, "%s.orig", pname);
|
||||
(void)snprintf(buf, sizeof(buf), "%s.orig", pname);
|
||||
(void)unlink(buf);
|
||||
/* FALLTHROUGH */
|
||||
case FILE_SECURE:
|
||||
(void)sprintf(buf, "%s.tmp", _PATH_SMP_DB);
|
||||
(void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_SMP_DB);
|
||||
(void)unlink(buf);
|
||||
/* FALLTHROUGH */
|
||||
case FILE_INSECURE:
|
||||
(void)sprintf(buf, "%s.tmp", _PATH_MP_DB);
|
||||
(void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_MP_DB);
|
||||
(void)unlink(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "usage: pwd_mkdb [-p] file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user