
    g9                         S SK r S SKJr  S SKJr  S SKJrJr  S SK	J
r
JrJr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 " S
 S\
5      r " S S\5      rg)    N)system_session)DOMAIN_PASSWORD_COMPLEXDOMAIN_PASSWORD_STORE_CLEARTEXT)CommandCommandErrorOptionSuperCommand)NEVER_TIMESTAMPtimestamp_to_daystimestamp_to_mins)cmd_domain_passwordsettings_pso)SamDBc            	           \ rS rSrSrSr\R                  \R                  \R                  S.r
\" SSS\SS	S
9/rSS jrSrg) cmd_domain_passwordsettings_show%   z1Display current password settings for the domain.z%prog [options]	sambaoptsversionoptscredopts-H--URL%LDB URL for database or target serverURLHhelptypemetavardestNc                    UR                  5       nUR                  U5      n[        U[        5       XeS9nUR	                  5       nUR                  U[        R                  / SQS9n	[        U	5      S:X  d   e [        U	S   S   S   5      n
[        U	S   S   S   5      n[        U	S   S   S   5      n[        U	S   S	   S   5      n[        U	S   S
   S   5      n[        U	S   S   S   5      n[        U	S   S   S   5      n[        U	S   S   S   5      nU R                  SU-  5        U R                  S5        U
[        -  S:w  a  U R                  S5        OU R                  S5        U
[         -  S:w  a  U R                  S5        OU R                  S5        U R                  SU-  5        U R                  SU-  5        U R                  SU-  5        U R                  SU-  5        U R                  SU-  5        U R                  SU-  5        U R                  SU-  5        g ! [         a  n[        SU5      eS nAff = f)Nurlsession_infocredentialslp)pwdPropertiespwdHistoryLengthminPwdLength	minPwdAge	maxPwdAgelockoutDurationlockoutThresholdlockOutObservationWindow)scopeattrs   r   r&   r'   r(   r)   r*   r,   r+   r-   z'Could not retrieve password properties!z$Password information for domain '%s' zPassword complexity: onzPassword complexity: offzStore plaintext passwords: onzStore plaintext passwords: offzPassword history length: %dzMinimum password length: %dzMinimum password age (days): %dzMaximum password age (days): %dz#Account lockout duration (mins): %dz(Account lockout threshold (attempts): %dz&Reset account lockout after (mins): %d)get_loadparmget_credentialsr   r   	domain_dnsearchldb
SCOPE_BASElenintr   r   	Exceptionr   messager   r   )selfr   r   r   r   r%   credssamdbr4   res	pwd_propspwd_hist_lencur_min_pwd_lencur_min_pwd_agecur_max_pwd_agecur_account_lockout_thresholdcur_account_lockout_durationcur_reset_account_lockout_afteres                      F/usr/lib/python3/dist-packages/samba/netcmd/domain/passwordsettings.pyrun$cmd_domain_passwordsettings_show.run5   sX   ##%((,!.*:"'0 OO%	ll9CNN">  ? 3x1}}	MCF?3A67Is1v&89!<=L!#a&"8";<O/A{0CA0FGO/A{0CA0FGO,/A7I0J10M,N) ,=SVDU=VWX=Y+Z(.?AGa@bcd@e.f+ 	;iGHR..!3LL23LL3466!;LL89LL9:2\AB2_DE6HI6HI:=YYZ?B__`=@__`'  	MH!LL	Ms   8B H* *
I4I  I )NNNN__name__
__module____qualname____firstlineno____doc__synopsisoptionsSambaOptionsVersionOptionsCredentialsOptionstakes_optiongroupsr   strtakes_optionsrJ   __static_attributes__rL       rI   r   r   %   sU    ; H ))--.. 	tW#JQT3	(M
-ar\   r   c                   *   \ rS rSrSrSr\R                  \R                  \R                  S.r
\" SSS\SS	S
9\" SSSSS9\" SS/ SQSS9\" SS/ SQSS9\" SS\S9\" SS\S9\" SS\S9\" SS\S9\" S S!\S9\" S"S#\S9\" S$S%\S9/r     S)S' jrS(rg&)*cmd_domain_passwordsettings_sete   zSet password settings.

Password complexity, password lockout policy, history length,
minimum password length, the minimum and maximum password age) on
a Samba AD DC server.

Use against a Windows DC is possible, but group policy will override it.
z%prog <options> [options]r   r   r   r   r   r   r   z-qz--quietzBe quiet
store_true)r   actionz--complexitychoice)onoffdefaultz=The password complexity (on | off | default). Default is 'on')r   choicesr   z--store-plaintextzStore plaintext passwords where account have 'store passwords with reversible encryption' set (on | off | default). Default is 'off'z--history-lengthzBThe password history length (<integer> | default).  Default is 24.)r   r   z--min-pwd-lengthzAThe minimum password length (<integer> | default).  Default is 7.z--min-pwd-agezFThe minimum password age (<integer in days> | default).  Default is 1.z--max-pwd-agezGThe maximum password age (<integer in days> | default).  Default is 43.z--account-lockout-durationzThe length of time an account is locked out after exceeding the limit on bad password attempts (<integer in mins> | default).  Default is 30 mins.z--account-lockout-thresholdzThe number of bad password attempts allowed before locking out the account (<integer> | default).  Default is 0 (never lock out).z--reset-account-lockout-afterzuAfter this time is elapsed, the recorded number of attempts restarts from zero (<integer> | default).  Default is 30.Nc                 
   UR                  5       nUR                  U5      n[        U[        5       UUS9nUR	                  5       n/ n[
        R                  " 5       n[
        R                  " UU5      Ul        [        UR                  5       5      nUR                  5       nUR                  5       nUbH  US:X  d  US:X  a  U[        -  nUR                  S5        O!US:X  a  U[        ) -  nUR                  S5        UbH  US:X  d  US:X  a  U[        -  nUR                  S5        O!US:X  a  U[        ) -  nUR                  S5        Uc  Ub2  [
        R                   " [#        U5      [
        R$                  S	5      US	'   Ubn  US:X  a  S
nO[        U5      nUS:  d  US
:  a  ['        S5      e[
        R                   " [#        U5      [
        R$                  S5      US'   UR                  S5        Ubn  US:X  a  SnO[        U5      nUS:  d  US:  a  ['        S5      e[
        R                   " [#        U5      [
        R$                  S5      US'   UR                  S5        Ub}  US:X  a  SnO[        U5      nUS:  d  US:  a  ['        S5      e[        US-  5      * n[
        R                   " [#        U5      [
        R$                  S5      US'   UR                  S5        Ub  US:X  a  SnO[        U5      nUS:  d  US:  a  ['        S5      eUS:X  a  [(        nO[        US-  5      * n[
        R                   " [#        U5      [
        R$                  S5      US'   UR                  S5        U	b  U	S:X  a  Sn	O[        U	5      n	U	S:  d  U	S :  a  ['        S!5      eU	S:X  a  [(        nO[        U	S"-  5      * n[
        R                   " [#        U5      [
        R$                  S#5      US#'   UR                  S$5        U
bW  U
S:X  a  Sn
O[        U
5      n
[
        R                   " [#        U
5      [
        R$                  S%5      US%'   UR                  S&5        Ub  US:X  a  SnO[        U5      nUS:  d  US :  a  ['        S'5      eUS:X  a  [(        nO[        US"-  5      * n[
        R                   " [#        U5      [
        R$                  S(5      US('   UR                  S)5        U(       d  U(       a0  [+        U5      n[+        U5      nUS:w  a  X#:  a  ['        S*X24-  5      e[-        U5      S:X  a  ['        S+5      eUR/                  U5        UR                  S,5        U R1                  S-R3                  U5      5        g ).Nr!   rc   re   zPassword complexity activated!rd   z Password complexity deactivated!z;Plaintext password storage for changed passwords activated!z=Plaintext password storage for changed passwords deactivated!r&      r   z8Password history length must be in the range of 0 to 24!r'   z Password history length changed!      z8Minimum password length must be in the range of 0 to 14!r(   z Minimum password length changed!r0   i  z6Minimum password age must be in the range of 0 to 998!g   8M%iBr)   zMinimum password age changed!+   i  z6Maximum password age must be in the range of 0 to 999!r*   zMaximum password age changed!   i z<Account lockout duration must be in the range of 0 to 99999!g    Ar+   z!Account lockout duration changed!r,   z"Account lockout threshold changed!z8Maximum password age must be in the range of 0 to 99999!r-   z0Duration to reset account lockout after changed!zIMaximum password age (%d) must be greater than minimum password age (%d)!z7You must specify at least one option to set. Try --helpz!All changes applied successfully!
)r2   r3   r   r   r4   r6   MessageDndnr9   get_pwdPropertiesget_maxPwdAgeget_minPwdAger   appendr   MessageElementrY   FLAG_MOD_REPLACEr   r
   r   r8   modifyr;   join)r<   r   min_pwd_agemax_pwd_agequiet
complexitystore_plaintexthistory_lengthmin_pwd_lengthaccount_lockout_durationaccount_lockout_thresholdreset_account_lockout_afterr   r   r   r%   r=   r>   r4   msgsmr@   max_pwd_age_ticksmin_pwd_age_ticksrA   min_pwd_lenaccount_lockout_duration_ticks!reset_account_lockout_after_tickss                               rI   rJ   #cmd_domain_passwordsettings_set.run   s   
 ##%((,!.*:"'B0 OO%	KKMvveY'//12	 "//1!//1!T!Z9%<%(??	<=u$%*A)AB	>?&$&/Y*F%(GG	YZ E)%*I)IJ	[\!_%@!$!3!3C	N474H4H/"[Ao %*!">2a<"#4"#]^^$'$6$6s<7H7:7K7KM_%aA !KK:;%*!.1Q+"2"#]^^ # 2 23{3C363G3G!YAnKK:;"i'!+.Q+"3"#[\\ "%[4F%G!H H //4E0F030D0DkSAkNKK78"i' !+.Q+"3"#[\\ a$3!%(8J)K%L$L! //4E0F030D0DkSAkNKK78#/'94+-(+./G+H('!+/G%/O" $I J J (1,1@.256NRZ6[2\1\.#&#5#5c:X6Y696J6JL]$_A KK;<$0(I5,-),/0I,J)$'$6$6s;T7U7:7K7KM_%aA !KK<=&2*i7.0+.12M.N+*Q.2MPU2U"#]^^ +a/4C1589TX`9a5b4b1,/,>,>sCd?e?B?S?SUo-qA()KKJK+ ,,=>K+,=>KaK$>"#nr}  rL  $L  M  Mq6Q;XYYQ78TYYt_%r\   rL   )NNNFNNNNNNNNNNrM   rL   r\   rI   r^   r^   e   s3    +H ))--.. 	tW#JQT3	(tYZE~H6NS	U";S [	\!X_b	d!W^a	c\cf	h]dg	i+ i  ps	t, X  _b	c. L  SV	W)M0 9=OSZ^GK	d&r\   r^   c                   X    \ rS rSrSr0 r\" 5       \S'   \" 5       \S'   \" 5       \S'   Sr	g)cmd_domain_passwordsettingsi6  z Manage password policy settings.psoshowsetrL   N)
rN   rO   rP   rQ   rR   subcommandsr   r   r^   r[   rL   r\   rI   r   r   6  s1    *K8:K:<K8:Kr\   r   )r6   samba.getoptgetoptrT   
samba.authr   samba.dcerpc.samrr   r   samba.netcmdr   r   r   r	   samba.netcmd.commonr
   r   r   samba.netcmd.psor   samba.samdbr   r   r^   r   rL   r\   rI   <module>r      sV   2   %@ D D4 4 < =aw =a@N&g N&b;, ;r\   