1a9e8641dSBaptiste Daroussin /* 2e56bad4aSBaptiste Daroussin * Copyright (c) 2008-2014, Simon Schubert <2@0x2c.org>. 3a9e8641dSBaptiste Daroussin * Copyright (c) 2008 The DragonFly Project. All rights reserved. 4a9e8641dSBaptiste Daroussin * 5a9e8641dSBaptiste Daroussin * This code is derived from software contributed to The DragonFly Project 6e56bad4aSBaptiste Daroussin * by Simon Schubert <2@0x2c.org> and 7a9e8641dSBaptiste Daroussin * Matthias Schmidt <matthias@dragonflybsd.org>. 8a9e8641dSBaptiste Daroussin * 9a9e8641dSBaptiste Daroussin * Redistribution and use in source and binary forms, with or without 10a9e8641dSBaptiste Daroussin * modification, are permitted provided that the following conditions 11a9e8641dSBaptiste Daroussin * are met: 12a9e8641dSBaptiste Daroussin * 13a9e8641dSBaptiste Daroussin * 1. Redistributions of source code must retain the above copyright 14a9e8641dSBaptiste Daroussin * notice, this list of conditions and the following disclaimer. 15a9e8641dSBaptiste Daroussin * 2. Redistributions in binary form must reproduce the above copyright 16a9e8641dSBaptiste Daroussin * notice, this list of conditions and the following disclaimer in 17a9e8641dSBaptiste Daroussin * the documentation and/or other materials provided with the 18a9e8641dSBaptiste Daroussin * distribution. 19a9e8641dSBaptiste Daroussin * 3. Neither the name of The DragonFly Project nor the names of its 20a9e8641dSBaptiste Daroussin * contributors may be used to endorse or promote products derived 21a9e8641dSBaptiste Daroussin * from this software without specific, prior written permission. 22a9e8641dSBaptiste Daroussin * 23a9e8641dSBaptiste Daroussin * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24a9e8641dSBaptiste Daroussin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25a9e8641dSBaptiste Daroussin * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26a9e8641dSBaptiste Daroussin * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 27a9e8641dSBaptiste Daroussin * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28a9e8641dSBaptiste Daroussin * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 29a9e8641dSBaptiste Daroussin * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30a9e8641dSBaptiste Daroussin * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 31a9e8641dSBaptiste Daroussin * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32a9e8641dSBaptiste Daroussin * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 33a9e8641dSBaptiste Daroussin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34a9e8641dSBaptiste Daroussin * SUCH DAMAGE. 35a9e8641dSBaptiste Daroussin */ 36a9e8641dSBaptiste Daroussin 37a9e8641dSBaptiste Daroussin #ifndef DMA_H 38a9e8641dSBaptiste Daroussin #define DMA_H 39a9e8641dSBaptiste Daroussin 40a9e8641dSBaptiste Daroussin #include <sys/types.h> 41a9e8641dSBaptiste Daroussin #include <sys/queue.h> 42a9e8641dSBaptiste Daroussin #include <sys/socket.h> 43a9e8641dSBaptiste Daroussin #include <arpa/nameser.h> 44a9e8641dSBaptiste Daroussin #include <arpa/inet.h> 45a9e8641dSBaptiste Daroussin #include <openssl/ssl.h> 46a9e8641dSBaptiste Daroussin #include <netdb.h> 47e56bad4aSBaptiste Daroussin #include <sysexits.h> 48a9e8641dSBaptiste Daroussin 49a9e8641dSBaptiste Daroussin #define VERSION "DragonFly Mail Agent " DMA_VERSION 50a9e8641dSBaptiste Daroussin 51a9e8641dSBaptiste Daroussin #define BUF_SIZE 2048 522382c29eSBaptiste Daroussin #define ERRMSG_SIZE 1024 53a9e8641dSBaptiste Daroussin #define USERNAME_SIZE 50 54*fbe95b88SBaptiste Daroussin #define EHLO_RESPONSE_SIZE BUF_SIZE 55a9e8641dSBaptiste Daroussin #define MIN_RETRY 300 /* 5 minutes */ 56a9e8641dSBaptiste Daroussin #define MAX_RETRY (3*60*60) /* retry at least every 3 hours */ 57a9e8641dSBaptiste Daroussin #define MAX_TIMEOUT (5*24*60*60) /* give up after 5 days */ 58a9e8641dSBaptiste Daroussin #define SLEEP_TIMEOUT 30 /* check for queue flush every 30 seconds */ 59a9e8641dSBaptiste Daroussin #ifndef PATH_MAX 60a9e8641dSBaptiste Daroussin #define PATH_MAX 1024 /* Max path len */ 61a9e8641dSBaptiste Daroussin #endif 62a9e8641dSBaptiste Daroussin #define SMTP_PORT 25 /* Default SMTP port */ 63a9e8641dSBaptiste Daroussin #define CON_TIMEOUT (5*60) /* Connection timeout per RFC5321 */ 64a9e8641dSBaptiste Daroussin 65a9e8641dSBaptiste Daroussin #define STARTTLS 0x002 /* StartTLS support */ 66*fbe95b88SBaptiste Daroussin #define SECURETRANSFER 0x004 /* SSL/TLS in general */ 67a9e8641dSBaptiste Daroussin #define NOSSL 0x008 /* Do not use SSL */ 68a9e8641dSBaptiste Daroussin #define DEFER 0x010 /* Defer mails */ 69a9e8641dSBaptiste Daroussin #define INSECURE 0x020 /* Allow plain login w/o encryption */ 70a9e8641dSBaptiste Daroussin #define FULLBOUNCE 0x040 /* Bounce the full message */ 71a9e8641dSBaptiste Daroussin #define TLS_OPP 0x080 /* Opportunistic STARTTLS */ 72a9e8641dSBaptiste Daroussin #define NULLCLIENT 0x100 /* Nullclient support */ 73a9e8641dSBaptiste Daroussin 74a9e8641dSBaptiste Daroussin #ifndef CONF_PATH 75a9e8641dSBaptiste Daroussin #error Please define CONF_PATH 76a9e8641dSBaptiste Daroussin #endif 77a9e8641dSBaptiste Daroussin 78a9e8641dSBaptiste Daroussin #ifndef LIBEXEC_PATH 79a9e8641dSBaptiste Daroussin #error Please define LIBEXEC_PATH 80a9e8641dSBaptiste Daroussin #endif 81a9e8641dSBaptiste Daroussin 82a9e8641dSBaptiste Daroussin #define SPOOL_FLUSHFILE "flush" 83a9e8641dSBaptiste Daroussin 84a9e8641dSBaptiste Daroussin #ifndef DMA_ROOT_USER 85a9e8641dSBaptiste Daroussin #define DMA_ROOT_USER "mail" 86a9e8641dSBaptiste Daroussin #endif 87a9e8641dSBaptiste Daroussin #ifndef DMA_GROUP 88a9e8641dSBaptiste Daroussin #define DMA_GROUP "mail" 89a9e8641dSBaptiste Daroussin #endif 90a9e8641dSBaptiste Daroussin 91a9e8641dSBaptiste Daroussin #ifndef MBOX_STRICT 92a9e8641dSBaptiste Daroussin #define MBOX_STRICT 0 93a9e8641dSBaptiste Daroussin #endif 94a9e8641dSBaptiste Daroussin 95a9e8641dSBaptiste Daroussin 96a9e8641dSBaptiste Daroussin struct stritem { 97a9e8641dSBaptiste Daroussin SLIST_ENTRY(stritem) next; 98a9e8641dSBaptiste Daroussin char *str; 99a9e8641dSBaptiste Daroussin }; 100a9e8641dSBaptiste Daroussin SLIST_HEAD(strlist, stritem); 101a9e8641dSBaptiste Daroussin 102a9e8641dSBaptiste Daroussin struct alias { 103a9e8641dSBaptiste Daroussin LIST_ENTRY(alias) next; 104a9e8641dSBaptiste Daroussin char *alias; 105a9e8641dSBaptiste Daroussin struct strlist dests; 106a9e8641dSBaptiste Daroussin }; 107a9e8641dSBaptiste Daroussin LIST_HEAD(aliases, alias); 108a9e8641dSBaptiste Daroussin 109a9e8641dSBaptiste Daroussin struct qitem { 110a9e8641dSBaptiste Daroussin LIST_ENTRY(qitem) next; 111a9e8641dSBaptiste Daroussin const char *sender; 112a9e8641dSBaptiste Daroussin char *addr; 113a9e8641dSBaptiste Daroussin char *queuefn; 114a9e8641dSBaptiste Daroussin char *mailfn; 115a9e8641dSBaptiste Daroussin char *queueid; 116a9e8641dSBaptiste Daroussin FILE *queuef; 117a9e8641dSBaptiste Daroussin FILE *mailf; 118a9e8641dSBaptiste Daroussin int remote; 119a9e8641dSBaptiste Daroussin }; 120a9e8641dSBaptiste Daroussin LIST_HEAD(queueh, qitem); 121a9e8641dSBaptiste Daroussin 122a9e8641dSBaptiste Daroussin struct queue { 123a9e8641dSBaptiste Daroussin struct queueh queue; 124a9e8641dSBaptiste Daroussin char *id; 125a9e8641dSBaptiste Daroussin FILE *mailf; 126a9e8641dSBaptiste Daroussin char *tmpf; 127a9e8641dSBaptiste Daroussin const char *sender; 128a9e8641dSBaptiste Daroussin }; 129a9e8641dSBaptiste Daroussin 130a9e8641dSBaptiste Daroussin struct config { 131a9e8641dSBaptiste Daroussin const char *smarthost; 132a9e8641dSBaptiste Daroussin int port; 133a9e8641dSBaptiste Daroussin const char *aliases; 134a9e8641dSBaptiste Daroussin const char *spooldir; 135a9e8641dSBaptiste Daroussin const char *authpath; 136a9e8641dSBaptiste Daroussin const char *certfile; 137a9e8641dSBaptiste Daroussin int features; 138a9e8641dSBaptiste Daroussin const char *mailname; 139a9e8641dSBaptiste Daroussin const char *masquerade_host; 140a9e8641dSBaptiste Daroussin const char *masquerade_user; 141*fbe95b88SBaptiste Daroussin const unsigned char *fingerprint; 142a9e8641dSBaptiste Daroussin 143a9e8641dSBaptiste Daroussin /* XXX does not belong into config */ 144a9e8641dSBaptiste Daroussin SSL *ssl; 145a9e8641dSBaptiste Daroussin }; 146a9e8641dSBaptiste Daroussin 147a9e8641dSBaptiste Daroussin 148a9e8641dSBaptiste Daroussin struct authuser { 149a9e8641dSBaptiste Daroussin SLIST_ENTRY(authuser) next; 150a9e8641dSBaptiste Daroussin char *login; 151a9e8641dSBaptiste Daroussin char *password; 152a9e8641dSBaptiste Daroussin char *host; 153a9e8641dSBaptiste Daroussin }; 154a9e8641dSBaptiste Daroussin SLIST_HEAD(authusers, authuser); 155a9e8641dSBaptiste Daroussin 156a9e8641dSBaptiste Daroussin 157a9e8641dSBaptiste Daroussin struct mx_hostentry { 158a9e8641dSBaptiste Daroussin char host[MAXDNAME]; 159a9e8641dSBaptiste Daroussin char addr[INET6_ADDRSTRLEN]; 160a9e8641dSBaptiste Daroussin int pref; 161a9e8641dSBaptiste Daroussin struct addrinfo ai; 162a9e8641dSBaptiste Daroussin struct sockaddr_storage sa; 163a9e8641dSBaptiste Daroussin }; 164a9e8641dSBaptiste Daroussin 165*fbe95b88SBaptiste Daroussin struct smtp_auth_mechanisms { 166*fbe95b88SBaptiste Daroussin int cram_md5; 167*fbe95b88SBaptiste Daroussin int login; 168*fbe95b88SBaptiste Daroussin }; 169*fbe95b88SBaptiste Daroussin 170*fbe95b88SBaptiste Daroussin struct smtp_features { 171*fbe95b88SBaptiste Daroussin struct smtp_auth_mechanisms auth; 172*fbe95b88SBaptiste Daroussin int starttls; 173*fbe95b88SBaptiste Daroussin }; 174a9e8641dSBaptiste Daroussin 175a9e8641dSBaptiste Daroussin /* global variables */ 176a9e8641dSBaptiste Daroussin extern struct aliases aliases; 177a9e8641dSBaptiste Daroussin extern struct config config; 178a9e8641dSBaptiste Daroussin extern struct strlist tmpfs; 179a9e8641dSBaptiste Daroussin extern struct authusers authusers; 180a9e8641dSBaptiste Daroussin extern char username[USERNAME_SIZE]; 181a9e8641dSBaptiste Daroussin extern uid_t useruid; 182a9e8641dSBaptiste Daroussin extern const char *logident_base; 183a9e8641dSBaptiste Daroussin 184a9e8641dSBaptiste Daroussin extern char neterr[ERRMSG_SIZE]; 185a9e8641dSBaptiste Daroussin extern char errmsg[ERRMSG_SIZE]; 186a9e8641dSBaptiste Daroussin 187a9e8641dSBaptiste Daroussin /* aliases_parse.y */ 188a9e8641dSBaptiste Daroussin int yyparse(void); 189e56bad4aSBaptiste Daroussin int yywrap(void); 190e56bad4aSBaptiste Daroussin int yylex(void); 191a9e8641dSBaptiste Daroussin extern FILE *yyin; 192a9e8641dSBaptiste Daroussin 193a9e8641dSBaptiste Daroussin /* conf.c */ 194a9e8641dSBaptiste Daroussin void trim_line(char *); 195a9e8641dSBaptiste Daroussin void parse_conf(const char *); 196a9e8641dSBaptiste Daroussin void parse_authfile(const char *); 197a9e8641dSBaptiste Daroussin 198a9e8641dSBaptiste Daroussin /* crypto.c */ 199a9e8641dSBaptiste Daroussin void hmac_md5(unsigned char *, int, unsigned char *, int, unsigned char *); 200a9e8641dSBaptiste Daroussin int smtp_auth_md5(int, char *, char *); 201*fbe95b88SBaptiste Daroussin int smtp_init_crypto(int, int, struct smtp_features*); 202a9e8641dSBaptiste Daroussin 203a9e8641dSBaptiste Daroussin /* dns.c */ 204a9e8641dSBaptiste Daroussin int dns_get_mx_list(const char *, int, struct mx_hostentry **, int); 205a9e8641dSBaptiste Daroussin 206a9e8641dSBaptiste Daroussin /* net.c */ 207a9e8641dSBaptiste Daroussin char *ssl_errstr(void); 208a9e8641dSBaptiste Daroussin int read_remote(int, int, char *); 209a9e8641dSBaptiste Daroussin ssize_t send_remote_command(int, const char*, ...) __attribute__((__nonnull__(2), __format__ (__printf__, 2, 3))); 210*fbe95b88SBaptiste Daroussin int perform_server_greeting(int, struct smtp_features*); 211a9e8641dSBaptiste Daroussin int deliver_remote(struct qitem *); 212a9e8641dSBaptiste Daroussin 213a9e8641dSBaptiste Daroussin /* base64.c */ 214a9e8641dSBaptiste Daroussin int base64_encode(const void *, int, char **); 215a9e8641dSBaptiste Daroussin int base64_decode(const char *, void *); 216a9e8641dSBaptiste Daroussin 217a9e8641dSBaptiste Daroussin /* dma.c */ 218a9e8641dSBaptiste Daroussin #define EXPAND_ADDR 1 219a9e8641dSBaptiste Daroussin #define EXPAND_WILDCARD 2 220a9e8641dSBaptiste Daroussin int add_recp(struct queue *, const char *, int); 221a9e8641dSBaptiste Daroussin void run_queue(struct queue *); 222a9e8641dSBaptiste Daroussin 223a9e8641dSBaptiste Daroussin /* spool.c */ 224a9e8641dSBaptiste Daroussin int newspoolf(struct queue *); 225a9e8641dSBaptiste Daroussin int linkspool(struct queue *); 226a9e8641dSBaptiste Daroussin int load_queue(struct queue *); 227a9e8641dSBaptiste Daroussin void delqueue(struct qitem *); 228a9e8641dSBaptiste Daroussin int acquirespool(struct qitem *); 229a9e8641dSBaptiste Daroussin void dropspool(struct queue *, struct qitem *); 230a9e8641dSBaptiste Daroussin int flushqueue_since(unsigned int); 231a9e8641dSBaptiste Daroussin int flushqueue_signal(void); 232a9e8641dSBaptiste Daroussin 233a9e8641dSBaptiste Daroussin /* local.c */ 234a9e8641dSBaptiste Daroussin int deliver_local(struct qitem *); 235a9e8641dSBaptiste Daroussin 236a9e8641dSBaptiste Daroussin /* mail.c */ 237a9e8641dSBaptiste Daroussin void bounce(struct qitem *, const char *); 238a9e8641dSBaptiste Daroussin int readmail(struct queue *, int, int); 239a9e8641dSBaptiste Daroussin 240a9e8641dSBaptiste Daroussin /* util.c */ 241a9e8641dSBaptiste Daroussin const char *hostname(void); 242*fbe95b88SBaptiste Daroussin const char *systemhostname(void); 243a9e8641dSBaptiste Daroussin void setlogident(const char *, ...) __attribute__((__format__ (__printf__, 1, 2))); 244a9e8641dSBaptiste Daroussin void errlog(int, const char *, ...) __attribute__((__format__ (__printf__, 2, 3))); 245a9e8641dSBaptiste Daroussin void errlogx(int, const char *, ...) __attribute__((__format__ (__printf__, 2, 3))); 246a9e8641dSBaptiste Daroussin void set_username(void); 247a9e8641dSBaptiste Daroussin void deltmp(void); 248a9e8641dSBaptiste Daroussin int do_timeout(int, int); 249a9e8641dSBaptiste Daroussin int open_locked(const char *, int, ...); 250a9e8641dSBaptiste Daroussin char *rfc822date(void); 251a9e8641dSBaptiste Daroussin int strprefixcmp(const char *, const char *); 252a9e8641dSBaptiste Daroussin void init_random(void); 253a9e8641dSBaptiste Daroussin 254a9e8641dSBaptiste Daroussin #endif 255