4 * locate the originating host
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
21 #include "serv_extensions.h"
22 #include "locate_host.h"
23 #include "sysdep_decls.h"
28 void locate_host(char *tbuf, size_t n, const struct in_addr *addr)
35 lprintf(9, "locate_host() called\n");
37 #ifdef HAVE_NONREENTRANT_NETDB
38 begin_critical_section(S_NETDB);
41 if ((ch = gethostbyaddr((const char *) addr, sizeof(*addr), AF_INET)) ==
44 i = (const char *) addr;
49 snprintf(tbuf, n, "%d.%d.%d.%d", a1, a2, a3, a4);
50 goto end; /* because we might need to end the critical
53 /* check if the forward DNS agrees; if not, they're spoofing */
54 j = strdoop(ch->h_name);
55 ch = gethostbyname(j);
60 /* check address for consistency */
61 for (; *ch->h_addr_list; ch->h_addr_list++)
62 if (!memcmp(*ch->h_addr_list, addr,
64 safestrncpy(tbuf, ch->h_name, 63);
67 goto bad_dns; /* they were spoofing. report a numeric IP
72 #ifdef HAVE_NONREENTRANT_NETDB
73 end_critical_section(S_NETDB);
77 lprintf(9, "locate_host() exiting\n");
82 * Check to see if a host is on some sort of spam list (RBL)
83 * If spammer, returns nonzero and places reason in 'message_to_spammer'
85 int rbl_check_addr(struct in_addr *addr, char *message_to_spammer)
92 char rbl_domains[SIZ];
94 strcpy(message_to_spammer, "ok");
96 i = (const char *) addr;
100 a4 = ((*i++) & 0xff);
102 /* See if we have any RBL domains configured */
103 num_rbl = get_hosts(rbl_domains, "rbl");
104 if (num_rbl < 1) return(0);
106 /* Try all configured RBL */
107 for (rbl=0; rbl<num_rbl; ++rbl) {
108 snprintf(tbuf, sizeof tbuf,
111 extract(&tbuf[strlen(tbuf)], rbl_domains, rbl);
113 if (gethostbyname(tbuf) != NULL) {
114 strcpy(message_to_spammer,
115 "Message rejected due to "
116 "known spammer source IP address"
127 * Check to see if the client host is on some sort of spam list (RBL)
128 * If spammer, returns nonzero and places reason in 'message_to_spammer'
130 int rbl_check(char *message_to_spammer) {
131 struct sockaddr_in sin;
134 if (!getpeername(CC->client_socket, (struct sockaddr *) &sin, &len)) {
135 return(rbl_check_addr(&sin.sin_addr, message_to_spammer));