1 /* $Id: conf.h,v 1.58 2014/02/04 15:19:25 manu Exp $ */
2 
3 /*
4  * Copyright (c) 2004 Emmanuel Dreyfus
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *        This product includes software developed by Emmanuel Dreyfus
18  *
19  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _CONF_H_
33 #define _CONF_H_
34 
35 #include "config.h"
36 #if defined(HAVE_OLD_QUEUE_H) || !defined(HAVE_SYS_QUEUE_H)
37 #include "queue.h"
38 #else
39 #include <sys/queue.h>
40 #endif
41 
42 #include <stdio.h>
43 #include <pthread.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
47 
48 #include "pending.h"
49 
50 #ifndef CONFFILE
51 #define CONFFILE "/etc/mail/greylist.conf"
52 #endif
53 
54 #ifndef DRACDB
55 #define DRACDB "/usr/local/etc/dracdb.db"
56 #endif
57 
58 TAILQ_HEAD(conf_list, conf_rec);
59 struct conf_rec {
60 	int c_refcount;
61 	time_t c_timestamp;
62 	TAILQ_ENTRY(conf_rec) c_chain;
63 
64 	int c_forced;
65 	int c_debug;
66 	int c_acldebug;
67 	int c_quiet;
68 	int c_noauth;
69 	int c_multiracl;
70 	int c_noaccessdb;
71 	int c_nospf;
72 	int c_delayedreject;
73 	int c_testmode;
74 	int c_delay;
75 	int c_autowhite_validity;
76 	int c_tarpit;
77 	tarpit_scope_t c_tarpit_scope;
78 	char *c_pidfile;
79 	char *c_dumpfile;
80 	int c_dumpfile_mode;
81 	struct in_addr c_match_mask;
82 #ifdef AF_INET6
83 	struct in6_addr c_match_mask6;
84 #endif
85 	char *c_socket;
86 	int c_socket_mode;
87 	char *c_user;
88 	char *c_syncaddr;
89 	char *c_syncport;
90 	char *c_syncsrcaddr;
91 	char *c_syncsrcport;
92 	int c_syncmaxqlen;
93 	int c_nodetach;
94 	int c_report;
95 	int c_lazyaw;
96 	int c_dumpfreq;
97 	int c_timeout;
98 	int c_extendedregex;
99 	int c_unbracket;
100 	char *c_dracdb;
101 	int c_nodrac;
102 	int c_dump_no_time_translation;
103 	int c_logexpired;
104 	int c_logfac;
105 	char c_pidfile_storage[QSTRLEN + 1];
106 	char c_dumpfile_storage[QSTRLEN + 1];
107 	char c_socket_storage[QSTRLEN + 1];
108 	char c_user_storage[QSTRLEN + 1];
109 	char c_syncaddr_storage[IPADDRSTRLEN + 1];
110 	char c_syncport_storage[NUMLEN + 1];
111 	char c_syncsrcaddr_storage[IPADDRSTRLEN + 1];
112 	char c_syncsrcport_storage[NUMLEN + 1];
113 	char c_dracdb_storage[QSTRLEN + 1];
114 	size_t c_maxpeek;
115 	int c_domainexact;
116 #ifdef USE_P0F
117 	char c_p0fsock[QSTRLEN + 1];
118 #endif
119 #ifdef USE_SPAMD
120 	char c_spamdsock[QSTRLEN + 1];
121 	char c_spamdsocktype[QSTRLEN + 1];
122 #endif
123 	struct sockaddr_storage c_localaddr;
124 	char c_localaddr_string[IPADDRSTRLEN];
125 	int c_fixldapcheck;
126 };
127 
128 /* c_forced flags */
129 #define C_GLNONE	0x00000
130 #define C_DEBUG		0x00001
131 #define C_QUIET		0x00002
132 #define C_NOAUTH	0x00004
133 #define C_NOSPF		0x00008
134 #define C_TESTMODE	0x00010
135 #define C_DELAY		0x00020
136 #define C_AUTOWHITE	0x00040
137 #define C_PIDFILE	0x00080
138 #define C_DUMPFILE	0x00100
139 #define C_MATCHMASK	0x00200
140 #define C_SOCKET	0x00400
141 #define C_USER		0x00800
142 #define C_NODETACH	0x01000
143 #define C_LAZYAW	0x02000
144 #define C_MATCHMASK6	0x04000
145 #define C_ACLDEBUG	0x08000
146 #define C_DOMAINEXACT	0x10000
147 #define C_TARPIT	0x20000
148 #define C_TARPIT_SCOPE	0x40000
149 #define C_NOTFORCED(x) 	((conf.c_forced & (x)) == 0)
150 
151 /* c_report */
152 #define C_NOTHING	0x0
153 #define C_DELAYS	0x1
154 #define C_NODELAYS	0x2
155 #define C_ALL		0x3
156 
157 extern struct conf_rec defconf;
158 extern pthread_key_t conf_key;
159 #define GET_CONF() ((struct conf_rec *)pthread_getspecific(conf_key))
160 #define conf (*GET_CONF())
161 extern char *conffile;
162 extern int conf_cold;
163 extern int conf_specified;
164 
165 void conf_init(void);
166 void conf_load(void);
167 void conf_update(void);
168 void conf_retain(void);
169 void conf_release(void);
170 
171 extern FILE *conf_in;
172 extern int conf_line;
173 extern int conf_acl_end;
174 extern int conf_racl_end;
175 extern int conf_dacl_end;
176 
177 int conf_parse(void);
178 void conf_dispose_input_file(void);
179 char *quotepath(char *, char *, size_t);
180 char *quotepath_alloc(const char *);
181 void conf_defaults(struct conf_rec *);
182 
183 #endif /* _CONF_H_ */
184