]> code.citadel.org Git - citadel.git/commitdiff
Merge branch 'master' of ssh://git.citadel.org/var/www/gitroot/citadel
authorArt Cancro <ajc@citadel.org>
Sat, 17 Dec 2022 23:16:07 +0000 (18:16 -0500)
committerArt Cancro <ajc@citadel.org>
Sat, 17 Dec 2022 23:16:07 +0000 (18:16 -0500)
citadel/Makefile
citadel/config.mk [deleted file]
citadel/configure
citadel/server/database.c
citadel/server/modules/spam/serv_spam.c

index 726a39d6f4e5de5808b00baa859d3208b667bb30..afadac976edd29d0c624c0fa1de5de5e2e47c68b 100644 (file)
@@ -1,9 +1,8 @@
 # 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.
diff --git a/citadel/config.mk b/citadel/config.mk
deleted file mode 100644 (file)
index 58e36c7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# 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
index c7b6e94eea4c61f61c03c2e6ec47e500670856f7..9fe4e8819d12eabcf309229bf94c57d4f8b9573b 100755 (executable)
@@ -110,7 +110,7 @@ cc $tempcc -o $tempfile && {
 
 
 ########################################################################
-# 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}'\"'
index 8d0848c7b58c0f426e0ee0876d0f035540017d3f..c52ac2ae2e65f08c336e0e9b68a526b7ab7cdc9d 100644 (file)
@@ -175,22 +175,34 @@ void open_databases(void) {
        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));
@@ -258,7 +270,7 @@ void open_databases(void) {
                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);
@@ -279,9 +291,7 @@ void cdb_chmod_data(void) {
                        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);
@@ -317,7 +327,6 @@ void close_databases(void) {
 
        // 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
 
@@ -427,7 +436,8 @@ int cdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen)
                        free(compressed_data);
                }
                return ret;
-       } else {
+       }
+       else {
                bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
 
              retry:
@@ -441,11 +451,13 @@ int cdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen)
                        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);
@@ -713,7 +725,7 @@ void cdb_trunc(int cdb) {
                        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);
                        }
index 0a576a37baf9d1374c3c9234c83be22543e7fe33..76a422d8524da1dbf82c2a16c02e4187203acf62 100644 (file)
@@ -1,19 +1,9 @@
-/*
- * 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];
@@ -61,18 +46,16 @@ int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) {
        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);
@@ -80,24 +63,22 @@ int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) {
                 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;
@@ -105,13 +86,11 @@ int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) {
        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;
@@ -152,7 +131,8 @@ int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) {
 
                CM_PrependToField(msg, eMesageText, buf, headerlen);
 
-       } else {
+       }
+       else {
                 syslog(LOG_DEBUG, "reject spam code used");
                if (!strncasecmp(buf, "Spam: True", 10)) {
                        is_spam = 1;
@@ -164,8 +144,8 @@ int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) {
        }
 
 bail:  close(sock);
-       FreeStrBuf(&CCC->SBuf.Buf);
-       FreeStrBuf(&CCC->sMigrateBuf);
+       FreeStrBuf(&CC->SBuf.Buf);
+       FreeStrBuf(&CC->sMigrateBuf);
        return(is_spam);
 }
 
@@ -176,6 +156,6 @@ char *ctdl_module_init_spam(void) {
                CtdlRegisterMessageHook(spam_assassin, EVT_SMTPSCAN);
        }
        
-       /* return our module name for the log */
+       // return our module name for the log
         return "spam";
 }