HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/samba/tests/__pycache__/pso.cpython-310.pyc
o

�/a�,�@sLddlZddlmZmZmZddlmZmZGdd�d�ZGdd�d�ZdS)�N)�FLAG_MOD_DELETE�FLAG_MOD_ADD�FLAG_MOD_REPLACE)�DOMAIN_PASSWORD_COMPLEX�DOMAIN_PASSWORD_STORE_CLEARTEXTc@sVeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)�TestUserNcCsfd}||_||_d||p
d|j��f|_|g|_|g|_|jj|||d�|j�d|�d|_dS)Nz
Initial12#zCN=%s,%s,%szCN=Users)�userouz(sAMAccountName=%s))	�name�ldb�	domain_dn�dn�all_old_passwords�pwd_history�newuser�enable_account�last_pso)�self�username�samdbr�initial_password�r�1/usr/lib/python3/dist-packages/samba/tests/pso.py�__init__s
�
zTestUser.__init__cCs|dkrgS|j|d�S)z0Returns the expected password history for the DCrN)r�r�hist_lenrrr�old_invalid_passwords-szTestUser.old_invalid_passwordscCs6|dkr|jdd�Stt|j�|�}|jd|�S)zAReturns old passwords that fall outside the DC's expected historyrN)r
�min�lenrrrrr�old_valid_passwords5szTestUser.old_valid_passwordscCsH||jvr|j�|�|j�|�||jvr|j�|�|j�|�dS)z@Updates the user's password history to reflect a password changeN)r
�remove�appendr)r�new_passwordrrr�update_pwd_historyCs

zTestUser.update_pwd_historycCs8|jj|jdgd�}d|dvrt|ddd�SdS)z=Returns the DN of the applicable PSO, or None if none applieszmsDS-ResultantPSO)�attrsrN)r
�searchr�str)r�resrrr�get_resultant_PSORszTestUser.get_resultant_PSOcCs
|jdS)z#Returns the user's current password���)r
)rrrr�get_password[s
zTestUser.get_passwordcCs.d|j|��|f}|j�|�|�|�dS)z$Attempts to change a user's passwordzd
dn: %s
changetype: modify
delete: userPassword
userPassword: %s
add: userPassword
userPassword: %s
N)rr)r
�modify_ldifr")rr!�ldifrrr�set_password`s
�zTestUser.set_passwordcCsbt||�}|dkr
g|_n|t|j�kr|j|d�|_|dkr-|dkr/|��g|_dSdSdS)ay
        Updates the effective password history, to reflect changes on the DC.
        When the PasswordHistoryLength applied to a user changes from a low
        setting (e.g. 2) to a higher setting (e.g. 4), passwords #3 and #4
        won't actually have been stored on the DC, so we need to make sure they
        are removed them from our mirror pwd_history list.
        rN)rrrr))r�old_hist_len�new_hist_lenrrrr�pwd_history_changeps
�zTestUser.pwd_history_changecCs^|jj|dgtjd�}|dd}t��}t�|j|j�|_t�|td�|d<|j�|�dS)z>Sets a user's primaryGroupID to be that of the specified group�primaryGroupToken)�baser#�scoper�primaryGroupIDN)	r
r$�
SCOPE_BASE�Message�Dnr�MessageElementr�modify)r�group_dnr&�group_id�mrrr�set_primary_group�s��zTestUser.set_primary_group�N)�__name__�
__module__�__qualname__rrrr"r'r)r,r/r<rrrrrs
	rc@sLeZdZdd�Z				
ddd�Zd
d�Zefdd�Zdd�Zddd�Z	d
S)�PasswordSettingscCs0gd�}|j|��tj|d�}d|_d|_||_d|_t|ddd�t@|_	t|ddd�t
@|_t|ddd�|_t|ddd�|_
t|dd	d�|_t|dd
d�td�|_t|ddd�td�|_t|dd
d�td�|_t|ddd�td�|_dS)z�
        Returns a object representing the default password settings that will
        take effect (i.e. when no other Fine-Grained Password Policy applies)
        )	�	minPwdAge�lockoutDuration�lockOutObservationWindow�lockoutThreshold�	maxPwdAgerB�minPwdLength�pwdHistoryLength�
pwdProperties)r2r#�DefaultsNrrIrGrErHrC��cArDrBrF)r$rr
r4r	r�
precedence�intr�
complexityr�store_plaintext�password_len�lockout_attempts�history_len�lockout_duration�lockout_window�password_age_min�password_age_max)rr�pw_attrsr&rrr�default_settings�s(��� � $z!PasswordSettings.default_settings�
Tr���'�FNc
Cs�|dur	|�|�S|dur|��}
d|
}||_d||f|_||_||_||_||_||_||_	|
|_
||_||_||_
|	|_|j�|���dS)Nz+CN=Password Settings Container,CN=System,%szCN=%s,%s)rXrr	rr
rLrNrOrPrQrRrSrTrUrV�add_ldif�get_ldif)rr	rrLrNrPrQrSrUrVrRrO�	container�base_dnrrrr�s&
zPasswordSettings.__init__c
Cs�|jrdnd}|jrdnd}t|jd�}t|jd�}t|jd�}t|jd�}d�|j|j	||j
||j|||j||�}|S)N�TRUE�FALSErKav
dn: {0}
objectClass: msDS-PasswordSettings
msDS-PasswordSettingsPrecedence: {1}
msDS-PasswordReversibleEncryptionEnabled: {2}
msDS-PasswordHistoryLength: {3}
msDS-PasswordComplexityEnabled: {4}
msDS-MinimumPasswordLength: {5}
msDS-MinimumPasswordAge: {6}
msDS-MaximumPasswordAge: {7}
msDS-LockoutThreshold: {8}
msDS-LockoutObservationWindow: {9}
msDS-LockoutDuration: {10}
)
rNrOrMrSrTrUrV�formatrrLrRrPrQ)r�complexity_str�
plaintext_strrSrT�min_age�max_ager+rrrr^�s
��zPasswordSettings.get_ldifcCs<t��}t�|j|j�|_t�||d�|d<|j�|�dS)zAUpdates this Password Settings Object to apply to a user or groupzmsDS-PSOAppliesToN)r
r5r6rr7r8)r�
user_group�	operationr;rrr�apply_to�s�zPasswordSettings.apply_tocCs|j|td�dS)z6Updates this PSO to no longer apply to a user or group)riN)rjr)rrhrrr�unapplyszPasswordSettings.unapplycCs0|dur|j}d|j|f}|�|�||_dS)Nzh
dn: %s
changetype: modify
replace: msDS-PasswordSettingsPrecedence
msDS-PasswordSettingsPrecedence: %u
)r
rr*rL)r�new_precedencerr+rrr�set_precedences�

zPasswordSettings.set_precedence)
rYTrYrrZrr[r\FNr=)
r>r?r@rXrr^rrjrkrmrrrrrA�s
�$rA)	r
rrr�samba.dcerpc.samrrrrrArrrr�<module>s
|