o
    Žõ±j°	  ã                   @   sV   d dl Z d dlZd dlmZ d dlmZ d dlmZmZ dd„ Z	e
dkr)e	ƒ  dS dS )é    N)ÚMSLDAPClientConnection)ÚLDAPConnectionFactory)ÚMSADUserÚMSADMachinec                  C   s¨  dd l } | jdd�}|jdddddd� |jd	d
d� |jddd� |jdd�}d|_d|_|jddd�}|jddd� |jddd�}|jddd� |jddd�}| ¡ }|jdkrbt	j
t	jd� nt	j
t	jd� t |j¡}| ¡ }| ¡ }	tt|ƒƒ tt|	ƒƒ t||	ƒ}
|jdkr•t|
 ¡ ƒ d S |jdk�r|
 ¡  |
 ¡ }t|jdddd��%}tj|dd�}| tj¡ |
  ¡ D ]}| | !tj¡¡ q¾W d   ƒ n1 sÔw   Y  t|jd  dddd��&}tj|dd�}| t"j¡ |
 #¡ D ]}| | !t"j¡¡ qöW d   ƒ d S 1 �sw   Y  d S |jdk�rR|
 ¡  |
 ¡ \}}t|jdddd��}|
 $¡ D ]}| %|j&d! ¡ �q3W d   ƒ d S 1 �sKw   Y  d S d S )"Nr   zMS LDAP library)Údescriptionz-vz	--verboseÚcountzVerbosity, can be stacked)ÚactionÚdefaultÚhelpÚ
connectionz Connection string in URL format.)r
   z--treez$LDAP tree to perform the searches onÚcommandsTÚcommandÚdumpz!Dump all user objects to TSV fileÚoutfilezoutput fileÚspnzBDump all users with servicePrincipalName attribute set to TSV fileÚdsazGrab basic info about the AD)ÚlevelÚwÚ Úutf8)ÚnewlineÚencodingú	)Ú	delimiterÚ_compz
)'ÚargparseÚArgumentParserÚadd_argumentÚadd_subparsersÚrequiredÚdestÚ
add_parserÚ
parse_argsÚverboseÚloggingÚbasicConfigÚINFOÚDEBUGr   Úfrom_urlr   Úget_credentialÚ
get_targetÚprintÚstrr   r   Úget_server_infoÚconnectÚget_ad_infoÚopenr   ÚcsvÚwriterÚwriterowr   Ú	TSV_ATTRSÚget_all_user_objectsÚget_rowr   Úget_all_machine_objectsÚget_all_service_user_objectsÚwriteÚsAMAccountName)r   ÚparserÚ
subparsersÚ
dump_groupÚ	spn_groupÚ	dsa_groupÚargsÚurl_decÚcredsÚtargetr   ÚadinfoÚfr2   ÚuserÚcompÚerr© rI   ú‚/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/msldap/__main__.pyÚrun   sf   


ÿýÿ$ýÿ$ÿýrK   Ú__main__)r$   r1   Úmsldap.connectionr   Úmsldap.commons.factoryr   Úmsldap.ldap_objectsr   r   rK   Ú__name__rI   rI   rI   rJ   Ú<module>   s   <
ÿ