Check domain at user mail creation/changing

This commit is contained in:
Kload 2013-06-08 10:31:52 +02:00
parent f278b3b6a0
commit a8572559ac
2 changed files with 9 additions and 4 deletions

View file

@ -104,11 +104,9 @@ def domain_add(domains, web=False):
domain +'. IN SOA ns.'+ domain +'. root.'+ domain +'. '+ timestamp +' 10800 3600 604800 38400',
domain +'. IN NS ns.'+ domain +'.',
domain +'. IN A '+ ip,
domain +'. IN MX 5 mail.'+ domain +'.',
domain +'. IN MX 5 '+ domain +'.',
domain +'. IN TXT "v=spf1 a mx a:'+ domain +' ?all"',
'mail.'+ domain +'. IN A '+ ip,
'ns.'+ domain +'. IN A '+ ip,
'root.'+ domain +'. IN A '+ ip
]
with open('/var/lib/bind/' + domain + '.zone', 'w') as zone:
for line in zone_lines:

View file

@ -8,6 +8,7 @@ import random
import string
import getpass
from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args
from yunohost_domain import domain_list
def user_list(fields=None, filter=None, limit=None, offset=None):
"""
@ -92,7 +93,8 @@ def user_create(username, firstname, lastname, mail, password):
#if not os.system("getent passwd " + username):
# raise YunoHostError(17, _("Username not available"))
#TODO: check if mail belongs to a domain
if mail[mail.find('@')+1:] not in domain_list()['Domains']:
raise YunoHostError(22, _("Domain not found : ")+ mail[mail.find('@')+1:])
# Get random UID/GID
uid_check = gid_check = 0
@ -187,6 +189,7 @@ def user_update(username, firstname=None, lastname=None, mail=None, change_passw
with YunoHostLDAP() as yldap:
attrs_to_fetch = ['givenName', 'sn', 'mail', 'maildrop']
new_attr_dict = {}
domains = domain_list()['Domains']
# Populate user informations
result = yldap.search(base='ou=users,dc=yunohost,dc=org', filter='uid=' + username, attrs=attrs_to_fetch)
@ -214,6 +217,8 @@ def user_update(username, firstname=None, lastname=None, mail=None, change_passw
if mail:
yldap.validate_uniqueness({ 'mail': mail })
if mail[mail.find('@')+1:] not in domains:
raise YunoHostError(22, _("Domain not found : ")+ mail[mail.find('@')+1:])
del user['mail'][0]
new_attr_dict['mail'] = [mail] + user['mail']
@ -222,6 +227,8 @@ def user_update(username, firstname=None, lastname=None, mail=None, change_passw
add_mailalias = [ add_mailalias ]
for mail in add_mailalias:
yldap.validate_uniqueness({ 'mail': mail })
if mail[mail.find('@')+1:] not in domains:
raise YunoHostError(22, _("Domain not found : ")+ mail[mail.find('@')+1:])
user['mail'].append(mail)
new_attr_dict['mail'] = user['mail']