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

@ -5,14 +5,14 @@ This module contains functions for registering new members, registering
members for terms, searching for members, and other member-related
Transactions are used in each method that modifies the database.
Transactions are used in each method that modifies the database.
Future changes to the members database that need to be atomic
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,11 +179,16 @@ def check_email(email):
if c in ('"', "'", ',', '|', '$', '/', '#', ':'):
return 'Invalid character in address: %s' % c
# Start by searching for host record
host = match.group(1)
ip = socket.gethostbyname(host)
ip = socket.getaddrinfo(host, None)
return 'Invalid host: %s' % host
# Check for MX record
dns.resolver.query(host, 'MX')
return 'Invalid host: %s' % host
def current_email(username):
@ -433,7 +438,7 @@ def set_shell(userid, shell):
def create_club(username, name):
Creates a UNIX user account with options tailored to CSC-hosted clubs.
username - the desired UNIX username
name - the club name
@ -449,7 +454,7 @@ def create_club(username, name):
# check username format
if not username or not re.match(cfg['username_regex'], username):
raise InvalidArgument("username", username, "expected format %s" % repr(cfg['username_regex']))
request = ceo_pb2.AddUser()
request.type = ceo_pb2.AddUser.CLUB