
    g                     j    S SK Jr  S SKJr  S SKJr  S SKJrJ	r	J
r
  S SKJr  S SKJr   " S S\5      rg)	    N)ldb)system_session)CommandCommandErrorOption)SamDB)ATYPE_NORMAL_ACCOUNTc            	           \ rS rSrSrSr\" SSS\SSS	9/rS
/r	\
R                  \
R                  \
R                  S.r  SS jrSrg)cmd_user_delete   a  Delete a user.

This command deletes a user account from the Active Directory domain.  The username specified on the command is the sAMAccountName.

Once the account is deleted, all permissions and memberships associated with that account are deleted.  If a new user account is added with the same name as a previously deleted account name, the new user does not have the previous permissions.  The new account user will be assigned a new security identifier (SID) and permissions and memberships will have to be added.

The command may be run from the root userid or another authorized userid.  The -H or --URL= option can be used to execute the command against a remote server.

Example1:
samba-tool user delete User1 -H ldap://samba.samdom.example.com --username=administrator --password=passw1rd

Example1 shows how to delete a user in the domain against a remote LDAP server.  The -H parameter is used to specify the remote target server.  The --username= and --password= options are used to pass the username and password of a user that exists on the remote server and is authorized to issue the command on that server.

Example2:
sudo samba-tool user delete User2

Example2 shows how to delete a user in the domain against the local server.   sudo is used so a user may run the command as root.

z%prog <username> [options]z-Hz--URLz%LDB URL for database or target serverURLH)helptypemetavardestusername)	sambaoptscredoptsversionoptsNc                    UR                  5       nUR                  USS9n[        U[        5       XvS9nS[        R
                  " U5       S[         S3n	 UR                  UR                  5       [        R                  U	S/S9n
U
S	   R                  n UR                  U5        U R                  R!                  SU-  5        g ! [         a    [        S
U-  5      ef = f! [         a  n[        SU-  U5      eS nAff = f)NT)fallback_machine)urlsession_infocredentialslpz(&(sAMAccountName=z)(sAMAccountType=z))dn)basescope
expressionattrsr   zUnable to find user "%s"zFailed to remove user "%s"zDeleted user %s
)get_loadparmget_credentialsr   r   r   binary_encoder	   search	domain_dnSCOPE_SUBTREEr   
IndexErrorr   delete	Exceptionoutfwrite)selfr   r   r   r   r   r   credssamdbfilterresuser_dnes                :/usr/lib/python3/dist-packages/samba/netcmd/user/delete.pyruncmd_user_delete.run@   s   ##%((d(C!.*:"'0 's'8'8'B&C D%%9$:">	H,,EOO$5%(%6%6*0&*V  -C !fiiG	KLL! 			+h67  	H9XFGG	H
  	K;hFJJ	Ks$   >C C! C!
C?+C::C? )NNNN)__name__
__module____qualname____firstlineno____doc__synopsisr   strtakes_options
takes_argsoptionsSambaOptionsCredentialsOptionsVersionOptionstakes_optiongroupsr5   __static_attributes__r7       r4   r   r      si    & ,H 	tW#JQT3	(M
 J))..-- HL8rG   r   )samba.getoptgetoptrA   sambar   
samba.authr   samba.netcmdr   r   r   samba.samdbr   
samba.dsdbr	   r   r7   rG   r4   <module>rO      s(   ,   % 6 6  +:8g :8rG   