/************************************************************ ** $Id: mx.c,v 0.3 2003/10/29 00:35:13 bcx Exp $ ** ** Copyright Bryan Costales and Perforce Software, Inc. 2003 ** ** This code is "open source" as defined by version 1.9 of ** the Open Source Definition from: ** ** http://www.opensource.org/docs/definition.php. ** ** Entry points defined in this file: ** ** getmx(): ** Look up MX records for the passed host, and then ** look up the IP addresses of each found host. *************************************************************/ # define EXTERN extern #include "slow.h" char ** getmx(char *host, char **list) { char buf[BUFSIZ]; char *cp; HEADER *hp; QBUF qbuf; int len; int acnt, qdcnt; u_short pref; /* not used */ u_short type; /* not used */ u_long ttl; /* not used */ struct hostent *hostp; char **p, **pp; unsigned char *ep, *up; struct in_addr in; extern int h_errno; errno = 0; if (host == NULL || *host == '\0') return NULL; (void)strcpy(buf, host); /* * Make sure host ends in a dot to short circuit lookups */ cp = buf + strlen(buf) - 1; if (*cp != '.') *(++cp) = '.'; *(++cp) = '\0'; /* * Make sure host does not begin with a dot. */ cp = buf; if (*cp == '.') ++cp; /* * We query for speed. Note the trailing dot above. */ len = res_query(cp, C_IN, T_MX, (u_char *) &qbuf, sizeof(qbuf)); if (len < 0) { (void) fprintf(stderr, "%s: %s(%d): %s: %s\n", Prog, __FILE__, __LINE__, host, hstrerror(h_errno)); exit(h_errno); } hp = (HEADER *)&qbuf; up = (u_char *)&qbuf + HFIXEDSZ; ep = (u_char *)&qbuf + len; for (qdcnt = ntohs(hp->qdcount); qdcnt--; up += len + QFIXEDSZ) { if ((len = dn_skipname(up, ep)) < 0) { (void) fprintf(stderr, "%s: %s(%d): %s: %s\n", Prog, __FILE__, __LINE__, host, hstrerror(h_errno)); exit(h_errno); } } acnt = ntohs(hp->ancount); while (--acnt >= 0 && up < ep) { if ((len = dn_expand((u_char *)&qbuf, ep, up, (RES_UNC_T) buf, BUFSIZ-1)) < 0) { break; } up += len; GETSHORT(type, up); up += INT16SZ; GETLONG(ttl, up); GETSHORT(len, up); if (type != T_MX) { up += len; continue; } GETSHORT(pref, up); if ((len = dn_expand((u_char *)&qbuf, ep, up, (RES_UNC_T) buf, BUFSIZ-1)) < 0) { break; } up += len; if (is_in_list(cp, list) == FALSE) list = push_list(cp, list); hostp = gethostbyname(cp); if (hostp == NULL) { continue; } for (p = hostp->h_addr_list; *p != 0; p++) { (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr)); (void) sprintf(buf, "%s", inet_ntoa(in)); if (is_in_list(buf, list) == FALSE) list = push_list(buf, list); for (pp = hostp->h_aliases; *pp != 0; pp++) { sprintf(buf, "%s", *pp); if (is_in_list(buf, list) == FALSE) list = push_list(buf, list); } } } return list; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 4222 | bryan_costales |
Massive rewrite to speed up the database writes. Using a single database now with duplicate keys where the keys are the IP numbers. Added a purge command and removed the garbage command. Fixed some leaking memory bugs and properly closed the database in a few places were it was not properly closed. Updated the docs to reflect this and bumped both the database version and release number. Running on a FreeBSD 3.x machine and a Solaris 9 machine. |
||
#4 | 4052 | bryan_costales |
Implimented: whitelisting AddMXHost for MX servers that lie Converted to thread safe DNS routines garbage collection RunAsUser and RunAsGroup for root startups rebuild the database summarize by IP number Finished all documentation. Moved release from alpha to beta |
||
#3 | 3998 | bryan_costales |
Brought the whole distribution up to V0.9 Added a huge abount of documentation. Added slowedit find Created startup scripts to launch for testing Fixed numerous bugs. Fixed a few portablity issues. Installed hooks for whitelisting and IP aliases. |
||
#2 | 3957 | bryan_costales |
Added rbl lookup support and testing for same. Folded in support for smfi_stop(). Added lots of slowedit commands Fixed a serious bug in MX lookups. Added to documentation. |
||
#1 | 3838 | bryan_costales |
This is pre-release 0.5 (rcs numbering) which includes: The milter source files and Makefile A regressive testing subdirectory with Makefile and /bin/sh scripts. A patches subdirectory with a patch file for V8.13 sendmail All have been compiled and tested on a 64bit Sun Solaris 9 machine. |