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