diff options
author | Marian Sigler <m@qjym.de> | 2012-09-26 19:23:07 +0200 |
---|---|---|
committer | Marian Sigler <m@qjym.de> | 2012-09-26 19:23:07 +0200 |
commit | a4191e10683444cfff8119c0ce46be689e65c3ef (patch) | |
tree | af0450a7d1a00004bbf9ccbfc9a44d9106c9ab73 | |
parent | 8f46b1f1b131a57d46e8d1536d408b86105afac5 (diff) | |
download | web-a4191e10683444cfff8119c0ce46be689e65c3ef.tar.gz web-a4191e10683444cfff8119c0ce46be689e65c3ef.tar.bz2 web-a4191e10683444cfff8119c0ce46be689e65c3ef.zip |
add get_by_uid
-rw-r--r-- | account.py | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -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) |