
    Id9                         d dl 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mZmZ d dlmZmZmZ d dlmZ d dlmZ  G d d	e
      Z G d
 de
      Z G d de      Zy)    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                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZddZy
) cmd_domain_passwordsettings_showz1Display 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                    |j                         }|j                  |      }t        |t               ||      }|j	                         }|j                  |t        j                  g d      }	t        |	      dk(  sJ 	 t        |	d   d   d         }
t        |	d   d   d         }t        |	d   d   d         }t        |	d   d	   d         }t        |	d   d
   d         }t        |	d   d   d         }t        |	d   d   d         }t        |	d   d   d         }| j                  d|z         | j                  d       |
t        z  dk7  r| j                  d       n| j                  d       |
t         z  dk7  r| j                  d       n| j                  d       | j                  d|z         | j                  d|z         | j                  d|z         | j                  d|z         | j                  d|z         | j                  d|z         | j                  d|z         y # t        $ r}t        d|      d }~ww xY w)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samdbr3   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runz$cmd_domain_passwordsettings_show.run5   sZ   ##%((,!.*:"'B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   >B H. .	I7II)NNNN__name__
__module____qualname____doc__synopsisoptionsSambaOptionsVersionOptionsCredentialsOptionstakes_optiongroupsr   strtakes_optionsrI        rH   r   r   %   sU    ; H ))--.. 	tW#JQT3	(M
-arX   r   c                   b   e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	       e
d
ddd       e
ddg dd       e
ddg dd       e
dde       e
dde       e
dde       e
dde       e
dd e       e
d!d"e       e
d#d$e      gZ	 	 	 	 	 d'd&Zy%)(cmd_domain_passwordsettings_seta  Set 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                 
   |j                         }|j                  |      }t        |t               ||      }|j	                         }g }t        j                         }t        j                  ||      |_        t        |j                               }|j                         }|j                         }|E|dk(  s|dk(  r|t        z  }|j                  d       n |dk(  r|t         z  }|j                  d       |E|dk(  s|dk(  r|t        z  }|j                  d       n |dk(  r|t         z  }|j                  d       ||1t        j                   t#        |      t
        j$                  d	      |d	<   |j|dk(  rd
}nt        |      }|dk  s|d
kD  rt'        d      t        j                   t#        |      t
        j$                  d      |d<   |j                  d       |j|dk(  rd}nt        |      }|dk  s|dkD  rt'        d      t        j                   t#        |      t
        j$                  d      |d<   |j                  d       |y|dk(  rd}nt        |      }|dk  s|dkD  rt'        d      t        |dz         }t        j                   t#        |      t
        j$                  d      |d<   |j                  d       ||dk(  rd}nt        |      }|dk  s|dkD  rt'        d      |dk(  rt(        }nt        |dz         }t        j                   t#        |      t
        j$                  d      |d<   |j                  d       |	|	dk(  rd}	nt        |	      }	|	dk  s|	d kD  rt'        d!      |	dk(  rt(        }nt        |	d"z         }t        j                   t#        |      t
        j$                  d#      |d#<   |j                  d$       |
U|
dk(  rd}
nt        |
      }
t        j                   t#        |
      t
        j$                  d%      |d%<   |j                  d&       ||dk(  rd}nt        |      }|dk  s|d kD  rt'        d'      |dk(  rt(        }nt        |d"z         }t        j                   t#        |      t
        j$                  d(      |d(<   |j                  d)       |s|r0t+        |      }t+        |      }|dk7  r||k\  rt'        d*||fz        t-        |      dk(  rt'        d+      |j/                  |       |j                  d,       | j1                  d-j3                  |             y ).Nr    r^   r`   zPassword complexity activated!r_   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!r/   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!
)r1   r2   r   r   r3   r5   MessageDndnr8   get_pwdPropertiesget_maxPwdAgeget_minPwdAger   appendr   MessageElementrU   FLAG_MOD_REPLACEr   r
   r   r7   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=   r3   msgsmr?   max_pwd_age_ticksmin_pwd_age_ticksr@   min_pwd_lenaccount_lockout_duration_ticks!reset_account_lockout_after_tickss                               rH   rI   z#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}  @K  rL  $L  M  Mq6Q;XYYQ78TYYt_%rX   )NNNFNNNNNNNNNNrJ   rW   rX   rH   rZ   rZ   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&rX   rZ   c                   P    e Zd ZdZi Z e       ed<    e       ed<    e       ed<   y)cmd_domain_passwordsettingsz Manage password policy settings.psoshowsetN)rK   rL   rM   rN   subcommandsr   r   rZ   rW   rX   rH   r   r   6  s1    *K8:K:<K8:KrX   r   )r5   samba.getoptgetoptrP   
samba.authr   samba.dcerpc.samrr   r   samba.netcmdr   r   r   r	   samba.netcmd.commonr
   r   r   samba.netcmd.psor   samba.samdbr   r   rZ   r   rW   rX   rH   <module>r      sV   2   %@ D D4 4 < =aw =a@N&g N&b;, ;rX   