#include #include #include #include #include #include #include #include #include "dns.h" #include "qrschedule.h" #include "mmap.h" #include "log.h" /*int ask_dnsmx(const char *domain, struct ips **ips) { struct ips *cur = malloc(sizeof(*cur)); if (!cur) return -1; *ips = cur; if (!strcmp(domain, "a.example.org") || !strcmp(domain, "c.example.org")) { inet_pton(AF_INET6, "::192.168.2.61", &cur->addr); cur->priority = 10; cur->next = NULL; } else if (!strcmp(domain, "b.example.org") || !strcmp(domain, "d.example.org")) { inet_pton(AF_INET6, "::192.168.2.61", &cur->addr); cur->priority = 15; cur->next = NULL; } else if (!strcmp(domain, "host1.example.net")) { inet_pton(AF_INET6, "::172.16.88.153", &cur->addr); cur->priority = 17; cur->next = malloc(sizeof(*cur)); if (!cur->next) return -1; cur = cur->next; inet_pton(AF_INET6, "::172.16.96.146", &cur->addr); cur->priority = 15; cur->next = malloc(sizeof(*cur)); if (!cur->next) return -1; cur = cur->next; inet_pton(AF_INET6, "::172.16.96.145", &cur->addr); cur->priority = 10; cur->next = NULL; } else if (!strcmp(domain, "example.net")) { inet_pton(AF_INET6, "::172.16.96.146", &cur->addr); cur->priority = 15; cur->next = malloc(sizeof(*cur)); if (!cur->next) return -1; cur = cur->next; inet_pton(AF_INET6, "::172.16.96.145", &cur->addr); cur->priority = 10; cur->next = NULL; } else if (!strcmp(domain, "host2.example.net")) { inet_pton(AF_INET6, "::172.16.96.145", &cur->addr); cur->priority = 2; cur->next = malloc(sizeof(*cur)); if (!cur->next) return -1; cur = cur->next; inet_pton(AF_INET6, "::172.16.96.146", &cur->addr); cur->priority = 10; cur->next = NULL; } else { printf("error: %s\n", domain); } return 0; } */ void freerecips(struct recip *recips, const unsigned int num) { unsigned int i; for (i = 0; i < num; i++) { freeips(recips[i].mx); free(recips[i].address); } free(recips); } int rsend(const struct recip *tgt, const int num) { const struct recip *cur; const char **args; char destaddr[INET6_ADDRSTRLEN + 2]; int i; args = malloc(sizeof(*args) * (num + 4)); if (!args) { // FIXME: error handling exit(ENOMEM); } args[0] = "Qremote"; if (tgt->mx->next) { // FIXME: this has a race condition between the two MX lookups args[1] = tgt->domain; } else { size_t pos; destaddr[0] = '['; inet_ntop(AF_INET6, &tgt->mx->addr, destaddr + 1, sizeof(destaddr) - 1); pos = strlen(destaddr); destaddr[pos++] = ']'; destaddr[pos] = '\0'; args[1] = destaddr; } args[2] = "sender@domain.invalid"; // FIXME: sender address cur = tgt; for (i = 0; i < num; i++) { args[3 + i] = cur->address; cur = cur->next; } args[3 + num] = NULL; printf("%s %s %s\n", args[0], args[1], args[2]); i = 3; while (args[i]) printf("\t%s\n", args[i++]); printf("\n"); free(args); return 0; } int main(void) { struct recip *r; int n; //FIXME: use AUTOQMAIL if (chdir("/var/qmail")) return errno; n = loadrecips(&r, 180570); if (!n) return 1; return rschedule(r, n); }