
    5i                    <   d dl Z d dlZd dlZd dlZd dlmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ d dl
mZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlT d dl m!Z!m"Z"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z)m*Z* d dl+m,Z,m-Z-  G d d          Z.dS )    N)DictListTuple)UniCredential)ACCESS_ALLOWED_OBJECT_ACEADS_ACCESS_MASK)GUID)SECURITY_DESCRIPTOR)r   )SID)logger)MSLDAPClientStatus)LDAPSearchException)MSLDAPTarget)
KNOWN_SIDS)MSLDAPClientConnection)*)ALL_ATTRIBUTESBASELEVEL)Control)escape_filter_chars)SDFlagsRequestSDFlagsRequestValue)
DNS_RECORDDnsPropertyFactoryc                      e Zd ZdZddedefdZd Zd Zd	 Z	d
 Z
d Zd Zd Zddedee         deeeeef                  dedef
dZddedefdZefdee         fdZefdee         fdZefdee         fdZefdee         fdZdee         fdZd Zd Zd efd!Ze fdee         fd"Z!d#efd$Z"d#efd%Z#d#efd&Z$d' Z%d( Z&dd)e'fd*Z(dd)e'fd+Z)e*j+        e*j,        z  e*j-        z  fd ed,e*fd-Z.e*j+        e*j,        z  e*j-        z  fd ed,e*fd.Z/e*j+        e*j,        z  e*j-        z  fd/ed0e0d,e*fd1Z1e2fdee         fd2Z3e4fdee         fd3Z5d4efd5Z6d6efd7Z7d8efd9Z8dd ed:e'fd;Z9d<efd=Z:d efd>Z;d?efd@Z<d efdAZ=dB Z>dC Z?e@fdee         fdDZAd6edEefdFZBd6edGefdHZCd6efdIZDd6efdJZEd6efdKZFd6edLefdMZGd6edLefdNZHd6edOefdPZId6efdQZJdd6edRedSefdTZKd6ed4efdUZLd6ed4efdVZMdd efdWZNdd edXeOeePf         deOeePf         fdYZQd edeOeePf         fdZZRd efd[ZSd6ed4efd\ZTdd6ed]efd^ZUdd_ed`efdaZVdb ZWdc ZXdd ZYde ZZddfefdgZ[dh Z\e]fde^fdiZ_ddjedEefdkZ`d ed?efdlZadmebpe0fdnZcdd8edpedpe'fdqZedr Zfds Zgdt Zhdu Zidv Zjdw Zkdx Zldy Zmdz Znd{ Zodee         fd|Zpd} Zqd~ ZrddZsd Ztd Zud edefdZvdS )MSLDAPClienta  
	High level API for LDAP operations.

	target, creds, ldap_query_page_size

	:param target: The target object describing the connection info
	:type target: :class:`MSLDAPTarget`
	:param creds: The credential object describing the authentication to be used
	:type creds: :class:`MSLDAPCredential`
	:param ldap_query_page_size: 
	:type ldap_query_page_size: int
	:return: A dictionary representing the LDAP tree
	:rtype: dict

	NFtargetcredsc                 b   || _         || _        || _        d| _        d| _        d| _        d| _        | j        | j        j        | _        d| _        | j        | j        j        | _        d | _        d | _	        || _
        d | _        d| _        d | _        i | _        i | _        d | _        d | _        d S )Ni  Fr   
   )r   r   	keepaliveldap_query_page_size_disable_channel_binding_disable_signing_null_channel_bindingldap_query_ratelimit_tree	_ldapinfo_con_MSLDAPClient__keepalive_taskkeepalive_perioddisconnected_evt
_sid_cache_domainsid_cache
domainname	domainsid)selfr   r   
connectionr"   s        C/home/kali/Ninja/venv/lib/python3.11/site-packages/msldap/client.py__init__zMSLDAPClient.__init__3   s    $*$+$."$"'$$$$	[#{?4$	[#{?4$*$.$)$$$$/$$/$...    c                 
   K   | S N r2   s    r4   
__aenter__zMSLDAPClient.__aenter__N   s      	+r6   c                 f   K   t          j        |                                 d           d {V  d S )N   )timeout)asynciowait_for
disconnect)r2   exc_typeexc	tracebacks       r4   	__aexit__zMSLDAPClient.__aexit__Q   s>      **a888888888888r6   c                   K   	 | j                                         su| j        4d|z  }|                     |t                    2 3 d {V \  }}|d |fc S 6 t          j        | j                   d {V  | j                                         sd S d S # t
          j        $ r Y d S t          $ r7}t          d|z             |                                  d {V  Y d }~d S d }~ww xY w)N(distinguishedName=%s)zKeepalive exception: %s)r-   is_setr*   pagedsearchMSADInfo_ATTRSr?   sleepr,   CancelledError	ExceptionprintrA   )r2   temptreeldap_filterentryerres         r4   __keepalivezMSLDAPClient.__keepaliveT   si     "))++ /y,x7[!--k>JJ       zuc	Ci 
 K --
.
........ "))++ / / / / / 
	 
 
 
	66	   	"Q	&'''			s0   A B A
B :B C&&	C&/,C!!C&c                    K   	 | j         | j                                          | j        | j                                         d {V  | j                                         d S # t          $ r}d|fcY d }~S d }~ww xY wNF)r+   cancelr*   rA   r-   setrM   )r2   rS   s     r4   rA   zMSLDAPClient.disconnectf   s      	
'  """
i
)


 
        	   
(??????s   AA% %
A=/A82A=8A=c                   K   	 t          j                    | _        | j        t	          | j        | j                  | _        | j        | j        _        | j        | j        _        | j	        | j        _	        | j        
                                 d {V \  }}||| j        j        du r)| j                                         d {V \  }}|d|fS nt          j        d           | j                                         d {V \  }}|||t!          d           n|| _        |d         | _        |                                  d {V \  | _        }| j        j        du rD||| j        j        | j        | j        j        <   | j        j        | _        | j        j        | _        | j        du r2t          j        |                     |d                             | _        dS # t<          $ r}d|fcY d }~S d }~ww xY w)NFzSkipping bind for no auth!z:RootDSE is empty! You will need to find the tree manually!defaultNamingContextTTN)r?   Eventr-   r*   r   r   r   r$   r%   r&   connectis_anonbindr   debugget_serverinforN   _serverinfor(   get_ad_infor)   namer/   	objectSidr0   r1   r"   create_task_MSLDAPClient__keepaliver+   rM   )r2   _rR   resrS   s        r4   r]   zMSLDAPClient.connectr   s+     #"=??4
i&t{DJ??DI)-)FDI&!%!6DI&*&@DI#9$$&&&&&&&&FAs
YyE!!inn&&&&&&&&XS#CZ 	 \.///I,,........83	o
I	k	
FGGGGD+,DJ $ 0 0 2 2222222DNCyE!!i7;~7JT4>34~*T_n.T^~$01A1A#F\B]1^1^__T
*	   
(??????s%   CG# DG# #
G;-G60G;6G;c                     | j         S r8   )rb   r:   s    r4   get_server_infozMSLDAPClient.get_server_info   s    		r6   c                    K   | j         	| j         d fS |                                  d {V \  | _        }|d |fS | j        j        | _         | j         |fS r8   )r0   rc   r)   rd   )r2   rR   s     r4   get_domain_namezMSLDAPClient.get_domain_name   sm      	_ 
/4
"..00000000$.#_
)N'$/	#	r6      query
attributescontrolstreesearch_scopec           	       K   t          j        d|dd                    |                     | j        j        t
          j        k    r+| j        j        t
          j        k    rt          d           dS || j	        }|t          d          g }|D ])}|                    |                                           *|}g }|O|D ]L}|                    t          |d                                         |d         |d	         d
                     M|}| j                            |||| j        || j        |          2 3 d{V \  }	}
|

d|
fW V   dS |	d         dk    r|	d         dk    r/|	dfW V  76 dS )a  
		Performs a paged search on the AD, using the filter and attributes as a normal query does.
			!The LDAP connection MUST be active before invoking this function!

		:param query: LDAP query filter
		:type query: str
		:param attributes: List of requested attributes
		:type attributes: List[str]
		:param controls: additional controls to be passed in the query
		:type controls: dict
		:param tree: Base tree to perform the search on
		:type tree: str
		:param search_scope: LDAP search scope
		:type search_scope: int

		:return: Async generator which yields (`dict`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`dict`, :class:`Exception`)]

		zPaged search, filter: z attributes: ,z%There was an error in the connection!NzBIND first!r   r=   rn   )controlTypecriticalitycontrolValue)rp   
size_limitrq   
rate_limitrs   
objectName rp   )r   r`   joinr*   statusr   RUNNINGERRORrN   r(   rM   appendencoder   rI   r#   r'   )r2   ro   rp   rq   rr   rs   txcontrolrQ   rR   s              r4   rI   zMSLDAPClient.pagedsearch   s     ( 	,,EEE388JCWCWCWXYYY	Y+333
i,222	
1222
F	\
*4	\	=	!	!!!  a88AHHJJ*!  wHHWAJ%%''AJQZ        ()//)' 0         JE3 9____VV\b  U<%8B%>%>
+#  s   ?E6root_dnlevelc           	        K   t          j        d|d|           i }| j                            |ddg| j        t
          d| j                  2 3 d{V \  }}|||dk    ri c S d|d	         vs |d	         d         |d	         d         g k    rC|                     |d	         d         |d
z
             d{V }|||d	         d         <   6 ||iS )a  
		Returns a dictionary representing a tree starting from 'dn' containing all subtrees.

		:param root_dn: The start DN of the tree
		:type root_dn: str
		:param level: Recursion level
		:type level: int

		:return: A dictionary representing the LDAP tree
		:rtype: dict
		z
Tree, dn: z level: z(distinguishedName=*)s   distinguishedNameNrp   ry   rs   rq   rz   r   distinguishedNamerp   r=   r   )r   r`   r*   rI   r#   r   r'   get_tree_plot)r2   r   r   rr   rQ   rR   subtrees          r4   r   zMSLDAPClient.get_tree_plot   sd      	,,777EE:;;;	$)//
%&)' 0   = = = = = = =JE3 YzzYYY %"555|9LM`9a9imrs  nA  BU  nV  Z\  n\  n\&&u\':;N'OY^`aYa&bbbbbbbbG5<D|	0	122'( D	s   Cattrsc                  K   t          j        d           d}|                     ||          2 3 d{V \  }}|
d|fW V   dS t                              || j                  dfW V  <6 t          j        d           dS )a  
		Fetches all user objects available in the LDAP tree and yields them as MSADUser object.
		
		:return: Async generator which yields (`MSADUser`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADUser`, :class:`Exception`)]
		
		Polling AD for all user objectsz(sAMAccountType=805306368)NFinished polling for entries!)r   r`   rI   MSADUser	from_ldapr)   r2   r   rP   rQ   rR   s        r4   get_all_userszMSLDAPClient.get_all_users  s       	,0111-+**;>> 9 9 9 9 9 9 9JE3	o
)OOOO
FF			E4>	2	2D	888888	 ?
 	,./////   A+c                  K   t          j        d           d}|                     ||          2 3 d{V \  }}|
d|fW V   dS t                              || j                  dfW V  <6 t          j        d           dS )a  
		Fetches all machine objects available in the LDAP tree and yields them as MSADMachine object.

		:param attrs: Lists of attributes to request (eg. `['sAMAccountName', 'dNSHostName']`) Default: all attrs.
		:type attrs: list
		:return: Async generator which yields (`MSADMachine`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADMachine`, :class:`Exception`)]
		
		r   (sAMAccountType=805306369)Nr   )r   r`   rI   MSADMachiner   r)   r   s        r4   get_all_machineszMSLDAPClient.get_all_machines  s       	,0111-+**;>> < < < < < < <JE3	o
)OOOO
FF			udn	5	5t	;;;;;;	 ?
 	,./////r   c                   K   d}|                      ||          2 3 d{V \  }}|
d|fW V   dS t                              |          dfW V  66 dS )a   
		Fetches all GPOs available in the LDAP tree and yields them as MSADGPO object.
		
		:return: Async generator which yields (`MSADGPO`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADGPO`, :class:`Exception`)]
		
		z%(objectCategory=groupPolicyContainer)N)rI   MSADGPOr   r   s        r4   get_all_gposzMSLDAPClient.get_all_gpos0  s       9+**;>> ( ( ( ( ( ( (JE3	o
)OOOO
FF			5	!	!4	''''''	 ?>>   Ac                   K   t          j        d           d}|                     ||          2 3 d{V \  }}|
d|fW V   dS t                              |          dfW V  66 t          j        d           dS )a  
		Fetches all container objects available in the LDAP tree and yields them as MSADContainer object.
		
		:return: Async generator which yields (`MSADUser`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADUser`, :class:`Exception`)]
		
		z$Polling AD for all container objectsz4(&(objectCategory=container)(objectClass=container))Nr   )r   r`   rI   MSADContainerr   r   s        r4   get_all_containerszMSLDAPClient.get_all_containers@  s       	,5666G+**;>> . . . . . . .JE3	o
)OOOO
FF		 	 	'	'	------	 ?
 	,./////s   A%c                x   K   d}|                      ||          2 3 d {V \  }}|
d |fW V   d S |d fW V  6 d S )NzR(&(objectClass=foreignSecurityPrincipal)(objectCategory=foreignSecurityPrincipal))rI   r   s        r4   !get_all_foreignsecurityprincipalsz.MSLDAPClient.get_all_foreignsecurityprincipalsQ  s      e+**;>>       JE3	o
)OOOO
FF		 ?>>s   9c                h   K   d}ddg}|                      ||          2 3 d{V \  }}||fW V  6 dS )  
		Fetches all LAPS passwords for all machines. This functionality is only available to specific high-privileged users.

		:return: Async generator which yields (`dict`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`dict`, :class:`Exception`)]
		r   cnms-mcs-AdmPwdNr   r2   rP   rp   rQ   rR   s        r4   get_all_lapszMSLDAPClient.get_all_lapsY  su       .+_%***;
CC       JE3	 DCCs   1c                  K   d}ddg}|                      ||          2 3 d{V \  }}||fW V  6 ddg}|                      ||          2 3 d{V \  }}||fW V  6 ddg}|                      ||          2 3 d{V \  }}||fW V  6 ddg}|                      ||          2 3 d{V \  }}||fW V  6 ddg}|                      ||          2 3 d{V \  }}||fW V  6 dS )	r   r   r   zmsLAPS-PasswordNzmsLAPS-EncryptedPasswordzmsLAPS-EncryptedPasswordHistoryzmsLAPS-EncryptedDSRMPasswordz#msLAPS-EncryptedDSRMPasswordHistoryr   r   s        r4   get_all_laps_windowsz!MSLDAPClient.get_all_laps_windowsf  s
      .+&'***;
CC       JE3	 D /0***;
CC       JE3	 D 67***;
CC       JE3	 D 34***;
CC       JE3	 D :;***;
CC       JE3	 DCCs   1A9B&B8C%dnc                 $  K   t          j        d|z             | j                            |dt	          |          z  d t
          D             | j        t          d          2 3 d{V \  }}||t          	                    |          dfc S 6 dS )z
		Fetches one Schema entriy identified by dn

		:return: (`MSADSchemaEntry`, None) tuple on success or (None, `Exception`) on error
		:rtype: (:class:`MSADSchemaEntry`, :class:`Exception`)
		zPolling Schema entry for %srG   c                 6    g | ]}|                                 S r9   r   .0r   s     r4   
<listcomp>z0MSLDAPClient.get_schemaentry.<locals>.<listcomp>  s     ;;;;;;r6   N)rp   ry   rs   rq   NN)
r   r`   r*   rI   r   MSADSCHEMAENTRY_ATTRSr#   r   MSADSchemaEntryr   )r2   r   rQ   rR   s       r4   get_schemaentryzMSLDAPClient.get_schemaentry  s       	,,b0111)//22666;;%:;;;) 0         JE3 Y$$U++T1111 *s   #Bc                  K   |                      | j        d         d           d{V }|D ]}||         D ]}| j                            |dt	          |          z  d |D             | j        t          d| j                  2 3 d{V \  }}|d|fW V     dS t          	                    |          dfW V   n6 dW V  t          j        d	           dS )
z
		Fetches all Schema entries under CN=Schema,CN=Configuration,...

		:return: Async generator which yields (`MSADSchemaEntry`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADSchemaEntry`, :class:`Exception`)]
		schemaNamingContextr=   r   NrG   c                 6    g | ]}|                                 S r9   r   r   s     r4   r   z4MSLDAPClient.get_all_schemaentry.<locals>.<listcomp>  s     ---!188::---r6   r   r   r   )r   rb   r*   rI   r   r#   r   r'   r   r   r   r`   )r2   r   ri   r   r   rQ   rR   s          r4   get_all_schemaentryz MSLDAPClient.get_all_schemaentry  sU        !12G!HRS TTTTTTTT#  aV  r I11!4R!8!88--u---+) 2         jeS 
3Yvvvv%%e,,d22222e  #& 	,./////s   B<sAMAccountNamec                 j   K   d|z  }ddg}|                      ||          2 3 d{V \  }}||fc S 6 dS )a1  
		Fetches the LAPS password for a machine. This functionality is only available to specific high-privileged users.
		
		:param sAMAccountName: The username of the machine (eg. `COMP123$`).
		:type sAMAccountName: str
		:return: Laps attributes as a `dict`
		:rtype: (:class:`dict`, :class:`Exception`)
		0(&(sAMAccountType=805306369)(sAMAccountName=%s))r   r   Nr   )r2   r   rP   rp   rQ   rR   s         r4   get_lapszMSLDAPClient.get_laps  su       DnT+_%***;
CC       JE3
* DCCs   2c                    K   t          j        d|z             d|z  }|                     |t                    2 3 d{V \  }}|d|fc S t                              || j                  dfc S 6 dS )a9  
		Fetches one user object from the AD, based on the sAMAccountName attribute (read: username) 
		
		:param sAMAccountName: The username of the user.
		:type sAMAccountName: str
		:return: A tuple with the user as `MSADUser` and an `Exception` is there was any
		:rtype: (:class:`MSADUser`, :class:`Exception`)
		Polling AD for user %sz((&(objectClass=user)(sAMAccountName=%s))Nr   r   r`   rI   MSADUser_ATTRSr   r   r)   r2   r   rP   rQ   rR   s        r4   get_userzMSLDAPClient.get_user  s       	,'7888;nL+**;GG       JE3	o9


UDN
3
3T
9999 H
 *   A0c                    K   t          j        d|z             d|z  }|                     |t                    2 3 d{V \  }}|d|fc S t                              || j                  dfc S 6 dS )aE  
		Fetches one machine object from the AD, based on the sAMAccountName attribute (read: username) 
		
		:param sAMAccountName: The username of the machine.
		:type sAMAccountName: str
		:return: A tuple with the user as `MSADMachine` and an `Exception` is there was any
		:rtype: (:class:`MSADMachine`, :class:`Exception`)
		r   r   Nr   )r   r`   rI   MSADMachine_ATTRSr   r   r)   r   s        r4   get_machinezMSLDAPClient.get_machine  s       	,'7888CnT+**;8IJJ       JE3	o9


t~
6
6
<<<< K
 *r   c                   K   t          j        d           d| j        z  }|                     |t                    2 3 d{V \  }}|d|fc S t
                              |          | _        | j        dfc S 6 t          j        d           dS )z
		Polls for basic AD information (needed for determine password usage characteristics!)
		
		:return: A tuple with the domain information as `MSADInfo` and an `Exception` is there was any
		:rtype: (:class:`MSADInfo`, :class:`Exception`)
		zPolling AD for basic inforG   NzPoll finished!)r   r`   r(   rI   rJ   MSADInfor   r)   r2   rP   rQ   rR   s       r4   rc   zMSLDAPClient.get_ad_info  s       	,*+++)DJ6+**;GG       JE3	o9&&u--4>
.$
	 H 	,     s   A8c                   K   t          j        d           d}g d}|                     ||          2 3 d{V \  }}||fW V  6 dS )a  
		Fetches all service user objects from the AD, and returns MSADUser object.
		Service user refers to an user with SPN (servicePrincipalName) attribute set

		:param include_machine: Specifies wether machine accounts should be included in the query
		:type include_machine: bool
		:return: Async generator which yields tuples with a string in SPN format and an Exception if there was any
		:rtype: Iterator[(:class:`str`, :class:`Exception`)]
		
		zPolling AD for all SPN entriesz(&(sAMAccountType=805306369)))re   r   servicePrincipalNameN)r   r`   rI   r   s        r4   get_all_spn_entriesz MSLDAPClient.get_all_spn_entries  s       	,/0000+EEE***;
CC       JE3	 DCCs   Ainclude_machinec                &  K   t          j        d|z             |dk    rd}nd}|                     |t                    2 3 d{V \  }}|
d|fW V   dS t                              || j                  dfW V  <6 t          j        d           dS )a  
		Fetches all service user objects from the AD, and returns MSADUser object.
		Service user refers to an user with SPN (servicePrincipalName) attribute set

		:param include_machine: Specifies wether machine accounts should be included in the query
		:type include_machine: bool
		
		:return: Async generator which yields (`MSADUser`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADUser`, :class:`Exception`)]

		>Polling AD for all user objects, machine accounts included: %sTz(servicePrincipalName=*)z1(&(servicePrincipalName=*)(!(sAMAccountName=*$)))Nr   r   r2   r   rP   rQ   rR   s        r4   get_all_service_usersz"MSLDAPClient.get_all_service_users  s       	,OQ``aaa,;;E;**;GG 9 9 9 9 9 9 9JE3	o
)OOOO
FF			E4>	2	2D	888888	 H
 	,./////    A<c                &  K   t          j        d|z             |dk    rd}nd}|                     |t                    2 3 d{V \  }}|
d|fW V   dS t                              || j                  dfW V  <6 t          j        d           dS )a  
		Fetches all user objects with useraccountcontrol DONT_REQ_PREAUTH flag set from the AD, and returns MSADUser object.
		
		:param include_machine: Specifies wether machine accounts should be included in the query
		:type include_machine: bool
		:return: Async generator which yields (`MSADUser`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADUser`, :class:`Exception`)]

		r   Tz4(userAccountControl:1.2.840.113556.1.4.803:=4194304)zM(&(userAccountControl:1.2.840.113556.1.4.803:=4194304)(!(sAMAccountName=*$)))Nr   r   r   s        r4   get_all_knoreq_usersz!MSLDAPClient.get_all_knoreq_users1  s       	,OQ``aaaH;;a;**;GG 9 9 9 9 9 9 9JE3	o
)OOOO
FF			E4>	2	2D	888888	 H
 	,./////r   flagsc                6  K   t          d|i          }dt          |          z  }t          j        }dd|                                fg}|                     |||          2 3 d{V \  }}|
d|fW V   dS t                              |          dfW V  66 dS )a  
		Returns the full or partial Security Descriptor of the object specified by it's DN.
		The flags indicate which part of the security Descriptor to be returned.
		By default the full SD info is returned.

		:param object_dn: The object's DN
		:type object_dn: str
		:param flags: Flags indicate the data type to be returned.
		:type flags: :class:`SDFlagsRequest`
		:return: 
		:rtype: :class:`MSADSecurityInfo`

		FlagsrG   1.2.840.113556.1.4.801Trq   N)r   r   MSADSecurityInfoATTRSdumprI   r   	r2   r   r   	req_flagsrP   rp   rq   rQ   rR   s	            r4   get_objectacl_by_dn_pz"MSLDAPClient.get_objectacl_by_dn_pH  s       "7U"344)),?,C,CC+%*'y~~/?/?@A(**;
x*XX 1 1 1 1 1 1 1JE3	o
)OOOO
FF		#	#E	*	*D	000000	 YXXs   "Bc                   K   t          d|i          }dt          |          z  }dg}dd|                                fg}|                     |||          2 3 d{V \  }}|d|fc S |d                             d          dfc S 6 d	S )
a  
		Returns the full or partial Security Descriptor of the object specified by it's DN.
		The flags indicate which part of the security Descriptor to be returned.
		By default the full SD info is returned.

		:param object_dn: The object's DN
		:type object_dn: str
		:param flags: Flags indicate the data type to be returned.
		:type flags: :class:`SDFlagsRequest`
		:return: nTSecurityDescriptor attribute of the object as `bytes` and an `Exception` is there was any
		:rtype: (:class:`bytes`, :class:`Exception`)

		r   rG   nTSecurityDescriptorr   Tr   Nrp   r   )r   r   r   rI   getr   s	            r4   get_objectacl_by_dnz MSLDAPClient.get_objectacl_by_dnc  s       "7U"344)),?,C,CC+&'*'y~~/?/?@A(**;
x*XX @ @ @ @ @ @ @JE3	o9


!
!"8
9
94
???? Y 
s   B
	object_dndatac                    K   t          d|i          }t          d|                                dd          g}dd|fgi}| j                            |||           d{V S )	a  
		Updates the security descriptor of the LDAP object
		
		:param object_dn: The object's DN
		:type object_dn: str
		:param data: The actual data as bytearray to be updated in the Security Descriptor of the specified object 
		:type data: bytes
		:param flags: Flags indicate the data type to be updated.
		:type flags: :class:`SDFlagsRequest`
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: tuple

		r      1.2.840.113556.1.4.801Trv   rx   rw   r   replacer   N)r   r   r   r*   modify)r2   r   r   r   r   rq   changess          r4   set_objectacl_by_dnz MSLDAPClient.set_objectacl_by_dn~  s       "7U"344)/nn&&   ( Y-.' y	7xHH	H	H	H	H	H	HHr6   c                   K   d}|                      ||          2 3 d{V \  }}|
d|fW V   dS t                              |          dfW V  66 dS )z
		Yields all Groups present in the LDAP tree.  
		
		:return: Async generator which yields (`MSADGroup`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADGroup`, :class:`Exception`)]
		z(objectClass=group)N)rI   	MSADGroupr   r   s        r4   get_all_groupszMSLDAPClient.get_all_groups  s       '+**;>> * * * * * * *JE3	o
)OOOO
FF			U	#	#T	))))))	 ?>>r   c                   K   d}|                      ||          2 3 d{V \  }}|
d|fW V   dS t                              |          dfW V  66 dS )z
		Yields all OUs present in the LDAP tree.  

		:return: Async generator which yields (`MSADOU`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADOU`, :class:`Exception`)]
		z (objectClass=organizationalUnit)N)rI   MSADOUr   r   s        r4   get_all_ouszMSLDAPClient.get_all_ous  s       4+**;>> ' ' ' ' ' ' 'JE3	o
)OOOO
FF			%	 	 $	&&&&&&	 ?>>r   group_dnc                    K   dt          |          z  }|                     |t                    2 3 d{V \  }}|d|fc S t                              |          dfc S 6 dt          d          fS )z
		Returns an `MSADGroup` object for the group specified by group_dn

		:param group_dn: The user's DN
		:type group_dn: str
		:return: tuple of `MSADGroup` and an `Exception` is there was any
		:rtype: (:class:`MSADGroup`, :class:`Exception`)
		z,(&(objectClass=group)(distinguishedName=%s))NSearch returned no results!)r   rI   MSADGroup_ATTRSr   r   rM   )r2   r   rP   rQ   rR   s        r4   get_group_by_dnzMSLDAPClient.get_group_by_dn  s       @BUV^B_B__+**;HH + + + + + + +JE3	o9


e
$
$d
**** I
 
y677	77   A user_dnc                    K   d|z  }|                      |t                    2 3 d{V \  }}|d|fc S t                              |          dfc S 6 dt	          d          fS )z
		Fetches the DN for an object specified by `user_dn`

		:param user_dn: The user's DN
		:type user_dn: str
		:return: The user object
		:rtype: (:class:`MSADUser`, :class:`Exception`)
		z+(&(objectClass=user)(distinguishedName=%s))Nr   )rI   r   r   r   rM   )r2   r   rP   rQ   rR   s        r4   get_user_by_dnzMSLDAPClient.get_user_by_dn  s       ?H+**;GG * * * * * * *JE3	o9


U
#
#T
)))) H
 
y677	77s   Asidc                    K   dt          |          z  }|                     |t                    2 3 d{V \  }}|d|fc S t                              |          dfc S 6 dt          d          fS )zd
		Fetches the DN for an object specified by `sid`

		:param sid: The user's SID
		:type sid: str
		(objectSid=%s)Nr   )strrI   r   r   r   rM   )r2   r   rP   rQ   rR   s        r4   get_user_by_sidzMSLDAPClient.get_user_by_sid  s       "CHH,+**;GG * * * * * * *JE3	o9


U
#
#T
)))) H
 
y677	77r   	recursivec                `  K   |                      |           d{V \  }}|	d|fW V  dS |j        ry|j        D ]s}|                     |          2 3 d{V \  }}t          |t                    r2|r0|                     |j        d          2 3 d{V \  }}||fW V  6 Q||fW V  Y6 rdS dS )a~  
		Fetches the DN for an object specified by `objectsid`

		:param dn: The object's DN
		:type dn: str
		:param recursive: Indicates wether the lookup should recursively affect all groups
		:type recursive: bool
		:return: Async generator which yields (`MSADUser`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADUser`, :class:`Exception`)]
		NT)r  )r   memberget_object_by_dn
isinstancer   get_group_membersr   )r2   r   r  grouprR   r  resultusers           r4   r	  zMSLDAPClient.get_group_members  sI      ))"--------*%_	s????	6
\   v!226::       kfc69%% ) !33F4LZ^3__       	c3Y `_ CK ;:  s   B*B 	objectsidc                    K   dt          |          z  }|                     |dg          2 3 d{V \  }}|d|fc S |d         d         dfc S 6 dt          d          fS )z
		Fetches the DN for an object specified by `objectsid`

		:param objectsid: The object's SID
		:type objectsid: str
		:return: The distinguishedName
		:rtype: (:class:`str`, :class:`Exception`)

		r  r   Nrp   r   )r  rI   rM   )r2   r  rP   rQ   rR   s        r4   get_dn_for_objectsidz!MSLDAPClient.get_dn_for_objectsid  s       "C	NN2+**;9L8MNN 9 9 9 9 9 9 9JE3	o9

1
2D
8888	 O 
y677	77   Ac                    K   dt          |          z  }|                     |dg          2 3 d{V \  }}|d|fc S |d         d         dfc S 6 dt          d          fS )z
		Fetches the objectsid for an object specified by `dn`

		:param dn: The object's distinguishedName
		:type dn: str
		:return: The SID of the pobject
		:rtype: (:class:`str`, :class:`Exception`)

		rG   re   Nrp   r   r   rI   rM   )r2   r   rP   rQ   rR   s        r4   get_objectsid_for_dnz!MSLDAPClient.get_objectsid_for_dn  s       *,?,C,CC+**;FF 1 1 1 1 1 1 1JE3	o9

k
*D
0000	 G 
y677	77r  samaccountnamec                 T  K   dt          |          z  }d }|                     |dg          2 3 d {V \  }}|d |fc S |d         d         }!6 |d t          d|z            fS g }|                     |          2 3 d {V \  }}|d |fc S |                    |           (6 |d fS )N(sAMAccountName=%s)r   rp   zUser not found! %s)r   rI   rM   get_tokengroupsr   )r2   r  rP   r   rQ   rR   
tokengroupsidss           r4   get_tokengroups_userz!MSLDAPClient.get_tokengroups_user-  s(     &)<^)L)LL+'**;9L8MNN 6 6 6 6 6 6 6JE3	o9< !4577	 O _
	.?@@
@@*--g66       ID#	o9T 7
 
T	s   A=B%c                  K   dt          |          z  }dg}| j                            |||| j        t          | j                  2 3 d{V \  }}|
d|fW V   dS d|d         v r|d         d         D ]	}|dfW V  
96 dS )z
		Yields SIDs of groups that the given DN is a member of.

		:return: Async generator which yields (`str`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`str`, :class:`Exception`)]

		rG      tokenGroupsrp   ry   rs   rz   NtokenGroupsrp   )r   r*   rI   r#   r   r'   )r2   r   rP   rp   rQ   rR   sid_datas          r4   r  zMSLDAPClient.get_tokengroupsA  s       *,?,C,CC+*)//)' 0         JE3 9____VV l+++<(7  dN  s   B c           
       K   d}|                      |g d          2 3 d{V \  }}|
d|fW V   dS d|v r| j                             |d         dt          |d                   z  dg| j        t          | j                  2 3 d{V \  }}|	d|fW V   ngd	|d
         v r[|d
         d	         D ]L}|d
         d         |d         |d
         d         |d
         d         |d
         d         d         |ddfW V  M{6 6 dS )a  
		Yields all effective group membership information for all objects of the following type:
		Users, Groups, Computers

		:return: Async generator which yields (`dict`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`dict`, :class:`Exception`)]

		zJ(|(sAMAccountType=805306369)(objectClass=group)(sAMAccountType=805306368)))r   r   re   objectClass
objectGUIDrp   Nr{   rG   r  r  r  rp   r   r"  re   r!  )r   r   guidr   typetoken)rI   r*   r   r#   r   r'   )r2   rP   rQ   rR   entry2r'  s         r4   get_all_tokengroupsz MSLDAPClient.get_all_tokengroups]  s      ^+**EEE +                JE3 9____VVu"i33L"5eL6I"J"JJ"#,* 4         {vs /Ci
6,/
/
/L)-8 		 		E|$T*|$&|4%k2&}5b9   
 
 
 
 
  s   DC?c                  K   t           j        t           j        z  t           j        z  }t	          d|i          }d}|                     |dg          2 3 d{V \  }}|
d|fW V   dS dt          |d                   z  }t          j        }dd	|	                                fg}|                     |||
          2 3 d{V \  }}|d|fW V    dS t          
                    |          dfW V  76 6 dS )a>  
		Yields the security descriptor of all objects in the LDAP tree of the following types:  
		Users, Computers, GPOs, OUs, Groups

		:return: Async generator which yields (`MSADSecurityInfo`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADSecurityInfo`, :class:`Exception`)]

		r   z(|(objectClass=organizationalUnit)(objectCategory=groupPolicyContainer)(sAMAccountType=805306369)(objectClass=group)(sAMAccountType=805306368))r   r#  NrG   r{   r   Tr   )r   DACL_SECURITY_INFORMATIONGROUP_SECURITY_INFORMATIONOWNER_SECURITY_INFORMATIONr   rI   r   r   r   r   r   )	r2   flags_valuer   rP   rQ   rR   rp   rq   r(  s	            r4   get_all_objectaclzMSLDAPClient.get_all_objectacl  sp      89bbcq  dM  M+!7["9::) c+**;dV*LL 3 3 3 3 3 3 3JE3	o
)OOOO
FF*-@|AT-U-UU; &:($	0@0@AB8 ,,[*QY,ZZ 3 3 3 3 3 3 3[VS
9____VVV

$
$V
,
,d
222222	 [Z MLLs   C7>C5c                   K   d}|                      ||          2 3 d{V \  }}|
d|fW V   dS t                              |          dfW V  66 dS )z
		Yields all trusted domains.

		:return: Async generator which yields (`MSADDomainTrust`, None) tuple on success or (None, `Exception`) on error
		:rtype: Iterator[(:class:`MSADDomainTrust`, :class:`Exception`)]

		z(objectClass=trustedDomain)r#  N)rI   MSADDomainTrustr   r   s        r4   get_all_trustszMSLDAPClient.get_all_trusts  s       /+**;U*KK 0 0 0 0 0 0 0JE3	o
)OOOO
FF		"	"5	)	)4	//////	 LKKs   Apasswordc                   K   	 |                     d          d         dd         }| j        dd                             dd          }g d|||d                    ||          d	}| j                            ||           d{V \  }}|d
|fS |                     ||           d{V \  }}|d
|fS |                     |           d{V \  }}|d
|fS dS # t          $ r}d
|fcY d}~S d}~ww xY w)a[  
		Creates a new user object with a password and enables the user so it can be used immediately.
		
		:param user_dn: The user's DN
		:type user_dn: str
		:param password: The password of the user
		:type password: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)

		ru   r      Nz,DC=.)organizationalPersonpersontopr  z{}@{})r!  snr   displayNameuserPrincipalNameFr[   )	splitr(   r   formatr*   addchange_passwordenable_userrM   )	r2   r   r3  r:  domainrp   rh   rR   rS   s	            r4   create_user_dnzMSLDAPClient.create_user_dn  s]     c1abb!2JqrrN""6#..6EEE
!..V44 : )--4444444461c	o#:&&w9999999961c	o#:""7++++++++61c	o#:
*	   
(??????s*   BC $C 7#C 
C5'C0*C50C5computer_sidc                 F  K   	 |                     d          d         dd         }g d|||ddddt          j        d	|                                z            d
	}| j                            ||           d{V \  }}|d|fS dS # t          $ r}d|fcY d}~S d}~ww xY w)zz
		This will create a dmsa service user that can be used for neferious reasons, but DO NOT USE THIS FOR ANYTHING ELSE!

		ru   r   r5  N)z#msDS-DelegatedManagedServiceAccountr7  r8  r9  r  computer         z!O:S-1-5-32-544D:(A;;0xf01ff;;;%s))	r!  r:  r   r;  zmsDS-DelegatedMSAStatezmsDS-ManagedPasswordIntervalzmsDS-SupportedEncryptionTypesuserAccountControlmsDS-GroupMSAMembershipFr[   )r=  r
   	from_sddlupperr*   r?  rM   )r2   r   rD  r:  rp   rh   rR   rS   s           r4   create_broken_dmsa_userz$MSLDAPClient.create_broken_dmsa_user  s      
c1abb!2www
 $&%'2<=`cocucucwcw=wxx
 
: )--4444444461c	o#:
*	   
(??????s   BB 
B BB B c                 R   K   ddgi}| j                             ||           d{V S )z
		Unlocks the user by clearing the lockoutTime attribute.
		
		:param user_dn: The user's DN
		:type user_dn: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)

		lockoutTime)r   r   Nr*   r   r2   r   r   s      r4   unlock_userzMSLDAPClient.unlock_user  sC       >"' y11	1	1	1	1	1	11r6   c                 R   K   ddgi}| j                             ||           d{V S )a
  
		Sets the user object to enabled by modifying the UserAccountControl attribute.
		
		:param user_dn: The user's DN
		:type user_dn: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)

		rJ  )r   i   NrQ  rR  s      r4   rA  zMSLDAPClient.enable_user  sD       *+' y11	1	1	1	1	1	11r6   c                 R   K   ddgi}| j                             ||           d{V S )a  
		Sets the user object to disabled by modifying the UserAccountControl attribute.
		
		:param user_dn: The user's DN
		:type user_dn: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)

		rJ  )r   rn   NrQ  rR  s      r4   disable_userzMSLDAPClient.disable_user  sC       .)' y11	1	1	1	1	1	11r6   spnc                 V   K   dd|fgi}| j                             ||           d{V S )K  
		Adds an SPN record to the user object.
		
		:param user_dn: The user's DN
		:type user_dn: str
		:param spn: The SPN to be added. It must follow the SPN string format specifications.
		:type spn: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)

		r   r?  NrQ  r2   r   rW  r   s       r4   add_user_spnzMSLDAPClient.add_user_spn$  sF       UCL>' y11	1	1	1	1	1	11r6   c                 V   K   dd|fgi}| j                             ||           d{V S )rY  r   deleteNrQ  rZ  s       r4   del_user_spnzMSLDAPClient.del_user_spn5  sG       XsO,' y11	1	1	1	1	1	11r6   hostnamec                 V   K   dd|fgi}| j                             ||           d{V S )z
		Adds additional hostname to the user object.
		
		:param user_dn: The user's DN
		:type user_dn: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)

		zmsds-additionaldnshostnamer?  NrQ  )r2   r   r_  r   s       r4   add_additional_hostnamez$MSLDAPClient.add_additional_hostnameF  sH        5("3!4' y11	1	1	1	1	1	11r6   c                 F   K   | j                             |           d{V S )z
		Deletes the user.
		This action is destructive!
		
		:param user_dn: The user's DN
		:type user_dn: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)

		Nr*   r]  )r2   r   s     r4   delete_userzMSLDAPClient.delete_userV  s0       y((	(	(	(	(	(	((r6   newpassoldpassc                   K   dg i}|A|d                              dd|z  f           |d                              dd|z  f           n |d                              dd|z  f           | j                            ||           d{V S )a  
		Changes the password of a user.  
		If used with a high-privileged account (eg. Domain admin, Account operator...), the old password can be `None` 
		
		:param user_dn: The user's DN
		:type user_dn: str
		:param newpass: The new password
		:type newpass: str		
		:param oldpass: The current password
		:type oldpass: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)

		
unicodePwdNr]  z"%s"r?  r   )r   r*   r   )r2   r   re  rf  r   s        r4   r@  zMSLDAPClient.change_passwordc  s        ' 
<6G+; <===
<(8 9:::: <FW,< =>>>y11	1	1	1	1	1	11r6   c                 V   K   dd|fgi}| j                             ||           d{V S )a
  
		Adds a user to a group

		:param user_dn: The user's DN
		:type user_dn: str
		:param group_dn: The groups's DN
		:type group_dn: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)


		r  r?  NrQ  r2   r   r   r   s       r4   add_user_to_groupzMSLDAPClient.add_user_to_group  sH       ug' y'22	2	2	2	2	2	22r6   c                 V   K   dd|fgi}| j                             ||           d{V S )a  
		Removes user from group

		:param user_dn: The user's DN
		:type user_dn: str
		:param group_dn: The groups's DN
		:type group_dn: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)


		r  r]  NrQ  rj  s       r4   del_user_from_groupz MSLDAPClient.del_user_from_group  sH       x!"' y'22	2	2	2	2	2	22r6   c                  K   dt          |          z  }|                     |t                    2 3 d {V \  }}|
d |fW V   d S |d                             d          }|r|                    |          d fW V  |s|d fW V  Wd|v r t
                              |          d fW V  {d|v rt                              |          d fW V  6 d S )NrG   rp   r!  r  r
  )r   rI   r   r   r   r   r   )r2   r   expected_classrP   rQ   rR   temps          r4   r  zMSLDAPClient.get_object_by_dn  s6     ),?,C,CC+**;GG + + + + + + +JE3	o
)OOOO
FF


!
!-
0
04 0

"
"5
)
)4
/////
 +
+$


U
#
#T
))))))4


e
$
$d
***** HGGs   Cr   c                    K   |g }g }|D ]$}|                     t          |                     %| j                            |||           d{V S )a  
		Performs the modify operation.
		
		:param dn: The DN of the object whose attributes are to be modified
		:type dn: str
		:param changes: Describes the changes to be made on the object. Must be a dictionary of the following format: {'attribute': [('change_type', [value])]}
		:type changes: dict
		:param controls: additional controls to be passed in the query
		:type controls: dict
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)
		Nr   )r   r   r*   r   )r2   r   r   rq   controls_convr   s         r4   r   zMSLDAPClient.modify  su       8- * *g(())))yGmDD	D	D	D	D	D	DDr6   c                 H   K   | j                             ||           d{V S )a4  
		Performs the add operation.
		
		:param dn: The DN of the object to be added
		:type dn: str
		:param attributes: Attributes to be used in the operation
		:type attributes: dict
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)
		N)r*   r?  )r2   r   rp   s      r4   r?  zMSLDAPClient.add  s0       y}}R,,	,	,	,	,	,	,,r6   c                 F   K   | j                             |           d{V S )z
		Performs the delete operation.
		
		:param dn: The DN of the object to be deleted
		:type dn: str
		:return: A tuple of (True, None) on success or (False, Exception) on error. 
		:rtype: (:class:`bool`, :class:`Exception`)
		Nrc  )r2   r   s     r4   r]  zMSLDAPClient.delete  s0       y##	#	#	#	#	#	##r6   c                   K   	 |                      |           d{V \  }}|||                     |           d{V \  }}|||t          d          t          j        |          }t          j        |          }t                      }t          j	        |          |_
        t          j	        d          |_        t          j        |_        d|_        |j        j                            |           dd|                                fgi}	t+          dt,          j        i          }
d|
                                d	d
g}|                     ||	|           d{V \  }}||dS # t          $ r}d	|fcY d}~S d}~ww xY w)zDAdds AddMember rights to the user on the group specified by group_dnNFailed to get forest's SDz$bf9679c0-0de6-11d0-a285-00aa003049e2r   r   r   r   r   Fr   r[   )r  r   rM   r
   
from_bytescopydeepcopyr   r   from_stringSidr	   
ObjectTyper   
WRITE_PROPMaskAceFlagsDaclacesr   to_bytesr   r   r+  r   r   )r2   r   r   user_sidrR   ri   group_sdnew_sdace_1r   r   rq   rh   rS   s                 r4   add_priv_addmemberzMSLDAPClient.add_priv_addmember  s     (227;;;;;;;;=8S	o
I,,X6666666683	o
I	k
0
1
11!,S118M(##6$&&5x((59&'MNN5*5:5>	;5!!! y&//*;*;<=7 #^5$  9 -NN$$  8
 ++h::::::::61c	o
I
*	   
(??????s   E%E+ +
F5E>8F>F	forest_dnc                   K   	 |                      |           d{V \  }}|||| j        j        }|                     |           d{V \  }}|||t	          d          t          j        |          }t          j        |          }t                      }t          j        |          |_        t          j        d          |_        t          j        |_        d|_        |j        j                            |           t                      }	t          j        |          |	_        t          j        d          |	_        t          j        |	_        d|	_        |j        j                            |	           dd|                                fgi}
t/          dt0          j        i          }d	|                                d
dg}|                     ||
|           d{V \  }}||dS # t          $ r}d
|fcY d}~S d}~ww xY w)zzAdds DCSync rights to the given user by modifying the forest's Security Descriptor to add GetChanges and GetChangesAll ACENrv  z$1131f6aa-9c07-11d1-f79f-00c04fc2dcd2r   z$1131f6ad-9c07-11d1-f79f-00c04fc2dcd2r   r   r   r   Fr   r[   )r  r)   r   r   rM   r
   rw  rx  ry  r   r   rz  r{  r	   r|  r   CONTROL_ACCESSr~  r  r  r  r   r  r   r   r+  r   r   )r2   r   r  r  rR   ri   	forest_sdr  r  ace_2r   r   rq   rh   rS   s                  r4   add_priv_dcsynczMSLDAPClient.add_priv_dcsync  s>     5227;;;;;;;;=8S	o
I0I,,Y7777777783	o
I	k
0
1
11"-c229 M)$$6$&&5x((59&'MNN5.5:5> 
;5!!!$&&5x((59&'MNN5.5:5>	;5!!! y&//*;*;<=7 #^5$  9 -NN$$  8
 ++i(;;;;;;;;61c	o
I
*	   
(??????s   G*G0 0
H:H=HHnew_owner_sid	target_dnc                   K   	 	 t          j        |          }n#  dt          d          fcY S xY wd}||dk    r9d}|                     |           d{V \  }}||t	          j        |          }n\d|z  }|                     ||g          2 3 d{V \  }}||t	          j        |d         |                   } n6 t          d          t          j        |          }	||	_	        |d	|	
                                fgi}
|                     ||
           d{V \  }}||d
S # t          $ r}d|fcY d}~S d}~ww xY w)zChanges the owner in a Security Descriptor to the new_owner_sid on an LDAP object or on an LDAP object's attribute identified by target_dn and target_attribute. target_attribute can be omitted to change the target_dn's SD's ownerFzIncorrect SIDNr|   r   rG   rp   zTarget DN not found!r   r[   )r   rz  rM   r   r
   rw  rI   rx  ry  Ownerr  r   )r2   r  r  target_attribute	target_sdri   rR   ro   rQ   r  r   rh   rS   s                r4   change_priv_ownerzMSLDAPClient.change_priv_ownerI  s     $-OM22MM-)O,,,,,, 9"2b"8"8---i88888888HC
Y#.s33II$y0E ,,U5E4FGG - - - - - - -jeSi$/l0CDT0UVVY
U	 H +,,,M)$$66< FOO$5$5677 ++i1111111161c	o
I
*	   
(??????s=    D* /D* A"D* CBD* *
E4D=7E=Ec                  K   	 d}d| j         j        z  }|                     |t          |          2 3 d {V \  }}|
d |fW V   d S t                              |d          d fW V  76 d S # t          $ r}d |fW V  Y d }~d S d }~ww xY w)N$(objectClass=certificationAuthority)zSCN=Certification Authorities,CN=Public Key Services,CN=Services,CN=Configuration,%srp   rr   ROOTCAr)   r   rI   MSADCA_ATTRSMSADCAr   rM   r2   rP   rr   rQ   rR   rS   s         r4   list_root_caszMSLDAPClient.list_root_casq  s      
7;
_bfbp  cC  C4++Kl[_+`` 2 2 2 2 2 2 2ZUC
9____VV


5(
+
+T
111111	 a`` 
 
 
 
	q====	66666
'   .A, A)A, "A, ,
B6BBc                  K   	 d}d| j         j        z  }|                     |t          |          2 3 d {V \  }}|
d |fW V   d S t                              |d          d fW V  76 d S # t          $ r}d |fW V  Y d }~d S d }~ww xY w)Nr  zLCN=NTAuthCertificates,CN=Public Key Services,CN=Services,CN=Configuration,%sr  NTCAr  r  s         r4   
list_ntcaszMSLDAPClient.list_ntcas  s      
7;
X[_[i[{
{4++Kl[_+`` 0 0 0 0 0 0 0ZUC
9____VV


5&
)
)4
//////	 a`` 
 
 
 
	q====	66666
r  c                  K   	 d}d| j         j        z  }|                     |t          |          2 3 d {V \  }}|
d |fW V   d S t                              |d          d fW V  76 d S # t          $ r}d |fW V  Y d }~d S d }~ww xY w)Nr  z=CN=AIA,CN=Public Key Services,CN=Services,CN=Configuration,%sr  AIACAr  r  s         r4   list_aiacaszMSLDAPClient.list_aiacas  s      
7;
IDNLl
l4++Kl[_+`` 1 1 1 1 1 1 1ZUC
9____VV


5'
*
*D
000000	 a`` 
 
 
 
	q====	66666
r  c                  K   	 d}d| j         j        z  }|                     |t          |          2 3 d {V \  }}|
d |fW V   d S t                              |          d fW V  66 d S # t          $ r}d |fW V  Y d }~d S d }~ww xY w)Nz%(objectCategory=pKIEnrollmentService)CN=Configuration,%sr  )r)   r   rI   MSADEnrollmentService_ATTRSMSADEnrollmentServicer   rM   r  s         r4   list_enrollment_servicesz%MSLDAPClient.list_enrollment_services  s      
8;
$."B
B4++KFajn+oo 7 7 7 7 7 7 7ZUC
9____VV

)
)%
0
0$
666666	 poo 
 
 
 
	q====	66666
s'   .A+ A(A+ !A+ +
B5BBrd   c                  K   	 t          dt          j        t          j        z  t          j        z  i          }dd|                                fg}d}|d|z  }d| j        j        z  }|                     |t          ||          2 3 d {V \  }}|
d |fW V   d S t                              |          d fW V  66 d S # t          $ r}d |fW V  Y d }~d S d }~ww xY w)Nr   r   Tz'(objectCategory=pKICertificateTemplate)z3(&(objectCategory=pKICertificateTemplate)(name=%s))r  )rp   rq   rr   )r   r   r+  r,  r-  r   r)   r   rI   MSADCertificateTemplate_ATTRSMSADCertificateTemplater   rM   )	r2   rd   r   rq   rP   rr   rQ   rR   rS   s	            r4   list_certificate_templatesz'MSLDAPClient.list_certificate_templates  si     
"Gn.VWe  XA  /A  BP  Bk  /k  $l  m  m9($	0@0@AB8:;
G$NK
$."B
B4++KFcnv  @D+  E  E 9 9 9 9 9 9 9ZUC
9____VV
!
+
+E
2
2D
888888	 E  E  E 
 
 
 
	q====	66666
s*   BC  B=C  !C   
C
CCc                `  K   	 d}|                      |g d          2 3 d {V \  }}|d d d |fW V   d S |d                             d          |d                             d          |d                             d          d fW V  m6 d S # t          $ r}d d d |fW V  Y d }~d S d }~ww xY w)N-(objectClass=msDS-GroupManagedServiceAccount))r   rK  msDS-ManagedPasswordr#  rp   r   rK  r  )rI   r   rM   )r2   rP   rQ   rR   rS   s        r4   	list_gmsazMSLDAPClient.list_gmsa  so     

A;++K  GK  GK  GK+  L  L _ _ _ _ _ _ _ZUC
tS     VV


!
!"2
3
3U<5H5L5LMf5g5gino{i|  jA  jA  BX  jY  jY  [_  _  _  _  _  _  _	 L  L  L 
 
 
 
	tT1		66666
s'   B BB AB 
B-	B((B-c                   K   	 d}|                      |t                    2 3 d {V \  }}|
d |fW V   d S t                              |          }|d fW V  86 d S # t          $ r}d |fW V  Y d }~d S d }~ww xY w)Nr  r#  )rI   r   MSADGMSAUserr   rM   )r2   rp   rP   rQ   rR   gmsauserrS   s          r4   get_all_gmsazMSLDAPClient.get_all_gmsa  s      
A;++Kn+UU       ZUC
9____VV%%e,,H
D. VUU 
 
 
 
	q====	66666
s&   A AA #A 
A9'A44A9computernamec                   K   	 |/dd                     d t          d          D                       z  }|                    d          du r|dz  }|,d                     d t          d          D                       }| j        j                            d	d                              d
d                              dd          }g d||d d         d                    |d d         |          d}d|d d         d| j        j        }|                     ||           d {V \  }}||ddgi}| j        	                    ||           d {V \  }}||| 
                    ||           d {V \  }}|||                     |           d {V \  }	}|||	|d fS # t          $ r}
d d |
fcY d }
~
S d }
~
ww xY w)NzCOMP%s$r|   c              3   l   K   | ]/}t          j        t          j        t          j        z             V  0d S r8   randomchoicestringascii_uppercasedigitsr   rh   s     r4   	<genexpr>z,MSLDAPClient.add_computer.<locals>.<genexpr>  s7      &o&oabv}V5Kfm5['\'\&o&o&o&o&o&or6      $Fc              3   r   K   | ]2}t          j        t          j        t          j        z   d z             V  3dS )z!@#$%+Nr  r  s     r4   r  z,MSLDAPClient.add_computer.<locals>.<genexpr>  s<      kk\]v}V%;fm%Kh%VWWkkkkkkr6      DC=ru   r6  )r9  r8  r7  r  rF  r$  z
HOST/{}.{})r!  r   rd   r   zCN=z,CN=Computers,rJ  )r   rI  )r}   rangeendswithr)   r   r   r>  r?  r*   r   r@  r   rM   )r2   r  r3  rB  rp   r   rh   rR   r   rF  rS   s              r4   add_computerzMSLDAPClient.add_computer  si     ,rww&o&ofklmfnfn&o&o&ooooLC  E))CLwwkkafgiajajkkkkkH N,44T"==EEc"MMUUVYZ]^^6QQQ"")00crc1BFKK :: $0#4#4#4dn6V6VW2((2z********61c	o
I ,-7 )""2w////////61c	o
I &&r84444444461c	o
I )),77777777=8S	o
I Hd
""	   
a-s   F#F( (
G2F<6G<Gc                    K   	 dd|fgi}| j                             ||           d {V \  }}||d S # t          $ r}|cY d }~S d }~ww xY w)Nr   r   )r*   r   rM   )r2   r   r  r   rh   rR   rS   s          r4   change_samaccountnamez"MSLDAPClient.change_samaccountname  s      		>237 )""2w////////61c	o
I
$	   
888888s   /5 
AA AAsdc                   K   	 t          |t                    rt          j        |          }i }i }d|t	          |j                  <   d|t	          |j                  <   |j        &|j        j        D ]}d|t	          |j	                  <   |j
        &|j
        j        D ]}d|t	          |j	                  <   |D ],}|                     |           d{V \  }}}||||f||<   -|dfS # t          $ r}	d|	fcY d}	~	S d}	~	ww xY w)zDResolves all SIDs found in security descriptor, returns lookup tabler=   N)r  bytesr
   rw  r  r  Groupr  r  r{  Sacl
resolv_sidrM   )
r2   r  lookup_tabler  acer   rB  usernamerR   rS   s
             r4   	resolv_sdzMSLDAPClient.resolv_sd  sM     U ,		'	+	+B<
44BH4BHgw|  T#cg,,gw|  T#cg,, + +s"&//#"6"6666666FHc
Y*L

	   
'>>>>>>s   C'C, ,
D6C?9D?DT	use_cachec                 N  K   	 t          |                                          }|t          v rdt          |         dfS d}d}|                    dd          d         }|| j        vrt          j        d|z             dS | j        |         }|| j        v r| j        |         }nTd|z  }|                     |d	g
          2 3 d{V \  }}|dd|fc S |d         	                    d	          }/6 ||ddfS |du r
|| j        |<   ||dfS # t          $ r}	dd|	fcY d}	~	S d}	~	ww xY w)zSPerforms a SID lookup for object and returns the domain name and the samaccountnameBUILTINN-r=   r   zDomain SID "%s" was not found! )???r  Nr  r   r#  rp   r  T)r  rM  r   rsplitr/   r   r`   r.   rI   r   rM   )
r2   r   r  rB  r  r1   rP   rQ   rR   rS   s
             r4   r  zMSLDAPClient.resolv_sid1  s     	S		3	Zjot++68zz#a  #9t,,,
L2Y>???!),6	T_s#HH $c)K ,,[HXGY,ZZ : : : : : : :jeS4_l#''(899XX [
 E4 4#DOC
(D
  	   
a-sB   9D A D  AD C0D #D 8D 
D$DD$D$c                 D   K   | j                                          d {V S r8   )r*   whoamir:   s    r4   r  zMSLDAPClient.whoamiR  s,      y!!	!	!	!	!	!	!!r6   c                   K   i }	 |                                   d{V \  }}||||d<   g |d<   |                    d          du r#|dd                             dd          \  }}||d	<   ||d
<   |                     |           d{V \  }}||t	          |j                  |d<   |d                             t	          |j                             i |d<   |                     |j                  2 3 d{V \  }}|||d                             t	          |                     d|d         |<   | 	                    |           d{V \  }}}||||f|d         |<   r6 |dfS #  |dfcY S xY w)zFull whoamiNrawtokengroupszu:Trn   \r=   rB  r  r   groups)NAr  )
r  
startswithr=  r   r  re   r   r  r   r  )	r2   r  ri   rR   rB  r  r  	group_sidr  s	            r4   
whoamifullzMSLDAPClient.whoamifullU  s      &KKMM!!!!!!83	o
I6%=6-	nnTd"" W]]433FNF8-FmmN33333333ID#
Y''F5M
=  T^!4!4555F8 $ 4 4T5K L L 6 6 6 6 6 6 6niiM!!#i..111#.VHi #'??9#=#=======VXsi$*H#5VHi   !M $,
$,s   C3E0 9E+?A0E0 0E8c                   K   d}|                      |dg          2 3 d {V \  }}|
d |fW V   d S |                    di                               d          d fW V  E6 t          j        d           d S )Nz(&(sAMAccountType=805306369)(!(userAccountControl:1.2.840.113556.1.4.803:=8192))(userAccountControl:1.2.840.113556.1.4.803:=524288))r   rp   r   rI   r   r   r`   r   s       r4   get_unconstrained_machinesz'MSLDAPClient.get_unconstrained_machinesx  s       X+**;9I8JKK A A A A A A AJE3	o
)OOOO
FF	<	$	$	(	()9	:	:D	@@@@@@	 L
 	,./////   A!c                   K   d}|                      |dg          2 3 d {V \  }}|
d |fW V   d S |                    di                               d          d fW V  E6 t          j        d           d S )NzP(&(sAMAccountType=805306368)(userAccountControl:1.2.840.113556.1.4.803:=524288))r   rp   r   r  r   s       r4   get_unconstrained_usersz$MSLDAPClient.get_unconstrained_users  s      c+**;9I8JKK A A A A A A AJE3	o
)OOOO
FF	<	$	$	(	()9	:	:D	@@@@@@	 L
 	,./////r  c                   K   d}|                      |ddg          2 3 d {V \  }}|
d |fW V   d S |                    di           d fW V  26 t          j        d           d S )NzV(&(|(sAMAccountType=805306369)(sAMAccountType=805306368))(msDS-AllowedToDelegateTo=*))r   zmsDS-AllowedToDelegateTorp   r   r  r   s       r4   get_all_constrainedz MSLDAPClient.get_all_constrained  s      i+**;9IKe8fgg + + + + + + +JE3	o
)OOOO
FF	<	$	$d	******	 h
 	,./////s   Ac                   K   d}|                      |dg          2 3 d {V \  }}|
d |fW V   d S |                    di                               d          d fW V  E6 t          j        d           d S )Nzo(&(|(sAMAccountType=805306369)(sAMAccountType=805306368))(userAccountControl:1.2.840.113556.1.4.803:=16777216))r   rp   r   r  r   s       r4   get_all_s4u2proxyzMSLDAPClient.get_all_s4u2proxy  s       C+**;9I8JKK A A A A A A AJE3	o
)OOOO
FF	<	$	$	(	()9	:	:D	@@@@@@	 L
 	,./////r  c                    K   	 d|z  }|                      |ddg          2 3 d{V \  }}|||d         d         dfc S 6 dS # t          $ r}d|fcY d}~S d}~ww xY w)z7Fetches the DN of an object based on the sAMAccountNamer  r   re   Nrp   rI   rM   )r2   r   ro   rQ   rR   rS   s         r4   sam2dnzMSLDAPClient.sam2dn  s       >15++E4G3UVV : : : : : : :ZUC
Y23T9999 WVV 
   
'>>>>>>s-   A AA A 
AAAAc                    K   	 d|z  }|                      |dg          2 3 d{V \  }}|||d         d         dfc S 6 dS # t          $ r}d|fcY d}~S d}~ww xY w)z2Fetches the DN of an object based on the objectSidr  r   Nrp   r  )r2   r   ro   rQ   rR   rS   s         r4   sid2dnzMSLDAPClient.sid2dn  s      c!5++E4G3HII : : : : : : :ZUC
Y23T9999 JII 
   
'>>>>>>s-   A A A  A 
AAAAc                    K   	 dt          |          z  }|                     |dg          2 3 d{V \  }}|||d         d         dfc S 6 dS # t          $ r}d|fcY d}~S d}~ww xY w)z2Fetches the objectSid of an object based on the DNrG   re   Nrp   r  r2   r   ro   rQ   rR   rS   s         r4   dn2sidzMSLDAPClient.dn2sid  s      #&9"&=&==5++EK=AA 2 2 2 2 2 2 2ZUC
Y{+T1111 BAA 
   
'>>>>>>-   )A AA A 
A(A#A(#A(c                    K   	 dt          |          z  }|                     |dg          2 3 d{V \  }}|||d         d         dfc S 6 dS # t          $ r}d|fcY d}~S d}~ww xY w)z7Fetches the sAMAccountName of an object based on the DNrG   r   Nrp   r  r  s         r4   dn2samzMSLDAPClient.dn2sam  s      #&9"&=&==5++E4D3EFF 7 7 7 7 7 7 7ZUC
Y/0$6666 GFF 
   
'>>>>>>r  c                    K   	 dt          |          z  }|                     ||          2 3 d{V \  }}|||d         dfc S 6 dS # t          $ r}d|fcY d}~S d}~ww xY w)z/Fetches attributes of an object specified by DNrG   Nrp   r   r  )r2   r   r   ro   rQ   rR   rS   s          r4   dnattrszMSLDAPClient.dnattrs  s      #&9"&=&==5++E599 % % % % % % %ZUC
Y$$$$ : *	   
'>>>>>>s-   (A	 AA	 A	 	
A!AA!A!c                   K   	 d}g d}|                      |||d          2 3 d {V \  }}|||d         d fW V  6 d S # t          $ r}d |fW V  Y d }~d S d }~ww xY w)Nz(|(objectClass=container)(objectClass=organizationalUnit)(sAMAccountType=805306369)(objectClass=group)(&(objectCategory=person)(objectClass=user))))re   r!  r"  r   r   sAMAccountTyper=   )rr   rs   rp   r  )r2   r   ro   r   rQ   rR   rS   s          r4   get_childobjectszMSLDAPClient.get_childobjects  s       a5
m
m
m5++E5rPQ+RR $ $ $ $ $ $ $ZUC
Y

t
###### SRR 
   	q==========s    A ?A 
AAAc                  K   d| j         z  d| j         z  d| j         z  g}g d}t                      }	 |D ]}d}|                     |ddg|          2 3 d	{V \  }}|||d
         d         t          fd|D                       r;t	          |j        |d
         d                   }t          |d           }	|	d	fW V  s6 d	S # t          $ r}
d	|
fW V  Y d	}
~
d	S d	}
~
ww xY w)z!Lists all DNS zones in the forest$CN=MicrosoftDNS,DC=DomainDnsZones,%s$CN=MicrosoftDNS,DC=ForestDnsZones,%sCN=MicrosoftDNS,CN=System,%s)RootDNSServersz..TrustAnchors_msdcsz(objectClass=dnsZone)dcdNSPropertyr  Nrp   c              3       K   | ]}|vV  	d S r8   r9   )r   r   zones     r4   r  z,MSLDAPClient.dnslistzones.<locals>.<genexpr>  s'      --aATM------r6   c                     | j         S r8   )_id)props    r4   <lambda>z+MSLDAPClient.dnslistzones.<locals>.<lambda>  s    tx r6   )key)r(   r   rI   allmaprw  sortedrM   )r2   dnsroots	blacklistfactorydnsrootro   rQ   rR   map_objpropsrS   r
  s              @r4   dnslistzoneszMSLDAPClient.dnslistzones  s     
 *DJ6)DJ6!DJ.(  )   '  w#E ,,Um?T[b,cc 
 
 
 
 
 
 
jeSi,%T----9----- G&l(;M(JKKgW"7"7888e% dc  
   	q==========s$    C CA/C 
C'C""C'c                  K   d| j         z  d| j         z  d| j         z  g}|                                 2 3 d{V \  }}}|||                    d|z             (6 	 |D ]}d}	 |                     |g d|          2 3 d{V \  }}||d	|d
         vs|d
         d	         'd|d
         v r|d
         d         du r|du rFd|d
         vrQ|d
         d         D ])}	||d
         d	         t	          j        |	          dfW V  *6 # t          $ r |nt          d|z            Y w xY wdS # t          $ r}
ddd|
fW V  Y d}
~
dS d}
~
ww xY w)z#Lists all DNS entries in the forestr  r  r  Nz'CN=MicrosoftDNS,DC=ForestDnsZones,DC=%sz(objectClass=dnsNode))	dnsRecorddNSTombstonedrd   r  rd   rp   r  TFr  zZone %s not found!)r(   r  r   rI   r   rw  r   rM   )r2   r
  with_tombstonesr  rQ   rh   rR   r  ro   
recorddatarS   s              r4   
dnsentrieszMSLDAPClient.dnsentries  sj      *DJ6)DJ6!DJ.( "..00 F F F F F F FME1c	o
I??<uDEEEE	 1 3 3w#E3!--e@d@d@dkr-ss [ [ [ [ [ [ [zuc	y	u\*	*	*eL.A&.I.Q	E,/	/	/E,4G4X\`4`4`
U
"
"	E,/	/	/l+K8 [ [*eL)&1:3H3T3TVZZZZZZZ[ ts"  3 3 3
*T1222 d3)3 32 
   	tT1	sN   AD2 %D?D	BD
D2 D-*D2 ,D--D2 2
E<	EEc                   K   d}|                      |t                    2 3 d{V \  }}|d|fW V  t                              |          dfW V  46 dS )z*Lists all domain controllers in the forestzN(&(sAMAccountType=805306369)(userAccountControl:1.2.840.113556.1.4.803:=8192))N)rI   r   r   r   r   s       r4   get_all_domain_controllersz'MSLDAPClient.get_all_domain_controllers0  s       b+**;8IJJ , , , , , , ,JE3	o
)OOOO			u	%	%t	++++++	 KJJs   Ac                   K   |                      dt                    2 3 d{V \  }}||t                              |          dfW V  .6 dS )zLists all DGMAs in the forestz1(objectClass=msDS-DelegatedManagedServiceAccount)N)rI   MSADDMSAUser_ATTRSMSADDMSAUserr   )r2   rQ   rR   s      r4   get_all_dmsaszMSLDAPClient.get_all_dmsas:  s      **+_astt - - - - - - -JE3	o
I				&	&	,,,,,, utts   A
class_typec                 |  K   |dk    rt           }n:|dk    rt          }n,|dk    rt          }n|dk    rt          }n|dk    rt          }nd}t          j        d|z             d|z  }|                     |t                    2 3 d{V \  }}|d|fc S ||	                    || j
                  dfc S |dfc S 6 d	S )
a5  
		Fetches one object from the AD, based on the DN attribute 
		
		:param dn: The DN of the object.
		:type dn: str
		:param class_type: The class of the object.
		:type class_type: str
		:return: A tuple with the object and an `Exception` is there was any
		:rtype: (:class:`MSADUser`, :class:`Exception`)
		r  rF  r
  	containerdmsaNzPolling AD for object %srG   r   )r   r   r   r   r$  r   r`   rI   r   r   r)   )r2   r   r&  ocrP   rQ   rR   s          r4   get_obj_by_dnzMSLDAPClient.get_obj_by_dnA  s      622Z22W22[  22V222,)2-...)B.+**;GG       JE3	o9n<<t~..4444$; H *s   B;rV   )NNrn   )rn   )Fr8   r   )T)w__name__
__module____qualname____doc__r   r   r5   r;   rE   rg   rA   r]   rk   rm   r  r   r   intrI   r   r   r   r   r   MSADGPO_ATTRSr   MSADContainer_ATTRSr   r   r   r   r   r   r   r   r   r   rc   r   boolr   r   r   r+  r,  r-  r   r   r  r   r   r   MSADOU_ATTRSr   r   r   r  r	  r  r  r  r  r)  r/  MSADDomainTrust_ATTRSr2  rC  rN  rS  rA  rV  r[  r^  ra  rd  r@  rk  rm  r  r   objectr   r?  r]  r  r  r  r  r  r  r  r  r  MSADGMSAUser_ATTRSlistr  r  r  r
   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r!  r%  r+  r9   r6   r4   r   r   #   s
         < }    6  9 9 9  $
 
 
$ $ $L    ? ?3 ?49 ?tERUWZ\_R_L`Ga ?or ?  IL ? ? ? ?B# #s ## # # # #J 2@ 0 0T#Y 0 0 0 0" 5F 0 0S	 0 0 0 0( 1> ( (DI ( ( ( (  7J 0 0$s) 0 0 0 0"c           D0C 0 0 0 02 8M 0 049 0 0 0 0<    0 0 0 0 0&0C 0 0 0 0&! ! !"  &0 0t 0 0 0 020 0d 0 0 0 0. GUFno}  pY  GY  Zh  ZC  GC 1 1# 1^ 1 1 1 16 ESDlm{  nW  EW  Xf  XA  EA   >    6 XfW  AO  Aj  Xj  ky  kT  XT I Is I In I I I I: 3B * *d3i * * * * 0< ' '49 ' ' ' '8# 8 8 8 8$8 8 8 8 8$8S 8 8 8 8  c T    48 8 8 8 8(8 8 8 8 8(S    (C    8+ + +Z3 3 3: 3H 0 0d3i 0 0 0 0 % %c % % % %N 3    22S 2 2 2 22S 2 2 2 22c 2 2 2 22c 2s 2 2 2 2"2c 2s 2 2 2 2"2 2s 2 2 2 2 )S ) ) ) )2 2# 2 2S 2 2 2 283C 33 3 3 3 3$3c 3S 3 3 3 3&+ +S + + + +"E E3 ES&[(9 EDfDU E E E E*- -S&[(9 - - - -
$3 
$ 
$ 
$ 
$*C *# * * * *X7 7 7 7 7 7 7r& & & & & & &P
 
 

 
 

 
 

 
 

 
 
 
 
 
(
 
 
 1C 
 
 
 
 
 
- -3 - - - - -^
# 
c 
 
 
 
1:U    8 
s d    B" " "! ! !F0 0 00 0 00 0 00 0 0	 	 		 	 		 	 		 	 	
49 
 
 
 
	 	 	# # #J* * * *X, , ,- - -#0# #0# #0 #0 #0 #0 #0 #0r6   r   )/r?   rx  r  r  typingr   r   r   asyauth.common.credentialsr   winacl.dtyp.acer   r   winacl.dtyp.guidr	   winacl.dtyp.security_descriptorr
   winacl.dtyp.sidr   msldapr   msldap.commons.commonr   msldap.commons.exceptionsr   msldap.commons.targetr   msldap.commons.utilsr   msldap.connectionr   msldap.ldap_objectsmsldap.protocol.constantsr   r   r   msldap.protocol.messagesr   msldap.protocol.queryr   #msldap.wintypes.asn1.sdflagsrequestr   r   msldap.wintypes.dnsp.structuresr   r   r   r9   r6   r4   <module>rK     s       $ $ $ $ $ $ $ $ $ $ 4 4 4 4 4 4 F F F F F F F F ! ! ! ! ! ! ? ? ? ? ? ? 5 5 5 5 5 5             4 4 4 4 4 4 9 9 9 9 9 9 . . . . . . + + + + + + 4 4 4 4 4 4 ! ! ! ! A A A A A A A A A A , , , , , , 5 5 5 5 5 5F F F F F F F F J J J J J J J JA0 A0 A0 A0 A0 A0 A0 A0 A0 A0r6   