comparison src/dnsbl.cpp @ 177:a4d313c2460b

start embedded dcc filtering
author carl
date Sun, 30 Sep 2007 10:27:14 -0700
parents da0c41b9f672
children d6531c702be3
comparison
equal deleted inserted replaced
176:4ec928b24bab 177:a4d313c2460b
5 http://www.gnu.org/licenses/gpl-3.0.txt 5 http://www.gnu.org/licenses/gpl-3.0.txt
6 6
7 Based on a sample milter Copyright (c) 2000-2003 Sendmail, Inc. and its 7 Based on a sample milter Copyright (c) 2000-2003 Sendmail, Inc. and its
8 suppliers. Inspired by the DCC by Rhyolite Software 8 suppliers. Inspired by the DCC by Rhyolite Software
9 9
10 -b port The port used to talk to the dcc interface daemon
10 -r port The port used to talk to our internal dns resolver processes 11 -r port The port used to talk to our internal dns resolver processes
11 -p port The port through which the MTA will connect to this milter. 12 -p port The port through which the MTA will connect to this milter.
12 -t sec The timeout value. 13 -t sec The timeout value.
13 -c Check the config, and print a copy to stdout. Don't start the 14 -c Check the config, and print a copy to stdout. Don't start the
14 milter or do anything with the socket. 15 milter or do anything with the socket.
93 std::set<int> fd_pool; 94 std::set<int> fd_pool;
94 int NULL_SOCKET = -1; 95 int NULL_SOCKET = -1;
95 const time_t ERROR_SOCKET_TIME = 60; // number of seconds between attempts to open a socket to the dns resolver process 96 const time_t ERROR_SOCKET_TIME = 60; // number of seconds between attempts to open a socket to the dns resolver process
96 char *resolver_port = NULL; // unix domain socket to talk to the dns resolver process 97 char *resolver_port = NULL; // unix domain socket to talk to the dns resolver process
97 int resolver_socket = NULL_SOCKET; // socket used to listen for resolver requests 98 int resolver_socket = NULL_SOCKET; // socket used to listen for resolver requests
99 char *dccifd_port = NULL; // unix domain socket to talk to the dcc interface daemon
98 time_t last_error_time; 100 time_t last_error_time;
99 int resolver_sock_count = 0; // protected with fd_pool_mutex 101 int resolver_sock_count = 0; // protected with fd_pool_mutex
100 int resolver_pool_size = 0; // protected with fd_pool_mutex 102 int resolver_pool_size = 0; // protected with fd_pool_mutex
101 rcpt_rates rcpt_counts; // protected with rate_mutex 103 rcpt_rates rcpt_counts; // protected with rate_mutex
102 104
357 my_disconnect(fd); 359 my_disconnect(fd);
358 } 360 }
359 } 361 }
360 } 362 }
361 363
362 int mlfiPriv::my_write(char *buf, int len) { 364 size_t mlfiPriv::my_write(const char *buf, size_t len) {
363 if (err) return 0; 365 if (err) return 0;
364 int rs = 0; 366 size_t rs = 0;
365 while (len) { 367 while (len) {
366 int ws = write(fd, buf, len); 368 size_t ws = write(fd, buf, len);
367 if (ws > 0) { 369 if (ws > 0) {
368 rs += ws; 370 rs += ws;
369 len -= ws; 371 len -= ws;
370 buf += ws; 372 buf += ws;
371 } 373 }
377 } 379 }
378 } 380 }
379 return rs; 381 return rs;
380 } 382 }
381 383
382 int mlfiPriv::my_read(char *buf, int len) { 384 size_t mlfiPriv::my_read(char *buf, size_t len) {
383 if (err) return 0; 385 if (err) return 0;
384 int rs = 0; 386 size_t rs = 0;
385 while (len) { 387 while (len) {
386 int ws = read(fd, buf, len); 388 size_t ws = read(fd, buf, len);
387 if (ws > 0) { 389 if (ws > 0) {
388 rs += ws; 390 rs += ws;
389 len -= ws; 391 len -= ws;
390 buf += ws; 392 buf += ws;
391 } 393 }
1317 1319
1318 1320
1319 void usage(char *prog); 1321 void usage(char *prog);
1320 void usage(char *prog) 1322 void usage(char *prog)
1321 { 1323 {
1322 fprintf(stderr, "Usage: %s [-d [level]] [-c] [-s] [-e from|to] -r port -p sm-sock-addr [-t timeout]\n", prog); 1324 fprintf(stderr, "Usage: %s [-d [level]] [-c] [-s] [-e from|to] [-b dccifd-addr] -r port -p sm-sock-addr [-t timeout]\n", prog);
1325 fprintf(stderr, "where dccifd_addr is for the connection to dccifd\n");
1326 fprintf(stderr, " and should be local-domain-socket-file-name\n");
1323 fprintf(stderr, "where port is for the connection to our own dns resolver processes\n"); 1327 fprintf(stderr, "where port is for the connection to our own dns resolver processes\n");
1324 fprintf(stderr, " and should be local-domain-socket-file-name\n"); 1328 fprintf(stderr, " and should be local-domain-socket-file-name\n");
1325 fprintf(stderr, "where sm-sock-addr is for the connection to sendmail\n"); 1329 fprintf(stderr, "where sm-sock-addr is for the connection to sendmail\n");
1326 fprintf(stderr, " and should be one of\n"); 1330 fprintf(stderr, " and should be one of\n");
1327 fprintf(stderr, " inet:port@ip-address\n"); 1331 fprintf(stderr, " inet:port@ip-address\n");
1364 bool stress = false; 1368 bool stress = false;
1365 bool setconn = false; 1369 bool setconn = false;
1366 bool setreso = false; 1370 bool setreso = false;
1367 char *email = NULL; 1371 char *email = NULL;
1368 int c; 1372 int c;
1369 const char *args = "r:p:t:e:d:chs"; 1373 const char *args = "b:r:p:t:e:d:chs";
1370 extern char *optarg; 1374 extern char *optarg;
1371 1375
1372 // Process command line options 1376 // Process command line options
1373 while ((c = getopt(argc, argv, args)) != -1) { 1377 while ((c = getopt(argc, argv, args)) != -1) {
1374 switch (c) { 1378 switch (c) {
1379 case 'b':
1380 if (optarg == NULL || *optarg == '\0') {
1381 fprintf(stderr, "Illegal dccifd socket: %s\n", optarg);
1382 exit(EX_USAGE);
1383 }
1384 dccifd_port = strdup(optarg);
1385 break;
1386
1375 case 'r': 1387 case 'r':
1376 if (optarg == NULL || *optarg == '\0') { 1388 if (optarg == NULL || *optarg == '\0') {
1377 fprintf(stderr, "Illegal resolver socket: %s\n", optarg); 1389 fprintf(stderr, "Illegal resolver socket: %s\n", optarg);
1378 exit(EX_USAGE); 1390 exit(EX_USAGE);
1379 } 1391 }