Skip to content

Commit 345cbbf

Browse files
author
dr
committed
added function get_dn()
1 parent 0a4ddce commit 345cbbf

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

msldap/client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,25 @@ async def get_all_schemaentry(self, attrs:List[str] = MSADSCHEMAENTRY_ATTRS):
444444

445445
logger.debug('Finished polling for entries!')
446446

447+
async def get_dn(self, sAMAccountName: str):
448+
"""
449+
Fetches the distinguished name for a samAccountName.
450+
451+
:param sAMAccountName: The username of the machine (eg. COMP123$).
452+
:type sAMAccountName: str
453+
:return: DN if found, else None; and an error if any.
454+
:rtype: Tuple[Optional[str], Optional[Exception]]
455+
456+
"""
457+
ldap_filter = r'(sAMAccountName=%s)' % str(sAMAccountName)
458+
async for entry, err in self.pagedsearch(ldap_filter, ['distinguishedName']):
459+
if err is not None:
460+
return None, err
461+
462+
return entry['attributes']['distinguishedName'], None
463+
464+
return None, Exception('Search returned no results!')
465+
447466
async def get_laps(self, sAMAccountName:str):
448467
"""
449468
Fetches the LAPS password for a machine. This functionality is only available to specific high-privileged users.

0 commit comments

Comments
 (0)