summaryrefslogtreecommitdiffstats
path: root/account.py
diff options
context:
space:
mode:
Diffstat (limited to 'account.py')
-rw-r--r--account.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/account.py b/account.py
index e78dc93..5575edd 100644
--- a/account.py
+++ b/account.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import ldap
from utils import Service
+from uuid import uuid4
LDAP_HOST = 'ldap://localhost:5678'
@@ -104,12 +105,12 @@ class AccountService:
return users[0]
def find_by_uid(self, uid, wildcard=False):
- return self.find({'uid':uid}, wildcard)
+ return self.find({'uid': uid}, wildcard)
def find_by_mail(self, mail, wildcard=False):
- return self.find({'mail':mail}, wildcard)
+ return self.find({'mail': mail}, wildcard)
- def find(self, filters = {}, wildcard=False):
+ def find(self, filters={}, wildcard=False):
"""
Find accounts by a given filter with key:value semantic)
"""
@@ -129,7 +130,7 @@ class AccountService:
if len(filter_as_list) > 1:
filterstr = '(&%s)' % filterstr
- data = self.connection.search_s(dn,ldap.SCOPE_SUBTREE,filterstr)
+ data = self.connection.search_s(dn, ldap.SCOPE_SUBTREE, filterstr)
accounts = []
for a in data:
@@ -238,6 +239,15 @@ class AccountService:
for service, passwords in account.new_password_services.items():
dn = 'uid=%s,cn=%s,ou=services,%s' % (account.uid, service, self.base_dn)
+ if service not in account.services:
+ # initialize with random password because the schema requires that
+ attr = [('objectClass', ['top', 'servicePassword']),
+ ('uid', account.uid), ('userPassword', uuid4().hex)]
+
+ sub = AccountService(self.ldap_host, self.base_dn, self.admin_user,
+ self.admin_pass, self.services)
+ self.connection.add_s(dn, attr)
+
old, new = passwords
if self.admin:
self.connection.passwd_s(dn, None, new)