>From 9dde7f59a1733a88bc6bd711e0953bcf2eea5bbf Mon Sep 17 00:00:00 2001 From: Rowland Penny Date: Mon, 16 Nov 2015 15:44:06 +0000 Subject: [PATCH 1/4] samdb.py: get object dn from samaccountname Signed-off-by: Rowland Penny --- python/samba/samdb.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/python/samba/samdb.py b/python/samba/samdb.py index 5750291..155d0df 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -944,3 +944,19 @@ accountExpires: %u is removed, this routine will put a tombstone in the record. ''' return dsdb_dns.replace_by_dn(self, dn, new_records) + + def get_object_dn(self, search_filter): + """Gets an objects DN + + :param search_filter: LDAP filter to find the object (eg + samaccountname=name) + """ + res = self.search(base=self.domain_dn(), + scope=ldb.SCOPE_SUBTREE, + expression=search_filter, + attrs=["dn", "sAMAccountName"]) + if len(res) == 0: + raise Exception('Unable to find object "%s"' % + search_filter) + assert(len(res) == 1) + return res[0].dn -- 1.7.10.4