/** * ns_mxcheck.C: Check MX records for registering email. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Copyright © 2007 Atheme Development Group * Rights to this code are as documented in doc/pod/license.pod. * * $Id: ns_mxcheck.C,v 1.4 2007/09/16 18:54:43 pippijn Exp $ */ #include #include #include #include #include "atheme.h" #include static char const rcsid[] = "$Id: ns_mxcheck.C,v 1.4 2007/09/16 18:54:43 pippijn Exp $"; REGISTER_MODULE ("nickserv/mxcheck", false, "Jamie L. Penman-Smithson "); static int count_mx (char const * const host) { u_char nsbuf[4096]; ns_msg amsg; int l; l = res_query (host, ns_c_any, ns_t_mx, nsbuf, sizeof (nsbuf)); if (l < 0) return 0; ns_initparse (nsbuf, l, &amsg); l = ns_msg_count (amsg, ns_s_an); return l; } static bool check_registration (sourceinfo_t *si, char const * const account, char const * const email) { char buf[1024]; int count; strlcpy (buf, email, sizeof buf); /* char const * const user = */strtok (buf, "@"); char const * const domain = strtok (NULL, "@"); count = count_mx (domain); if (count > 0) /* there are MX records for this domain */ snoop ("REGISTER: mxcheck: %d MX records for %s", count, domain); else { /* no MX records or error */ struct hostent *host; /* attempt to resolve host (fallback to A) */ if ((host = gethostbyname (domain)) == NULL) { snoop ("REGISTER: mxcheck: no A/MX records for %s - " "REGISTER failed", domain); command_fail (si, fault::noprivs, "Sorry, \2%s\2 does not exist, " "I can't send mail there. Please check and try again.", domain); return false; } } return true; } bool _modinit (module *m) { user_t::callback.can_register.attach (check_registration); return true; } void _moddeinit (void) { user_t::callback.can_register.detach (check_registration); }