From: Art Cancro Date: Thu, 24 Aug 2023 13:55:33 +0000 (-0900) Subject: Makefile: restructured so that backends can be compiled into utilities X-Git-Tag: v989~51 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=7d327eaa0500ed510350362e6e1eb74f3500a911;p=citadel.git Makefile: restructured so that backends can be compiled into utilities 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. --- diff --git a/citadel/Makefile b/citadel/Makefile index c398891bb..a4c7f5536 100644 --- a/citadel/Makefile +++ b/citadel/Makefile @@ -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 diff --git a/citadel/server/backends/berkeley_db/berkeley_db.c b/citadel/server/backends/berkeley_db/berkeley_db.c index a55c6113a..2a8e2f14a 100644 --- a/citadel/server/backends/berkeley_db/berkeley_db.c +++ b/citadel/server/backends/berkeley_db/berkeley_db.c @@ -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 index 000000000..ac1ebbad6 --- /dev/null +++ b/citadel/server/backends/common/database.c @@ -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 +#include +#include +#include +#include +#include +#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); + } +} + + diff --git a/citadel/server/config.c b/citadel/server/config.c index 49ef9600c..0f1432618 100644 --- a/citadel/server/config.c +++ b/citadel/server/config.c @@ -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 ); diff --git a/citadel/server/config.h b/citadel/server/config.h index 23f144a48..df6838292 100644 --- a/citadel/server/config.h +++ b/citadel/server/config.h @@ -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; diff --git a/citadel/server/control.c b/citadel/server/control.c index b6e4d88be..9476e40be 100644 --- a/citadel/server/control.c +++ b/citadel/server/control.c @@ -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 index 8327ed500..000000000 --- a/citadel/server/database.c +++ /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 -#include -#include -#include -#include -#include -#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); - } -} - - diff --git a/citadel/server/modules/upgrade/serv_upgrade.c b/citadel/server/modules/upgrade/serv_upgrade.c index 2c662245f..4fab951b2 100644 --- a/citadel/server/modules/upgrade/serv_upgrade.c +++ b/citadel/server/modules/upgrade/serv_upgrade.c @@ -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); diff --git a/citadel/utils/ctdldump.c b/citadel/utils/ctdldump.c index ccd6c18cc..208585271 100644 --- a/citadel/utils/ctdldump.c +++ b/citadel/utils/ctdldump.c @@ -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) { diff --git a/citadel/utils/ctdlload.c b/citadel/utils/ctdlload.c index 406618b22..3a5f64a6c 100644 --- a/citadel/utils/ctdlload.c +++ b/citadel/utils/ctdlload.c @@ -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) {