Makefile: restructured so that backends can be compiled into utilities
authorArt Cancro <ajc@citadel.org>
Thu, 24 Aug 2023 13:55:33 +0000 (04:55 -0900)
committerArt Cancro <ajc@citadel.org>
Thu, 24 Aug 2023 13:55:33 +0000 (04:55 -0900)
database.c has been moved from server/ into server/backends/common.
Makefile now separates server objects from backend objects.
This is all in preparation for ctdldump and ctdlload to link the backend
code instead of calling BDB directly.

citadel/Makefile
citadel/server/backends/berkeley_db/berkeley_db.c
citadel/server/backends/common/database.c [new file with mode: 0644]
citadel/server/config.c
citadel/server/config.h
citadel/server/control.c
citadel/server/database.c [deleted file]
citadel/server/modules/upgrade/serv_upgrade.c
citadel/utils/ctdldump.c
citadel/utils/ctdlload.c

index c398891bb505ba80964a0f41475eabdd38a9a234..a4c7f55365c279e886bf036241b90917bbe823ca 100644 (file)
@@ -13,18 +13,22 @@ include config.mk
 all := ctdldump ctdlload citserver setup sendcommand citmail chkpw chkpwd
 all: $(all)
 
-SRCDIRS := $(wildcard server server/modules/* server/backends/*)
-SOURCES := $(wildcard server/*.c server/modules/*/*.c server/backends/*/*.c)
-OBJECTS := $(patsubst %.c,%.o,$(SOURCES))
+SERVER_SOURCES := $(wildcard server/*.c server/modules/*/*.c)
+SERVER_OBJECTS := $(patsubst %.c,%.o,$(SERVER_SOURCES))
+BACKEND_SOURCES := $(wildcard server/backends/*/*.c)
+BACKEND_OBJECTS := $(patsubst %.c,%.o,$(BACKEND_SOURCES))
 
-citserver: $(OBJECTS)
+citserver: $(SERVER_OBJECTS) $(BACKEND_OBJECTS)
        cc ${CFLAGS} \
-               $(OBJECTS) \
+               $(SERVER_OBJECTS) $(BACKEND_OBJECTS) \
                ${LDFLAGS} \
                -lresolv -lcitadel -lpthread -lz -lical -lldap -lcrypt -lexpat -lcurl -ldb \
                -o citserver
 
-$(SOURCES): server/*.h server/modules/*/*.h server/backends/*/*.h
+$(SERVER_SOURCES): server/*.h server/modules/*/*.h server/backends/*/*.h
+       @touch $@
+
+$(BACKEND_SOURCES): server/*.h server/modules/*/*.h server/backends/*/*.h
        @touch $@
 
 %.o: %.c
index a55c6113a2df523a69ccaf8be1edc855e98f53cb..2a8e2f14a819635ad0946e4135ab6c124808e5e3 100644 (file)
@@ -177,11 +177,9 @@ void bdb_checkpoint(void) {
        }
 
        // After a successful checkpoint, we can cull the unused logs
-       if (CtdlGetConfigInt("c_auto_cull")) {
-               ret = bdb_env->log_set_config(bdb_env, DB_LOG_AUTO_REMOVE, 1);
-       }
-       else {
-               ret = bdb_env->log_set_config(bdb_env, DB_LOG_AUTO_REMOVE, 0);
+       ret = bdb_env->log_set_config(bdb_env, DB_LOG_AUTO_REMOVE, 1);
+       if (ret != 0) {
+               syslog(LOG_ERR, "bdb: bdb_checkpoint() auto coll logs: %s", db_strerror(ret));
        }
 }
 
diff --git a/citadel/server/backends/common/database.c b/citadel/server/backends/common/database.c
new file mode 100644 (file)
index 0000000..ac1ebba
--- /dev/null
@@ -0,0 +1,79 @@
+// Copyright (c) 1987-2023 by the citadel.org team
+// This program is open source software.  Use, duplication, or disclosure
+// are subject to the terms of the GNU General Public License, version 3.
+
+// The functions in this file handle the selection and activation of a storage backend for Citadel Server.
+// Right now, it simply activates Berkeley DB because that's the only one we have.
+
+#include "../../sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <libcitadel.h>
+#include "../../ctdl_module.h"
+#include "../../control.h"
+#include "../../citserver.h"
+#include "../../config.h"
+
+// Header files for all available backends must be included here.
+#include "../berkeley_db/berkeley_db.h"
+
+// Backends must include implementations of all these functions, but with their own prefix instead of "cdb_".
+// The initialization function of the selected backend will map them.
+void                   (*cdb_open_databases)(void)                             = NULL;
+void                   (*cdb_close_databases)(void)                            = NULL;
+struct cdbdata                 (*cdb_fetch)(int, const void *, int)                    = NULL;
+int                    (*cdb_store)(int, const void *, int, void *, int)       = NULL;
+int                    (*cdb_delete)(int, void *, int)                         = NULL;
+struct cdbkeyval       (*cdb_next_item)(int)                                   = NULL;
+void                   (*cdb_close_cursor)(int)                                = NULL;
+void                   (*cdb_begin_transaction)(void)                          = NULL;
+void                   (*cdb_end_transaction)(void)                            = NULL;
+void                   (*cdb_check_handles)(void)                              = NULL;
+void                   (*cdb_trunc)(int)                                       = NULL;
+void                   (*check_handles)(void *)                                = NULL;
+void                   (*cdb_compact)(void)                                    = NULL;
+void                   (*cdb_checkpoint)(void)                                 = NULL;
+void                   (*cdb_rewind)(int)                                      = NULL;
+
+// This function is responsible for choosing and initializing a back end.
+void cdb_init_backends(void) {
+       bdb_init_backend();             // for now, this is the only one, so we select it always.
+}
+
+
+// Make sure we own all the files, because in a few milliseconds we're going to drop root privs.
+void cdb_chmod_data(void) {
+       DIR *dp;
+       struct dirent *d;
+       char filename[PATH_MAX];
+
+       // Silently try to create the database subdirectory.  If it's already there, no problem.
+       if ((mkdir(ctdl_db_dir, 0700) != 0) && (errno != EEXIST)) {
+               syslog(LOG_ERR, "bdb: database directory [%s] does not exist and could not be created: %m", ctdl_db_dir);
+               exit(CTDLEXIT_DB);
+       }
+       if (chmod(ctdl_db_dir, 0700) != 0) {
+               syslog(LOG_ERR, "bdb: unable to set database directory permissions [%s]: %m", ctdl_db_dir);
+               exit(CTDLEXIT_DB);
+       }
+       if (chown(ctdl_db_dir, ctdluid, (-1)) != 0) {
+               syslog(LOG_ERR, "bdb: unable to set the owner for [%s]: %m", ctdl_db_dir);
+               exit(CTDLEXIT_DB);
+       }
+       dp = opendir(ctdl_db_dir);
+       if (dp != NULL) {
+               while (d = readdir(dp), d != NULL) {
+                       if (d->d_name[0] != '.') {
+                               snprintf(filename, sizeof filename, "%s/%s", ctdl_db_dir, d->d_name);
+                               syslog(LOG_DEBUG, "bdb: chmod(%s, 0600) returned %d", filename, chmod(filename, 0600));
+                               syslog(LOG_DEBUG, "bdb: chown(%s, ctdluid, -1) returned %d", filename, chown(filename, ctdluid, (-1)));
+                       }
+               }
+               closedir(dp);
+       }
+}
+
+
index 49ef9600c69bf58734b727c8087cb19a8960f9da..0f14326189d4d118109692bc98827b45ccc400d0 100644 (file)
@@ -187,7 +187,6 @@ void migrate_legacy_config(struct legacy_config *lconfig) {
        CtdlSetConfigInt(       "c_imaps_port"          ,       lconfig->c_imaps_port           );
        CtdlSetConfigInt(       "c_pop3s_port"          ,       lconfig->c_pop3s_port           );
        CtdlSetConfigInt(       "c_smtps_port"          ,       lconfig->c_smtps_port           );
-       CtdlSetConfigInt(       "c_auto_cull"           ,       lconfig->c_auto_cull            );
        CtdlSetConfigInt(       "c_allow_spoofing"      ,       lconfig->c_allow_spoofing       );
        CtdlSetConfigInt(       "c_journal_email"       ,       lconfig->c_journal_email        );
        CtdlSetConfigInt(       "c_journal_pubmsgs"     ,       lconfig->c_journal_pubmsgs      );
index 23f144a482ba4eb4c147a998070e35ce5a71e43f..df68382922581dd62d558064dab717ddbd6e6534 100644 (file)
@@ -66,7 +66,7 @@ struct legacy_config {
        int c_imaps_port;
        int c_pop3s_port;
        int c_smtps_port;
-       char c_auto_cull;
+       char c_niu_4a;
        char c_niu_5;
        char c_allow_spoofing;
        char c_journal_email;
index b6e4d88bea0757699e4d774de376ef1e19f77f60..9476e40bea79270ccc8b5e449a8e1e8ed45418ed 100644 (file)
@@ -266,7 +266,7 @@ void cmd_conf(char *argbuf) {
                cprintf("%d\n",         CtdlGetConfigInt("c_pop3s_port"));
                cprintf("%d\n",         CtdlGetConfigInt("c_smtps_port"));
                cprintf("%d\n",         CtdlGetConfigInt("c_enable_fulltext"));
-               cprintf("%d\n",         CtdlGetConfigInt("c_auto_cull"));
+               cprintf("1\n");
                cprintf("1\n");
                cprintf("%d\n",         CtdlGetConfigInt("c_allow_spoofing"));
                cprintf("%d\n",         CtdlGetConfigInt("c_journal_email"));
@@ -456,7 +456,7 @@ void cmd_conf(char *argbuf) {
                                CtdlSetConfigInt("c_enable_fulltext", confbool(buf));
                                break;
                        case 43:
-                               CtdlSetConfigInt("c_auto_cull", confbool(buf));
+                               // niu
                                break;
                        case 44:
                                // niu
diff --git a/citadel/server/database.c b/citadel/server/database.c
deleted file mode 100644 (file)
index 8327ed5..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) 1987-2023 by the citadel.org team
-// This program is open source software.  Use, duplication, or disclosure
-// are subject to the terms of the GNU General Public License, version 3.
-
-// The functions in this file handle the selection and activation of a storage backend for Citadel Server.
-// Right now, it simply activates Berkeley DB because that's the only one we have.
-
-#include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <dirent.h>
-#include <libcitadel.h>
-#include "ctdl_module.h"
-#include "control.h"
-#include "citserver.h"
-#include "config.h"
-
-// Header files for all available backends must be included here.
-#include "backends/berkeley_db/berkeley_db.h"
-
-// Backends must include implementations of all these functions, but with their own prefix instead of "cdb_".
-// The initialization function of the selected backend will map them.
-void                   (*cdb_open_databases)(void)                             = NULL;
-void                   (*cdb_close_databases)(void)                            = NULL;
-struct cdbdata                 (*cdb_fetch)(int, const void *, int)                    = NULL;
-int                    (*cdb_store)(int, const void *, int, void *, int)       = NULL;
-int                    (*cdb_delete)(int, void *, int)                         = NULL;
-struct cdbkeyval       (*cdb_next_item)(int)                                   = NULL;
-void                   (*cdb_close_cursor)(int)                                = NULL;
-void                   (*cdb_begin_transaction)(void)                          = NULL;
-void                   (*cdb_end_transaction)(void)                            = NULL;
-void                   (*cdb_check_handles)(void)                              = NULL;
-void                   (*cdb_trunc)(int)                                       = NULL;
-void                   (*check_handles)(void *)                                = NULL;
-void                   (*cdb_compact)(void)                                    = NULL;
-void                   (*cdb_checkpoint)(void)                                 = NULL;
-void                   (*cdb_rewind)(int)                                      = NULL;
-
-// This function is responsible for choosing and initializing a back end.
-void cdb_init_backends(void) {
-       bdb_init_backend();             // for now, this is the only one, so we select it always.
-}
-
-
-// Make sure we own all the files, because in a few milliseconds we're going to drop root privs.
-void cdb_chmod_data(void) {
-       DIR *dp;
-       struct dirent *d;
-       char filename[PATH_MAX];
-
-       // Silently try to create the database subdirectory.  If it's already there, no problem.
-       if ((mkdir(ctdl_db_dir, 0700) != 0) && (errno != EEXIST)) {
-               syslog(LOG_ERR, "bdb: database directory [%s] does not exist and could not be created: %m", ctdl_db_dir);
-               exit(CTDLEXIT_DB);
-       }
-       if (chmod(ctdl_db_dir, 0700) != 0) {
-               syslog(LOG_ERR, "bdb: unable to set database directory permissions [%s]: %m", ctdl_db_dir);
-               exit(CTDLEXIT_DB);
-       }
-       if (chown(ctdl_db_dir, ctdluid, (-1)) != 0) {
-               syslog(LOG_ERR, "bdb: unable to set the owner for [%s]: %m", ctdl_db_dir);
-               exit(CTDLEXIT_DB);
-       }
-       dp = opendir(ctdl_db_dir);
-       if (dp != NULL) {
-               while (d = readdir(dp), d != NULL) {
-                       if (d->d_name[0] != '.') {
-                               snprintf(filename, sizeof filename, "%s/%s", ctdl_db_dir, d->d_name);
-                               syslog(LOG_DEBUG, "bdb: chmod(%s, 0600) returned %d", filename, chmod(filename, 0600));
-                               syslog(LOG_DEBUG, "bdb: chown(%s, ctdluid, -1) returned %d", filename, chown(filename, ctdluid, (-1)));
-                       }
-               }
-               closedir(dp);
-       }
-}
-
-
index 2c662245f62a51d6bc3f9d4b722716c4212b15b5..4fab951b22ffaa4ca1f13759836c93f821da9d76 100644 (file)
@@ -303,10 +303,6 @@ void update_config(void) {
                CtdlSetConfigInt("c_enable_fulltext", 1);
        }
 
-       if (oldver < 652) {
-               CtdlSetConfigInt("c_auto_cull", 1);
-       }
-
        if (oldver < 725) {
                CtdlSetConfigInt("c_xmpp_c2s_port", 5222);
                CtdlSetConfigInt("c_xmpp_s2s_port", 5269);
index ccd6c18cc41ff254376e8a43027afd845bc3e0b7..20858527166a560960c5cdf2c71530058c7617a0 100644 (file)
@@ -27,6 +27,7 @@
 #include "../server/server.h"
 #include "../server/citadel_dirs.h"
 
+uid_t ctdluid = 0;
 
 // Wrapper for realloc() that crashes and burns if the call fails.
 void *reallok(void *ptr, size_t size) {
index 406618b22af484e4e4e5783af45abf5fadfefdbd..3a5f64a6c3d266bb1d3951eb4f7fcba3d011b630 100644 (file)
@@ -28,6 +28,7 @@
 #include "../server/makeuserkey.h"
 #include "../server/citadel_dirs.h"
 
+uid_t ctdluid = 0;
 
 // Wrapper for realloc() that crashes and burns if the call fails.
 void *reallok(void *ptr, size_t size) {