Update check_email to handle hosts without an A record (either AAAA only or MX only)

This commit is contained in:
Zachary Seguin 2017-05-01 17:36:05 -04:00
parent 466af409b4
commit df5f61ffd0
1 changed files with 11 additions and 6 deletions

View File

@ -12,7 +12,7 @@ must also be moved into this module.
import os, re, subprocess, ldap, socket
from ceo import conf, ldapi, terms, remote, ceo_pb2
from ceo.excep import InvalidArgument
import dns.resolver
### Configuration ###
@ -179,9 +179,14 @@ def check_email(email):
if c in ('"', "'", ',', '|', '$', '/', '#', ':'):
return 'Invalid character in address: %s' % c
# Start by searching for host record
host = match.group(1)
try:
ip = socket.gethostbyname(host)
ip = socket.getaddrinfo(host, None)
except:
# Check for MX record
try:
dns.resolver.query(host, 'MX')
except:
return 'Invalid host: %s' % host