diff options
Diffstat (limited to 'account.py')
-rw-r--r-- | account.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/account.py b/account.py new file mode 100644 index 0000000..1c764a5 --- /dev/null +++ b/account.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +import ldap +import sys + +LDAP_HOST = 'localhost' +LDAP_BASE_DN = 'dc=nodomain' +USER = 'cn=admin' +PASS = 'blubb' + + +class Account(object): + def __init__(self, ldap_host, base_dn, user, password): + self.con = ldap.open(ldap_host) + self.con.simple_bind(user, password) + self.base_dn = base_dn + + + def list(self, *args, **kwargs): + entries = self.con.search_s(self.base_dn, ldap.SCOPE_SUBTREE, *args, **kwargs) + + for entry in entries: + print(entry) + + + def register(self, name, attr): + dn = 'cn=%s,%s' % (name, self.base_dn) + name = self.con.add_s(dn, attr) + print('Added ' % name) + + + def modify(self, name, attr): + dn = 'cn=%s,%s' % (name, self.base_dn) + name = self.con.modify_s(dn, attr) + print('Modify ' % name) + + + def delete(self, name): + dn = 'cn=%s,%s' % (name, self.base_dn) + name = self.con.delete_s(dn, attr) + print('Delete ' % name) + + +a = Account(LDAP_HOST, LDAP_BASE_DN, USER, PASS) + +class _Missing(object): + pass +_missing = _Missing() |