Mini Shell

Direktori : /lib64/python3.6/site-packages/pyanaconda/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/pyanaconda/__pycache__/input_checking.cpython-36.pyc

3

C��eZd�@s2ddlZddlmZddlmZddlmZmZddlmZddl	m
Z
e
e�Zdd�Z
Gd	d
�d
e�Ze�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�ZGd!d"�d"e�ZdS)#�N)�Signal)�_)�	constants�regexes)�users)�get_module_loggercCs |jjj|�}|s|jj�}|S)z�Get a policy corresponding to the name or default policy.

    If no policy is found for the name the default policy is returned.
    )ZanacondaZpwpolicy�
get_policyZPwPolicyData)Zkickstart_dataZpolicy_name�policy�r
�&/usr/lib64/python3.6/input_checking.pyr s
rc@s eZdZdZdd�Zdd�ZdS)�PwqualitySettingsCachea1Cache for libpwquality settings used for password validation.

    Libpwquality settings instantiation is probably not exactly cheap
    and we might need the settings for checking every password (even when
    it is being typed by the user) so it makes sense to cache the objects
    for reuse. As there might be multiple active policies for different
    passwords we need to be able to cache multiple policies based on
    minimum password length, as we don't input anything else to libpwquality
    than minimum password length and the password itself.
    cCs
i|_dS)N)�
_pwq_settings)�selfr
r
r�__init__6szPwqualitySettingsCache.__init__cCs8|jj|�}|dkr4tj�}|j�||_||j|<|S)N)r
�get�	pwqualityZPWQSettingsZread_config�minlen)rrZsettingsr
r
r�get_settings_by_minlen9s
z-PwqualitySettingsCache.get_settings_by_minlenN)�__name__�
__module__�__qualname__�__doc__rrr
r
r
rr+s
rc@s�eZdZdZdd�Zedd��Zejdd��Zedd��Zejd	d��Zed
d��Z	e	jdd��Z	ed
d��Z
edd��Zejdd��Zedd��Zejdd��Zedd��Z
e
jdd��Z
dS)�PasswordCheckRequestz�A wrapper for a password check request.

    This in general means the password to be checked as well as its validation criteria
    such as minimum length, if it can be empty, etc.
    cCs2d|_d|_d|_d|_d|_d|_tjj|_	dS)N��root)
�	_password�_password_confirmation�_policy�_pwquality_settings�	_username�	_fullnamer�
SecretType�PASSWORD�_secret_type)rr
r
rrMszPasswordCheckRequest.__init__cCs|jS)zlPassword string to be checked.

        :returns: password string for the check
        :rtype: str
        )r)rr
r
r�passwordVszPasswordCheckRequest.passwordcCs
||_dS)N)r)rZnew_passwordr
r
rr$_scCs|jS)zxContent of the password confirmation field.

        :returns: password confirmation string
        :rtype: str
        )r)rr
r
r�password_confirmationcsz*PasswordCheckRequest.password_confirmationcCs
||_dS)N)r)rZnew_password_confirmationr
r
rr%lscCs|jS)zLPassword quality policy.

        :returns: password quality policy
        )r)rr
r
rr	pszPasswordCheckRequest.policycCs
||_dS)N)r)rZ
new_policyr
r
rr	xscCs|jstj|jj�|_|jS)z�Settings for libpwquality (if any).

        :returns: libpwquality settings
        :rtype: pwquality settings object or None
        )r�pwquality_settings_cacherr	r)rr
r
r�pwquality_settings|sz'PasswordCheckRequest.pwquality_settingscCs|jS)aThe username for which the password is being set.

        If no username is provided, "root" will be used.
        Use username=None to disable the username check.

        :returns: username corresponding to the password
        :rtype: str or None
        )r)rr
r
r�username�s
zPasswordCheckRequest.usernamecCs
||_dS)N)r)r�new_usernamer
r
rr(�scCs|jS)z�The full name of the user for which the password is being set.

        If no full name is provided, "root" will be used.

        :returns: full user name corresponding to the password
        :rtype: str or None
        )r )rr
r
r�fullname�s	zPasswordCheckRequest.fullnamecCs
||_dS)N)r )r�new_fullnamer
r
rr*�scCs|jS)z�Type of secret that is being checked.

        At the moment is either a password or a passphrase and this property decides how it will be
        called in error and status messages.

        :returns: secret type
        :rtype: Enum
        )r#)rr
r
r�secret_type�s
z PasswordCheckRequest.secret_typecCs"|tjkrtdj|���||_dS)zYSet type of secret being checked.

        :param Enum new_type: new secret type
        zUnknown secret type: {}N)rr!�RuntimeError�formatr#)r�new_typer
r
rr,�s	
N)rrrrr�propertyr$�setterr%r	r'r(r*r,r
r
r
rrFs			rc@sLeZdZdZdd�Zedd��Zejdd��Zedd��Zejd	d��Zd
S)�CheckResultzResult of an input check.cCsd|_d|_t�|_dS)NFr)�_success�_error_messager�error_message_changed)rr
r
rr�szCheckResult.__init__cCs|jS)N)r3)rr
r
r�success�szCheckResult.successcCs
||_dS)N)r3)r�valuer
r
rr6�scCs|jS)z�Optional error message describing why the input is not valid.

        :returns: why the input is bad (provided it is bad) or None
        :rtype: str or None
        )r4)rr
r
r�
error_message�szCheckResult.error_messagecCs||_|jj|�dS)N)r4r5�emit)rZnew_error_messager
r
rr8�sN)	rrrrrr0r6r1r8r
r
r
rr2�s	r2cs�eZdZdZ�fdd�Zedd��Zejdd��Zedd��Zejd	d��Zed
d��Z	e	jdd��Z	ed
d��Z
e
jdd��Z
�ZS)�PasswordValidityCheckResultz+A wrapper for results for a password check.csFt�j�d|_t�|_d|_t�|_d|_t�|_d|_	t�|_
dS)NrrF)�superr�_password_scorer�password_score_changed�_status_text�status_text_changed�_password_quality�password_quality_changed�
_length_ok�length_ok_changed)r)�	__class__r
rr�s
z$PasswordValidityCheckResult.__init__cCs|jS)z�A high-level integer score indicating password quality.

        Goes from 0 (invalid password) to 4 (valid & very strong password).
        Mainly used to drive the password quality indicator in the GUI.
        )r<)rr
r
r�password_score�sz*PasswordValidityCheckResult.password_scorecCs||_|jj|�dS)N)r<r=r9)rZ	new_scorer
r
rrE�scCs|jS)z�A short overall status message describing the password.

        Generally something like "Good.", "Too short.", "Empty.", etc.

        :rtype: short status message
        :rtype: str
        )r>)rr
r
r�status_text�s	z'PasswordValidityCheckResult.status_textcCs||_|jj|�dS)N)r>r?r9)rZnew_status_textr
r
rrFscCs|jS)aiMore fine grained integer indicator describing password strength.

        This basically exports the quality score assigned by libpwquality to the password,
        which goes from 0 (unacceptable password) to 100 (strong password).

        Note of caution though about using the password quality value - it is intended
        mainly for on-line password strength hints, not for long-term stability,
        even just because password dictionary updates and other peculiarities of password
        strength judging.

        :returns: password quality value as reported by libpwquality
        :rtype: int
        )r@)rr
r
r�password_qualitysz,PasswordValidityCheckResult.password_qualitycCs||_|jj|�dS)N)r@rAr9)rr7r
r
rrGscCs|jS)zwReports if the password is long enough.

        :returns: if the password is long enough
        :rtype: bool
        )rB)rr
r
r�	length_ok!sz%PasswordValidityCheckResult.length_okcCs||_|jj|�dS)N)rBrCr9)rr7r
r
rrH*s)rrrrrr0rEr1rFrGrH�
__classcell__r
r
)rDrr:�s		r:c@sFeZdZdZdd�Zedd��Zedd��Zejdd��Zd	d
�Z	dS)�
InputCheckzInput checking base class.cCst�|_d|_dS)NF)r2�_result�_skip)rr
r
rr3szInputCheck.__init__cCs|jS)N)rK)rr
r
r�result7szInputCheck.resultcCs|jS)z/A flag hinting if this check should be skipped.)rL)rr
r
r�skip;szInputCheck.skipcCs|rd|j_d|j_||_dS)NrT)rMr8r6rL)rr7r
r
rrN@scCst�dS)z�Run the check.

        :param check_request: arbitrary input data to be processed

        Subclasses need to always implement this.
        N)�NotImplementedError)r�
check_requestr
r
r�runKszInputCheck.runN)
rrrrrr0rMrNr1rQr
r
r
rrJ0srJcs(eZdZdZ�fdd�Zdd�Z�ZS)�PasswordValidityCheckz-Check the validity and quality of a password.cst�j�t�|_dS)N)r;rr:rK)r)rDr
rrXs
zPasswordValidityCheck.__init__c	Cszd}d}d}y|jj|jd|j�}Wn.tjk
rR}z|jd}WYdd}~XnX|jjrxt	|j�|jj
kpt|j}nt	|j�|jj
k}|js�|jjr�d}nd}ttj
jj�}n�|s�d}ttj
jj�}ttj|j�}nf|r�d}ttj
jj�}nN|dk�rd}ttj
jj�}n0|dk�r.d	}ttj
jj�}nd
}ttj
jj�}|}||j_||j_||j_||j_||j_||j_dS)a�Check the validity and quality of a password.

           This is how password quality checking works:
           - starts with a password and an optional parameters
           - will report if this password can be used at all (score >0)
           - will report how strong the password approximately is on a scale of 1-100
           - if the password is unusable it will be reported why

           This function uses libpwquality to check the password strength.
           Pwquality will raise a PWQError on a weak password but this function does
           not pass that forward.

           If the password fails the PWQSettings conditions, the score will be set to 0
           and the resulting error message will contain the reason why the password is bad.

           :param check_request: a password check request wrapper
           :type check_request: a PasswordCheckRequest instance
           :returns: a password check result wrapper
           :rtype: a PasswordCheckResult instance
        FrrN����F��)r'�checkr$r(rZPWQError�argsr	Zemptyok�lenrrrZSecretStatusZEMPTYr7Z	TOO_SHORTZSECRET_TOO_SHORTr,ZWEAKZFAIRZGOODZSTRONGrMr6rErFrGr8rH)	rrPrHr8Z
pw_quality�eZpw_scorerFr6r
r
rrQ\sJ

zPasswordValidityCheck.run)rrrrrrQrIr
r
)rDrrRUsrRcsBeZdZdZ�fdd�Zedd��Zejdd��Zdd�Z�Z	S)	�PasswordConfirmationCheckz4Check if the password & password confirmation match.cst�j�d|_dS)NF)r;r�_success_if_confirmation_empty)r)rDr
rr�s
z"PasswordConfirmationCheck.__init__cCs|jS)a�Enables success-if-confirmation-empty mode.

        This property can be used to tell the check to report success if the confirmation filed is empty,
        which is a paradigm used by Anaconda uses for two things:
        - to make it possible for users to exit without setting a valid password
        - to make it possible to exit the spoke if only the password is set
          but confirmation is empty
        )r^)rr
r
r�success_if_confirmation_empty�s
z7PasswordConfirmationCheck.success_if_confirmation_emptycCs
||_dS)N)r^)rr7r
r
rr_�scCs^|jr |jr d|j_d|j_n:|j|jkrJttj|j	�|j_d|j_nd|j_d|j_dS)zQIf the user has entered confirmation data, check whether it matches the password.rTFN)
r_r%rMr8r6r$rrZSECRET_CONFIRM_ERROR_GUIr,)rrPr
r
rrQ�s

zPasswordConfirmationCheck.run)
rrrrrr0r_r1rQrIr
r
)rDrr]�s
r]c@seZdZdZdd�ZdS)�PasswordASCIICheckz�Check if the password contains non-ASCII characters.

    Non-ASCII characters might be hard to type in the console and in the LUKS volume unlocking
    screen, so check if the password contains them so we can warn the user.
    cCsPtdd�|jD��}|jr<|r<ttj|j�|j_d|j_nd|j_d|j_dS)z3Fail if the password contains non-ASCII characters.css|]}|tjkVqdS)N)rZPW_ASCII_CHARS)�.0�charr
r
r�	<genexpr>�sz)PasswordASCIICheck.run.<locals>.<genexpr>FrTN)	�anyr$rrZSECRET_ASCIIr,rMr8r6)rrPZ
has_non_ASCIIr
r
rrQ�s

zPasswordASCIICheck.runN)rrrrrQr
r
r
rr`�sr`c@seZdZdZdd�ZdS)�PasswordEmptyCheckzCheck if the password is set.cCs8|jrd|j_d|j_nttj|j�|j_d|j_dS)z3Check whether a password has been specified at all.rTFN)r$rMr8r6rrZSECRET_EMPTY_ERRORr,)rrPr
r
rrQ�s

zPasswordEmptyCheck.runN)rrrrrQr
r
r
rre�srecsBeZdZdZ�fdd�Zedd��Zejdd��Zdd�Z�Z	S)	�
UsernameCheckzCheck if the username is valid.cst�j�d|_dS)NF)r;r�_success_if_username_empty)r)rDr
rr�s
zUsernameCheck.__init__cCs|jS)z/Should empty username be considered a success ?)rg)rr
r
r�success_if_username_empty�sz'UsernameCheck.success_if_username_emptycCs
||_dS)N)rg)rr7r
r
rrh�scCsD|jr |jr d|j_d|j_n tj|j�\}}||j_||j_dS)zCheck if the username is valid.rTN)rhr(rMr8r6rZcheck_username)rrPr6r8r
r
rrQs
zUsernameCheck.run)
rrrrrr0rhr1rQrIr
r
)rDrrf�s
rfc@seZdZdZdd�ZdS)�
FullnameCheckzjCheck if the full user name is valid.

    Most importantly the full user name cannot contain colons.
    cCs8tjj|j�r d|j_d|j_ntd�|j_d|j_dS)z%Check if the full user name is valid.rTz)Full name cannot contain colon charactersFN)rZGECOS_VALID�matchr*rMr8r6r)rrPr
r
rrQs

zFullnameCheck.runN)rrrrrQr
r
r
rrisric@s2eZdZdZdd�Zedd��Zejdd��ZdS)�
InputFieldz�An input field containing data to be checked.

    The input field can have an initial value that can be
    monitored for change via signals.
    cCs&||_||_t�|_d|_t�|_dS)NF)�_initial_content�_contentr�changed�_initial_change_signal_fired�changed_from_initial_state)rZinitial_contentr
r
rr&s
zInputField.__init__cCs|jS)N)rm)rr
r
r�content-szInputField.contentcCsD|j}||_||kr@|jj�|jr@||jkr@|jj�d|_dS)NT)rmrnr9rorlrp)rZnew_contentZold_contentr
r
rrq1s

N)rrrrrr0rqr1r
r
r
rrksrkc@s�eZdZdZdd�Zedd��Zedd��Zedd	��Zed
d��Z	edd
��Z
edd��Zedd��Zedd��Z
edd��Zejdd��Zedd��Zejdd��Zedd��Zejdd��Zdd�Zdd �Zd!S)"�PasswordCheckera�Run multiple password and input checks in a given order and report the results.

    All added checks (in insertion order) will be run and results returned as error message
    and success value (True/False). If any check fails success will be False and the
    error message of the first check to fail will be returned.

    It's also possible to mark individual checks to be skipped by setting their skip property to True.
    Such check will be skipped during the checking run.
    cCszt|�|_t|�|_g|_d|_d|_g|_g|_||_d|_	d|_
tjj
|_|jjj|j�|jjj|j�t�|_dS)NFr)rkrr�_checksr3r4�_failed_checks�_successful_checksrrr rr!r"r#r$rnZconnect�
run_checksr%r�checks_done)rZinitial_password_contentZ%initial_password_confirmation_contentr	r
r
rrIs


zPasswordChecker.__init__cCs|jS)zMain password field.)r)rr
r
rr$]szPasswordChecker.passwordcCs|jS)zPassword confirmation field.)r)rr
r
rr%bsz%PasswordChecker.password_confirmationcCs|jS)N)rs)rr
r
r�checksgszPasswordChecker.checkscCs|jS)N)r3)rr
r
rr6kszPasswordChecker.successcCs|jS)N)r4)rr
r
rr8oszPasswordChecker.error_messagecCs|jS)z�List of successful checks during the last checking run.

        If no checks have succeeded the list will be empty.

        :returns: list of successful checks (if any)
        :rtype: list
        )ru)rr
r
r�successful_checksss	z!PasswordChecker.successful_checkscCs|jS)z�List of checks failed during the last checking run.

        If no checks have failed the list will be empty.

        :returns: list of failed checks (if any)
        :rtype: list
        )rt)rr
r
r�
failed_checks~s	zPasswordChecker.failed_checkscCs|jS)N)r)rr
r
rr	�szPasswordChecker.policycCs|jS)N)r)rr
r
rr(�szPasswordChecker.usernamecCs
||_dS)N)r)rr)r
r
rr(�scCs|jS)z�The full name of the user for which the password is being set.

        If no full name is provided, "root" will be used.

        :returns: full user name corresponding to the password
        :rtype: str or None
        )r )rr
r
rr*�s	zPasswordChecker.fullnamecCs
||_dS)N)r )rr+r
r
rr*�scCs|jS)z�Type of secret that is being checked.

        At the moment is either a password or a passphrase and this property decides how it will be
        called in error and status messages.

        :returns: secret type
        :rtype: Enum
        )r#)rr
r
rr,�s
zPasswordChecker.secret_typecCs"|tjkrtdj|���||_dS)zYSet type of secret being checked.

        :param Enum new_type: new secret type
        zUnknown secret type: {}N)rr!r-r.r#)rr/r
r
rr,�s	
cCs|jj|�dS)z%Add check instance to list of checks.N)rs�append)rZcheck_instancer
r
r�	add_check�szPasswordChecker.add_checkcCs�t�}|jj|_|jj|_|j|_|j|_|j|_|j|_g|_d}xN|j	D]D}|j
sL|j|�|jj
rv|jj|�qL|js�|jj}|jj|�qLW|jr�||_d|_nd|_d|_|jj|j�dS)NrFT)rr$rqr%r	r(r*r,rtrxrNrQrMr6rur{rzr8r4r3rwr9)rrPr8rYr
r
rrv�s.


zPasswordChecker.run_checksN)rrrrrr0r$r%rxr6r8ryrzr	r(r1r*r,r|rvr
r
r
rrr>s$	
rr)rZpyanaconda.core.signalrZpyanaconda.core.i18nrZpyanaconda.corerrrZpyanaconda.anaconda_loggersrr�logr�objectrr&rr2r:rJrRr]r`rerfrirkrrr
r
r
r�<module>s*zQ%X$