]> code.citadel.org Git - citadel.git/commitdiff
Restored `ctdl3264` but disabled it.
authorArt Cancro <ajc@citadel.org>
Wed, 29 Mar 2023 18:47:45 +0000 (14:47 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 29 Mar 2023 18:47:45 +0000 (14:47 -0400)
We may want to try this again.

citadel/Makefile
citadel/utils/ctdl3264.c [new file with mode: 0644]
citadel/utils/ctdl3264_prep.sh [new file with mode: 0755]

index c89f92cc0aa6d115a38e8ffef2d8962b5edd6228..7243f6b1d10836cb8f697cf56a7a9e5cd2df3f6c 100644 (file)
@@ -38,6 +38,13 @@ chkpw: utils/chkpw.c utils/*.h server/*.h
 chkpwd: utils/chkpwd.c utils/auth.c utils/*.h server/*.h
        cc ${CFLAGS} ${LDFLAGS} utils/chkpwd.c utils/auth.c -lcrypt -o chkpwd
 
+# The `ctdl3264` utility is being kept on hold for now, as it may be resurrected someday.
+# Add `ctdl3264` to the `all` target if we do that.
+#ctdl3264: utils/ctdl3264.c utils/*.h server/*.h utils/ctdl3264_structs.h
+#      cc ${CFLAGS} ${LDFLAGS} utils/ctdl3264.c -lcitadel -lz -ldb -o ctdl3264
+#utils/ctdl3264_structs.h: server/server.h utils/ctdl3264_prep.sh
+#      utils/ctdl3264_prep.sh
+
 config.mk: configure
        ./configure
 
diff --git a/citadel/utils/ctdl3264.c b/citadel/utils/ctdl3264.c
new file mode 100644 (file)
index 0000000..39c1f55
--- /dev/null
@@ -0,0 +1,195 @@
+// Attempt to convert your database from 32-bit to 64-bit.
+// Don't run this.  It doesn't work and if you try to run it you will immediately die.
+//
+// Copyright (c) 2023 by the citadel.org team
+//
+// This program is open source software.  Use, duplication, or disclosure
+// is subject to the terms of the GNU General Public License, version 3.
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netdb.h>
+#include <string.h>
+#include <pwd.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <libcitadel.h>
+#include <zlib.h>
+#include <db.h>
+#include "../server/sysdep.h"
+#include "../server/citadel_defs.h"
+#include "../server/server.h"
+#include "../server/citadel_dirs.h"
+#include "ctdl3264_structs.h"
+
+static DB *dbp[MAXCDB];                // One DB handle for each Citadel database
+static DB_ENV *dbenv;          // The DB environment (global)
+
+// Open the various databases we'll be using.  Any database which
+// does not exist should be created.  Note that we don't need a
+// critical section here, because there aren't any active threads
+// manipulating the database yet.
+void open_databases(void) {
+       int ret;
+       int i;
+       char dbfilename[32];
+       u_int32_t flags = 0;
+       int dbversion_major, dbversion_minor, dbversion_patch;
+
+       printf( "db: open_databases() starting\n"
+               "db:    Linked zlib: %s\n"
+               "db: Compiled libdb: %s\n"
+               "db:   Linked libdb: %s\n",
+               zlibVersion(),
+               DB_VERSION_STRING,
+               db_version(&dbversion_major, &dbversion_minor, &dbversion_patch)
+       );
+
+       // Create synthetic integer version numbers and compare them.
+       // Never allow citserver to run with a libdb older then the one with which it was compiled.
+       int compiled_db_version = ( (DB_VERSION_MAJOR * 1000000) + (DB_VERSION_MINOR * 1000) + (DB_VERSION_PATCH) );
+       int linked_db_version = ( (dbversion_major * 1000000) + (dbversion_minor * 1000) + (dbversion_patch) );
+       if (compiled_db_version > linked_db_version) {
+               printf( "db: citserver is running with a version of libdb older than the one with which it was compiled.\n"
+                       "db: This is an invalid configuration.  citserver will now exit to prevent data loss.");
+               exit(CTDLEXIT_DB);
+       }
+
+       printf("db: Setting up DB environment\n");
+       ret = db_env_create(&dbenv, 0);
+       if (ret) {
+               printf("db: db_env_create: %s\n", db_strerror(ret));
+               printf("db: exit code %d\n", ret);
+               exit(CTDLEXIT_DB);
+       }
+
+       // We want to specify the shared memory buffer pool cachesize, but everything else is the default.
+       ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0);
+       if (ret) {
+               printf("db: set_cachesize: %s\n", db_strerror(ret));
+               dbenv->close(dbenv, 0);
+               printf("db: exit code %d\n", ret);
+               exit(CTDLEXIT_DB);
+       }
+
+       if ((ret = dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT))) {
+               printf("db: set_lk_detect: %s\n", db_strerror(ret));
+               dbenv->close(dbenv, 0);
+               printf("db: exit code %d\n", ret);
+               exit(CTDLEXIT_DB);
+       }
+
+       flags = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_INIT_TXN | DB_INIT_LOCK | DB_THREAD | DB_INIT_LOG;
+       printf("db: dbenv->open(dbenv, %s, %d, 0)\n", ctdl_db_dir, flags);
+       ret = dbenv->open(dbenv, ctdl_db_dir, flags, 0);                                // try opening the database cleanly
+       if (ret == DB_RUNRECOVERY) {
+               printf("db: dbenv->open: %s\n", db_strerror(ret));
+               printf("db: attempting recovery...\n");
+               flags |= DB_RECOVER;
+               ret = dbenv->open(dbenv, ctdl_db_dir, flags, 0);                        // try recovery
+       }
+       if (ret == DB_RUNRECOVERY) {
+               printf("db: dbenv->open: %s\n", db_strerror(ret));
+               printf("db: attempting catastrophic recovery...\n");
+               flags &= ~DB_RECOVER;
+               flags |= DB_RECOVER_FATAL;
+               ret = dbenv->open(dbenv, ctdl_db_dir, flags, 0);                        // try catastrophic recovery
+       }
+       if (ret) {
+               printf("db: dbenv->open: %s\n", db_strerror(ret));
+               dbenv->close(dbenv, 0);
+               printf("db: exit code %d\n", ret);
+               exit(CTDLEXIT_DB);
+       }
+
+       for (i = 0; i < MAXCDB; ++i) {
+               printf("db: mounting database %d\n", i);
+               ret = db_create(&dbp[i], dbenv, 0);                                     // Create a database handle
+               if (ret) {
+                       printf("db: db_create: %s\n", db_strerror(ret));
+                       printf("db: exit code %d\n", ret);
+                       exit(CTDLEXIT_DB);
+               }
+
+               snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", i);                 // table names by number
+               ret = dbp[i]->open(dbp[i], NULL, dbfilename, NULL, DB_BTREE, DB_AUTO_COMMIT, 0600);
+               if (ret) {
+                       printf("db: db_open[%02x]: %s\n", i, db_strerror(ret));
+                       if (ret == ENOMEM) {
+                               printf("db: You may need to tune your database; please check http://www.citadel.org for more information.\n");
+                       }
+                       printf("db: exit code %d\n", ret);
+                       exit(CTDLEXIT_DB);
+               }
+       }
+}
+
+
+// Close all of the db database files we've opened.  This can be done in a loop, since it's just a bunch of closes.
+void close_databases(void) {
+       int i;
+       int ret;
+
+       //syslog(LOG_INFO, "db: performing final checkpoint");
+       //if ((ret = dbenv->txn_checkpoint(dbenv, 0, 0, 0))) {
+               //syslog(LOG_ERR, "db: txn_checkpoint: %s", db_strerror(ret));
+       //}
+
+       printf("db: flushing the database logs\n");
+       if ((ret = dbenv->log_flush(dbenv, NULL))) {
+               printf("db: log_flush: %s\n", db_strerror(ret));
+       }
+
+       // close the tables
+       printf("db: closing databases\n");
+       for (i = 0; i < MAXCDB; ++i) {
+               printf("db: closing database %02x\n", i);
+               ret = dbp[i]->close(dbp[i], 0);
+               if (ret) {
+                       printf("db: db_close: %s\n", db_strerror(ret));
+               }
+
+       }
+
+       // Close the handle.
+       ret = dbenv->close(dbenv, 0);
+       if (ret) {
+               printf("db: DBENV->close: %s\n", db_strerror(ret));
+       }
+}
+
+int main(int argc, char **argv) {
+       char ctdldir[PATH_MAX]=CTDLDIR;
+
+       // Check to make sure we're running on the target 64-bit system
+       if (sizeof(void *) != 8) {
+               fprintf(stderr, "%s: this is a %ld-bit system.\n", argv[0], sizeof(void *)*8);
+               fprintf(stderr, "%s: you must run this on a 64-bit system, onto which a 32-bit database has been copied.\n", argv[0]);
+               exit(1);
+       }
+
+       // Parse command line
+       int a;
+       while ((a = getopt(argc, argv, "h:")) != EOF) {
+               switch (a) {
+               case 'h':
+                       strncpy(ctdldir, optarg, sizeof ctdldir);
+                       break;
+               default:
+                       fprintf(stderr, "%s: usage: %s [-h server_dir]\n", argv[0], argv[0]);
+                       exit(2);
+               }
+       }
+
+       open_databases();
+       close_databases();
+
+       exit(0);
+}
diff --git a/citadel/utils/ctdl3264_prep.sh b/citadel/utils/ctdl3264_prep.sh
new file mode 100755 (executable)
index 0000000..9a2ac20
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+# Copyright (c) 2023 by the citadel.org team
+# This program is open source software.  Use, duplication, or disclosure
+# is subject to the terms of the GNU General Public License, version 3.
+
+# Source our data structures from the real live working code
+SERVER_H=server/server.h
+
+# Generate the "32-bit" versions of these structures.
+# Note that this is specifically converting "32-bit to 64-bit" -- NOT "any-to-any"
+convert_struct() {
+       start_line=$(cat ${SERVER_H} | egrep -n "^struct $1 {" | cut -d: -f1)
+       tail +${start_line} ${SERVER_H} | sed '/};/q' \
+       | sed s/"^struct $1 {"/"struct ${1}_32 {"/g \
+       | sed s/"long "/"int32_t "/g \
+       | sed s/"time_t "/"int32_t "/g \
+       | sed s/"struct ExpirePolicy "/"struct ExpirePolicy_32 "/g
+       echo ''
+
+}
+
+# Here we go.  Let's make this thing happen.
+(
+
+       echo '// This file was automatically generated by ctdl3264_prep.sh'
+       echo '// Attempting to modify it would be an exercise in futility.'
+       echo ''
+
+       convert_struct "ctdluser"
+       convert_struct "ExpirePolicy"
+       convert_struct "ctdlroom"
+       convert_struct "floor"
+       convert_struct "visit"
+
+) >utils/ctdl3264_structs.h