annotate src/dnsbl.cpp @ 60:390ed250c5d2 stable-4-1

use local unix domain socket for resolver process communication
author carl
date Thu, 06 Jan 2005 11:35:38 -0800
parents 510a511ad554
children 7f44a4974bf6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1 /*
96a9758165cd Initial revision
carl
parents:
diff changeset
2
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
3 Copyright (c) 2004, 2005 Carl Byington - 510 Software Group, released
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
4 under the GPL version 2 or any later version at your choice available at
0
96a9758165cd Initial revision
carl
parents:
diff changeset
5 http://www.fsf.org/licenses/gpl.txt
96a9758165cd Initial revision
carl
parents:
diff changeset
6
96a9758165cd Initial revision
carl
parents:
diff changeset
7 Based on a sample milter Copyright (c) 2000-2003 Sendmail, Inc. and its
96a9758165cd Initial revision
carl
parents:
diff changeset
8 suppliers. Inspired by the DCC by Rhyolite Software
96a9758165cd Initial revision
carl
parents:
diff changeset
9
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
10 -r port The port used to talk to our internal dns resolver processes
0
96a9758165cd Initial revision
carl
parents:
diff changeset
11 -p port The port through which the MTA will connect to this milter.
96a9758165cd Initial revision
carl
parents:
diff changeset
12 -t sec The timeout value.
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
13 -c Check the config, and print a copy to stdout. Don't start the
4
15a7e942adec updates to use dcc conf files
carl
parents: 3
diff changeset
14 milter or do anything with the socket.
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
15 -d Add debug syslog entries
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
16
0
96a9758165cd Initial revision
carl
parents:
diff changeset
17
13
2752e512fd32 finish documentation
carl
parents: 12
diff changeset
18 TODO:
2752e512fd32 finish documentation
carl
parents: 12
diff changeset
19 1) Add config for max_recipients for each mail domain. Recipients in
2752e512fd32 finish documentation
carl
parents: 12
diff changeset
20 excess of that limit will be rejected, and the entire data will be
2752e512fd32 finish documentation
carl
parents: 12
diff changeset
21 rejected if it is sent.
2752e512fd32 finish documentation
carl
parents: 12
diff changeset
22
2752e512fd32 finish documentation
carl
parents: 12
diff changeset
23 2) Add config for poison addresses. If any recipient is poison, all
2752e512fd32 finish documentation
carl
parents: 12
diff changeset
24 recipients are rejected even if they would be whitelisted, and the
2752e512fd32 finish documentation
carl
parents: 12
diff changeset
25 data is rejected if sent.
2752e512fd32 finish documentation
carl
parents: 12
diff changeset
26
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
27 3) Add option to only allow one recipient if the return path is empty.
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
28
53
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
29 4) Check if the envelope from domain name primary MX points 127.0.0.0/8
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
30
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
31 5) Add option for using smtp connections to verify addresses from backup
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
32 mx machines. This allows the backup mx to learn the valid addresses
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
33 on the primary machine.
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
34
0
96a9758165cd Initial revision
carl
parents:
diff changeset
35 */
96a9758165cd Initial revision
carl
parents:
diff changeset
36
96a9758165cd Initial revision
carl
parents:
diff changeset
37
96a9758165cd Initial revision
carl
parents:
diff changeset
38 // from sendmail sample
96a9758165cd Initial revision
carl
parents:
diff changeset
39 #include <sys/types.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
40 #include <sys/stat.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
41 #include <errno.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
42 #include <sysexits.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
43 #include <unistd.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
44
96a9758165cd Initial revision
carl
parents:
diff changeset
45 // needed for socket io
96a9758165cd Initial revision
carl
parents:
diff changeset
46 #include <sys/ioctl.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
47 #include <net/if.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
48 #include <arpa/inet.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
49 #include <netinet/in.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
50 #include <netinet/tcp.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
51 #include <netdb.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
52 #include <sys/socket.h>
42
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
53 #include <sys/un.h>
0
96a9758165cd Initial revision
carl
parents:
diff changeset
54
96a9758165cd Initial revision
carl
parents:
diff changeset
55 // needed for thread
96a9758165cd Initial revision
carl
parents:
diff changeset
56 #include <pthread.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
57
96a9758165cd Initial revision
carl
parents:
diff changeset
58 // needed for std c++ collections
96a9758165cd Initial revision
carl
parents:
diff changeset
59 #include <set>
96a9758165cd Initial revision
carl
parents:
diff changeset
60 #include <map>
96a9758165cd Initial revision
carl
parents:
diff changeset
61 #include <list>
96a9758165cd Initial revision
carl
parents:
diff changeset
62
96a9758165cd Initial revision
carl
parents:
diff changeset
63 // for the dns resolver
96a9758165cd Initial revision
carl
parents:
diff changeset
64 #include <netinet/in.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
65 #include <arpa/nameser.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
66 #include <resolv.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
67
96a9758165cd Initial revision
carl
parents:
diff changeset
68 // misc stuff needed here
96a9758165cd Initial revision
carl
parents:
diff changeset
69 #include <ctype.h>
96a9758165cd Initial revision
carl
parents:
diff changeset
70 #include <fstream>
96a9758165cd Initial revision
carl
parents:
diff changeset
71 #include <syslog.h>
42
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
72 #include <pwd.h>
0
96a9758165cd Initial revision
carl
parents:
diff changeset
73
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
74 static char* dnsbl_version="$Id$";
0
96a9758165cd Initial revision
carl
parents:
diff changeset
75
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
76 #define DEFAULT "default"
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
77 #define WHITE "white"
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
78 #define BLACK "black"
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
79 #define OK "ok"
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
80 #define MANY "many"
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
81
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
82 enum status {oksofar, // not rejected yet
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
83 white, // whitelisted by envelope from
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
84 black, // blacklisted by envelope from or to
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
85 reject, // rejected by a dns list
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
86 reject_tag, // too many bad html tags
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
87 reject_host}; // too many hosts/urls in body
1
bd0b1a153f67 no message
carl
parents: 0
diff changeset
88
0
96a9758165cd Initial revision
carl
parents:
diff changeset
89 using namespace std;
96a9758165cd Initial revision
carl
parents:
diff changeset
90
96a9758165cd Initial revision
carl
parents:
diff changeset
91 extern "C" {
96a9758165cd Initial revision
carl
parents:
diff changeset
92 #include "libmilter/mfapi.h"
96a9758165cd Initial revision
carl
parents:
diff changeset
93 sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr);
96a9758165cd Initial revision
carl
parents:
diff changeset
94 sfsistat mlfi_envfrom(SMFICTX *ctx, char **argv);
96a9758165cd Initial revision
carl
parents:
diff changeset
95 sfsistat mlfi_envrcpt(SMFICTX *ctx, char **argv);
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
96 sfsistat mlfi_body(SMFICTX *ctx, u_char *data, size_t len);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
97 sfsistat mlfi_eom(SMFICTX *ctx);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
98 sfsistat mlfi_abort(SMFICTX *ctx);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
99 sfsistat mlfi_close(SMFICTX *ctx);
96a9758165cd Initial revision
carl
parents:
diff changeset
100 }
96a9758165cd Initial revision
carl
parents:
diff changeset
101
96a9758165cd Initial revision
carl
parents:
diff changeset
102 struct ltstr {
96a9758165cd Initial revision
carl
parents:
diff changeset
103 bool operator()(char* s1, char* s2) const {
96a9758165cd Initial revision
carl
parents:
diff changeset
104 return strcmp(s1, s2) < 0;
96a9758165cd Initial revision
carl
parents:
diff changeset
105 }
96a9758165cd Initial revision
carl
parents:
diff changeset
106 };
96a9758165cd Initial revision
carl
parents:
diff changeset
107
96a9758165cd Initial revision
carl
parents:
diff changeset
108 struct DNSBL {
96a9758165cd Initial revision
carl
parents:
diff changeset
109 char *suffix; // blacklist suffix like blackholes.five-ten-sg.com
96a9758165cd Initial revision
carl
parents:
diff changeset
110 char *message; // error message with one or two %s operators for the ip address replacement
96a9758165cd Initial revision
carl
parents:
diff changeset
111 DNSBL(char *s, char *m);
96a9758165cd Initial revision
carl
parents:
diff changeset
112 };
96a9758165cd Initial revision
carl
parents:
diff changeset
113 DNSBL::DNSBL(char *s, char *m) {
96a9758165cd Initial revision
carl
parents:
diff changeset
114 suffix = s;
96a9758165cd Initial revision
carl
parents:
diff changeset
115 message = m;
96a9758165cd Initial revision
carl
parents:
diff changeset
116 }
96a9758165cd Initial revision
carl
parents:
diff changeset
117
96a9758165cd Initial revision
carl
parents:
diff changeset
118 typedef DNSBL * DNSBLP;
96a9758165cd Initial revision
carl
parents:
diff changeset
119 typedef list<DNSBLP> DNSBLL;
96a9758165cd Initial revision
carl
parents:
diff changeset
120 typedef DNSBLL * DNSBLLP;
96a9758165cd Initial revision
carl
parents:
diff changeset
121 typedef map<char *, char *, ltstr> string_map;
96a9758165cd Initial revision
carl
parents:
diff changeset
122 typedef map<char *, string_map *, ltstr> from_map;
96a9758165cd Initial revision
carl
parents:
diff changeset
123 typedef map<char *, DNSBLP, ltstr> dnsblp_map;
96a9758165cd Initial revision
carl
parents:
diff changeset
124 typedef map<char *, DNSBLLP, ltstr> dnsbllp_map;
96a9758165cd Initial revision
carl
parents:
diff changeset
125 typedef set<char *, ltstr> string_set;
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
126 typedef set<int> int_set;
0
96a9758165cd Initial revision
carl
parents:
diff changeset
127 typedef list<char *> string_list;
53
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
128 typedef map<char *, int, ltstr> ns_mapper;
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
129
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
130 struct ns_map {
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
131 // all the strings are owned by the keys/values in the ns_host string map
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
132 string_map ns_host; // nameserver name -> host name that uses this name server
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
133 ns_mapper ns_ip; // nameserver name -> ip address of the name server
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
134 };
0
96a9758165cd Initial revision
carl
parents:
diff changeset
135
96a9758165cd Initial revision
carl
parents:
diff changeset
136 struct CONFIG {
96a9758165cd Initial revision
carl
parents:
diff changeset
137 // the only mutable stuff once it has been loaded from the config file
96a9758165cd Initial revision
carl
parents:
diff changeset
138 int reference_count; // protected by the global config_mutex
96a9758165cd Initial revision
carl
parents:
diff changeset
139 // all the rest is constant after loading from the config file
29
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
140 int generation;
0
96a9758165cd Initial revision
carl
parents:
diff changeset
141 time_t load_time;
96a9758165cd Initial revision
carl
parents:
diff changeset
142 string_list config_files;
96a9758165cd Initial revision
carl
parents:
diff changeset
143 dnsblp_map dnsbls;
96a9758165cd Initial revision
carl
parents:
diff changeset
144 dnsbllp_map dnsblls;
96a9758165cd Initial revision
carl
parents:
diff changeset
145 from_map env_from;
96a9758165cd Initial revision
carl
parents:
diff changeset
146 string_map env_to_dnsbll; // map recipient to a named dnsbll
96a9758165cd Initial revision
carl
parents:
diff changeset
147 string_map env_to_chkfrom; // map recipient to a named from map
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
148 char * content_suffix; // for sbl url body filtering
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
149 char * content_message; // ""
57
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
150 string_set content_host_ignore;// hosts to ignore for content sbl checking
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
151 char * host_limit_message; // error message for excessive host names
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
152 int host_limit; // limit on host names
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
153 bool host_random; // pick a random selection of host names rather than error for excessive hosts
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
154 char * tag_limit_message; // error message for excessive bad html tags
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
155 int tag_limit; // limit on bad html tags
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
156 string_set html_tags; // set of valid html tags
28
33e1e3910506 add configurable list of tlds
carl
parents: 27
diff changeset
157 string_set tlds; // set of valid tld components
0
96a9758165cd Initial revision
carl
parents:
diff changeset
158 CONFIG();
96a9758165cd Initial revision
carl
parents:
diff changeset
159 ~CONFIG();
96a9758165cd Initial revision
carl
parents:
diff changeset
160 };
96a9758165cd Initial revision
carl
parents:
diff changeset
161 CONFIG::CONFIG() {
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
162 reference_count = 0;
29
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
163 generation = 0;
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
164 load_time = 0;
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
165 content_suffix = NULL;
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
166 content_message = NULL;
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
167 host_limit_message = NULL;
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
168 host_limit = 0;
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
169 host_random = false;
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
170 tag_limit_message = NULL;
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
171 tag_limit = 0;
0
96a9758165cd Initial revision
carl
parents:
diff changeset
172 }
96a9758165cd Initial revision
carl
parents:
diff changeset
173 CONFIG::~CONFIG() {
96a9758165cd Initial revision
carl
parents:
diff changeset
174 for (dnsblp_map::iterator i=dnsbls.begin(); i!=dnsbls.end(); i++) {
96a9758165cd Initial revision
carl
parents:
diff changeset
175 DNSBLP d = (*i).second;
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
176 // delete the underlying DNSBL objects.
0
96a9758165cd Initial revision
carl
parents:
diff changeset
177 delete d;
96a9758165cd Initial revision
carl
parents:
diff changeset
178 }
96a9758165cd Initial revision
carl
parents:
diff changeset
179 for (dnsbllp_map::iterator i=dnsblls.begin(); i!=dnsblls.end(); i++) {
96a9758165cd Initial revision
carl
parents:
diff changeset
180 DNSBLLP d = (*i).second;
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
181 // *d is a list of pointers to DNSBL objects, but
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
182 // the underlying objects have already been deleted above.
0
96a9758165cd Initial revision
carl
parents:
diff changeset
183 delete d;
96a9758165cd Initial revision
carl
parents:
diff changeset
184 }
96a9758165cd Initial revision
carl
parents:
diff changeset
185 for (from_map::iterator i=env_from.begin(); i!=env_from.end(); i++) {
96a9758165cd Initial revision
carl
parents:
diff changeset
186 string_map *d = (*i).second;
96a9758165cd Initial revision
carl
parents:
diff changeset
187 delete d;
96a9758165cd Initial revision
carl
parents:
diff changeset
188 }
96a9758165cd Initial revision
carl
parents:
diff changeset
189 }
96a9758165cd Initial revision
carl
parents:
diff changeset
190
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
191 static bool debug_syslog = false;
18
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
192 static bool loader_run = true; // used to stop the config loader thread
0
96a9758165cd Initial revision
carl
parents:
diff changeset
193 static string_set all_strings; // owns all the strings, only modified by the config loader thread
96a9758165cd Initial revision
carl
parents:
diff changeset
194 static CONFIG * config = NULL; // protected by the config_mutex
29
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
195 static int generation = 0; // protected by the config_mutex
0
96a9758165cd Initial revision
carl
parents:
diff changeset
196
96a9758165cd Initial revision
carl
parents:
diff changeset
197 static pthread_mutex_t config_mutex;
96a9758165cd Initial revision
carl
parents:
diff changeset
198 static pthread_mutex_t syslog_mutex;
96a9758165cd Initial revision
carl
parents:
diff changeset
199 static pthread_mutex_t resolve_mutex;
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
200 static pthread_mutex_t fd_pool_mutex;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
201 static std::set<int> fd_pool;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
202
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
203 static int NULL_SOCKET = -1;
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
204 static char *resolver_port = NULL; // unix domain socket to talk to the dns resolver process
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
205 static int resolver_socket = NULL_SOCKET; // socket used to listen for resolver requests
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
206 static time_t ERROR_SOCKET_TIME = 60; // number of seconds between attempts to open the spam filter socket
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
207 static time_t last_error_time;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
208
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
209 #ifdef NS_PACKETSZ
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
210 // packed structure to allow a single socket write to dump the
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
211 // length and the following answer. The packing attribute is gcc specific.
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
212 struct glommer {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
213 int length;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
214 u_char answer[NS_PACKETSZ];
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
215 } __attribute__ ((packed));
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
216 #endif
0
96a9758165cd Initial revision
carl
parents:
diff changeset
217
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
218 struct mlfiPriv;
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
219
0
96a9758165cd Initial revision
carl
parents:
diff changeset
220
96a9758165cd Initial revision
carl
parents:
diff changeset
221 ////////////////////////////////////////////////
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
222 // helper to discard the strings and objects held by an ns_map
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
223 //
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
224 static void discard(ns_map &s);
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
225 static void discard(ns_map &s) {
53
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
226 for (string_map::iterator i=s.ns_host.begin(); i!=s.ns_host.end(); i++) {
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
227 char *x = (*i).first;
53
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
228 char *y = (*i).second;
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
229 free(x);
53
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
230 free(y);
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
231 }
53
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
232 s.ns_ip.clear();
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
233 s.ns_host.clear();
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
234 }
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
235
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
236 ////////////////////////////////////////////////
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
237 // helper to register a string in an ns_map
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
238 //
53
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
239 static void register_string(ns_map &s, char *name, char *refer);
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
240 static void register_string(ns_map &s, char *name, char *refer) {
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
241 string_map::iterator i = s.ns_host.find(name);
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
242 if (i != s.ns_host.end()) return;
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
243 char *x = strdup(name);
53
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
244 char *y = strdup(refer);
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
245 s.ns_ip[x] = 0;
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
246 s.ns_host[x] = y;
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
247
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
248 }
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
249
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
250 ////////////////////////////////////////////////
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
251 // helper to discard the strings held by a string_set
0
96a9758165cd Initial revision
carl
parents:
diff changeset
252 //
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
253 static void discard(string_set &s);
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
254 static void discard(string_set &s) {
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
255 for (string_set::iterator i=s.begin(); i!=s.end(); i++) {
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
256 free(*i);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
257 }
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
258 s.clear();
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
259 }
0
96a9758165cd Initial revision
carl
parents:
diff changeset
260
12
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
261 ////////////////////////////////////////////////
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
262 // helper to register a string in a string set
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
263 //
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
264 static char* register_string(string_set &s, char *name);
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
265 static char* register_string(string_set &s, char *name) {
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
266 string_set::iterator i = s.find(name);
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
267 if (i != s.end()) return *i;
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
268 char *x = strdup(name);
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
269 s.insert(x);
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
270 return x;
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
271 }
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
272
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
273 ////////////////////////////////////////////////
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
274 // syslog a message
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
275 //
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
276 static void my_syslog(mlfiPriv *priv, char *text);
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
277
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
278
12
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
279 // include the content scanner
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
280 #include "scanner.cpp"
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
281
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
282
0
96a9758165cd Initial revision
carl
parents:
diff changeset
283 ////////////////////////////////////////////////
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
284 // disconnect the fd from the dns resolver process
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
285 //
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
286 void my_disconnect(int sock);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
287 void my_disconnect(int sock)
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
288 {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
289 if (sock != NULL_SOCKET) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
290 shutdown(sock, SHUT_RDWR);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
291 close(sock);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
292 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
293 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
294
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
295
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
296 ////////////////////////////////////////////////
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
297 // return fd connected to the dns resolver process
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
298 //
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
299 int my_connect();
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
300 int my_connect()
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
301 {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
302 // if we have had recent errors, don't even try to open the socket
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
303 time_t now = time(NULL);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
304 if ((now - last_error_time) < ERROR_SOCKET_TIME) return NULL_SOCKET;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
305
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
306 // nothing recent, maybe this time it will work
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
307 int sock = NULL_SOCKET;
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
308 sockaddr_un server;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
309 memset(&server, '\0', sizeof(server));
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
310 server.sun_family = AF_UNIX;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
311 strncpy(server.sun_path, resolver_port, sizeof(server.sun_path)-1);
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
312 sock = socket(AF_UNIX, SOCK_STREAM, 0);
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
313 if (sock != NULL_SOCKET) {
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
314 bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0);
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
315 if (!rc) {
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
316 int er = errno;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
317 my_disconnect(sock);
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
318 sock = NULL_SOCKET;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
319 last_error_time = now;
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
320 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
321 }
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
322 else last_error_time = now;
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
323 return sock;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
324 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
325
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
326
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
327 ////////////////////////////////////////////////
0
96a9758165cd Initial revision
carl
parents:
diff changeset
328 // mail filter private data, held for us by sendmail
96a9758165cd Initial revision
carl
parents:
diff changeset
329 //
96a9758165cd Initial revision
carl
parents:
diff changeset
330 struct mlfiPriv
96a9758165cd Initial revision
carl
parents:
diff changeset
331 {
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
332 // connection specific data
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
333 CONFIG *pc; // global context with our maps
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
334 int fd; // to talk to dns resolvers process
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
335 bool err; // did we get any errors on the resolver socket?
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
336 int ip; // ip4 address of the smtp client
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
337 map<DNSBLP, status> checked; // status from those lists
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
338 // message specific data
0
96a9758165cd Initial revision
carl
parents:
diff changeset
339 char *mailaddr; // envelope from value
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
340 char *queueid; // sendmail queue id
0
96a9758165cd Initial revision
carl
parents:
diff changeset
341 bool authenticated; // client authenticated? if so, suppress all dnsbl checks
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
342 bool have_whites; // have at least one whitelisted recipient? need to accept content and remove all non-whitelisted recipients if it fails
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
343 bool only_whites; // every recipient is whitelisted?
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
344 string_set non_whites; // remember the non-whitelisted recipients so we can remove them if need be
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
345 recorder *memory; // memory for the content scanner
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
346 url_scanner *scanner; // object to handle body scanning
0
96a9758165cd Initial revision
carl
parents:
diff changeset
347 mlfiPriv();
96a9758165cd Initial revision
carl
parents:
diff changeset
348 ~mlfiPriv();
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
349 void reset(bool final = false); // for a new message
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
350 void get_fd();
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
351 void return_fd();
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
352 int my_read(char *buf, int len);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
353 int my_write(char *buf, int len);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
354 };
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
355
0
96a9758165cd Initial revision
carl
parents:
diff changeset
356 mlfiPriv::mlfiPriv() {
96a9758165cd Initial revision
carl
parents:
diff changeset
357 pthread_mutex_lock(&config_mutex);
96a9758165cd Initial revision
carl
parents:
diff changeset
358 pc = config;
96a9758165cd Initial revision
carl
parents:
diff changeset
359 pc->reference_count++;
96a9758165cd Initial revision
carl
parents:
diff changeset
360 pthread_mutex_unlock(&config_mutex);
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
361 get_fd();
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
362 ip = 0;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
363 mailaddr = NULL;
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
364 queueid = NULL;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
365 authenticated = false;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
366 have_whites = false;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
367 only_whites = true;
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
368 memory = new recorder(this, &pc->html_tags, &pc->tlds);
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
369 scanner = new url_scanner(memory);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
370 }
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
371
0
96a9758165cd Initial revision
carl
parents:
diff changeset
372 mlfiPriv::~mlfiPriv() {
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
373 return_fd();
0
96a9758165cd Initial revision
carl
parents:
diff changeset
374 pthread_mutex_lock(&config_mutex);
96a9758165cd Initial revision
carl
parents:
diff changeset
375 pc->reference_count--;
96a9758165cd Initial revision
carl
parents:
diff changeset
376 pthread_mutex_unlock(&config_mutex);
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
377 reset(true);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
378 }
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
379
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
380 void mlfiPriv::reset(bool final) {
0
96a9758165cd Initial revision
carl
parents:
diff changeset
381 if (mailaddr) free(mailaddr);
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
382 if (queueid) free(queueid);
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
383 discard(non_whites);
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
384 delete memory;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
385 delete scanner;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
386 if (!final) {
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
387 mailaddr = NULL;
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
388 queueid = NULL;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
389 authenticated = false;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
390 have_whites = false;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
391 only_whites = true;
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
392 memory = new recorder(this, &pc->html_tags, &pc->tlds);
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
393 scanner = new url_scanner(memory);
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
394 }
0
96a9758165cd Initial revision
carl
parents:
diff changeset
395 }
96a9758165cd Initial revision
carl
parents:
diff changeset
396
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
397 void mlfiPriv::get_fd()
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
398 {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
399 err = true;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
400 fd = NULL_SOCKET;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
401 int result = pthread_mutex_lock(&fd_pool_mutex);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
402 if (!result) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
403 std::set<int>::iterator i;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
404 i = fd_pool.begin();
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
405 if (i != fd_pool.end()) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
406 // have at least one fd in the pool
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
407 err = false;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
408 fd = *i;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
409 fd_pool.erase(fd);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
410 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
411 else {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
412 // pool is empty, get a new fd
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
413 fd = my_connect();
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
414 err = (fd == NULL_SOCKET);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
415 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
416 pthread_mutex_unlock(&fd_pool_mutex);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
417 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
418 else {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
419 // cannot lock the pool, just get a new fd
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
420 fd = my_connect();
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
421 err = (fd == NULL_SOCKET);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
422 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
423 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
424
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
425 void mlfiPriv::return_fd()
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
426 {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
427 if (err) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
428 // this fd got a socket error, so close it, rather than returning it to the pool
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
429 my_disconnect(fd);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
430 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
431 else {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
432 int result = pthread_mutex_lock(&fd_pool_mutex);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
433 if (!result) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
434 // return the fd to the pool
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
435 fd_pool.insert(fd);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
436 pthread_mutex_unlock(&fd_pool_mutex);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
437 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
438 else {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
439 // could not lock the pool, so just close the fd
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
440 my_disconnect(fd);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
441 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
442 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
443 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
444
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
445 int mlfiPriv::my_write(char *buf, int len)
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
446 {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
447 if (err) return 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
448 int rs = 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
449 while (len) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
450 int ws = write(fd, buf, len);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
451 if (ws > 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
452 rs += ws;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
453 len -= ws;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
454 buf += ws;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
455 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
456 else {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
457 // peer closed the socket!
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
458 rs = 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
459 err = true;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
460 break;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
461 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
462 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
463 return rs;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
464 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
465
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
466 int mlfiPriv::my_read(char *buf, int len)
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
467 {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
468 if (err) return 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
469 int rs = 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
470 while (len > 1) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
471 int ws = read(fd, buf, len);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
472 if (ws > 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
473 rs += ws;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
474 len -= ws;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
475 buf += ws;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
476 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
477 else {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
478 // peer closed the socket!
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
479 rs = 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
480 err = true;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
481 break;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
482 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
483 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
484 return rs;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
485 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
486
0
96a9758165cd Initial revision
carl
parents:
diff changeset
487 #define MLFIPRIV ((struct mlfiPriv *) smfi_getpriv(ctx))
96a9758165cd Initial revision
carl
parents:
diff changeset
488
96a9758165cd Initial revision
carl
parents:
diff changeset
489
96a9758165cd Initial revision
carl
parents:
diff changeset
490 ////////////////////////////////////////////////
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
491 // syslog a message
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
492 //
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
493 static void my_syslog(mlfiPriv *priv, char *text) {
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
494 char buf[1000];
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
495 if (priv) {
42
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
496 snprintf(buf, sizeof(buf), "%s: %s", priv->queueid, text);
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
497 text = buf;
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
498 }
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
499 pthread_mutex_lock(&syslog_mutex);
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
500 openlog("dnsbl", LOG_PID, LOG_MAIL);
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
501 syslog(LOG_NOTICE, "%s", text);
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
502 closelog();
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
503 pthread_mutex_unlock(&syslog_mutex);
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
504 }
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
505
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
506 static void my_syslog(char *text);
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
507 static void my_syslog(char *text) {
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
508 my_syslog(NULL, text);
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
509 }
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
510
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
511 ////////////////////////////////////////////////
0
96a9758165cd Initial revision
carl
parents:
diff changeset
512 // register a global string
96a9758165cd Initial revision
carl
parents:
diff changeset
513 //
96a9758165cd Initial revision
carl
parents:
diff changeset
514 static char* register_string(char *name);
96a9758165cd Initial revision
carl
parents:
diff changeset
515 static char* register_string(char *name) {
12
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
516 return register_string(all_strings, name);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
517 }
96a9758165cd Initial revision
carl
parents:
diff changeset
518
96a9758165cd Initial revision
carl
parents:
diff changeset
519
96a9758165cd Initial revision
carl
parents:
diff changeset
520 static char* next_token(char *delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
521 static char* next_token(char *delim) {
96a9758165cd Initial revision
carl
parents:
diff changeset
522 char *name = strtok(NULL, delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
523 if (!name) return name;
96a9758165cd Initial revision
carl
parents:
diff changeset
524 return register_string(name);
96a9758165cd Initial revision
carl
parents:
diff changeset
525 }
96a9758165cd Initial revision
carl
parents:
diff changeset
526
96a9758165cd Initial revision
carl
parents:
diff changeset
527
96a9758165cd Initial revision
carl
parents:
diff changeset
528 ////////////////////////////////////////////////
96a9758165cd Initial revision
carl
parents:
diff changeset
529 // lookup an email address in the env_from or env_to maps
96a9758165cd Initial revision
carl
parents:
diff changeset
530 //
96a9758165cd Initial revision
carl
parents:
diff changeset
531 static char* lookup1(char *email, string_map map);
96a9758165cd Initial revision
carl
parents:
diff changeset
532 static char* lookup1(char *email, string_map map) {
96a9758165cd Initial revision
carl
parents:
diff changeset
533 string_map::iterator i = map.find(email);
96a9758165cd Initial revision
carl
parents:
diff changeset
534 if (i != map.end()) return (*i).second;
96a9758165cd Initial revision
carl
parents:
diff changeset
535 char *x = strchr(email, '@');
96a9758165cd Initial revision
carl
parents:
diff changeset
536 if (!x) return DEFAULT;
96a9758165cd Initial revision
carl
parents:
diff changeset
537 x++;
96a9758165cd Initial revision
carl
parents:
diff changeset
538 i = map.find(x);
96a9758165cd Initial revision
carl
parents:
diff changeset
539 if (i != map.end()) return (*i).second;
96a9758165cd Initial revision
carl
parents:
diff changeset
540 return DEFAULT;
96a9758165cd Initial revision
carl
parents:
diff changeset
541 }
96a9758165cd Initial revision
carl
parents:
diff changeset
542
96a9758165cd Initial revision
carl
parents:
diff changeset
543
96a9758165cd Initial revision
carl
parents:
diff changeset
544 ////////////////////////////////////////////////
96a9758165cd Initial revision
carl
parents:
diff changeset
545 // lookup an email address in the env_from or env_to maps
96a9758165cd Initial revision
carl
parents:
diff changeset
546 // this email address is passed in from sendmail, and will
96a9758165cd Initial revision
carl
parents:
diff changeset
547 // always be enclosed in <>. It may have mixed case, just
96a9758165cd Initial revision
carl
parents:
diff changeset
548 // as the mail client sent it.
96a9758165cd Initial revision
carl
parents:
diff changeset
549 //
96a9758165cd Initial revision
carl
parents:
diff changeset
550 static char* lookup(char* email, string_map map);
96a9758165cd Initial revision
carl
parents:
diff changeset
551 static char* lookup(char* email, string_map map) {
96a9758165cd Initial revision
carl
parents:
diff changeset
552 int n = strlen(email)-2;
96a9758165cd Initial revision
carl
parents:
diff changeset
553 if (n < 1) return DEFAULT; // malformed
96a9758165cd Initial revision
carl
parents:
diff changeset
554 char *key = strdup(email+1);
96a9758165cd Initial revision
carl
parents:
diff changeset
555 key[n] = '\0';
96a9758165cd Initial revision
carl
parents:
diff changeset
556 for (int i=0; i<n; i++) key[i] = tolower(key[i]);
96a9758165cd Initial revision
carl
parents:
diff changeset
557 char *rc = lookup1(key, map);
96a9758165cd Initial revision
carl
parents:
diff changeset
558 free(key);
96a9758165cd Initial revision
carl
parents:
diff changeset
559 return rc;
96a9758165cd Initial revision
carl
parents:
diff changeset
560 }
96a9758165cd Initial revision
carl
parents:
diff changeset
561
96a9758165cd Initial revision
carl
parents:
diff changeset
562
96a9758165cd Initial revision
carl
parents:
diff changeset
563 ////////////////////////////////////////////////
96a9758165cd Initial revision
carl
parents:
diff changeset
564 // find the dnsbl with a specific name
96a9758165cd Initial revision
carl
parents:
diff changeset
565 //
96a9758165cd Initial revision
carl
parents:
diff changeset
566 static DNSBLP find_dnsbl(CONFIG &dc, char *name);
96a9758165cd Initial revision
carl
parents:
diff changeset
567 static DNSBLP find_dnsbl(CONFIG &dc, char *name) {
96a9758165cd Initial revision
carl
parents:
diff changeset
568 dnsblp_map::iterator i = dc.dnsbls.find(name);
96a9758165cd Initial revision
carl
parents:
diff changeset
569 if (i == dc.dnsbls.end()) return NULL;
96a9758165cd Initial revision
carl
parents:
diff changeset
570 return (*i).second;
96a9758165cd Initial revision
carl
parents:
diff changeset
571 }
96a9758165cd Initial revision
carl
parents:
diff changeset
572
96a9758165cd Initial revision
carl
parents:
diff changeset
573
96a9758165cd Initial revision
carl
parents:
diff changeset
574 ////////////////////////////////////////////////
96a9758165cd Initial revision
carl
parents:
diff changeset
575 // find the dnsbll with a specific name
96a9758165cd Initial revision
carl
parents:
diff changeset
576 //
96a9758165cd Initial revision
carl
parents:
diff changeset
577 static DNSBLLP find_dnsbll(CONFIG &dc, char *name);
96a9758165cd Initial revision
carl
parents:
diff changeset
578 static DNSBLLP find_dnsbll(CONFIG &dc, char *name) {
96a9758165cd Initial revision
carl
parents:
diff changeset
579 dnsbllp_map::iterator i = dc.dnsblls.find(name);
96a9758165cd Initial revision
carl
parents:
diff changeset
580 if (i == dc.dnsblls.end()) return NULL;
96a9758165cd Initial revision
carl
parents:
diff changeset
581 return (*i).second;
96a9758165cd Initial revision
carl
parents:
diff changeset
582 }
96a9758165cd Initial revision
carl
parents:
diff changeset
583
96a9758165cd Initial revision
carl
parents:
diff changeset
584
96a9758165cd Initial revision
carl
parents:
diff changeset
585 ////////////////////////////////////////////////
96a9758165cd Initial revision
carl
parents:
diff changeset
586 // find the envfrom map with a specific name
96a9758165cd Initial revision
carl
parents:
diff changeset
587 //
96a9758165cd Initial revision
carl
parents:
diff changeset
588 static string_map* find_from_map(CONFIG &dc, char *name);
96a9758165cd Initial revision
carl
parents:
diff changeset
589 static string_map* find_from_map(CONFIG &dc, char *name) {
96a9758165cd Initial revision
carl
parents:
diff changeset
590 from_map::iterator i = dc.env_from.find(name);
96a9758165cd Initial revision
carl
parents:
diff changeset
591 if (i == dc.env_from.end()) return NULL;
96a9758165cd Initial revision
carl
parents:
diff changeset
592 return (*i).second;
96a9758165cd Initial revision
carl
parents:
diff changeset
593 }
96a9758165cd Initial revision
carl
parents:
diff changeset
594
96a9758165cd Initial revision
carl
parents:
diff changeset
595
96a9758165cd Initial revision
carl
parents:
diff changeset
596 static string_map& really_find_from_map(CONFIG &dc, char *name);
96a9758165cd Initial revision
carl
parents:
diff changeset
597 static string_map& really_find_from_map(CONFIG &dc, char *name) {
96a9758165cd Initial revision
carl
parents:
diff changeset
598 string_map *sm = find_from_map(dc, name);
96a9758165cd Initial revision
carl
parents:
diff changeset
599 if (!sm) {
96a9758165cd Initial revision
carl
parents:
diff changeset
600 sm = new string_map;
96a9758165cd Initial revision
carl
parents:
diff changeset
601 dc.env_from[name] = sm;
96a9758165cd Initial revision
carl
parents:
diff changeset
602 }
96a9758165cd Initial revision
carl
parents:
diff changeset
603 return *sm;
96a9758165cd Initial revision
carl
parents:
diff changeset
604 }
96a9758165cd Initial revision
carl
parents:
diff changeset
605
96a9758165cd Initial revision
carl
parents:
diff changeset
606
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
607
0
96a9758165cd Initial revision
carl
parents:
diff changeset
608 ////////////////////////////////////////////////
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
609 // read a resolver request from the socket, process it, and
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
610 // write the result back to the socket.
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
611
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
612 #ifdef NS_PACKETSZ
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
613 static void process_resolver_requests(int socket);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
614 static void process_resolver_requests(int socket) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
615 #ifdef NS_MAXDNAME
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
616 char question[NS_MAXDNAME];
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
617 #else
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
618 char question[1000];
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
619 #endif
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
620 glommer glom;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
621
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
622 int maxq = sizeof(question);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
623 while (true) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
624 // read a question
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
625 int rs = 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
626 while (true) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
627 int ns = read(socket, question+rs, maxq-rs);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
628 if (ns > 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
629 rs += ns;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
630 if (question[rs-1] == '\0') {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
631 // last byte read was the null terminator, we are done
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
632 break;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
633 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
634 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
635 else {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
636 // peer closed the socket
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
637 //my_syslog("!!child worker process, peer closed socket while reading question");
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
638 shutdown(socket, SHUT_RDWR);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
639 close(socket);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
640 return;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
641 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
642 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
643
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
644 // find the answer
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
645 //char text[1000];
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
646 //snprintf(text, sizeof(text), "!!child worker process has a question %s", question);
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
647 //my_syslog(text);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
648 glom.length = res_search(question, ns_c_in, ns_t_a, glom.answer, sizeof(glom.answer));
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
649 if (glom.length < 0) glom.length = 0; // represent all errors as zero length answers
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
650
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
651 // write the answer
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
652 char *buf = (char *)&glom;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
653 int len = glom.length + sizeof(glom.length);
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
654 //snprintf(text, sizeof(text), "!!child worker process writing answer length %d for total %d", glom.length, len);
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
655 //my_syslog(text);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
656 int ws = 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
657 while (len > ws) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
658 int ns = write(socket, buf+ws, len-ws);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
659 if (ns > 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
660 ws += ns;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
661 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
662 else {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
663 // peer closed the socket!
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
664 //my_syslog("!!child worker process, peer closed socket while writing answer");
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
665 shutdown(socket, SHUT_RDWR);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
666 close(socket);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
667 return;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
668 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
669 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
670 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
671 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
672 #endif
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
673
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
674
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
675 ////////////////////////////////////////////////
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
676 // ask a dns question and get an A record answer - we don't try
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
677 // very hard, just using the default resolver retry settings.
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
678 // If we cannot get an answer, we just accept the mail.
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
679 //
0
96a9758165cd Initial revision
carl
parents:
diff changeset
680 //
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
681 static int dns_interface(mlfiPriv &priv, char *question, bool maybe_ip, ns_map *nameservers);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
682 static int dns_interface(mlfiPriv &priv, char *question, bool maybe_ip, ns_map *nameservers) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
683 int ret_address = 0;
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
684 #ifdef NS_PACKETSZ
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
685
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
686 // this part can be done without locking the resolver mutex. Each
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
687 // milter thread is talking over its own socket to a separate resolver
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
688 // process, which does the actual dns resolution.
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
689 if (priv.err) return 0; // cannot ask more questions on this socket.
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
690 priv.my_write(question, strlen(question)+1); // write the question including the null terminator
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
691 glommer glom;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
692 char *buf = (char *)&glom;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
693 priv.my_read(buf, sizeof(glom.length));
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
694 buf += sizeof(glom.length);
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
695 ///char text[1000];
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
696 ///snprintf(text, sizeof(text), "!!milter thread wrote question %s and has answer length %d", question, glom.length);
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
697 ///my_syslog(text);
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
698 if ((glom.length < 0) || (glom.length > sizeof(glom.answer))) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
699 priv.err = true;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
700 return 0; // cannot process overlarge answers
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
701 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
702 priv.my_read(buf, glom.length);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
703
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
704 // now we need to lock the resolver mutex to keep the milter threads from
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
705 // stepping on each other while parsing the dns answer.
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
706 pthread_mutex_lock(&resolve_mutex);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
707 if (glom.length > 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
708 // parse the answer
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
709 ns_msg handle;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
710 ns_rr rr;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
711 if (ns_initparse(glom.answer, glom.length, &handle) == 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
712 // look for ns names
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
713 if (nameservers) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
714 ns_map &ns = *nameservers;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
715 int rrnum = 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
716 while (ns_parserr(&handle, ns_s_ns, rrnum++, &rr) == 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
717 if (ns_rr_type(rr) == ns_t_ns) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
718 char nam[NS_MAXDNAME+1];
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
719 char *n = nam;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
720 const u_char *p = ns_rr_rdata(rr);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
721 while (((n-nam) < NS_MAXDNAME) && ((p-glom.answer) < glom.length) && *p) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
722 size_t s = *(p++);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
723 if (s > 191) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
724 // compression pointer
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
725 s = (s-192)*256 + *(p++);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
726 if (s >= glom.length) break; // pointer outside bounds of answer
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
727 p = glom.answer + s;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
728 s = *(p++);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
729 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
730 if (s > 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
731 if ((n-nam) >= (NS_MAXDNAME-s)) break; // destination would overflow name buffer
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
732 if ((p-glom.answer) >= (glom.length-s)) break; // source outside bounds of answer
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
733 memcpy(n, p, s);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
734 n += s;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
735 p += s;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
736 *(n++) = '.';
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
737 }
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
738 }
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
739 if (n-nam) n--; // remove trailing .
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
740 *n = '\0'; // null terminate it
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
741 register_string(ns, nam, question); // ns host to lookup later
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
742 }
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
743 }
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
744 rrnum = 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
745 while (ns_parserr(&handle, ns_s_ar, rrnum++, &rr) == 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
746 if (ns_rr_type(rr) == ns_t_a) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
747 char* nam = (char*)ns_rr_name(rr);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
748 ns_mapper::iterator i = ns.ns_ip.find(nam);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
749 if (i != ns.ns_ip.end()) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
750 // we want this ip address
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
751 int address;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
752 memcpy(&address, ns_rr_rdata(rr), sizeof(address));
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
753 ns.ns_ip[nam] = address;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
754 }
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
755 }
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
756 }
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
757 }
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
758 int rrnum = 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
759 while (ns_parserr(&handle, ns_s_an, rrnum++, &rr) == 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
760 if (ns_rr_type(rr) == ns_t_a) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
761 int address;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
762 memcpy(&address, ns_rr_rdata(rr), sizeof(address));
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
763 ret_address = address;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
764 }
23
06de5ab6a232 add url decoding stage, allow http:/ single / in yahoo redirector, allow ip address hostnames
carl
parents: 22
diff changeset
765 }
06de5ab6a232 add url decoding stage, allow http:/ single / in yahoo redirector, allow ip address hostnames
carl
parents: 22
diff changeset
766 }
06de5ab6a232 add url decoding stage, allow http:/ single / in yahoo redirector, allow ip address hostnames
carl
parents: 22
diff changeset
767 }
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
768 if (maybe_ip && !ret_address) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
769 // might be a bare ip address
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
770 in_addr ip;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
771 if (inet_aton(question, &ip)) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
772 ret_address = ip.s_addr;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
773 }
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
774 }
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
775 pthread_mutex_unlock(&resolve_mutex);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
776 return ret_address;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
777
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
778 #else
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
779 // systems without the resolver interface
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
780 pthread_mutex_lock(&resolve_mutex);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
781 struct hostent *host = gethostbyname(question);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
782 if (host && (host->h_addrtype == AF_INET)) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
783 memcpy(&ret_address, host->h_addr, sizeof(ret_address));
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
784 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
785 pthread_mutex_unlock(&resolve_mutex);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
786 return ret_address;
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
787 #endif
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
788 }
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
789
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
790
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
791 ////////////////////////////////////////////////
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
792 // check a single dnsbl
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
793 //
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
794 static status check_single(mlfiPriv &priv, int ip, char *suffix);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
795 static status check_single(mlfiPriv &priv, int ip, char *suffix) {
0
96a9758165cd Initial revision
carl
parents:
diff changeset
796 // make a dns question
96a9758165cd Initial revision
carl
parents:
diff changeset
797 const u_char *src = (const u_char *)&ip;
96a9758165cd Initial revision
carl
parents:
diff changeset
798 if (src[0] == 127) return oksofar; // don't do dns lookups on localhost
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
799 #ifdef NS_MAXDNAME
0
96a9758165cd Initial revision
carl
parents:
diff changeset
800 char question[NS_MAXDNAME];
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
801 #else
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
802 char question[1000];
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
803 #endif
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
804 snprintf(question, sizeof(question), "%u.%u.%u.%u.%s.", src[3], src[2], src[1], src[0], suffix);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
805 // ask the question, if we get an A record it implies a blacklisted ip address
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
806 return (dns_interface(priv, question, false, NULL)) ? reject : oksofar;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
807 }
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
808
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
809
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
810 ////////////////////////////////////////////////
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
811 // check a single dnsbl
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
812 //
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
813 static status check_single(mlfiPriv &priv, int ip, DNSBL &bl);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
814 static status check_single(mlfiPriv &priv, int ip, DNSBL &bl) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
815 return check_single(priv, ip, bl.suffix);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
816 }
96a9758165cd Initial revision
carl
parents:
diff changeset
817
96a9758165cd Initial revision
carl
parents:
diff changeset
818
96a9758165cd Initial revision
carl
parents:
diff changeset
819 ////////////////////////////////////////////////
96a9758165cd Initial revision
carl
parents:
diff changeset
820 // check the dnsbls specified for this recipient
96a9758165cd Initial revision
carl
parents:
diff changeset
821 //
96a9758165cd Initial revision
carl
parents:
diff changeset
822 static status check_dnsbl(mlfiPriv &priv, DNSBLLP dnsbllp, DNSBLP &rejectlist);
96a9758165cd Initial revision
carl
parents:
diff changeset
823 static status check_dnsbl(mlfiPriv &priv, DNSBLLP dnsbllp, DNSBLP &rejectlist) {
96a9758165cd Initial revision
carl
parents:
diff changeset
824 if (priv.authenticated) return oksofar;
96a9758165cd Initial revision
carl
parents:
diff changeset
825 if (!dnsbllp) return oksofar;
96a9758165cd Initial revision
carl
parents:
diff changeset
826 DNSBLL &dnsbll = *dnsbllp;
96a9758165cd Initial revision
carl
parents:
diff changeset
827 for (DNSBLL::iterator i=dnsbll.begin(); i!=dnsbll.end(); i++) {
96a9758165cd Initial revision
carl
parents:
diff changeset
828 DNSBLP dp = *i; // non null by construction
96a9758165cd Initial revision
carl
parents:
diff changeset
829 status st;
96a9758165cd Initial revision
carl
parents:
diff changeset
830 map<DNSBLP, status>::iterator f = priv.checked.find(dp);
96a9758165cd Initial revision
carl
parents:
diff changeset
831 if (f == priv.checked.end()) {
96a9758165cd Initial revision
carl
parents:
diff changeset
832 // have not checked this list yet
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
833 st = check_single(priv, priv.ip, *dp);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
834 rejectlist = dp;
96a9758165cd Initial revision
carl
parents:
diff changeset
835 priv.checked[dp] = st;
96a9758165cd Initial revision
carl
parents:
diff changeset
836 }
96a9758165cd Initial revision
carl
parents:
diff changeset
837 else {
96a9758165cd Initial revision
carl
parents:
diff changeset
838 st = (*f).second;
96a9758165cd Initial revision
carl
parents:
diff changeset
839 rejectlist = (*f).first;
96a9758165cd Initial revision
carl
parents:
diff changeset
840 }
96a9758165cd Initial revision
carl
parents:
diff changeset
841 if (st == reject) return st;
96a9758165cd Initial revision
carl
parents:
diff changeset
842 }
96a9758165cd Initial revision
carl
parents:
diff changeset
843 return oksofar;
96a9758165cd Initial revision
carl
parents:
diff changeset
844 }
96a9758165cd Initial revision
carl
parents:
diff changeset
845
96a9758165cd Initial revision
carl
parents:
diff changeset
846
96a9758165cd Initial revision
carl
parents:
diff changeset
847 ////////////////////////////////////////////////
55
44babba1a9b9 updates for 3.6, better documentation on removing content filtering, missing some files in cvs
carl
parents: 53
diff changeset
848 // check the hosts from the body against the content dnsbl
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
849 //
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
850 static status check_hosts(mlfiPriv &priv, char *&host, int &ip);
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
851 static status check_hosts(mlfiPriv &priv, char *&host, int &ip) {
55
44babba1a9b9 updates for 3.6, better documentation on removing content filtering, missing some files in cvs
carl
parents: 53
diff changeset
852 CONFIG &dc = *priv.pc;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
853 int count = 0;
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
854 ns_map nameservers;
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
855 bool ran = priv.pc->host_random;
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
856 int lim = priv.pc->host_limit; // we should not look at more than this many hosts
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
857 int cnt = priv.memory->hosts.size(); // number of hosts we could look at
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
858 int_set ips; // remove duplicate ip addresses
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
859 for (string_set::iterator i=priv.memory->hosts.begin(); i!=priv.memory->hosts.end(); i++) {
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
860 host = *i; // a reference into priv.memory->hosts, which will live until this smtp transaction is closed
58
7bb8bbf79285 changes to handle 5iantlavalamp.com
carl
parents: 57
diff changeset
861
7bb8bbf79285 changes to handle 5iantlavalamp.com
carl
parents: 57
diff changeset
862 // don't bother looking up hosts on the ignore list
57
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
863 string_set::iterator j = priv.pc->content_host_ignore.find(host);
58
7bb8bbf79285 changes to handle 5iantlavalamp.com
carl
parents: 57
diff changeset
864 if (j != priv.pc->content_host_ignore.end()) continue;
7bb8bbf79285 changes to handle 5iantlavalamp.com
carl
parents: 57
diff changeset
865
7bb8bbf79285 changes to handle 5iantlavalamp.com
carl
parents: 57
diff changeset
866 // try to only look at lim/cnt fraction of the available cnt host names in random mode
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
867 if ((cnt > lim) && (lim > 0) && ran) {
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
868 int r = rand() % cnt;
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
869 if (r >= lim) {
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
870 char buf[1000];
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
871 snprintf(buf, sizeof(buf), "host %s skipped", host);
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
872 my_syslog(&priv, buf);
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
873 continue;
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
874 }
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
875 }
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
876 count++;
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
877 if ((count > lim) && (lim > 0) && (!ran)) {
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
878 discard(nameservers);
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
879 return reject_host;
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
880 }
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
881 ip = dns_interface(priv, host, true, &nameservers);
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
882 if (debug_syslog) {
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
883 char buf[1000];
29
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
884 if (ip) {
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
885 char adr[sizeof "255.255.255.255"];
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
886 adr[0] = '\0';
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
887 inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr));
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
888 snprintf(buf, sizeof(buf), "host %s found at %s", host, adr);
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
889 }
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
890 else {
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
891 snprintf(buf, sizeof(buf), "host %s not found", host);
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
892 }
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
893 my_syslog(&priv, buf);
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
894 }
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
895 if (ip) {
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
896 int_set::iterator i = ips.find(ip);
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
897 if (i == ips.end()) {
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
898 ips.insert(ip);
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
899 status st = check_single(priv, ip, dc.content_suffix);
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
900 if (st == reject) {
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
901 discard(nameservers);
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
902 return st;
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
903 }
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
904 }
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
905 }
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
906 }
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
907 lim *= 4; // allow average of 3 ns per host name
53
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
908 for (ns_mapper::iterator i=nameservers.ns_ip.begin(); i!=nameservers.ns_ip.end(); i++) {
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
909 count++;
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
910 if ((count > lim) && (lim > 0)) {
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
911 if (ran) continue; // don't complain
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
912 discard(nameservers);
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
913 return reject_host;
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
914 }
36
95607fbef608 no message
carl
parents: 35
diff changeset
915 host = (*i).first; // a transient reference that needs to be replaced before we return it
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
916 ip = (*i).second;
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
917 if (!ip) ip = dns_interface(priv, host, false, NULL);
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
918 if (debug_syslog) {
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
919 char buf[200];
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
920 if (ip) {
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
921 char adr[sizeof "255.255.255.255"];
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
922 adr[0] = '\0';
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
923 inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr));
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
924 snprintf(buf, sizeof(buf), "ns %s found at %s", host, adr);
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
925 }
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
926 else {
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
927 snprintf(buf, sizeof(buf), "ns %s not found", host);
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
928 }
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
929 my_syslog(&priv, buf);
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
930 }
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
931 if (ip) {
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
932 int_set::iterator i = ips.find(ip);
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
933 if (i == ips.end()) {
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
934 ips.insert(ip);
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
935 status st = check_single(priv, ip, dc.content_suffix);
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
936 if (st == reject) {
53
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
937 string_map::iterator j = nameservers.ns_host.find(host);
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
938 if (j != nameservers.ns_host.end()) {
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
939 char *refer = (*j).second;
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
940 char buf[1000];
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
941 snprintf(buf, sizeof(buf), "%s with nameserver %s", refer, host);
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
942 host = register_string(priv.memory->hosts, buf); // put a copy into priv.memory->hosts, and return that reference
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
943 }
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
944 else {
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
945 host = register_string(priv.memory->hosts, host); // put a copy into priv.memory->hosts, and return that reference
c2371bb6cf84 3.5 - better error message when rejecting based on ns records on the sbl
carl
parents: 48
diff changeset
946 }
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
947 discard(nameservers);
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
948 return st;
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
949 }
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
950 }
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
951 }
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
952 }
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
953 discard(nameservers);
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
954 host = NULL;
26
fdae7ab30cfc allow normal and terminator versions of tags
carl
parents: 24
diff changeset
955 int bin = priv.memory->binary_tags;
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
956 int bad = priv.memory->bad_html_tags;
34
fc7f8f3ea90f look for NS records on the SBL also
carl
parents: 29
diff changeset
957 lim = priv.pc->tag_limit;
41
d95af8129dfa updates for 3.2, changing file layout, add queueid to messages
carl
parents: 40
diff changeset
958 if (3*bin > bad) return oksofar; // probably .zip or .tar.gz with random content
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
959 if ((bad > lim) && (lim > 0)) return reject_tag;
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
960 return oksofar;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
961 }
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
962
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
963
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
964 ////////////////////////////////////////////////
0
96a9758165cd Initial revision
carl
parents:
diff changeset
965 // start of sendmail milter interfaces
96a9758165cd Initial revision
carl
parents:
diff changeset
966 //
96a9758165cd Initial revision
carl
parents:
diff changeset
967 sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
96a9758165cd Initial revision
carl
parents:
diff changeset
968 {
96a9758165cd Initial revision
carl
parents:
diff changeset
969 // allocate some private memory
96a9758165cd Initial revision
carl
parents:
diff changeset
970 mlfiPriv *priv = new mlfiPriv;
96a9758165cd Initial revision
carl
parents:
diff changeset
971 if (hostaddr->sa_family == AF_INET) {
96a9758165cd Initial revision
carl
parents:
diff changeset
972 priv->ip = ((struct sockaddr_in *)hostaddr)->sin_addr.s_addr;
96a9758165cd Initial revision
carl
parents:
diff changeset
973 }
96a9758165cd Initial revision
carl
parents:
diff changeset
974
96a9758165cd Initial revision
carl
parents:
diff changeset
975 // save the private data
96a9758165cd Initial revision
carl
parents:
diff changeset
976 smfi_setpriv(ctx, (void*)priv);
96a9758165cd Initial revision
carl
parents:
diff changeset
977
96a9758165cd Initial revision
carl
parents:
diff changeset
978 // continue processing
96a9758165cd Initial revision
carl
parents:
diff changeset
979 return SMFIS_CONTINUE;
96a9758165cd Initial revision
carl
parents:
diff changeset
980 }
96a9758165cd Initial revision
carl
parents:
diff changeset
981
96a9758165cd Initial revision
carl
parents:
diff changeset
982 sfsistat mlfi_envfrom(SMFICTX *ctx, char **from)
96a9758165cd Initial revision
carl
parents:
diff changeset
983 {
96a9758165cd Initial revision
carl
parents:
diff changeset
984 mlfiPriv &priv = *MLFIPRIV;
96a9758165cd Initial revision
carl
parents:
diff changeset
985 priv.mailaddr = strdup(from[0]);
96a9758165cd Initial revision
carl
parents:
diff changeset
986 priv.authenticated = (smfi_getsymval(ctx, "{auth_authen}") != NULL);
96a9758165cd Initial revision
carl
parents:
diff changeset
987 return SMFIS_CONTINUE;
96a9758165cd Initial revision
carl
parents:
diff changeset
988 }
96a9758165cd Initial revision
carl
parents:
diff changeset
989
96a9758165cd Initial revision
carl
parents:
diff changeset
990 sfsistat mlfi_envrcpt(SMFICTX *ctx, char **rcpt)
96a9758165cd Initial revision
carl
parents:
diff changeset
991 {
96a9758165cd Initial revision
carl
parents:
diff changeset
992 DNSBLP rejectlist = NULL; // list that caused the reject
96a9758165cd Initial revision
carl
parents:
diff changeset
993 status st = oksofar;
96a9758165cd Initial revision
carl
parents:
diff changeset
994 mlfiPriv &priv = *MLFIPRIV;
96a9758165cd Initial revision
carl
parents:
diff changeset
995 CONFIG &dc = *priv.pc;
42
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
996 if (!priv.queueid) priv.queueid = strdup(smfi_getsymval(ctx, "i"));
0
96a9758165cd Initial revision
carl
parents:
diff changeset
997 char *rcptaddr = rcpt[0];
96a9758165cd Initial revision
carl
parents:
diff changeset
998 char *dnsname = lookup(rcptaddr, dc.env_to_dnsbll);
96a9758165cd Initial revision
carl
parents:
diff changeset
999 char *fromname = lookup(rcptaddr, dc.env_to_chkfrom);
96a9758165cd Initial revision
carl
parents:
diff changeset
1000 if ((strcmp(dnsname, BLACK) == 0) ||
96a9758165cd Initial revision
carl
parents:
diff changeset
1001 (strcmp(fromname, BLACK) == 0)) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1002 st = black; // two options to blacklist this recipient
96a9758165cd Initial revision
carl
parents:
diff changeset
1003 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1004 else if (strcmp(fromname, WHITE) == 0) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1005 st = white;
96a9758165cd Initial revision
carl
parents:
diff changeset
1006 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1007 else {
96a9758165cd Initial revision
carl
parents:
diff changeset
1008 // check an env_from map
96a9758165cd Initial revision
carl
parents:
diff changeset
1009 string_map *sm = find_from_map(dc, fromname);
96a9758165cd Initial revision
carl
parents:
diff changeset
1010 if (sm != NULL) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1011 fromname = lookup(priv.mailaddr, *sm); // returns default if name not in map
96a9758165cd Initial revision
carl
parents:
diff changeset
1012 if (strcmp(fromname, BLACK) == 0) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1013 st = black; // blacklist this envelope from value
96a9758165cd Initial revision
carl
parents:
diff changeset
1014 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1015 if (strcmp(fromname, WHITE) == 0) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1016 st = white; // blacklist this envelope from value
96a9758165cd Initial revision
carl
parents:
diff changeset
1017 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1018 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1019 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1020 if ((st == oksofar) && (strcmp(dnsname, WHITE) != 0)) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1021 // check dns lists
96a9758165cd Initial revision
carl
parents:
diff changeset
1022 st = check_dnsbl(priv, find_dnsbll(dc, dnsname), rejectlist);
96a9758165cd Initial revision
carl
parents:
diff changeset
1023 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1024
96a9758165cd Initial revision
carl
parents:
diff changeset
1025 if (st == reject) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1026 // reject the recipient based on some dnsbl
96a9758165cd Initial revision
carl
parents:
diff changeset
1027 char adr[sizeof "255.255.255.255"];
96a9758165cd Initial revision
carl
parents:
diff changeset
1028 adr[0] = '\0';
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1029 inet_ntop(AF_INET, (const u_char *)&priv.ip, adr, sizeof(adr));
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1030 char buf[2000];
96a9758165cd Initial revision
carl
parents:
diff changeset
1031 snprintf(buf, sizeof(buf), rejectlist->message, adr, adr);
96a9758165cd Initial revision
carl
parents:
diff changeset
1032 smfi_setreply(ctx, "550", "5.7.1", buf);
96a9758165cd Initial revision
carl
parents:
diff changeset
1033 return SMFIS_REJECT;
96a9758165cd Initial revision
carl
parents:
diff changeset
1034 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1035 else if (st == black) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1036 // reject the recipient based on blacklisting either from or to
96a9758165cd Initial revision
carl
parents:
diff changeset
1037 smfi_setreply(ctx, "550", "5.7.1", "no such user");
96a9758165cd Initial revision
carl
parents:
diff changeset
1038 return SMFIS_REJECT;
96a9758165cd Initial revision
carl
parents:
diff changeset
1039 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1040 else {
96a9758165cd Initial revision
carl
parents:
diff changeset
1041 // accept the recipient
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1042 if (st == oksofar) {
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1043 // but remember the non-whites
12
6ac6d6b822ce fix memory leak with duplicate url host names,
carl
parents: 11
diff changeset
1044 register_string(priv.non_whites, rcptaddr);
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1045 priv.only_whites = false;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1046 }
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1047 if (st == white) {
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1048 priv.have_whites = true;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1049 }
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1050 return SMFIS_CONTINUE;
96a9758165cd Initial revision
carl
parents:
diff changeset
1051 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1052 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1053
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1054 sfsistat mlfi_body(SMFICTX *ctx, u_char *data, size_t len)
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1055 {
96a9758165cd Initial revision
carl
parents:
diff changeset
1056 mlfiPriv &priv = *MLFIPRIV;
55
44babba1a9b9 updates for 3.6, better documentation on removing content filtering, missing some files in cvs
carl
parents: 53
diff changeset
1057 if (priv.authenticated) return SMFIS_CONTINUE;
44babba1a9b9 updates for 3.6, better documentation on removing content filtering, missing some files in cvs
carl
parents: 53
diff changeset
1058 if (priv.only_whites) return SMFIS_CONTINUE;
44babba1a9b9 updates for 3.6, better documentation on removing content filtering, missing some files in cvs
carl
parents: 53
diff changeset
1059 if (!priv.pc->content_suffix) return SMFIS_CONTINUE;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1060 priv.scanner->scan(data, len);
11
2c206836b4cc integration work on url scanner
carl
parents: 9
diff changeset
1061 return SMFIS_CONTINUE;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1062 }
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1063
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1064 sfsistat mlfi_eom(SMFICTX *ctx)
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1065 {
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1066 sfsistat rc;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1067 mlfiPriv &priv = *MLFIPRIV;
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1068 char *host = NULL;
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1069 int ip;
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1070 status st;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1071 // process end of message
55
44babba1a9b9 updates for 3.6, better documentation on removing content filtering, missing some files in cvs
carl
parents: 53
diff changeset
1072 if (priv.authenticated ||
44babba1a9b9 updates for 3.6, better documentation on removing content filtering, missing some files in cvs
carl
parents: 53
diff changeset
1073 priv.only_whites ||
44babba1a9b9 updates for 3.6, better documentation on removing content filtering, missing some files in cvs
carl
parents: 53
diff changeset
1074 (!priv.pc->content_suffix) ||
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1075 ((st=check_hosts(priv, host, ip)) == oksofar)) rc = SMFIS_CONTINUE;
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1076 else {
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1077 if (!priv.have_whites) {
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1078 // can reject the entire message
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1079 char buf[2000];
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1080 if (st == reject_tag) {
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1081 // rejected due to excessive bad html tags
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1082 snprintf(buf, sizeof(buf), priv.pc->tag_limit_message);
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1083 }
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1084 else if (st == reject_host) {
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1085 // rejected due to excessive unique host/urls
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1086 snprintf(buf, sizeof(buf), priv.pc->host_limit_message);
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1087 }
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1088 else {
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1089 char adr[sizeof "255.255.255.255"];
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1090 adr[0] = '\0';
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1091 inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr));
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1092 snprintf(buf, sizeof(buf), priv.pc->content_message, host, adr);
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1093 }
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1094 smfi_setreply(ctx, "550", "5.7.1", buf);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1095 rc = SMFIS_REJECT;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1096 }
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1097 else {
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1098 // need to accept it but remove the recipients that don't want it
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1099 for (string_set::iterator i=priv.non_whites.begin(); i!=priv.non_whites.end(); i++) {
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1100 char *rcpt = *i;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1101 smfi_delrcpt(ctx, rcpt);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1102 }
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1103 rc = SMFIS_CONTINUE;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1104 }
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1105 }
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1106 // reset for a new message on the same connection
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1107 mlfi_abort(ctx);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1108 return rc;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1109 }
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1110
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1111 sfsistat mlfi_abort(SMFICTX *ctx)
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1112 {
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1113 mlfiPriv &priv = *MLFIPRIV;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1114 priv.reset();
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1115 return SMFIS_CONTINUE;
96a9758165cd Initial revision
carl
parents:
diff changeset
1116 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1117
96a9758165cd Initial revision
carl
parents:
diff changeset
1118 sfsistat mlfi_close(SMFICTX *ctx)
96a9758165cd Initial revision
carl
parents:
diff changeset
1119 {
96a9758165cd Initial revision
carl
parents:
diff changeset
1120 mlfiPriv *priv = MLFIPRIV;
96a9758165cd Initial revision
carl
parents:
diff changeset
1121 if (!priv) return SMFIS_CONTINUE;
96a9758165cd Initial revision
carl
parents:
diff changeset
1122 delete priv;
96a9758165cd Initial revision
carl
parents:
diff changeset
1123 smfi_setpriv(ctx, NULL);
96a9758165cd Initial revision
carl
parents:
diff changeset
1124 return SMFIS_CONTINUE;
96a9758165cd Initial revision
carl
parents:
diff changeset
1125 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1126
96a9758165cd Initial revision
carl
parents:
diff changeset
1127 struct smfiDesc smfilter =
96a9758165cd Initial revision
carl
parents:
diff changeset
1128 {
96a9758165cd Initial revision
carl
parents:
diff changeset
1129 "DNSBL", // filter name
96a9758165cd Initial revision
carl
parents:
diff changeset
1130 SMFI_VERSION, // version code -- do not change
96a9758165cd Initial revision
carl
parents:
diff changeset
1131 SMFIF_DELRCPT, // flags
96a9758165cd Initial revision
carl
parents:
diff changeset
1132 mlfi_connect, // connection info filter
96a9758165cd Initial revision
carl
parents:
diff changeset
1133 NULL, // SMTP HELO command filter
96a9758165cd Initial revision
carl
parents:
diff changeset
1134 mlfi_envfrom, // envelope sender filter
96a9758165cd Initial revision
carl
parents:
diff changeset
1135 mlfi_envrcpt, // envelope recipient filter
96a9758165cd Initial revision
carl
parents:
diff changeset
1136 NULL, // header filter
96a9758165cd Initial revision
carl
parents:
diff changeset
1137 NULL, // end of header
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1138 mlfi_body, // body block filter
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1139 mlfi_eom, // end of message
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1140 mlfi_abort, // message aborted
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1141 mlfi_close, // connection cleanup
96a9758165cd Initial revision
carl
parents:
diff changeset
1142 };
96a9758165cd Initial revision
carl
parents:
diff changeset
1143
96a9758165cd Initial revision
carl
parents:
diff changeset
1144
96a9758165cd Initial revision
carl
parents:
diff changeset
1145 static void dumpit(char *name, string_map map);
96a9758165cd Initial revision
carl
parents:
diff changeset
1146 static void dumpit(char *name, string_map map) {
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1147 fprintf(stdout, "\n");
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1148 for (string_map::iterator i=map.begin(); i!=map.end(); i++) {
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1149 fprintf(stdout, "%s %s->%s\n", name, (*i).first, (*i).second);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1150 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1151 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1152
96a9758165cd Initial revision
carl
parents:
diff changeset
1153
96a9758165cd Initial revision
carl
parents:
diff changeset
1154 static void dumpit(from_map map);
96a9758165cd Initial revision
carl
parents:
diff changeset
1155 static void dumpit(from_map map) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1156 for (from_map::iterator i=map.begin(); i!=map.end(); i++) {
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1157 char buf[2000];
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1158 snprintf(buf, sizeof(buf), "envelope from map for %s", (*i).first);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1159 string_map *sm = (*i).second;
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1160 dumpit(buf, *sm);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1161 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1162 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1163
96a9758165cd Initial revision
carl
parents:
diff changeset
1164
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1165 static void dumpit(CONFIG &dc);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1166 static void dumpit(CONFIG &dc) {
5
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1167 dumpit(dc.env_from);
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1168 dumpit("envelope to (dnsbl list)", dc.env_to_dnsbll);
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1169 dumpit("envelope to (from map)", dc.env_to_chkfrom);
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1170 fprintf(stdout, "\ndnsbls\n");
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1171 for (dnsblp_map::iterator i=dc.dnsbls.begin(); i!=dc.dnsbls.end(); i++) {
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1172 fprintf(stdout, "%s %s %s\n", (*i).first, (*i).second->suffix, (*i).second->message);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1173 }
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1174 fprintf(stdout, "\ndnsbl_lists\n");
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1175 for (dnsbllp_map::iterator i=dc.dnsblls.begin(); i!=dc.dnsblls.end(); i++) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1176 char *name = (*i).first;
96a9758165cd Initial revision
carl
parents:
diff changeset
1177 DNSBLL &dl = *((*i).second);
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1178 fprintf(stdout, "%s", name);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1179 for (DNSBLL::iterator j=dl.begin(); j!=dl.end(); j++) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1180 DNSBL &d = **j;
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1181 fprintf(stdout, " %s", d.suffix);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1182 }
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1183 fprintf(stdout, "\n");
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1184 }
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1185 if (dc.content_suffix) {
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1186 fprintf(stdout, "\ncontent filtering enabled with %s %s\n", dc.content_suffix, dc.content_message);
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1187 }
57
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1188 for (string_set::iterator i=dc.content_host_ignore.begin(); i!=dc.content_host_ignore.end(); i++) {
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1189 fprintf(stdout, "ignore %s\n", (*i));
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1190 }
46
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1191 if (dc.host_limit && !dc.host_random) {
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1192 fprintf(stdout, "\ncontent filtering for host names hard limit %d %s\n", dc.host_limit, dc.host_limit_message);
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1193 }
46
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1194 if (dc.host_limit && dc.host_random) {
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1195 fprintf(stdout, "\ncontent filtering for host names soft limit %d\n", dc.host_limit);
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
1196 }
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1197 if (dc.tag_limit) {
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1198 fprintf(stdout, "\ncontent filtering for excessive html tags enabled with limit %d %s\n", dc.tag_limit, dc.tag_limit_message);
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1199 }
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1200 fprintf(stdout, "\nfiles\n");
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1201 for (string_list::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1202 char *f = *i;
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1203 fprintf(stdout, "config includes %s\n", f);
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1204 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1205 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1206
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1207
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1208 ////////////////////////////////////////////////
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1209 // check for redundant or recursive include files
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1210 //
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1211 static bool ok_to_include(CONFIG &dc, char *fn);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1212 static bool ok_to_include(CONFIG &dc, char *fn) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1213 if (!fn) return false;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1214 bool ok = true;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1215 for (string_list::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1216 char *f = *i;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1217 if (strcmp(f, fn) == 0) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1218 my_syslog("redundant or recursive include file detected");
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1219 ok = false;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1220 break;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1221 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1222 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1223 return ok;
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1224 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1225
96a9758165cd Initial revision
carl
parents:
diff changeset
1226
96a9758165cd Initial revision
carl
parents:
diff changeset
1227 ////////////////////////////////////////////////
96a9758165cd Initial revision
carl
parents:
diff changeset
1228 // load a single config file
96a9758165cd Initial revision
carl
parents:
diff changeset
1229 //
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1230 static void load_conf_dcc(CONFIG &dc, char *name, char *fn);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1231 static void load_conf_dcc(CONFIG &dc, char *name, char *fn) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1232 ifstream is(fn);
40
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1233 if (is.fail()) {
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1234 char buf[1000];
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1235 snprintf(buf, sizeof(buf), "include file %s not found", fn);
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1236 my_syslog(buf);
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1237 return;
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1238 }
39
6e9d0b2d0720 fix handling of missing include files
carl
parents: 36
diff changeset
1239 dc.config_files.push_back(fn);
6e9d0b2d0720 fix handling of missing include files
carl
parents: 36
diff changeset
1240 const int LINE_SIZE = 2000;
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1241 char line[LINE_SIZE];
39
6e9d0b2d0720 fix handling of missing include files
carl
parents: 36
diff changeset
1242 char *list = BLACK;
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1243 char *delim = " \t";
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1244 int curline = 0;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1245 while (!is.eof()) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1246 is.getline(line, LINE_SIZE);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1247 curline++;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1248 int n = strlen(line);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1249 if (!n) continue;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1250 for (int i=0; i<n; i++) line[i] = tolower(line[i]);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1251 if (line[0] == '#') continue;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1252 char *head = line;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1253 if (strspn(line, delim) == 0) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1254 // have a leading ok/many tag to fetch
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1255 char *cmd = strtok(line, delim);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1256 if (strcmp(cmd, MANY) == 0) list = BLACK;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1257 else if (strcmp(cmd, OK) == 0) list = WHITE;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1258 head = cmd + strlen(cmd) + 1;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1259 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1260 char *cmd = strtok(head, delim);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1261 if (!cmd) continue;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1262 if (strcmp(cmd, "env_from") == 0) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1263 char *from = next_token(delim);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1264 if (from) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1265 string_map &fm = really_find_from_map(dc, name);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1266 fm[from] = list;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1267 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1268 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1269 else if (strcmp(cmd, "env_to") == 0) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1270 char *to = next_token(delim);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1271 if (to) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1272 dc.env_to_dnsbll[to] = list;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1273 dc.env_to_chkfrom[to] = list;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1274 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1275 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1276 else if (strcmp(cmd, "substitute") == 0) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1277 char *tag = next_token(delim);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1278 if (tag && (strcmp(tag, "mail_host") == 0)) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1279 char *from = next_token(delim);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1280 if (from) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1281 string_map &fm = really_find_from_map(dc, name);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1282 fm[from] = list;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1283 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1284 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1285 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1286 else if (strcmp(cmd, "include") == 0) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1287 char *fn = next_token(delim);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1288 if (ok_to_include(dc, fn)) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1289 load_conf_dcc(dc, name, fn);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1290 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1291 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1292
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1293 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1294 is.close();
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1295 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1296
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1297
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1298 static void load_conf(CONFIG &dc, char *fn);
96a9758165cd Initial revision
carl
parents:
diff changeset
1299 static void load_conf(CONFIG &dc, char *fn) {
39
6e9d0b2d0720 fix handling of missing include files
carl
parents: 36
diff changeset
1300 ifstream is(fn);
40
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1301 if (is.fail()) {
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1302 char buf[1000];
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1303 snprintf(buf, sizeof(buf), "include file %s not found", fn);
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1304 my_syslog(buf);
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1305 return;
dc3d8d1aa2d2 fix handling of missing include files
carl
parents: 39
diff changeset
1306 }
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1307 dc.config_files.push_back(fn);
96a9758165cd Initial revision
carl
parents:
diff changeset
1308 map<char*, int, ltstr> commands;
57
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1309 enum {dummy, tld, content, ignore, hostlimit, hostslimit, htmllimit, htmltag, dnsbl, dnsbll, envfrom, envto, include, includedcc};
46
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1310 commands["tld" ] = tld;
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1311 commands["content" ] = content;
57
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1312 commands["ignore" ] = ignore;
46
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1313 commands["host_limit" ] = hostlimit;
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1314 commands["host_soft_limit"] = hostslimit;
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1315 commands["html_limit" ] = htmllimit;
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1316 commands["html_tag" ] = htmltag;
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1317 commands["dnsbl" ] = dnsbl;
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1318 commands["dnsbl_list" ] = dnsbll;
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1319 commands["env_from" ] = envfrom;
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1320 commands["env_to" ] = envto;
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1321 commands["include" ] = include;
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1322 commands["include_dcc" ] = includedcc;
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1323 const int LINE_SIZE = 2000;
96a9758165cd Initial revision
carl
parents:
diff changeset
1324 char line[LINE_SIZE];
96a9758165cd Initial revision
carl
parents:
diff changeset
1325 char orig[LINE_SIZE];
96a9758165cd Initial revision
carl
parents:
diff changeset
1326 char *delim = " \t";
96a9758165cd Initial revision
carl
parents:
diff changeset
1327 int curline = 0;
96a9758165cd Initial revision
carl
parents:
diff changeset
1328 while (!is.eof()) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1329 is.getline(line, LINE_SIZE);
96a9758165cd Initial revision
carl
parents:
diff changeset
1330 snprintf(orig, sizeof(orig), "%s", line);
96a9758165cd Initial revision
carl
parents:
diff changeset
1331 curline++;
96a9758165cd Initial revision
carl
parents:
diff changeset
1332 int n = strlen(line);
96a9758165cd Initial revision
carl
parents:
diff changeset
1333 for (int i=0; i<n; i++) line[i] = tolower(line[i]);
96a9758165cd Initial revision
carl
parents:
diff changeset
1334 char *cmd = strtok(line, delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1335 if (cmd && (cmd[0] != '#') && (cmd[0] != '\0')) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1336 // have a decent command
96a9758165cd Initial revision
carl
parents:
diff changeset
1337 bool processed = false;
96a9758165cd Initial revision
carl
parents:
diff changeset
1338 switch (commands[cmd]) {
28
33e1e3910506 add configurable list of tlds
carl
parents: 27
diff changeset
1339 case tld: {
29
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1340 char *tld = next_token(delim);
28
33e1e3910506 add configurable list of tlds
carl
parents: 27
diff changeset
1341 if (!tld) break; // no tld value
29
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1342 dc.tlds.insert(tld);
28
33e1e3910506 add configurable list of tlds
carl
parents: 27
diff changeset
1343 processed = true;
33e1e3910506 add configurable list of tlds
carl
parents: 27
diff changeset
1344 } break;
33e1e3910506 add configurable list of tlds
carl
parents: 27
diff changeset
1345
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1346 case content: {
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1347 char *suff = strtok(NULL, delim);
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1348 if (!suff) break; // no dns suffix
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1349 char *msg = suff + strlen(suff);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1350 if ((msg - line) >= strlen(orig)) break; // line ended with the dns suffix
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1351 msg = strchr(msg+1, '\'');
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1352 if (!msg) break; // no reply message template
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1353 msg++; // move over the leading '
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1354 if ((msg - line) >= strlen(orig)) break; // line ended with the leading quote
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1355 char *last = strchr(msg, '\'');
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1356 if (!last) break; // no trailing quote
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1357 *last = '\0'; // make it a null terminator
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1358 dc.content_suffix = register_string(suff);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1359 dc.content_message = register_string(msg);
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1360 processed = true;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1361 } break;
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1362
57
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1363 case ignore: {
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1364 char *host = next_token(delim);
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1365 if (!host) break;
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1366 dc.content_host_ignore.insert(host);
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1367 processed = true;
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1368 } break;
419e00901570 changes to handle 5iantlavalamp.com
carl
parents: 55
diff changeset
1369
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1370 case hostlimit: {
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1371 char *limit = strtok(NULL, delim);
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1372 if (!limit) break; // no integer limit
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1373 char *msg = limit + strlen(limit);
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1374 if ((msg - line) >= strlen(orig)) break; // line ended with the limit
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1375 msg = strchr(msg+1, '\'');
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1376 if (!msg) break; // no reply message template
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1377 msg++; // move over the leading '
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1378 if ((msg - line) >= strlen(orig)) break; // line ended with the leading quote
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1379 char *last = strchr(msg, '\'');
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1380 if (!last) break; // no trailing quote
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1381 *last = '\0'; // make it a null terminator
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1382 dc.host_limit = atoi(limit);
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1383 dc.host_limit_message = register_string(msg);
46
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1384 dc.host_random = false;
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1385 processed = true;
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1386 } break;
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1387
46
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1388 case hostslimit: {
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1389 char *limit = next_token(delim);
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1390 if (!limit) break; // no integer limit
66c66a6ee65f changes for 3.2
carl
parents: 44
diff changeset
1391 dc.host_limit = atoi(limit);
44
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
1392 dc.host_random = true;
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
1393 processed = true;
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
1394 } break;
6b79046b18c2 changes for 3.2
carl
parents: 43
diff changeset
1395
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1396 case htmllimit: {
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1397 char *limit = strtok(NULL, delim);
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1398 if (!limit) break; // no integer limit
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1399 char *msg = limit + strlen(limit);
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1400 if ((msg - line) >= strlen(orig)) break; // line ended with the limit
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1401 msg = strchr(msg+1, '\'');
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1402 if (!msg) break; // no reply message template
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1403 msg++; // move over the leading '
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1404 if ((msg - line) >= strlen(orig)) break; // line ended with the leading quote
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1405 char *last = strchr(msg, '\'');
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1406 if (!last) break; // no trailing quote
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1407 *last = '\0'; // make it a null terminator
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1408 dc.tag_limit = atoi(limit);
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1409 dc.tag_limit_message = register_string(msg);
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1410 processed = true;
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1411 } break;
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1412
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1413 case htmltag: {
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1414 char *tag = next_token(delim);
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1415 if (!tag) break; // no html tag value
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1416 dc.html_tags.insert(tag); // base version
26
fdae7ab30cfc allow normal and terminator versions of tags
carl
parents: 24
diff changeset
1417 char buf[200];
fdae7ab30cfc allow normal and terminator versions of tags
carl
parents: 24
diff changeset
1418 snprintf(buf, sizeof(buf), "/%s", tag);
27
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1419 dc.html_tags.insert(register_string(buf)); // leading /
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1420 snprintf(buf, sizeof(buf), "%s/", tag);
43a4f6b3e668 add configurable host name limit and bad html tag limits.
carl
parents: 26
diff changeset
1421 dc.html_tags.insert(register_string(buf)); // trailing /
24
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1422 processed = true;
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1423 } break;
2e23b7184d2b start coding for bad html tag detection
carl
parents: 23
diff changeset
1424
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1425 case dnsbl: {
96a9758165cd Initial revision
carl
parents:
diff changeset
1426 // have a new dnsbl to use
96a9758165cd Initial revision
carl
parents:
diff changeset
1427 char *name = next_token(delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1428 if (!name) break; // no name name
96a9758165cd Initial revision
carl
parents:
diff changeset
1429 if (find_dnsbl(dc, name)) break; // duplicate entry
96a9758165cd Initial revision
carl
parents:
diff changeset
1430 char *suff = strtok(NULL, delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1431 if (!suff) break; // no dns suffic
96a9758165cd Initial revision
carl
parents:
diff changeset
1432 char *msg = suff + strlen(suff);
96a9758165cd Initial revision
carl
parents:
diff changeset
1433 if ((msg - line) >= strlen(orig)) break; // line ended with the dns suffix
96a9758165cd Initial revision
carl
parents:
diff changeset
1434 msg = strchr(msg+1, '\'');
96a9758165cd Initial revision
carl
parents:
diff changeset
1435 if (!msg) break; // no reply message template
96a9758165cd Initial revision
carl
parents:
diff changeset
1436 msg++; // move over the leading '
96a9758165cd Initial revision
carl
parents:
diff changeset
1437 if ((msg - line) >= strlen(orig)) break; // line ended with the leading quote
96a9758165cd Initial revision
carl
parents:
diff changeset
1438 char *last = strchr(msg, '\'');
96a9758165cd Initial revision
carl
parents:
diff changeset
1439 if (!last) break; // no trailing quote
96a9758165cd Initial revision
carl
parents:
diff changeset
1440 *last = '\0'; // make it a null terminator
96a9758165cd Initial revision
carl
parents:
diff changeset
1441 dc.dnsbls[name] = new DNSBL(register_string(suff), register_string(msg));
96a9758165cd Initial revision
carl
parents:
diff changeset
1442 processed = true;
96a9758165cd Initial revision
carl
parents:
diff changeset
1443 } break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1444
96a9758165cd Initial revision
carl
parents:
diff changeset
1445 case dnsbll: {
96a9758165cd Initial revision
carl
parents:
diff changeset
1446 // define a new combination of dnsbls
96a9758165cd Initial revision
carl
parents:
diff changeset
1447 char *name = next_token(delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1448 if (!name) break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1449 if (find_dnsbll(dc, name)) break; // duplicate entry
96a9758165cd Initial revision
carl
parents:
diff changeset
1450 char *list = next_token(delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1451 if (!list || (*list == '\0') || (*list == '#')) break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1452 DNSBLLP d = new DNSBLL;
96a9758165cd Initial revision
carl
parents:
diff changeset
1453 DNSBLP p = find_dnsbl(dc, list);
96a9758165cd Initial revision
carl
parents:
diff changeset
1454 if (p) d->push_back(p);
96a9758165cd Initial revision
carl
parents:
diff changeset
1455 while (true) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1456 list = next_token(delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1457 if (!list || (*list == '\0') || (*list == '#')) break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1458 DNSBLP p = find_dnsbl(dc, list);
96a9758165cd Initial revision
carl
parents:
diff changeset
1459 if (p) d->push_back(p);
96a9758165cd Initial revision
carl
parents:
diff changeset
1460 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1461 dc.dnsblls[name] = d;
96a9758165cd Initial revision
carl
parents:
diff changeset
1462 processed = true;
96a9758165cd Initial revision
carl
parents:
diff changeset
1463 } break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1464
96a9758165cd Initial revision
carl
parents:
diff changeset
1465 case envfrom: {
96a9758165cd Initial revision
carl
parents:
diff changeset
1466 // add an entry into the named string_map
96a9758165cd Initial revision
carl
parents:
diff changeset
1467 char *name = next_token(delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1468 if (!name) break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1469 char *from = next_token(delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1470 if (!from) break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1471 char *list = next_token(delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1472 if (!list) break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1473 if ((strcmp(list, WHITE) == 0) ||
96a9758165cd Initial revision
carl
parents:
diff changeset
1474 (strcmp(list, BLACK) == 0)) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1475 string_map &fm = really_find_from_map(dc, name);
96a9758165cd Initial revision
carl
parents:
diff changeset
1476 fm[from] = list;
96a9758165cd Initial revision
carl
parents:
diff changeset
1477 processed = true;
96a9758165cd Initial revision
carl
parents:
diff changeset
1478 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1479 else {
96a9758165cd Initial revision
carl
parents:
diff changeset
1480 // list may be the name of a previously defined from_map
96a9758165cd Initial revision
carl
parents:
diff changeset
1481 string_map *m = find_from_map(dc, list);
96a9758165cd Initial revision
carl
parents:
diff changeset
1482 if (m && (strcmp(list,name) != 0)) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1483 string_map &pm = *m;
96a9758165cd Initial revision
carl
parents:
diff changeset
1484 string_map &fm = really_find_from_map(dc, name);
96a9758165cd Initial revision
carl
parents:
diff changeset
1485 fm.insert(pm.begin(), pm.end());
96a9758165cd Initial revision
carl
parents:
diff changeset
1486 processed = true;
96a9758165cd Initial revision
carl
parents:
diff changeset
1487 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1488 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1489 } break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1490
96a9758165cd Initial revision
carl
parents:
diff changeset
1491 case envto: {
96a9758165cd Initial revision
carl
parents:
diff changeset
1492 // define the dnsbl_list and env_from maps to use for this recipient
96a9758165cd Initial revision
carl
parents:
diff changeset
1493 char *to = next_token(delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1494 if (!to) break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1495 char *list = next_token(delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1496 if (!list) break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1497 char *from = next_token(delim);
96a9758165cd Initial revision
carl
parents:
diff changeset
1498 if (!from) break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1499 dc.env_to_dnsbll[to] = list;
96a9758165cd Initial revision
carl
parents:
diff changeset
1500 dc.env_to_chkfrom[to] = from;
96a9758165cd Initial revision
carl
parents:
diff changeset
1501 processed = true;
96a9758165cd Initial revision
carl
parents:
diff changeset
1502 } break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1503
96a9758165cd Initial revision
carl
parents:
diff changeset
1504 case include: {
96a9758165cd Initial revision
carl
parents:
diff changeset
1505 char *fn = next_token(delim);
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1506 if (ok_to_include(dc, fn)) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1507 load_conf(dc, fn);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1508 processed = true;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1509 }
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1510 } break;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1511
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1512 case includedcc: {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1513 char *name = next_token(delim);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1514 if (!name) break;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1515 char *fn = next_token(delim);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1516 if (ok_to_include(dc, fn)) {
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1517 load_conf_dcc(dc, name, fn);
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1518 processed = true;
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1519 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1520 } break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1521
96a9758165cd Initial revision
carl
parents:
diff changeset
1522 default: {
96a9758165cd Initial revision
carl
parents:
diff changeset
1523 } break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1524 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1525 if (!processed) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1526 pthread_mutex_lock(&syslog_mutex);
96a9758165cd Initial revision
carl
parents:
diff changeset
1527 openlog("dnsbl", LOG_PID, LOG_MAIL);
96a9758165cd Initial revision
carl
parents:
diff changeset
1528 syslog(LOG_ERR, "ignoring file %s line %d : %s\n", fn, curline, orig);
96a9758165cd Initial revision
carl
parents:
diff changeset
1529 closelog();
96a9758165cd Initial revision
carl
parents:
diff changeset
1530 pthread_mutex_unlock(&syslog_mutex);
96a9758165cd Initial revision
carl
parents:
diff changeset
1531 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1532 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1533 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1534 is.close();
96a9758165cd Initial revision
carl
parents:
diff changeset
1535 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1536
96a9758165cd Initial revision
carl
parents:
diff changeset
1537
96a9758165cd Initial revision
carl
parents:
diff changeset
1538 ////////////////////////////////////////////////
96a9758165cd Initial revision
carl
parents:
diff changeset
1539 // reload the config
96a9758165cd Initial revision
carl
parents:
diff changeset
1540 //
96a9758165cd Initial revision
carl
parents:
diff changeset
1541 static CONFIG* new_conf();
96a9758165cd Initial revision
carl
parents:
diff changeset
1542 static CONFIG* new_conf() {
96a9758165cd Initial revision
carl
parents:
diff changeset
1543 CONFIG *newc = new CONFIG;
29
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1544 pthread_mutex_lock(&config_mutex);
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1545 newc->generation = generation++;
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1546 pthread_mutex_unlock(&config_mutex);
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1547 char buf[200];
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1548 snprintf(buf, sizeof(buf), "loading configuration generation %d", newc->generation);
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1549 my_syslog(buf);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1550 load_conf(*newc, "dnsbl.conf");
96a9758165cd Initial revision
carl
parents:
diff changeset
1551 newc->load_time = time(NULL);
96a9758165cd Initial revision
carl
parents:
diff changeset
1552 return newc;
96a9758165cd Initial revision
carl
parents:
diff changeset
1553 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1554
96a9758165cd Initial revision
carl
parents:
diff changeset
1555
96a9758165cd Initial revision
carl
parents:
diff changeset
1556 ////////////////////////////////////////////////
96a9758165cd Initial revision
carl
parents:
diff changeset
1557 // thread to watch the old config files for changes
96a9758165cd Initial revision
carl
parents:
diff changeset
1558 // and reload when needed. we also cleanup old
96a9758165cd Initial revision
carl
parents:
diff changeset
1559 // configs whose reference count has gone to zero.
96a9758165cd Initial revision
carl
parents:
diff changeset
1560 //
96a9758165cd Initial revision
carl
parents:
diff changeset
1561 static void* config_loader(void *arg);
96a9758165cd Initial revision
carl
parents:
diff changeset
1562 static void* config_loader(void *arg) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1563 typedef set<CONFIG *> configp_set;
96a9758165cd Initial revision
carl
parents:
diff changeset
1564 configp_set old_configs;
18
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
1565 while (loader_run) {
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1566 sleep(180); // look for modifications every 3 minutes
18
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
1567 if (!loader_run) break;
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1568 CONFIG &dc = *config;
96a9758165cd Initial revision
carl
parents:
diff changeset
1569 time_t then = dc.load_time;
96a9758165cd Initial revision
carl
parents:
diff changeset
1570 struct stat st;
96a9758165cd Initial revision
carl
parents:
diff changeset
1571 bool reload = false;
96a9758165cd Initial revision
carl
parents:
diff changeset
1572 for (string_list::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1573 char *fn = *i;
96a9758165cd Initial revision
carl
parents:
diff changeset
1574 if (stat(fn, &st)) reload = true; // file disappeared
96a9758165cd Initial revision
carl
parents:
diff changeset
1575 else if (st.st_mtime > then) reload = true; // file modified
96a9758165cd Initial revision
carl
parents:
diff changeset
1576 if (reload) break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1577 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1578 if (reload) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1579 CONFIG *newc = new_conf();
96a9758165cd Initial revision
carl
parents:
diff changeset
1580 // replace the global config pointer
96a9758165cd Initial revision
carl
parents:
diff changeset
1581 pthread_mutex_lock(&config_mutex);
96a9758165cd Initial revision
carl
parents:
diff changeset
1582 CONFIG *old = config;
96a9758165cd Initial revision
carl
parents:
diff changeset
1583 config = newc;
96a9758165cd Initial revision
carl
parents:
diff changeset
1584 pthread_mutex_unlock(&config_mutex);
96a9758165cd Initial revision
carl
parents:
diff changeset
1585 if (old) old_configs.insert(old);
96a9758165cd Initial revision
carl
parents:
diff changeset
1586 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1587 // now look for old configs with zero ref counts
96a9758165cd Initial revision
carl
parents:
diff changeset
1588 for (configp_set::iterator i=old_configs.begin(); i!=old_configs.end(); ) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1589 CONFIG *old = *i;
96a9758165cd Initial revision
carl
parents:
diff changeset
1590 if (!old->reference_count) {
29
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1591 char buf[200];
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1592 snprintf(buf, sizeof(buf), "freeing memory for old configuration generation %d", old->generation);
4dfdf33f1db0 add syslog msg freeing memory, use bare tld names without leading period
carl
parents: 28
diff changeset
1593 my_syslog(buf);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1594 delete old; // destructor does all the work
96a9758165cd Initial revision
carl
parents:
diff changeset
1595 old_configs.erase(i++);
96a9758165cd Initial revision
carl
parents:
diff changeset
1596 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1597 else i++;
96a9758165cd Initial revision
carl
parents:
diff changeset
1598 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1599 }
18
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
1600 return NULL;
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1601 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1602
96a9758165cd Initial revision
carl
parents:
diff changeset
1603
96a9758165cd Initial revision
carl
parents:
diff changeset
1604 static void usage(char *prog);
96a9758165cd Initial revision
carl
parents:
diff changeset
1605 static void usage(char *prog)
96a9758165cd Initial revision
carl
parents:
diff changeset
1606 {
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1607 fprintf(stderr, "Usage: %s [-d] [-c] -r port -p sm-sock-addr [-t timeout]\n", prog);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1608 fprintf(stderr, "where port is for the connection to our own dns resolver processes\n");
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1609 fprintf(stderr, " and should be local-domain-socket-file-name\n");
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1610 fprintf(stderr, "where sm-sock-addr is for the connection to sendmail\n");
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1611 fprintf(stderr, " and should be one of\n");
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1612 fprintf(stderr, " inet:port@ip-address\n");
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1613 fprintf(stderr, " local:local-domain-socket-file-name\n");
9
8c65411cd7ab integration work on url scanner
carl
parents: 8
diff changeset
1614 fprintf(stderr, "-c will load and dump the config to stdout\n");
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
1615 fprintf(stderr, "-d will add some syslog debug messages\n");
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1616 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1617
96a9758165cd Initial revision
carl
parents:
diff changeset
1618
42
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
1619
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
1620 static void setup_socket(char *sock);
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
1621 static void setup_socket(char *sock) {
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
1622 unlink(sock);
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1623 // sockaddr_un addr;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1624 // memset(&addr, '\0', sizeof addr);
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1625 // addr.sun_family = AF_UNIX;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1626 // strncpy(addr.sun_path, sock, sizeof(addr.sun_path)-1);
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1627 // int s = socket(AF_UNIX, SOCK_STREAM, 0);
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1628 // bind(s, (sockaddr*)&addr, sizeof(addr));
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1629 // close(s);
42
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
1630 }
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
1631
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
1632
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1633 int main(int argc, char**argv)
96a9758165cd Initial revision
carl
parents:
diff changeset
1634 {
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1635 bool check = false;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1636 bool setconn = false;
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1637 bool setreso = false;
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1638 int c;
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1639 const char *args = "r:p:t:hcd";
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1640 extern char *optarg;
96a9758165cd Initial revision
carl
parents:
diff changeset
1641
96a9758165cd Initial revision
carl
parents:
diff changeset
1642 // Process command line options
96a9758165cd Initial revision
carl
parents:
diff changeset
1643 while ((c = getopt(argc, argv, args)) != -1) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1644 switch (c) {
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1645 case 'r':
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1646 if (optarg == NULL || *optarg == '\0') {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1647 fprintf(stderr, "Illegal resolver socket: %s\n", optarg);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1648 exit(EX_USAGE);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1649 }
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1650 resolver_port = strdup(optarg);
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1651 setup_socket(resolver_port);
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1652 setreso = true;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1653 break;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1654
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1655 case 'p':
96a9758165cd Initial revision
carl
parents:
diff changeset
1656 if (optarg == NULL || *optarg == '\0') {
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1657 fprintf(stderr, "Illegal sendmail socket: %s\n", optarg);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1658 exit(EX_USAGE);
96a9758165cd Initial revision
carl
parents:
diff changeset
1659 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1660 if (smfi_setconn(optarg) == MI_FAILURE) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1661 fprintf(stderr, "smfi_setconn failed\n");
96a9758165cd Initial revision
carl
parents:
diff changeset
1662 exit(EX_SOFTWARE);
96a9758165cd Initial revision
carl
parents:
diff changeset
1663 }
42
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
1664 if (strncasecmp(optarg, "unix:", 5) == 0) setup_socket(optarg + 5);
afcf403709ef updates for 3.2, try to drop root privileges
carl
parents: 41
diff changeset
1665 else if (strncasecmp(optarg, "local:", 6) == 0) setup_socket(optarg + 6);
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1666 setconn = true;
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1667 break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1668
96a9758165cd Initial revision
carl
parents:
diff changeset
1669 case 't':
96a9758165cd Initial revision
carl
parents:
diff changeset
1670 if (optarg == NULL || *optarg == '\0') {
96a9758165cd Initial revision
carl
parents:
diff changeset
1671 fprintf(stderr, "Illegal timeout: %s\n", optarg);
96a9758165cd Initial revision
carl
parents:
diff changeset
1672 exit(EX_USAGE);
96a9758165cd Initial revision
carl
parents:
diff changeset
1673 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1674 if (smfi_settimeout(atoi(optarg)) == MI_FAILURE) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1675 fprintf(stderr, "smfi_settimeout failed\n");
96a9758165cd Initial revision
carl
parents:
diff changeset
1676 exit(EX_SOFTWARE);
96a9758165cd Initial revision
carl
parents:
diff changeset
1677 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1678 break;
96a9758165cd Initial revision
carl
parents:
diff changeset
1679
3
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1680 case 'c':
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1681 check = true;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1682 break;
7e1eb343a825 updates to use dcc conf files
carl
parents: 2
diff changeset
1683
16
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
1684 case 'd':
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
1685 debug_syslog = true;
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
1686 break;
2ae8d953f1d0 add scanning for bare hostnames
carl
parents: 14
diff changeset
1687
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1688 case 'h':
96a9758165cd Initial revision
carl
parents:
diff changeset
1689 default:
96a9758165cd Initial revision
carl
parents:
diff changeset
1690 usage(argv[0]);
96a9758165cd Initial revision
carl
parents:
diff changeset
1691 exit(EX_USAGE);
96a9758165cd Initial revision
carl
parents:
diff changeset
1692 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1693 }
5
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1694
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1695 if (check) {
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1696 CONFIG &dc = *new_conf();
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1697 dumpit(dc);
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1698 return 0;
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1699 }
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1700
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1701 if (!setconn) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1702 fprintf(stderr, "%s: Missing required -p argument\n", argv[0]);
96a9758165cd Initial revision
carl
parents:
diff changeset
1703 usage(argv[0]);
96a9758165cd Initial revision
carl
parents:
diff changeset
1704 exit(EX_USAGE);
96a9758165cd Initial revision
carl
parents:
diff changeset
1705 }
5
793ac9cc114d updates to use dcc conf files
carl
parents: 4
diff changeset
1706
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1707 if (!setreso) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1708 fprintf(stderr, "%s: Missing required -r argument\n", argv[0]);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1709 usage(argv[0]);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1710 exit(EX_USAGE);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1711 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1712
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1713 if (smfi_register(smfilter) == MI_FAILURE) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1714 fprintf(stderr, "smfi_register failed\n");
96a9758165cd Initial revision
carl
parents:
diff changeset
1715 exit(EX_UNAVAILABLE);
96a9758165cd Initial revision
carl
parents:
diff changeset
1716 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1717
96a9758165cd Initial revision
carl
parents:
diff changeset
1718 // switch to background mode
96a9758165cd Initial revision
carl
parents:
diff changeset
1719 if (daemon(1,0) < 0) {
96a9758165cd Initial revision
carl
parents:
diff changeset
1720 fprintf(stderr, "daemon() call failed\n");
96a9758165cd Initial revision
carl
parents:
diff changeset
1721 exit(EX_UNAVAILABLE);
96a9758165cd Initial revision
carl
parents:
diff changeset
1722 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1723
96a9758165cd Initial revision
carl
parents:
diff changeset
1724 // write the pid
96a9758165cd Initial revision
carl
parents:
diff changeset
1725 const char *pidpath = "/var/run/dnsbl.pid";
96a9758165cd Initial revision
carl
parents:
diff changeset
1726 unlink(pidpath);
96a9758165cd Initial revision
carl
parents:
diff changeset
1727 FILE *f = fopen(pidpath, "w");
96a9758165cd Initial revision
carl
parents:
diff changeset
1728 if (f) {
22
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1729 #ifdef linux
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1730 // from a comment in the DCC source code:
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1731 // Linux threads are broken. Signals given the
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1732 // original process are delivered to only the
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1733 // thread that happens to have that PID. The
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1734 // sendmail libmilter thread that needs to hear
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1735 // SIGINT and other signals does not, and that breaks
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1736 // scripts that need to stop milters.
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1737 // However, signaling the process group works.
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1738 fprintf(f, "-%d\n", (u_int)getpgrp());
22
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1739 #else
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1740 fprintf(f, "%d\n", (u_int)getpid());
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1741 #endif
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1742 fclose(f);
96a9758165cd Initial revision
carl
parents:
diff changeset
1743 }
96a9758165cd Initial revision
carl
parents:
diff changeset
1744
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1745 // initialize the thread sync objects
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1746 pthread_mutex_init(&config_mutex, 0);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1747 pthread_mutex_init(&syslog_mutex, 0);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1748 pthread_mutex_init(&resolve_mutex, 0);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1749 pthread_mutex_init(&fd_pool_mutex, 0);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1750
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1751 // drop root privs
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1752 struct passwd *pw = getpwnam("dnsbl");
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1753 if (pw) {
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1754 if (setgid(pw->pw_gid) == -1) {
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1755 my_syslog("failed to switch to group dnsbl");
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1756 }
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1757 if (setuid(pw->pw_uid) == -1) {
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1758 my_syslog("failed to switch to user dnsbl");
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1759 }
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1760 }
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1761
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1762 #ifdef NS_PACKETSZ
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1763 // fork off the resolver listener process
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1764 pid_t child = fork();
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1765 if (child < 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1766 my_syslog("failed to create resolver listener process");
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1767 exit(0);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1768 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1769 if (child == 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1770 // we are the child - dns resolver listener process
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1771 resolver_socket = socket(AF_UNIX, SOCK_STREAM, 0);
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1772 if (resolver_socket < 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1773 my_syslog("child failed to create resolver socket");
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1774 exit(0); // failed
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1775 }
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1776 sockaddr_un server;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1777 memset(&server, '\0', sizeof(server));
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1778 server.sun_family = AF_UNIX;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1779 strncpy(server.sun_path, resolver_port, sizeof(server.sun_path)-1);
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1780 // set the socket options
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1781 ///int reuse_addr = 1;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1782 ///linger linger_opt;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1783 ///linger_opt.l_onoff = 0; // off
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1784 ///linger_opt.l_linger = 0;
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1785 ///setsockopt(resolver_socket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&reuse_addr), sizeof(reuse_addr));
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1786 ///setsockopt(resolver_socket, SOL_SOCKET, SO_LINGER, reinterpret_cast<char*>(&linger_opt), sizeof(linger_opt));
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1787 ///// set nonblocking mode
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1788 ///int dummy = 0;
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1789 ///int flags = fcntl(resolver_socket, F_GETFL, dummy);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1790 ///if (flags >= 0) fcntl(resolver_socket, F_SETFL, flags | O_NONBLOCK);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1791 //try to bind the address to the socket.
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1792 if (bind(resolver_socket, (sockaddr *)&server, sizeof(server)) < 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1793 // bind failed
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1794 shutdown(resolver_socket, SHUT_RDWR);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1795 close(resolver_socket);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1796 my_syslog("child failed to bind resolver socket");
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1797 exit(0); // failed
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1798 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1799
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1800 //listen on the socket.
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1801 if (listen(resolver_socket, 10) < 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1802 // listen failed
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1803 shutdown(resolver_socket, SHUT_RDWR);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1804 close(resolver_socket);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1805 my_syslog("child failed to listen to the resolver socket");
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1806 exit(0); // failed
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1807 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1808 while (true) {
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1809 sockaddr_un client;
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1810 socklen_t clientlen = sizeof(client);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1811 int s = accept(resolver_socket, (sockaddr *)&client, &clientlen);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1812 if (s > 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1813 // accept worked, it did not get cancelled before we could accept it
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1814 // fork off a process to handle this connection
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1815 int newchild = fork();
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1816 if (newchild == 0) {
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1817 // this is the worker process
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1818 // child does not need the listening socket
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1819 close(resolver_socket);
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1820 my_syslog("child forked a worker process");
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1821 process_resolver_requests(s);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1822 my_syslog("child terminated a worker process");
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1823 exit(0);
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1824 }
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1825 else {
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1826 // this is the parent
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1827 // parent does not need the accepted socket
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1828 close(s);
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1829 }
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1830 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1831 }
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1832 exit(0); // make sure we don't fall thru.
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1833 }
60
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1834 else {
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1835 sleep(2); // allow child to get started
390ed250c5d2 use local unix domain socket for resolver process communication
carl
parents: 59
diff changeset
1836 }
59
510a511ad554 Add resolver processes to allow better performance on busy machines
carl
parents: 58
diff changeset
1837 #endif
48
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1838
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1839 // load the initial config
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1840 config = new_conf();
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1841
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1842 // only create threads after the fork() in daemon
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1843 pthread_t tid;
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1844 if (pthread_create(&tid, 0, config_loader, 0))
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1845 my_syslog("failed to create config loader thread");
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1846 if (pthread_detach(tid))
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1847 my_syslog("failed to detach config loader thread");
5ef10dc14457 properly drop root privs
carl
parents: 46
diff changeset
1848
18
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
1849 time_t starting = time(NULL);
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
1850 int rc = smfi_main();
22
c21b888cc175 fix restart code, add ifdef for linux pid issues
carl
parents: 18
diff changeset
1851 if ((rc != MI_SUCCESS) && (time(NULL) > starting+5*60)) {
18
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
1852 my_syslog("trying to restart after smfi_main()");
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
1853 loader_run = false; // eventually the config loader thread will terminate
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
1854 execvp(argv[0], argv);
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
1855 }
041ea016b684 add scanning for bare hostnames
carl
parents: 16
diff changeset
1856 exit((rc == MI_SUCCESS) ? 0 : EX_UNAVAILABLE);
0
96a9758165cd Initial revision
carl
parents:
diff changeset
1857 }
8
dbe18921f741 integration work on url scanner
carl
parents: 5
diff changeset
1858