]> arthur.barton.de Git - netatalk.git/commitdiff
Backport from trunk: New cnid_didname_verify command.
authorsrittau <srittau>
Mon, 31 Dec 2001 20:14:18 +0000 (20:14 +0000)
committersrittau <srittau>
Mon, 31 Dec 2001 20:14:18 +0000 (20:14 +0000)
bin/Makefile.am
bin/cnid/Makefile.am [new file with mode: 0644]
bin/cnid/cnid_didname_verify.c [new file with mode: 0644]
configure.in

index ea8f9c95eebcaeea24c3716e711964c5119b4768..bd2db832f56ee858931a8d2103367032f6133150 100644 (file)
@@ -1,3 +1,3 @@
 # Makefile.am for bin/
 
-SUBDIRS = adv1tov2 aecho afile afppasswd getzones megatron nbp pap psorder
+SUBDIRS = adv1tov2 aecho afile afppasswd cnid getzones megatron nbp pap psorder
diff --git a/bin/cnid/Makefile.am b/bin/cnid/Makefile.am
new file mode 100644 (file)
index 0000000..6f3fb13
--- /dev/null
@@ -0,0 +1,12 @@
+# Makefile.am for bin/cnid/
+
+CFLAGS = @CFLAGS@ @DB3_CFLAGS@
+LIBS = @LIBS@ @DB3_LIBS@
+
+if COMPILE_CNID
+bin_PROGRAMS = cnid_didname_verify
+else
+bin_PROGRAMS =
+endif
+
+cnid_didname_verify_SOURCES = cnid_didname_verify.c
diff --git a/bin/cnid/cnid_didname_verify.c b/bin/cnid/cnid_didname_verify.c
new file mode 100644 (file)
index 0000000..6e36dc6
--- /dev/null
@@ -0,0 +1,220 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1996, 1997, 1998, 1999, 2000
+ *     Sleepycat Software.  All rights reserved.
+ *
+ * Modified to check the consistency of didname.db by
+ * Joe Clarke <marcus@marcuscom.com>
+ *
+ * $Id: cnid_didname_verify.c,v 1.7.2.1 2001-12-31 20:14:18 srittau Exp $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+#include <sys/param.h>
+
+#include <db.h>
+
+#include <atalk/cnid.h>
+#include <atalk/util.h>
+
+#ifndef MIN
+#define MIN(a, b)  ((a) < (b) ? (a) : (b))
+#endif /* ! MIN */
+
+#define DBDIDNAME "didname.db"
+
+int    main __P((int, char *[]));
+void   usage __P((void));
+void   version_check __P((void));
+
+const char
+*progname = "cnid_didname_verify";                     /* Program name. */
+
+static __inline__ int compare_did(const DBT *a, const DBT *b) {
+    u_int32_t dida, didb;
+
+    memcpy(&dida, a->data, sizeof(dida));
+    memcpy(&didb, b->data, sizeof(didb));
+    return dida - didb;
+}
+
+#if DB_VERSION_MINOR > 1
+static int compare_unix(DB *db, const DBT *a, const DBT *b)
+#else /* DB_VERSION_MINOR < 1 */
+static int compare_unix(const DBT *a, const DBT *b)
+#endif /* DB_VERSION_MINOR */
+{
+    u_int8_t *sa, *sb;
+    int len, ret;
+
+    if ((ret = compare_did(a, b)))
+        return ret;
+
+    sa = (u_int8_t *) a->data + 4;
+    sb = (u_int8_t *) b->data + 4;
+    for (len = MIN(a->size, b->size); len-- > 4; sa++, sb++)
+        if ((ret = (*sa - *sb)))
+            return ret;
+    return a->size - b->size;
+}
+
+int
+main(argc, argv)
+int argc;
+char *argv[];
+{
+    extern char *optarg;
+    extern int optind;
+    DB *dbp;
+    DB_ENV *dbenv;
+    int ch, e_close, exitval, nflag, quiet, ret, t_ret;
+    char *home;
+
+    version_check();
+
+    dbenv = NULL;
+    e_close = exitval = nflag = quiet = 0;
+    home = NULL;
+    while ((ch = getopt(argc, argv, "h:NqV")) != EOF)
+        switch (ch) {
+        case 'h':
+            home = optarg;
+            break;
+        case 'N':
+            nflag = 1;
+            if ((ret = db_env_set_panicstate(0)) != 0) {
+                fprintf(stderr,
+                        "%s: db_env_set_panicstate: %s\n",
+                        progname, db_strerror(ret));
+                exit (1);
+            }
+            break;
+            break;
+        case 'q':
+            quiet = 1;
+            break;
+        case 'V':
+            printf("%s\n", db_version(NULL, NULL, NULL));
+            exit(0);
+        case '?':
+        default:
+            usage();
+        }
+    argc -= optind;
+    argv += optind;
+
+    /*
+     * Create an environment object and initialize it for error
+     * reporting.
+     */
+    if ((ret = db_env_create(&dbenv, 0)) != 0) {
+        fprintf(stderr, "%s: db_env_create: %s\n",
+                progname, db_strerror(ret));
+        goto shutdown;
+    }
+    e_close = 1;
+
+    /*
+     * XXX
+     * We'd prefer to have error output configured while calling
+     * db_env_create, but there's no way to turn it off once it's
+     * turned on.
+     */
+    if (!quiet) {
+        dbenv->set_errfile(dbenv, stderr);
+        dbenv->set_errpfx(dbenv, progname);
+    }
+
+#if DB_VERSION_MINOR > 1
+    if (nflag && (ret = dbenv->set_mutexlocks(dbenv, 0)) != 0) {
+        dbenv->err(dbenv, ret, "set_mutexlocks");
+        goto shutdown;
+    }
+#else /* DB_VERSION_MINOR < 1 */
+    if (nflag && (ret = db_env_set_mutexlocks(0)) != 0) {
+        dbenv->err(dbenv, ret, "db_env_set_mutexlocks");
+        goto shutdown;
+    }
+#endif /* DB_VERSION_MINOR */
+
+    /*
+     * Attach to an mpool if it exists, but if that fails, attach
+     * to a private region.
+     */
+    if ((ret = dbenv->open(dbenv,
+                           home, DB_INIT_MPOOL | DB_USE_ENVIRON, 0)) != 0 &&
+            (ret = dbenv->open(dbenv, home,
+                               DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_USE_ENVIRON, 0)) != 0) {
+        dbenv->err(dbenv, ret, "open");
+        goto shutdown;
+    }
+
+    if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
+        fprintf(stderr,
+                "%s: db_create: %s\n", progname, db_strerror(ret));
+        goto shutdown;
+    }
+
+    /* This is the crux of the program.  We need to make sure we verify
+     * using the correct sort routine.  Else, the database will report
+     * corruption. */
+    dbp->set_bt_compare(dbp, &compare_unix);
+
+    if (!quiet) {
+        dbp->set_errfile(dbp, stderr);
+        dbp->set_errpfx(dbp, progname);
+    }
+    if ((ret = dbp->verify(dbp, DBDIDNAME, NULL, NULL, 0)) != 0)
+        dbp->err(dbp, ret, "DB->verify: %s", DBDIDNAME);
+    if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0) {
+        dbp->err(dbp, ret, "DB->close: %s", DBDIDNAME);
+        ret = t_ret;
+    }
+    if (ret != 0)
+        goto shutdown;
+
+    if (0) {
+shutdown:      exitval = 1;
+    }
+    if (e_close && (ret = dbenv->close(dbenv, 0)) != 0) {
+        exitval = 1;
+        fprintf(stderr,
+                "%s: dbenv->close: %s\n", progname, db_strerror(ret));
+    }
+
+    return (exitval);
+}
+
+void
+usage()
+{
+    fprintf(stderr, "usage: db_verify [-NqV] [-h home] ...\n");
+    exit (1);
+}
+
+void
+version_check()
+{
+    int v_major, v_minor, v_patch;
+
+    /* Make sure we're loaded with the right version of the DB library. */
+    (void)db_version(&v_major, &v_minor, &v_patch);
+    if (v_major != DB_VERSION_MAJOR ||
+            v_minor != DB_VERSION_MINOR || v_patch != DB_VERSION_PATCH) {
+        fprintf(stderr,
+                "%s: version %d.%d.%d doesn't match library version %d.%d.%d\n",
+                progname, DB_VERSION_MAJOR, DB_VERSION_MINOR,
+                DB_VERSION_PATCH, v_major, v_minor, v_patch);
+        exit (1);
+    }
+}
index 1b28eaf05ed4ba5775728d49796a880e21218b3e..ecc39226b9f816fb70015e37ac2eed54189a5eab 100644 (file)
@@ -1,4 +1,4 @@
-dnl $Id: configure.in,v 1.126.2.8 2001-12-31 20:11:22 srittau Exp $
+dnl $Id: configure.in,v 1.126.2.9 2001-12-31 20:14:18 srittau Exp $
 dnl configure.in for netatalk
 
 AC_INIT(bin/adv1tov2/adv1tov2.c)
@@ -225,6 +225,7 @@ elif test "x$did_scheme" = "xcnid"; then
 else
        AC_MSG_ERROR([unknown DID scheme])
 fi
+AM_CONDITIONAL(COMPILE_CNID, test "x$did_scheme" = "xcnid")
 
 dnl Check for Berkeley DB3 library
 if test "x$db3_required" = "xyes"; then
@@ -609,6 +610,7 @@ AC_OUTPUT([Makefile
        bin/aecho/Makefile
        bin/afile/Makefile
        bin/afppasswd/Makefile
+       bin/cnid/Makefile
        bin/getzones/Makefile
        bin/megatron/Makefile
        bin/nbp/Makefile