Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/pwd_mkdb Add explicit endianness overrides.



details:   https://anonhg.NetBSD.org/src/rev/9f9f393450d2
branches:  trunk
changeset: 480945:9f9f393450d2
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Sun Jan 23 19:59:32 2000 +0000

description:
Add explicit endianness overrides.

diffstat:

 usr.sbin/pwd_mkdb/Makefile   |    4 +-
 usr.sbin/pwd_mkdb/pwd_mkdb.8 |   11 +++-
 usr.sbin/pwd_mkdb/pwd_mkdb.c |  110 +++++++++++++++++++++++++++---------------
 3 files changed, 81 insertions(+), 44 deletions(-)

diffs (287 lines):

diff -r 0e7947161027 -r 9f9f393450d2 usr.sbin/pwd_mkdb/Makefile
--- a/usr.sbin/pwd_mkdb/Makefile        Sun Jan 23 19:38:53 2000 +0000
+++ b/usr.sbin/pwd_mkdb/Makefile        Sun Jan 23 19:59:32 2000 +0000
@@ -1,12 +1,12 @@
 #      from: @(#)Makefile      8.1 (Berkeley) 6/6/93
-#      $NetBSD: Makefile,v 1.12 1997/10/25 06:58:32 lukem Exp $
+#      $NetBSD: Makefile,v 1.13 2000/01/23 19:59:32 mycroft Exp $
 
 PROG=  pwd_mkdb
 SRCS=  pwd_mkdb.c getpwent.c
 MAN=   pwd_mkdb.8
 LDADD+=        -lutil
 DPADD+=        ${LIBUTIL}
-CPPFLAGS+=     -I${.CURDIR}/../../lib/libc/include
+CPPFLAGS+=     -I${.CURDIR}/../../lib/libc/include -D__DBINTERFACE_PRIVATE
 
 .PATH: ${.CURDIR}/../../lib/libc/gen
 
diff -r 0e7947161027 -r 9f9f393450d2 usr.sbin/pwd_mkdb/pwd_mkdb.8
--- a/usr.sbin/pwd_mkdb/pwd_mkdb.8      Sun Jan 23 19:38:53 2000 +0000
+++ b/usr.sbin/pwd_mkdb/pwd_mkdb.8      Sun Jan 23 19:59:32 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: pwd_mkdb.8,v 1.10 1999/12/17 13:11:22 abs Exp $
+.\"    $NetBSD: pwd_mkdb.8,v 1.11 2000/01/23 19:59:32 mycroft Exp $
 .\"
 .\" Copyright (c) 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -41,7 +41,7 @@
 .Nd "generate the password databases"
 .Sh SYNOPSIS
 .Nm
-.Op Fl p
+.Op Fl pBL
 .Op Fl d Ar directory
 .Ar file
 .Sh DESCRIPTION
@@ -71,6 +71,10 @@
 .Dq Pa /
 to
 .Ar directory .
+.It Fl B
+Store data in big-endian format.
+.It Fl L
+Store data in little-endian format.
 .El
 .Pp
 The two databases differ in that the secure version contains the user's 
@@ -116,6 +120,9 @@
 and
 .Xr vipw 8
 handle the locking necessary to avoid this problem.
+.Pp
+Although the DB format is endian-transparent, the data stored in the DB is
+not.  This is difficult to fix without breaking compatibility.
 .Sh COMPATIBILITY
 Previous versions of the system had a program similar to
 .Nm
diff -r 0e7947161027 -r 9f9f393450d2 usr.sbin/pwd_mkdb/pwd_mkdb.c
--- a/usr.sbin/pwd_mkdb/pwd_mkdb.c      Sun Jan 23 19:38:53 2000 +0000
+++ b/usr.sbin/pwd_mkdb/pwd_mkdb.c      Sun Jan 23 19:59:32 2000 +0000
@@ -34,16 +34,12 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\n\
+__COPYRIGHT("@(#) Copyright (c) 2000\n\
+       The NetBSD Foundation, Inc.  All rights reserved.\n\
+Copyright (c) 1991, 1993, 1994\n\
        The Regents of the University of California.  All rights reserved.\n");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "from: @(#)pwd_mkdb.c   8.5 (Berkeley) 4/20/94";
-#else
-__RCSID("$NetBSD: pwd_mkdb.c,v 1.16 1998/07/27 00:52:02 mycroft Exp $");
-#endif
+__SCCSID("from: @(#)pwd_mkdb.c 8.5 (Berkeley) 4/20/94");
+__RCSID("$NetBSD: pwd_mkdb.c,v 1.17 2000/01/23 19:59:33 mycroft Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -93,7 +89,7 @@
 int    main __P((int, char **));
 void   mv __P((char *, char *));
 void   rm __P((char *));
-int    scan __P((FILE *, struct passwd *, int *));
+int    scan __P((FILE *, struct passwd *, u_int32_t *));
 void   usage __P((void));
 
 int
@@ -105,17 +101,19 @@
        DBT data, key;
        FILE *fp, *oldfp;
        sigset_t set;
-       int ch, cnt, len, makeold, tfd, flags;
+       int ch, len, makeold, tfd;
+       u_int32_t x, cnt, flags;
        char *p;
        const char *t;
        char buf[MAX(MAXPATHLEN, LINE_MAX * 2)], tbuf[1024];
        int hasyp = 0;
        DBT ypdata, ypkey;
+       int lorder = BYTE_ORDER;
 
        oldfp = NULL;
        strcpy(prefix, "/");
        makeold = 0;
-       while ((ch = getopt(argc, argv, "d:pv")) != -1)
+       while ((ch = getopt(argc, argv, "d:pvBL")) != -1)
                switch(ch) {
                case 'd':
                        strncpy(prefix, optarg, sizeof(prefix));
@@ -126,6 +124,12 @@
                        break;
                case 'v':                       /* backward compatible */
                        break;
+               case 'B':
+                       lorder = BIG_ENDIAN;
+                       break;
+               case 'L':
+                       lorder = LITTLE_ENDIAN;
+                       break;
                case '?':
                default:
                        usage();
@@ -156,6 +160,8 @@
        if (!(fp = fopen(pname, "r")))
                error(pname);
 
+       openinfo.lorder = lorder;
+
        /* Open the temporary insecure password database. */
        (void)snprintf(pwd_db_tmp, sizeof(pwd_db_tmp), "%s%s.tmp", prefix,
                _PATH_MP_DB);
@@ -220,24 +226,32 @@
                                    cnt);
                }
 
+               if (lorder != BYTE_ORDER) {
+                       M_32_SWAP(pwd.pw_uid);
+                       M_32_SWAP(pwd.pw_gid);
+                       M_32_SWAP(pwd.pw_change);
+                       M_32_SWAP(pwd.pw_expire);
+                       M_32_SWAP(flags);
+               }
+
                /* Create insecure data. */
                p = buf;
                COMPACT(pwd.pw_name);
                COMPACT("*");
-               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);
+               memmove(p, &pwd.pw_uid, sizeof(pwd.pw_uid));
+               p += sizeof(pwd.pw_uid);
+               memmove(p, &pwd.pw_gid, sizeof(pwd.pw_gid));
+               p += sizeof(pwd.pw_gid);
+               memmove(p, &pwd.pw_change, sizeof(pwd.pw_change));
+               p += sizeof(pwd.pw_change);
                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);
-               memmove(p, &flags, sizeof(int));
-               p += sizeof(int);
+               memmove(p, &pwd.pw_expire, sizeof(pwd.pw_expire));
+               p += sizeof(pwd.pw_expire);
+               memmove(p, &flags, sizeof(flags));
+               p += sizeof(flags);
                data.size = p - buf;
 
                /* Store insecure by name. */
@@ -250,8 +264,11 @@
 
                /* Store insecure by number. */
                tbuf[0] = _PW_KEYBYNUM;
-               memmove(tbuf + 1, &cnt, sizeof(cnt));
-               key.size = sizeof(cnt) + 1;
+               x = cnt;
+               if (lorder != BYTE_ORDER)
+                       M_32_SWAP(x);
+               memmove(tbuf + 1, &x, sizeof(x));
+               key.size = sizeof(x) + 1;
                if ((dp->put)(dp, &key, &data, R_NOOVERWRITE) == -1)
                        wr_error(pwd_db_tmp);
 
@@ -308,24 +325,32 @@
        rewind(fp);
        for (cnt = 1; scan(fp, &pwd, &flags); ++cnt) {
 
+               if (lorder != BYTE_ORDER) {
+                       M_32_SWAP(pwd.pw_uid);
+                       M_32_SWAP(pwd.pw_gid);
+                       M_32_SWAP(pwd.pw_change);
+                       M_32_SWAP(pwd.pw_expire);
+                       M_32_SWAP(flags);
+               }
+
                /* 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);
+               memmove(p, &pwd.pw_uid, sizeof(pwd.pw_uid));
+               p += sizeof(pwd.pw_uid);
+               memmove(p, &pwd.pw_gid, sizeof(pwd.pw_gid));
+               p += sizeof(pwd.pw_gid);
+               memmove(p, &pwd.pw_change, sizeof(pwd.pw_change));
+               p += sizeof(pwd.pw_change);
                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);
-               memmove(p, &flags, sizeof(int));
-               p += sizeof(int);
+               memmove(p, &pwd.pw_expire, sizeof(pwd.pw_expire));
+               p += sizeof(pwd.pw_expire);
+               memmove(p, &flags, sizeof(flags));
+               p += sizeof(flags);
                data.size = p - buf;
 
                /* Store secure by name. */
@@ -338,8 +363,11 @@
 
                /* Store secure by number. */
                tbuf[0] = _PW_KEYBYNUM;
-               memmove(tbuf + 1, &cnt, sizeof(cnt));
-               key.size = sizeof(cnt) + 1;
+               x = cnt;
+               if (lorder != BYTE_ORDER)
+                       M_32_SWAP(x);
+               memmove(tbuf + 1, &x, sizeof(x));
+               key.size = sizeof(x) + 1;
                if ((edp->put)(edp, &key, &data, R_NOOVERWRITE) == -1)
                        wr_error(pwd_Sdb_tmp);
 
@@ -408,11 +436,12 @@
 scan(fp, pw, flags)
        FILE *fp;
        struct passwd *pw;
-       int *flags;
+       u_int32_t *flags;
 {
        static int lcnt;
        static char line[LINE_MAX];
        char *p;
+       int oflags;
 
        if (!fgets(line, sizeof(line), fp))
                return (0);
@@ -430,12 +459,13 @@
        *p = '\0';
        if (strcmp(line, "+") == 0)
                strcpy(line, "+:::::::::");     /* pw_scan() can't handle "+" */
-       *flags = 0;
-       if (!pw_scan(line, pw, flags)) {
+       oflags = 0;
+       if (!pw_scan(line, pw, &oflags)) {
                warnx("at line #%d", lcnt);
 fmt:           errno = EFTYPE; /* XXX */
                error(pname);
        }
+       *flags = oflags;
 
        return (1);
 }
@@ -510,6 +540,6 @@
 usage()
 {
 
-       (void)fprintf(stderr, "usage: pwd_mkdb [-p] [-d directory] file\n");
+       (void)fprintf(stderr, "usage: pwd_mkdb [-pBL] [-d directory] file\n");
        exit(1);
 }



Home | Main Index | Thread Index | Old Index