1/* 2 Copyright (C) 1999-2004 IC & S, dbmail@ic-s.nl 3 Copyright (C) 2001-2007 Aaron Stone, aaron@serendipity.cx 4 Copyright (C) 2004-2013 NFG Net Facilities Group BV, support@nfg.nl 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License as 8 published by the Free Software Foundation; either version 2 of 9 the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19*/ 20 21/** 22 * \file dbmail.h 23 * header file for a general configuration 24 */ 25 26#ifndef _DBMAIL_H 27#define _DBMAIL_H 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#define __EXTENSIONS__ /* solaris */ 34 35#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__SUNPRO_C) 36 37#define _XOPEN_SOURCE 38 39#else 40 41#define _XOPEN_SOURCE 500 42#include <features.h> 43 44#endif 45 46 47#include <assert.h> 48#include <arpa/inet.h> 49#include <ctype.h> 50#include <errno.h> 51#include <fcntl.h> 52#include <fnmatch.h> 53#include <gmime/gmime.h> 54#include <glib.h> 55#include <gmodule.h> 56#include <grp.h> 57#include <limits.h> 58#include <netinet/in.h> 59#include <netdb.h> 60#include <pwd.h> 61#include <signal.h> 62#include <syslog.h> 63#include <stdarg.h> 64#include <stdint.h> 65#include <inttypes.h> 66#include <stdbool.h> 67#include <stdio.h> 68#include <stdlib.h> 69#include <string.h> 70#include <strings.h> 71#include <sysexits.h> 72#include <dirent.h> 73#include <sys/types.h> 74#include <sys/stat.h> 75#include <sys/mman.h> 76#include <sys/socket.h> 77#include <sys/un.h> 78#include <sys/time.h> 79#include <sys/resource.h> 80#include <sys/wait.h> 81#include <sys/ipc.h> 82#include <sys/shm.h> 83#include <sys/utsname.h> 84#include <time.h> 85#include <termios.h> 86#include <unistd.h> 87#include <mhash.h> 88#include <sys/queue.h> 89#include <event2/event.h> 90#include <event2/thread.h> 91#include <evhttp.h> 92#include <math.h> 93#include <openssl/ssl.h> 94 95#ifdef AUTHLDAP 96#define LDAP_DEPRECATED 1 97#include <ldap.h> 98#endif 99 100#include <zdb.h> 101 102#include "dm_cram.h" 103#include "dm_capa.h" 104#include "dm_string.h" 105#include "dm_list.h" 106#include "dbmailtypes.h" 107#include "dm_config.h" 108#include "dm_debug.h" 109#include "dm_dsn.h" 110#include "dm_acl.h" 111#include "dm_misc.h" 112#include "dm_quota.h" 113#include "dm_tls.h" 114 115#include "dm_user.h" 116#include "dm_mailbox.h" 117#include "dm_message.h" 118#include "dm_imapsession.h" 119 120#include "imapcommands.h" 121#include "server.h" 122#include "clientsession.h" 123#include "clientbase.h" 124#include "lmtp.h" 125 126#include "dm_db.h" 127#include "dm_sievescript.h" 128 129#include "auth.h" 130#include "authmodule.h" 131 132#include "sort.h" 133#include "sortmodule.h" 134 135#include "dm_digest.h" 136#include "dm_cidr.h" 137#include "dm_iconv.h" 138#include "dm_getopt.h" 139#include "dm_match.h" 140#include "dm_sset.h" 141 142#ifdef SIEVE 143#include <sieve2.h> 144#include <sieve2_error.h> 145#endif 146 147#ifdef HAVE_SYSTEMD 148#include <systemd/sd-daemon.h> 149#endif 150 151#ifdef HAVE_CRYPT_H 152#include <crypt.h> 153#endif 154 155#ifdef HAVE_ENDIAN_H 156#include <endian.h> 157#endif 158 159#define GETCONFIGVALUE(key, sect, var) \ 160 config_get_value(key, sect, var); \ 161 if (strlen(var) > 0) \ 162 TRACE(TRACE_DEBUG, "key "#key" section "#sect" var "#var" value [%s]", var) 163 /* No final ';' so macro can be called "like a function" */ 164 165#define CONFIG_ERROR_LEVEL TRACE_WARNING 166 167#define PRINTF_THIS_IS_DBMAIL printf("This is %s\n\n%s\n", PACKAGE_STRING, COPYRIGHT) 168 169#define COPYRIGHT \ 170"Copyright (C) 1999-2004 IC & S, dbmail@ic-s.nl\n" \ 171"Copyright (C) 2001-2007 Aaron Stone, aaron@serendipity.cx\n" \ 172"Copyright (C) 2004-2013 NFG Net Facilities Group BV, support@nfg.nl\n" \ 173"\n" \ 174"Please see the AUTHORS and THANKS files for additional contributors.\n" \ 175"\n" \ 176"This program is free software; you can redistribute it and/or \n" \ 177"modify it under the terms of the GNU General Public License as\n" \ 178"published by the Free Software Foundation; either version 2 of\n" \ 179"the License, or (at your option) any later version.\n" \ 180"\n" \ 181"This program is distributed in the hope that it will be useful,\n" \ 182"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \ 183"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \ 184"GNU General Public License for more details.\n" \ 185"\n" \ 186"You should have received a copy of the GNU General Public License\n" \ 187"along with this program; if not, write to the Free Software\n" \ 188"Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n" \ 189"" 190 191/* include sql/sqlite/create_tables.sqlite for autocreation */ 192#define DM_SQLITECREATE @SQLITECREATE@ 193 194/* upgrade steps 195 */ 196#define DM_MYSQL_32001 @MYSQL_32001@ 197#define DM_PGSQL_32001 @PGSQL_32001@ 198#define DM_SQLITE_32001 @SQLITE_32001@ 199 200#define DM_MYSQL_32002 @MYSQL_32002@ 201#define DM_PGSQL_32002 @PGSQL_32002@ 202#define DM_SQLITE_32002 @SQLITE_32002@ 203 204#define DM_MYSQL_32003 @MYSQL_32003@ 205#define DM_PGSQL_32003 @PGSQL_32003@ 206#define DM_SQLITE_32003 @SQLITE_32003@ 207 208#define DM_MYSQL_32004 @MYSQL_32004@ 209#define DM_PGSQL_32004 @PGSQL_32004@ 210#define DM_SQLITE_32004 @SQLITE_32004@ 211 212#define DM_MYSQL_32005 @MYSQL_32005@ 213#define DM_PGSQL_32005 @PGSQL_32005@ 214#define DM_SQLITE_32005 @SQLITE_32005@ 215 216/* include dbmail.conf for autocreation */ 217#define DM_DEFAULT_CONFIGURATION @DM_DEFAULT_CONFIGURATION@ 218 219/** default directory and extension for pidfiles */ 220#define DEFAULT_PID_EXT ".pid" 221 222/** default locations */ 223#define DEFAULT_CONFIG_FILE SYSCONFDIR"/dbmail.conf" 224#define DEFAULT_LOG_FILE DEFAULT_LOG_DIR"/dbmail.log" 225#define DEFAULT_ERROR_LOG DEFAULT_LOG_DIR"/dbmail.err" 226#define DEFAULT_LIBRARY_DIR LIBDIR"/dbmail" 227 228#define IMAP_CAPABILITY_STRING "IMAP4rev1 AUTH=LOGIN AUTH=CRAM-MD5 ACL RIGHTS=texk NAMESPACE CHILDREN SORT QUOTA THREAD=ORDEREDSUBJECT UNSELECT IDLE STARTTLS ID UIDPLUS WITHIN LOGINDISABLED CONDSTORE LITERAL+ ENABLE QRESYNC" 229#define IMAP_TIMEOUT_MSG "* BYE dbmail IMAP4 server signing off due to timeout\r\n" 230/** prefix for #Users namespace */ 231#define NAMESPACE_USER "#Users" 232/** prefix for public namespace */ 233#define NAMESPACE_PUBLIC "#Public" 234/** seperator for namespaces and mailboxes and submailboxes */ 235#define MAILBOX_SEPARATOR "/" 236/** username for owner of public folders */ 237// FIXME: Should be #define PUBLIC_FOLDER_USER "__@!internal_public_user!@__" 238#define PUBLIC_FOLDER_USER "__public__" 239/* name of internal delivery user. */ 240#define DBMAIL_DELIVERY_USERNAME "__@!internal_delivery_user!@__" 241/* standard user for ACL anyone (see RFC 2086 and 4314) */ 242#define DBMAIL_ACL_ANYONE_USER "anyone" 243 244/* Consumers of this should be using POSTMASTER from dbmail.conf! */ 245#define DEFAULT_POSTMASTER "DBMAIL-MAILER@dbmail" 246#define AUTO_NOTIFY_SENDER "autonotify@dbmail" 247#define AUTO_NOTIFY_SUBJECT "NEW MAIL NOTIFICATION" 248 249/* maximum mime-recursion depth */ 250#ifndef MAX_MIME_DEPTH 251#define MAX_MIME_DEPTH 64 252#endif 253 254/* maximum mime boundary length (max = 70 according to RFC) */ 255#define MAX_MIME_BLEN 128 256 257/* input reading linelimit */ 258#define MAX_LINESIZE (64*1024) 259 260/* minumun number of free file descriptors required to run the daemon */ 261#define FREE_DF_THRESHOLD 16 262 263/* string length for query */ 264#define DEF_QUERYSIZE (32*1024) 265#define DEF_FRAGSIZE 256 266 267/** default table prefix */ 268#define DEFAULT_DBPFX "dbmail_" 269 270#define MATCH(x,y) ((x) && (y) && (strcasecmp((x),(y))==0)) 271#define SMATCH(x,y) (strcasecmp((x),(y))==0) 272 273#define min(x,y) ((x)<=(y)?(x):(y)) 274#define max(x,y) ((x)>=(y)?(x):(y)) 275#define ISCR(a) ((char)(a)=='\r') 276#define ISLF(a) ((char)(a)=='\n') 277#define ISDOT(a) ((char)(a)=='.') 278 279#define AUTHLOG_ERR "failed" 280#define AUTHLOG_ACT "active" 281#define AUTHLOG_FIN "closed" 282 283#define LOG_SQLERROR TRACE(TRACE_ERR,"SQLException: %s", Exception_frame.message) 284#define DISPATCH(f,a) \ 285 { \ 286 GError *err = NULL; \ 287 if (! g_thread_create((GThreadFunc)f, (gpointer)a, FALSE, &err) ) \ 288 TRACE(TRACE_DEBUG,"gthread creation failed [%s]", err->message); \ 289 } 290 291#define LOCK(a) g_static_rec_mutex_lock(a) 292#define UNLOCK(a) g_static_rec_mutex_unlock(a) 293 294#define PLOCK(a) if (pthread_mutex_lock(&(a))) { perror("pthread_mutex_lock failed"); } 295#define PUNLOCK(a) if (pthread_mutex_unlock(&(a))) { perror("pthread_mutex_unlock failed"); } 296 297#endif 298