# Makefile for Citadel Server
# Copyright (c) 1987-2022 by Art Cancro and the citadel.org team
-#
-# This is the new and improved version that does not use the GNU Autotools,
-# because it is The Current Year and we aren't trying to build for weird
-# obscure systems anymore.
+#
+# No, we are NOT using the obsolete GNU Autotools. This configure script works
+# well on the Linux operating system (which uses the Linux kernel) and on BSD.
#
# This program is open source software. Use, duplication, and/or
# disclosure are subject to the GNU General Purpose License version 3.
+++ /dev/null
-# config.mk is generated by configure
-CTDLDIR := /root/citadel/citadel
-CFLAGS := -ggdb -DHAVE_OPENSSL -DBUILD_ID=\"v957-74-g825c7f252\" -DCTDLDIR=\"/root/citadel/citadel\"
-LDFLAGS := -lssl -lcrypto -lz
########################################################################
-# FIXME do a real build id here
+# The build ID can be generated from git or from the date
########################################################################
CFLAGS=${CFLAGS}' -DBUILD_ID=\"'$(git describe 2>/dev/null || date +%y%03j)'\"'
CFLAGS=${CFLAGS}' -DCTDLDIR=\"'${CTDLDIR}'\"'
int dbversion_major, dbversion_minor, dbversion_patch;
syslog(LOG_DEBUG, "db: open_databases() starting");
+ syslog(LOG_DEBUG, "db: Linked zlib: %s", zlibVersion());
syslog(LOG_DEBUG, "db: Compiled libdb: %s", DB_VERSION_STRING);
syslog(LOG_DEBUG, "db: Linked libdb: %s", db_version(&dbversion_major, &dbversion_minor, &dbversion_patch));
- syslog(LOG_DEBUG, "db: Linked zlib: %s", zlibVersion());
+
+ // 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) {
+ syslog(LOG_ERR, "db: citserver is running with a version of libdb older than the one with which it was compiled.");
+ syslog(LOG_ERR, "db: This is an invalid configuration. citserver will now exit to prevent data loss.");
+ exit(CTDLEXIT_DB);
+ }
// 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, "db: unable to create database directory [%s]: %m", ctdl_db_dir);
+ syslog(LOG_ERR, "db: 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, "db: 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, "db: unable to set the owner for [%s]: %m", ctdl_db_dir);
+ exit(CTDLEXIT_DB);
}
syslog(LOG_DEBUG, "db: Setting up DB environment");
- // db_env_set_func_yield((int (*)(u_long, u_long))sched_yield);
ret = db_env_create(&dbenv, 0);
if (ret) {
syslog(LOG_ERR, "db: db_env_create: %s", db_strerror(ret));
if (ret) {
syslog(LOG_ERR, "db: db_open[%02x]: %s", i, db_strerror(ret));
if (ret == ENOMEM) {
- syslog(LOG_ERR, "db: You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information.");
+ syslog(LOG_ERR, "db: You may need to tune your database; please check http://www.citadel.org for more information.");
}
syslog(LOG_ERR, "db: exit code %d", ret);
exit(CTDLEXIT_DB);
if (d->d_name[0] != '.') {
snprintf(filename, sizeof filename, "%s/%s", ctdl_db_dir, d->d_name);
syslog(LOG_DEBUG, "db: chmod(%s, 0600) returned %d", filename, chmod(filename, 0600));
- syslog(LOG_DEBUG, "db: chown(%s, CTDLUID, -1) returned %d",
- filename, chown(filename, CTDLUID, (-1))
- );
+ syslog(LOG_DEBUG, "db: chown(%s, CTDLUID, -1) returned %d", filename, chown(filename, CTDLUID, (-1)));
}
}
closedir(dp);
// This seemed nifty at the time but did anyone really look at it?
// #ifdef DB_STAT_ALL
- // /* print some statistics... */
// dbenv->lock_stat_print(dbenv, DB_STAT_ALL);
// #endif
free(compressed_data);
}
return ret;
- } else {
+ }
+ else {
bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
retry:
if (ret == DB_LOCK_DEADLOCK) {
txabort(tid);
goto retry;
- } else {
+ }
+ else {
syslog(LOG_ERR, "db: cdb_store(%d): %s", cdb, db_strerror(ret));
cdb_abort();
}
- } else {
+ }
+ else {
txcommit(tid);
if (compressing) {
free(compressed_data);
else {
syslog(LOG_ERR, "db: cdb_truncate(%d): %s", cdb, db_strerror(ret));
if (ret == ENOMEM) {
- syslog(LOG_ERR, "db: You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information.");
+ syslog(LOG_ERR, "db: You may need to tune your database; please read http://www.citadel.org for more information.");
}
exit(CTDLEXIT_DB);
}
-/*
- * This module allows Citadel to use SpamAssassin to filter incoming messages
- * arriving via SMTP. For more information on SpamAssassin, visit
- * http://www.spamassassin.org (the SpamAssassin project is not in any way
- * affiliated with the Citadel project).
- *
- * Copyright (c) 1998-2022 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
+// This module allows Citadel to use an external SpamAssassin service to filter incoming messages arriving via SMTP.
+//
+// Copyright (c) 1998-2022 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.
#define SPAMASSASSIN_PORT "783"
#include "../../internet_addressing.h"
#include "../../domain.h"
#include "../../clientsocket.h"
-
-
#include "../../ctdl_module.h"
-
-/*
- * Connect to the SpamAssassin server and scan a message.
- */
+// Connect to the SpamAssassin server and scan a message.
int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) {
int sock = (-1);
char sahosts[SIZ];
int is_spam = 0;
int sa;
StrBuf *msgtext;
- CitContext *CCC=CC;
- /* For users who have authenticated to this server we never want to
- * apply spam filtering, because presumably they're trustworthy.
- */
+ // For users who have authenticated to this server we never want to
+ // apply spam filtering, because presumably they're trustworthy.
if (CC->logged_in) return(0);
- /* See if we have any SpamAssassin hosts configured */
+ // See if we have any SpamAssassin hosts configured
num_sahosts = get_hosts(sahosts, "spamassassin");
if (num_sahosts < 1) return(0);
- /* Try them one by one until we get a working one */
+ // Try them one by one until we get a working one
for (sa=0; sa<num_sahosts; ++sa) {
extract_token(buf, sahosts, sa, '|', sizeof buf);
syslog(LOG_INFO, "Connecting to SpamAssassin at <%s>\n", buf);
if (sock >= 0) syslog(LOG_DEBUG, "Connected!\n");
}
+ // If the service isn't running, just pass the mail through. Potentially throwing away mails isn't good.
if (sock < 0) {
- /* If the service isn't running, just pass the mail
- * through. Potentially throwing away mails isn't good.
- */
return(0);
}
- CCC->SBuf.Buf = NewStrBuf();
- CCC->sMigrateBuf = NewStrBuf();
- CCC->SBuf.ReadWritePointer = NULL;
+ CC->SBuf.Buf = NewStrBuf();
+ CC->sMigrateBuf = NewStrBuf();
+ CC->SBuf.ReadWritePointer = NULL;
- /* Command */
+ // Command
syslog(LOG_DEBUG, "Transmitting command\n");
sprintf(buf, "CHECK SPAMC/1.2\r\n\r\n");
sock_write(&sock, buf, strlen(buf));
- /* Message */
- CCC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
+ // Message
+ CC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1, 0);
msgtext = CC->redirect_buffer;
CC->redirect_buffer = NULL;
sock_write(&sock, SKEY(msgtext));
FreeStrBuf(&msgtext);
- /* Close one end of the socket connection; this tells SpamAssassin
- * that we're done.
- */
+ // Close one end of the socket connection; this tells SpamAssassin that we're done.
if (sock != -1)
sock_shutdown(sock, SHUT_WR);
- /* Response */
+ // Response
syslog(LOG_DEBUG, "Awaiting response\n");
if (sock_getln(&sock, buf, sizeof buf) < 0) {
goto bail;
CM_PrependToField(msg, eMesageText, buf, headerlen);
- } else {
+ }
+ else {
syslog(LOG_DEBUG, "reject spam code used");
if (!strncasecmp(buf, "Spam: True", 10)) {
is_spam = 1;
}
bail: close(sock);
- FreeStrBuf(&CCC->SBuf.Buf);
- FreeStrBuf(&CCC->sMigrateBuf);
+ FreeStrBuf(&CC->SBuf.Buf);
+ FreeStrBuf(&CC->sMigrateBuf);
return(is_spam);
}
CtdlRegisterMessageHook(spam_assassin, EVT_SMTPSCAN);
}
- /* return our module name for the log */
+ // return our module name for the log
return "spam";
}