dbnothing: temporary utility that just opens and closes the database as a test
authorArt Cancro <ajc@citadel.org>
Fri, 25 Aug 2023 00:06:31 +0000 (15:06 -0900)
committerArt Cancro <ajc@citadel.org>
Fri, 25 Aug 2023 00:06:31 +0000 (15:06 -0900)
citadel/Makefile
citadel/utils/dbnothing.c [new file with mode: 0644]

index 58425abe46bb2e23f8b7128a0540b77b6ec74363..2241feb9ddbe6c42224dd7c04f1557ffb784c63b 100644 (file)
@@ -10,7 +10,7 @@
 # config.mk is generated by ./configure
 include config.mk
 
-all := ctdldump ctdlload citserver setup sendcommand citmail chkpw chkpwd
+all := dbnothing ctdldump ctdlload citserver setup sendcommand citmail chkpw chkpwd
 all: $(all)
 
 SERVER_SOURCES := $(wildcard server/*.c server/modules/*/*.c)
@@ -53,6 +53,9 @@ 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
 
+dbnothing: utils/dbnothing.c utils/*.h server/*.h ${BACKEND_OBJECTS}
+       cc ${CFLAGS} ${LDFLAGS} utils/dbnothing.c ${BACKEND_OBJECTS} -lcitadel -lz ${BACKEND_LDFLAGS} -lpthread -o dbnothing
+
 ctdldump: utils/ctdldump.c utils/*.h server/*.h ${BACKEND_OBJECTS}
        cc ${CFLAGS} ${LDFLAGS} utils/ctdldump.c ${BACKEND_OBJECTS} -lcitadel -lz ${BACKEND_LDFLAGS} -lpthread -o ctdldump
 
diff --git a/citadel/utils/dbnothing.c b/citadel/utils/dbnothing.c
new file mode 100644 (file)
index 0000000..914f963
--- /dev/null
@@ -0,0 +1,80 @@
+// Don't run this.  It doesn't work and if you try to run it you will immediately die.
+//
+// Copyright (c) 2023 by Art Cancro citadel.org
+//
+// 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 <syslog.h>
+#include <libcitadel.h>
+#include <zlib.h>
+#include "../server/sysdep.h"
+#include "../server/citadel_defs.h"
+#include "../server/server.h"
+#include "../server/citadel_dirs.h"
+#include "../server/database.h"
+
+uid_t ctdluid = 0;
+
+
+int main(int argc, char **argv) {
+       int i = 0;
+       int confirmed = 0;
+       char *ctdldir = CTDLDIR;
+
+       // display the greeting
+       fprintf(stderr, "\033[44m\033[33m\033[1m \033[K\033[0m\n"
+                       "\033[44m\033[33m\033[1m dbnothing utility for Citadel \033[K\033[0m\n"
+                       "\033[44m\033[33m\033[1m Copyright (c) 2023 by citadel.org et al.  \033[K\033[0m\n"
+                       "\033[44m\033[33m\033[1m This program is open source software.  Use, duplication, or disclosure \033[K\033[0m\n"
+                       "\033[44m\033[33m\033[1m is subject to the terms of the GNU General Public license v3. \033[K\033[0m\n"
+                       "\033[44m\033[33m\033[1m \033[K\033[0m\n");
+
+       // Parse command line
+       int a;
+       while ((a = getopt(argc, argv, "h:y")) != EOF) {
+               switch (a) {
+               case 'h':
+                       ctdldir = optarg;
+                       break;
+               default:
+                       fprintf(stderr, "%s: usage: %s -s citadel_dir [>dumpfile]\n", argv[0], argv[0]);
+                       exit(2);
+               }
+       }
+
+       if (chdir(ctdldir) != 0) {
+               fprintf(stderr, "ctdlload: unable to change directory to [%s]: %m", ctdldir);
+               exit(2);
+       }
+
+       // backend modules use syslog -- redirect to stderr
+       openlog("dbnothing", LOG_PERROR , LOG_DAEMON);
+
+       // initialize the database backend
+       cdb_init_backends();
+       cdb_open_databases();
+
+       // do nothing
+       fprintf(stderr, "dbnothing: doing nothing\n");
+
+       // close databases
+       cdb_close_databases();
+
+       fprintf(stderr, "dbnothing: \033[32m\033[1mfinished\033[0m\n");
+       exit(0);
+}