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