Mercurial > dnsbl
comparison src/dnsbl.cpp @ 242:d8ee4c97b9ab stable-6-0-26
64 bit fixes for libresolv.a
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 19 Nov 2010 13:01:07 -0800 |
parents | 7b818a4e21a4 |
children | ef97c7cd4a6e |
comparison
equal
deleted
inserted
replaced
241:315c53fbbb77 | 242:d8ee4c97b9ab |
---|---|
117 | 117 |
118 | 118 |
119 struct ns_map { | 119 struct ns_map { |
120 // all the strings are owned by the keys/values in the ns_host string map | 120 // all the strings are owned by the keys/values in the ns_host string map |
121 string_map ns_host; // nameserver name -> host name that uses this name server | 121 string_map ns_host; // nameserver name -> host name that uses this name server |
122 ns_mapper ns_ip; // nameserver name -> ip address of the name server | 122 ns_mapper ns_ip; // nameserver name -> ipv4 address of the name server |
123 ~ns_map(); | 123 ~ns_map(); |
124 void add(const char *name, const char *refer); | 124 void add(const char *name, const char *refer); |
125 }; | 125 }; |
126 | 126 |
127 | 127 |
152 struct glommer { | 152 struct glommer { |
153 size_t length; | 153 size_t length; |
154 #ifdef NS_PACKETSZ | 154 #ifdef NS_PACKETSZ |
155 u_char answer[NS_PACKETSZ*4]; // with a resolver, we return resolver answers | 155 u_char answer[NS_PACKETSZ*4]; // with a resolver, we return resolver answers |
156 #else | 156 #else |
157 int answer; // without a resolver, we return a single ip4 address, 0 == no answer | 157 int32_t answer; // without a resolver, we return a single ipv4 address, 0 == no answer |
158 #endif | 158 #endif |
159 } __attribute__ ((packed)); | 159 } __attribute__ ((packed)); |
160 | 160 |
161 | 161 |
162 //////////////////////////////////////////////// | 162 //////////////////////////////////////////////// |
257 // ask a dns question and get an A record answer - we don't try | 257 // ask a dns question and get an A record answer - we don't try |
258 // very hard, just using the default resolver retry settings. | 258 // very hard, just using the default resolver retry settings. |
259 // If we cannot get an answer, we just accept the mail. | 259 // If we cannot get an answer, we just accept the mail. |
260 // | 260 // |
261 // | 261 // |
262 int dns_interface(mlfiPriv &priv, const char *question, bool maybe_ip, ns_map *nameservers); | 262 int32_t dns_interface(mlfiPriv &priv, const char *question, bool maybe_ip, ns_map *nameservers); |
263 int dns_interface(mlfiPriv &priv, const char *question, bool maybe_ip, ns_map *nameservers) { | 263 int32_t dns_interface(mlfiPriv &priv, const char *question, bool maybe_ip, ns_map *nameservers) { |
264 // tell sendmail we are still working | 264 // tell sendmail we are still working |
265 #if _FFR_SMFI_PROGRESS | 265 #if _FFR_SMFI_PROGRESS |
266 if (priv.eom) smfi_progress(priv.ctx); | 266 if (priv.eom) smfi_progress(priv.ctx); |
267 #endif | 267 #endif |
268 | 268 |
272 if (priv.err) return 0; // cannot ask more questions on this socket. | 272 if (priv.err) return 0; // cannot ask more questions on this socket. |
273 if (maybe_ip) { | 273 if (maybe_ip) { |
274 // might be a bare ip address, try this first to avoid dns lookups that may not be needed | 274 // might be a bare ip address, try this first to avoid dns lookups that may not be needed |
275 in_addr ip; | 275 in_addr ip; |
276 if (inet_aton(question, &ip)) { | 276 if (inet_aton(question, &ip)) { |
277 return (int)ip.s_addr; | 277 return (int32_t)ip.s_addr; |
278 } | 278 } |
279 } | 279 } |
280 int n = strlen(question); | 280 int n = strlen(question); |
281 if (question[n-1] == '.') { | 281 if (question[n-1] == '.') { |
282 priv.my_write(question, n+1); // write the question including the null terminator | 282 priv.my_write(question, n+1); // write the question including the null terminator |
347 if (ns_rr_type(rr) == ns_t_a) { | 347 if (ns_rr_type(rr) == ns_t_a) { |
348 char* nam = (char*)ns_rr_name(rr); | 348 char* nam = (char*)ns_rr_name(rr); |
349 ns_mapper::iterator i = ns.ns_ip.find(nam); | 349 ns_mapper::iterator i = ns.ns_ip.find(nam); |
350 if (i != ns.ns_ip.end()) { | 350 if (i != ns.ns_ip.end()) { |
351 // we want this ip address | 351 // we want this ip address |
352 int address; | 352 int32_t address; |
353 memcpy(&address, ns_rr_rdata(rr), sizeof(address)); | 353 memcpy(&address, ns_rr_rdata(rr), sizeof(address)); |
354 ns.ns_ip[nam] = address; | 354 ns.ns_ip[nam] = address; |
355 } | 355 } |
356 } | 356 } |
357 } | 357 } |
358 } | 358 } |
359 int rrnum = 0; | 359 int rrnum = 0; |
360 while (ns_parserr(&handle, ns_s_an, rrnum++, &rr) == 0) { | 360 while (ns_parserr(&handle, ns_s_an, rrnum++, &rr) == 0) { |
361 if (ns_rr_type(rr) == ns_t_a) { | 361 if (ns_rr_type(rr) == ns_t_a) { |
362 int address; | 362 int32_t address; |
363 memcpy(&address, ns_rr_rdata(rr), sizeof(address)); | 363 memcpy(&address, ns_rr_rdata(rr), sizeof(address)); |
364 ret_address = address; | 364 ret_address = address; |
365 } | 365 } |
366 } | 366 } |
367 } | 367 } |
816 | 816 |
817 | 817 |
818 //////////////////////////////////////////////// | 818 //////////////////////////////////////////////// |
819 // check a single dnsbl | 819 // check a single dnsbl |
820 // | 820 // |
821 bool check_single(mlfiPriv &priv, int ip, const char *suffix); | 821 bool check_single(mlfiPriv &priv, int32_t ip, const char *suffix); |
822 bool check_single(mlfiPriv &priv, int ip, const char *suffix) { | 822 bool check_single(mlfiPriv &priv, int32_t ip, const char *suffix) { |
823 // make a dns question | 823 // make a dns question |
824 const u_char *src = (const u_char *)&ip; | 824 const u_char *src = (const u_char *)&ip; |
825 if (src[0] == 127) return false; // don't do dns lookups on localhost | 825 if (src[0] == 127) return false; // don't do dns lookups on localhost |
826 if (src[0] == 10) return false; // don't do dns lookups on rfc1918 space | 826 if (src[0] == 10) return false; // don't do dns lookups on rfc1918 space |
827 if ((src[0] == 192) && (src[1] == 168)) return false; | 827 if ((src[0] == 192) && (src[1] == 168)) return false; |
838 | 838 |
839 | 839 |
840 //////////////////////////////////////////////// | 840 //////////////////////////////////////////////// |
841 // check a single dnsbl | 841 // check a single dnsbl |
842 // | 842 // |
843 bool check_single(mlfiPriv &priv, int ip, DNSBL &bl); | 843 bool check_single(mlfiPriv &priv, int32_t ip, DNSBL &bl); |
844 bool check_single(mlfiPriv &priv, int ip, DNSBL &bl) { | 844 bool check_single(mlfiPriv &priv, int32_t ip, DNSBL &bl) { |
845 return check_single(priv, ip, bl.suffix); | 845 return check_single(priv, ip, bl.suffix); |
846 } | 846 } |
847 | 847 |
848 | 848 |
849 //////////////////////////////////////////////// | 849 //////////////////////////////////////////////// |
873 | 873 |
874 //////////////////////////////////////////////// | 874 //////////////////////////////////////////////// |
875 // check the hosts from the body against the content filter and uribl dnsbls | 875 // check the hosts from the body against the content filter and uribl dnsbls |
876 // | 876 // |
877 // | 877 // |
878 bool check_hosts(mlfiPriv &priv, bool random, int limit, const char *&msg, const char *&host, int &ip, const char *&found); | 878 bool check_hosts(mlfiPriv &priv, bool random, int limit, const char *&msg, const char *&host, int32_t &ip, const char *&found); |
879 bool check_hosts(mlfiPriv &priv, bool random, int limit, const char *&msg, const char *&host, int &ip, const char *&found) { | 879 bool check_hosts(mlfiPriv &priv, bool random, int limit, const char *&msg, const char *&host, int32_t &ip, const char *&found) { |
880 found = NULL; // normally ip address style | 880 found = NULL; // normally ip address style |
881 if (!priv.content_suffix && !priv.uribl_suffix) return false; // nothing to check | 881 if (!priv.content_suffix && !priv.uribl_suffix) return false; // nothing to check |
882 string_set &hosts = priv.memory->get_hosts(); | 882 string_set &hosts = priv.memory->get_hosts(); |
883 string_set &ignore = *priv.content_host_ignore; | 883 string_set &ignore = *priv.content_host_ignore; |
884 | 884 |
885 int count = 0; | 885 int count = 0; |
886 int cnt = hosts.size(); // number of hosts we could look at | 886 int cnt = hosts.size(); // number of hosts we could look at |
887 int_set ips; | 887 int32_t_set ips; |
888 ns_map nameservers; | 888 ns_map nameservers; |
889 for (string_set::iterator i=hosts.begin(); i!=hosts.end(); i++) { | 889 for (string_set::iterator i=hosts.begin(); i!=hosts.end(); i++) { |
890 host = *i; // a reference into hosts, which will live until this smtp transaction is closed | 890 host = *i; // a reference into hosts, which will live until this smtp transaction is closed |
891 | 891 |
892 // don't bother looking up hosts on the ignore list | 892 // don't bother looking up hosts on the ignore list |
919 snprintf(buf, sizeof(buf), "host %s not found", host); | 919 snprintf(buf, sizeof(buf), "host %s not found", host); |
920 } | 920 } |
921 my_syslog(&priv, buf); | 921 my_syslog(&priv, buf); |
922 } | 922 } |
923 if (ip) { | 923 if (ip) { |
924 int_set::iterator i = ips.find(ip); | 924 int32_t_set::iterator i = ips.find(ip); |
925 if (i == ips.end()) { | 925 if (i == ips.end()) { |
926 // we haven't looked this up yet | 926 // we haven't looked this up yet |
927 ips.insert(ip); | 927 ips.insert(ip); |
928 // check dnsbl style list | 928 // check dnsbl style list |
929 if (priv.content_suffix && check_single(priv, ip, priv.content_suffix)) { | 929 if (priv.content_suffix && check_single(priv, ip, priv.content_suffix)) { |
957 snprintf(buf, sizeof(buf), "ns %s not found", host); | 957 snprintf(buf, sizeof(buf), "ns %s not found", host); |
958 } | 958 } |
959 my_syslog(&priv, buf); | 959 my_syslog(&priv, buf); |
960 } | 960 } |
961 if (ip) { | 961 if (ip) { |
962 int_set::iterator i = ips.find(ip); | 962 int32_t_set::iterator i = ips.find(ip); |
963 if (i == ips.end()) { | 963 if (i == ips.end()) { |
964 ips.insert(ip); | 964 ips.insert(ip); |
965 if (check_single(priv, ip, priv.content_suffix)) { | 965 if (check_single(priv, ip, priv.content_suffix)) { |
966 msg = priv.content_message; | 966 msg = priv.content_message; |
967 string_map::iterator j = nameservers.ns_host.find(host); | 967 string_map::iterator j = nameservers.ns_host.find(host); |
1310 sfsistat mlfi_eom(SMFICTX *ctx) | 1310 sfsistat mlfi_eom(SMFICTX *ctx) |
1311 { | 1311 { |
1312 sfsistat rc; | 1312 sfsistat rc; |
1313 mlfiPriv &priv = *MLFIPRIV; | 1313 mlfiPriv &priv = *MLFIPRIV; |
1314 const char *host = NULL; | 1314 const char *host = NULL; |
1315 int ip; | 1315 int32_t ip; |
1316 // process end of message | 1316 // process end of message |
1317 priv.eom = true; | 1317 priv.eom = true; |
1318 if (priv.authenticated || priv.only_whites) rc = SMFIS_CONTINUE; | 1318 if (priv.authenticated || priv.only_whites) rc = SMFIS_CONTINUE; |
1319 else { | 1319 else { |
1320 // assert env_to not empty, it contains the | 1320 // assert env_to not empty, it contains the |