diff --git a/yunohost_domain.py b/yunohost_domain.py index 3a0bdeb4..06135658 100644 --- a/yunohost_domain.py +++ b/yunohost_domain.py @@ -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: diff --git a/yunohost_user.py b/yunohost_user.py index 50825d18..a1a0558d 100644 --- a/yunohost_user.py +++ b/yunohost_user.py @@ -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']