Update check_email to handle hosts without an A record (either AAAA only or MX only)
This commit is contained in:
parent
466af409b4
commit
df5f61ffd0
|
@ -5,14 +5,14 @@ This module contains functions for registering new members, registering
|
||||||
members for terms, searching for members, and other member-related
|
members for terms, searching for members, and other member-related
|
||||||
functions.
|
functions.
|
||||||
|
|
||||||
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
|
Future changes to the members database that need to be atomic
|
||||||
must also be moved into this module.
|
must also be moved into this module.
|
||||||
"""
|
"""
|
||||||
import os, re, subprocess, ldap, socket
|
import os, re, subprocess, ldap, socket
|
||||||
from ceo import conf, ldapi, terms, remote, ceo_pb2
|
from ceo import conf, ldapi, terms, remote, ceo_pb2
|
||||||
from ceo.excep import InvalidArgument
|
from ceo.excep import InvalidArgument
|
||||||
|
import dns.resolver
|
||||||
|
|
||||||
### Configuration ###
|
### Configuration ###
|
||||||
|
|
||||||
|
@ -179,11 +179,16 @@ def check_email(email):
|
||||||
if c in ('"', "'", ',', '|', '$', '/', '#', ':'):
|
if c in ('"', "'", ',', '|', '$', '/', '#', ':'):
|
||||||
return 'Invalid character in address: %s' % c
|
return 'Invalid character in address: %s' % c
|
||||||
|
|
||||||
|
# Start by searching for host record
|
||||||
host = match.group(1)
|
host = match.group(1)
|
||||||
try:
|
try:
|
||||||
ip = socket.gethostbyname(host)
|
ip = socket.getaddrinfo(host, None)
|
||||||
except:
|
except:
|
||||||
return 'Invalid host: %s' % host
|
# Check for MX record
|
||||||
|
try:
|
||||||
|
dns.resolver.query(host, 'MX')
|
||||||
|
except:
|
||||||
|
return 'Invalid host: %s' % host
|
||||||
|
|
||||||
|
|
||||||
def current_email(username):
|
def current_email(username):
|
||||||
|
@ -433,7 +438,7 @@ def set_shell(userid, shell):
|
||||||
def create_club(username, name):
|
def create_club(username, name):
|
||||||
"""
|
"""
|
||||||
Creates a UNIX user account with options tailored to CSC-hosted clubs.
|
Creates a UNIX user account with options tailored to CSC-hosted clubs.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
username - the desired UNIX username
|
username - the desired UNIX username
|
||||||
name - the club name
|
name - the club name
|
||||||
|
@ -449,7 +454,7 @@ def create_club(username, name):
|
||||||
# check username format
|
# check username format
|
||||||
if not username or not re.match(cfg['username_regex'], username):
|
if not username or not re.match(cfg['username_regex'], username):
|
||||||
raise InvalidArgument("username", username, "expected format %s" % repr(cfg['username_regex']))
|
raise InvalidArgument("username", username, "expected format %s" % repr(cfg['username_regex']))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request = ceo_pb2.AddUser()
|
request = ceo_pb2.AddUser()
|
||||||
request.type = ceo_pb2.AddUser.CLUB
|
request.type = ceo_pb2.AddUser.CLUB
|
||||||
|
|
Loading…
Reference in New Issue