mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Use smbldap-tools to create user
This commit is contained in:
parent
1a39660f1e
commit
4311f3e7df
1 changed files with 10 additions and 39 deletions
|
@ -109,49 +109,20 @@ def user_create(username, firstname, lastname, mail, password):
|
||||||
'mail' : mail
|
'mail' : mail
|
||||||
})
|
})
|
||||||
|
|
||||||
# Check if unix user already exists (doesn't work)
|
|
||||||
#if not os.system("getent passwd " + username):
|
|
||||||
# raise YunoHostError(17, _("Username not available"))
|
|
||||||
|
|
||||||
if mail[mail.find('@')+1:] not in domain_list()['Domains']:
|
if mail[mail.find('@')+1:] not in domain_list()['Domains']:
|
||||||
raise YunoHostError(22, _("Domain not found : ")+ mail[mail.find('@')+1:])
|
raise YunoHostError(22, _("Domain not found : ")+ mail[mail.find('@')+1:])
|
||||||
|
|
||||||
# Get random UID/GID
|
user_added = os.system('/usr/sbin/smbldap-useradd -a -A 1 -m -M "'+ mail +'" -N "'+ firstname +'" -S "'+ lastname +'" -Z "objectclass=mailAccount,maildrop='+ username +'" -p '+ username')
|
||||||
uid_check = gid_check = 0
|
|
||||||
while uid_check == 0 and gid_check == 0:
|
|
||||||
uid = str(random.randint(200, 99999))
|
|
||||||
uid_check = os.system("getent passwd " + uid)
|
|
||||||
gid_check = os.system("getent group " + uid)
|
|
||||||
|
|
||||||
# Adapt values for LDAP
|
if user_added == 0:
|
||||||
fullname = firstname + ' ' + lastname
|
char_set = string.ascii_uppercase + string.digits
|
||||||
rdn = 'uid=' + username + ',ou=users'
|
salt = ''.join(random.sample(char_set,8))
|
||||||
char_set = string.ascii_uppercase + string.digits
|
salt = '$1$' + salt + '$'
|
||||||
salt = ''.join(random.sample(char_set,8))
|
attr_dict = {'userPassword': '{CRYPT}' + crypt.crypt(str(change_password), salt)}
|
||||||
salt = '$1$' + salt + '$'
|
if yldap.update('uid=' + username + ',ou=users', attr_dict):
|
||||||
pwd = '{CRYPT}' + crypt.crypt(str(password), salt)
|
#TODO: Send a welcome mail to user
|
||||||
attr_dict = {
|
win_msg(_("User successfully created"))
|
||||||
'objectClass' : ['mailAccount', 'inetOrgPerson', 'posixAccount'],
|
return { _("Fullname") : fullname, _("Username") : username, _("Mail") : mail }
|
||||||
'givenName' : firstname,
|
|
||||||
'sn' : lastname,
|
|
||||||
'displayName' : fullname,
|
|
||||||
'cn' : fullname,
|
|
||||||
'uid' : username,
|
|
||||||
'mail' : mail,
|
|
||||||
'maildrop' : username,
|
|
||||||
'userPassword' : pwd,
|
|
||||||
'gidNumber' : uid,
|
|
||||||
'uidNumber' : uid,
|
|
||||||
'homeDirectory' : '/home/' + username,
|
|
||||||
'loginShell' : '/bin/false'
|
|
||||||
}
|
|
||||||
|
|
||||||
if yldap.add(rdn, attr_dict):
|
|
||||||
# Create user /home directory by switching user
|
|
||||||
os.system("su - " + username + " -c ''")
|
|
||||||
#TODO: Send a welcome mail to user
|
|
||||||
win_msg(_("User successfully created"))
|
|
||||||
return { _("Fullname") : fullname, _("Username") : username, _("Mail") : mail }
|
|
||||||
else:
|
else:
|
||||||
raise YunoHostError(169, _("An error occured during user creation"))
|
raise YunoHostError(169, _("An error occured during user creation"))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue