diff --git a/smmapdfw/verify_worker/verify_worker.c b/smmapdfw/verify_worker/verify_worker.c index aba82d1..ed85c23 100644 --- a/smmapdfw/verify_worker/verify_worker.c +++ b/smmapdfw/verify_worker/verify_worker.c @@ -52,6 +52,9 @@ #include "stats.h" #include "dvl.h" + + + #define SMM_LOCAL_PERM_NOK 101 #define SMM_LOCAL_TEMP_NOK 102 #define SMM_LOCAL_OK 103 @@ -507,6 +510,25 @@ int verify_work(void *handle, void *work_handle, char *input, htbuffer_t *output return vwh->result->result; } +static void inner_resolve(char *domain, unsigned int **addresses, int *num_of_addresses) { + if (domain != NULL) { + syslog(LOG_DEBUG, "inner_resolve: %s", domain); + + a_rdata_t **a_rdata = get_a_rrs(domain); + a_rdata_t **a_rdata2; + if (NULL != a_rdata) { + for (a_rdata2 = a_rdata; *a_rdata2 != NULL; a_rdata2++) { + syslog(LOG_DEBUG, "inner_resolve: arranging result"); + *addresses = (unsigned int*)htrealloc(*addresses, sizeof(unsigned int)*(*num_of_addresses + 2)); /* 2 since first i==0 and + we always need one more + for the termination */ + *(*addresses + *num_of_addresses) = (*a_rdata2)->address; + *num_of_addresses += 1; + } + free_rrs((void**)a_rdata); + } + } +} static unsigned int *get_mx_ip_addresses(char *domain) { mx_rdata_t **mx_rdata, **mx_rdata2; @@ -520,31 +542,28 @@ static unsigned int *get_mx_ip_addresses(char *domain) { } mx_rdata = get_best_mx_rrs(domain); - if (NULL == mx_rdata) { - syslog(LOG_DEBUG, "get_mx_ip_address: no mx at all"); - return NULL; - } - - for (mx_rdata2 = mx_rdata; *mx_rdata2 != NULL; mx_rdata2++) { - syslog(LOG_DEBUG, "get_mx_ip_address: %s", (*mx_rdata2)->exchange); - - a_rdata = get_a_rrs((*mx_rdata2)->exchange); - if (NULL != a_rdata) { - for (a_rdata2 = a_rdata; *a_rdata2 != NULL; a_rdata2++) { - addresses = (unsigned int*)htrealloc(addresses, sizeof(unsigned int)*(i+2)); /* 2 since first i==0 and - we always need one more - for the termination */ - *(addresses+i) = (*a_rdata2)->address; - i++; - } - free_rrs((void**)a_rdata); + if (NULL != mx_rdata) { + for (mx_rdata2 = mx_rdata; *mx_rdata2 != NULL; mx_rdata2++) { + inner_resolve((*mx_rdata2)->exchange, &addresses, &i); } + free_rrs((void**)mx_rdata); + } else { + syslog(LOG_DEBUG, "get_mx_ip_address: no mx at all, trying a-rr"); + inner_resolve(domain, &addresses, &i); } if (NULL != addresses) *(addresses+i) = 0; /* termination */ - free_rrs((void**)mx_rdata); + syslog(LOG_DEBUG, "get_mx_ip_addresses: Found %d addresses", i); + int j; + for (j = 0; j < i; j++) + syslog(LOG_DEBUG, "get_mx_ip_addresses: %d.%d.%d.%d", + (htonl(*(addresses+j))&0xff000000)>>24, (htonl(*(addresses+j))&0x00ff0000)>>16, + (htonl(*(addresses+j))&0x0000ff00)>>8, (htonl(*(addresses+j))&0x000000ff)); + + + return addresses; } @@ -756,8 +775,8 @@ static void *worker_thread(void *arg) { syslog(LOG_DEBUG, "verify (%p) worker_thread: starting checker thread (%p) to %d.%d.%d.%d, for email-address %s", wt->vwh, ct, - (address&0xff000000)>>24, (address&0x00ff0000)>>16, - (address&0x0000ff00)>>8, (address&0x000000ff), + (htonl(address)&0xff000000)>>24, (htonl(address)&0x00ff0000)>>16, + (htonl(address)&0x0000ff00)>>8, (htonl(address)&0x000000ff), wt->input); @@ -781,8 +800,8 @@ static void *worker_thread(void *arg) { wt->checker_cnt -= 1; syslog(LOG_DEBUG, "verify (%p) worker_thread: got checker result for %d.%d.%d.%d: %s -> %d, %s", wt->vwh, - ((ct->ip_address)&0xff000000)>>24, ((ct->ip_address)&0x00ff0000)>>16, - ((ct->ip_address)&0x0000ff00)>>8, ((ct->ip_address)&0x000000ff), + (htonl(ct->ip_address)&0xff000000)>>24, (htonl(ct->ip_address)&0x00ff0000)>>16, + (htonl(ct->ip_address)&0x0000ff00)>>8, (htonl(ct->ip_address)&0x000000ff), wt->input, ct->result, ct->output); pthread_join(ct->thread, NULL);