File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments