
    g                     v    S SK J r   S SKJr  S SKJrJrJrJr  S SK	J
r
  S SKJrJrJr  S SKJr   " S S\5      rg)	    )getpassN)dsdbgenerate_random_passwordgensecldb)system_session)CommandCommandErrorOption)SamDBc                       \ rS rSrSrSr\R                  \R                  \R                  S.r
\" SSS\SS	S
9\" SS\S9\" SS\S9\" SSSS9\" SSSS9\" SSSS9\" SSSS9/rS/r    SS jrSrg)cmd_user_setpassword   a$  Set or reset the password of a user account.

This command sets or resets the logon password for a user account.  The username specified on the command is the sAMAccountName.  The username may also be specified using the --filter option.

If the password is not specified on the command through the --newpassword parameter, the user is prompted for the password to be entered through the command line.

It is good security practice for the administrator to use the --must-change-at-next-login option which requires that when the user logs on to the account for the first time following the password change, he/she must change the password.

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 setpassword TestUser1 --newpassword=passw0rd --URL=ldap://samba.samdom.example.com -Uadministrator%passw1rd

Example1 shows how to set the password of user TestUser1 on a remote LDAP server.  The --URL parameter is used to specify the remote target server.  The -U option is used to pass the username and password of a user that exists on the remote server and is authorized to update the server.

Example2:
sudo samba-tool user setpassword TestUser2 --newpassword=passw0rd --must-change-at-next-login

Example2 shows how an administrator would reset the TestUser2 user's password to passw0rd.  The user is running under the root userid using the sudo command.  In this example the user TestUser2 must change their password the next time they logon to the account.

Example3:
samba-tool user setpassword --filter=samaccountname=TestUser3 --newpassword=passw0rd

Example3 shows how an administrator would reset TestUser3 user's password to passw0rd using the --filter= option to specify the username.

z.%prog (<username>|--filter <filter>) [options])	sambaoptsversionoptscredoptsz-Hz--URLz%LDB URL for database or target serverURLH)helptypemetavardestz--filterzLDAP Filter to set password on)r   r   z--newpasswordzSet passwordz--must-change-at-next-loginz*Force password to be changed on next login
store_true)r   actionz--random-passwordzGenerate random passwordz--smartcard-requiredz*Require a smartcard for interactive logonsz--clear-smartcard-requiredz0Don't require a smartcard for interactive logonsz	username?Nc                    Uc  Uc  [        S5      eUnU
(       a8  Ub  US:w  a  [        S5      eU(       a  [        S5      eU(       a  [        S5      eU	(       a  U
(       d  [        SS5      n U
(       a  ODUb  US:w  a  O:[        S	5      n[        S
5      nX:X  d  S nU R                  R	                  S5        ML  Uc  S[
        R                  " U5      -  nUR                  5       nUR                  U5      nUR                  UR                  5       [        R                  -  5        [        U[        5       XS9nU
(       am  Sn SU=(       d    U-  n[        R                   nUR#                  UUSS9  SU=(       d    U-  nUR%                  U5        U R                  R	                  S5        g Sn U(       a/  SU=(       d    U-  n[        R                   nUR#                  UUSS9  SU=(       d    U-  nUR)                  X,UUS9  U R                  R	                  S5        g ! [&         a  n[        U< SU< 35      eS nAff = f! [&         a  n[        U< SU< 35      eS nAff = f)Nz4Either the username or '--filter' must be specified! zNIt is not allowed to specify --newpassword together with --smartcard-required.z\It is not allowed to specify --must-change-at-next-login together with --smartcard-required.z[It is not allowed to specify --clear-smartcard-required together with --smartcard-required.      TzNew Password: zRetype Password: zSorry, passwords do not match.
z((&(objectClass=user)(sAMAccountName=%s)))urlsession_infocredentialslpz1Failed to set UF_SMARTCARD_REQUIRED for user '%s')onz&Failed to enable account for user '%s'z: zAdded UF_SMARTCARD_REQUIRED OK
z4Failed to remove UF_SMARTCARD_REQUIRED for user '%s'Fz$Failed to set password for user '%s')force_change_at_next_loginusernamezChanged password OK
)r
   r   r   outfwriter   binary_encodeget_loadparmget_credentialsset_gensec_featuresget_gensec_featuresr   FEATURE_SEALr   r   r   UF_SMARTCARD_REQUIREDtoggle_userAccountFlagsenable_account	Exceptionsetpassword)selfr%   filterr   r   r   r   newpasswordmust_change_at_next_loginrandom_passwordsmartcard_requiredclear_smartcard_requiredpasswordpasswordverifyr"   credssamdbcommandflagsmsgs                       ?/usr/lib/python3/dist-packages/samba/netcmd/user/setpassword.pyruncmd_user_setpassword.runW   s{    >h.UVV#B" $I J J )" $I J J (" $I J J #5/S9H!#B/0H$%89N-		 BC  >?3CTCTU]C^_F##%((,!!%";";"=@S@S"ST!.*:"'0 G>MQYQc]cd22--fe-EBhFXRXY$$V, IIOO>?G>+TX`XjdjkG 66E11&%E1J@HDVPVW!!&=V+3 " 5 IIOO34%  >"w#<==>  >"w#<==>s2   AH" 1AI "
I,H>>I
I'I""I' )NNNNNNNFFFF)__name__
__module____qualname____firstlineno____doc__synopsisoptionsSambaOptionsVersionOptionsCredentialsOptionstakes_optiongroupsr   strtakes_options
takes_argsrB   __static_attributes__rD       rA   r   r      s    4 @H ))--.. 	tW#JQT3	(z @sK^#>,@"	$ 	"."	$ 	%@"	$ 	+F"	$M& JGK26=B?DJ5rT   r   )r   samba.getoptgetoptrK   sambar   r   r   r   
samba.authr   samba.netcmdr	   r
   r   samba.samdbr   r   rD   rT   rA   <module>r[      s-   ,   = = % 6 6 B57 B5rT   