%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.9/site-packages/cloudinit/config/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.9/site-packages/cloudinit/config/__pycache__/cc_set_passwords.cpython-39.pyc

a

��hF)�@sUdZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZddlmZmZmZdd	lmZdd
lmZddlmZdegegd
�Zeed<e�e�Z e!e"e!d�dd�Z#ee"e"d�dd�Z$ed�dd�Z%e"ee
e!dd�dd�Z&ddd�Z'dS)zFSet Passwords: Set user passwords and enable/disable SSH password auth�N)�List)�features�	lifecycle�subp�util)�Cloud)�Config)�
MetaSchema)�ALL_DISTROS�Distro�ug_util)�log_util)�PER_INSTANCE)�update_ssh_configZcc_set_passwords)�idZdistrosZ	frequencyZactivate_by_schema_keys�meta)�
users_list�pw_type�returncs|sgS�fdd�|D�S)zDeither password or type: RANDOM is required, user is always requiredcs0g|](}|�dd��kr|d|�dd�f�qS)�type�hash�name�password�RANDOM)�get)�.0�item�r��E/usr/lib/python3.9/site-packages/cloudinit/config/cc_set_passwords.py�
<listcomp>(s�z%get_users_by_type.<locals>.<listcomp>r)rrrrr�get_users_by_type#s�
��r!)�distro�service�
extra_argsc
GsZz"|jd|g|�R�t�d�Wn2tjyT}zt�d|�WYd}~n
d}~00dS)NZrestartzRestarted the SSH daemon.zm'ssh_pwauth' configuration may not be applied. Cloud-init was unable to restart SSH daemon due to error: '%s')Zmanage_service�LOG�debugrZProcessExecutionError�warning)r"r#r$�errr�_restart_ssh_daemon0s�r))r"cCs�|�dd�}d}t|t�r*tjdddd�t�|�r:d}nRt�|�rJd	}nBd
|�d�}|dusj|��d
krzt	�
d||�nt	�d||�dSt||i�}|s�t	�
d|�dS|�
�r�t�ddddd|g�j��}|��dvr�t||d�n
t||�dS)z�Apply sshd PasswordAuthentication changes.

    @param pw_auth: config setting from 'pw_auth'.
                    Best given as True, False, or "unchanged".
    @param distro: an instance of the distro class for the target distribution

    @return: NoneZssh_svcnameZsshZPasswordAuthenticationz-Using a string value for the 'ssh_pwauth' key�22.2z&Use a boolean value with 'ssh_pwauth'.�Z
deprecatedZdeprecated_versionZ
extra_messageZyes�nozLeaving SSH config 'z' unchanged.NZ	unchangedz%s ssh_pwauth=%sz$%s Unrecognized value: ssh_pwauth=%sz/No need to restart SSH service, %s not updated.Z	systemctlZshowz
--propertyZActiveStatez--value)ZactiveZ
activatingZ	reloadingz--job-mode=ignore-dependencies)Z
get_option�
isinstance�strr�	deprecaterZis_trueZis_false�lowerr%r&r'rZuses_systemdr�stdout�stripr))Zpw_authr"r#Zcfg_nameZcfg_valZbmsg�updated�staterrr�handle_ssh_pwauth<sH
�

��


�r5)r�cfg�cloud�argsrcCs,|j}|r2|d}d|vr@d|dvr@|dd=nt�|dd�}d}g}g}d|vr�|d}	tj|	dgd�}d|	vr�|	dr�tjdd	d
d�t|	dt�r�t�	d�t�|	d|�}n2tjd
ddd�t�	d�t�|	d�}
|
r�|
�
�}t�|	d|�}|�sD|�sD|�rDt�
||�\}}t�|�\}
}|
�r:d|
|fg}n
t�d�g}|�sT|�r�t|d�}dd�|D�}t|d�}dd�|D�}g}t|d�D]<\}
}t�}|�|
�|�|
|f�|�|
�d|����q�t�d�}|D]�}|�dd�\}}|�|�du�r&d|v�r&|�||f�|�|�nD|dk�s:|dk�rRt�}|�d||f�|�||f�|�|��q�|�r�zt�	d|�|j|dd �Wn>t�y�}z$|�|�t�td!|�WYd}~n
d}~00|�r6zt�	d"|�|j|dd �Wn>t�y4}z$|�|�t�td#|�WYd}~n
d}~00t|��rbd$d%�|�f}tjd&|ddd'�|�r�|}tj�r|||7}g}|D]^}z|� |�|�|�Wn>t�y�}z$|�|�t�td(|�WYd}~n
d}~00�q�|�r�t�	d)|�t!|�"d*�|�t|��r(t�	d+t|��|d,�dS)-Nr�chpasswd�listrT�users)�defaultzConfig key 'lists'z22.3zUse 'users' instead.r+z$Handling input for chpasswd as list.zThe chpasswd multiline stringr*zUse string type instead.z0Handling input for chpasswd as multiline string.�expirez%s:%sz2No default or defined user to change password for.�textcSsg|]\}}|�qSrr�r�user�_rrrr ��zhandle.<locals>.<listcomp>rcSsg|]\}}|�qSrrr?rrrr �rBr�:z\$(1|2a|2y|5|6)(\$.+){2}��RzChanging password for %s:F)Zhashedz,Failed to set passwords with chpasswd for %szSetting hashed password for %s:z3Failed to set hashed passwords with chpasswd for %sz%Set the following 'random' passwords
�
z%s
%s
)�stderrZfallback_to_stdoutzFailed to set 'expire' for %szExpired passwords for: %s usersZ
ssh_pwauthz+%s errors occurred, re-raising the last one���)#r"rZget_cfg_option_strZget_cfg_option_listrr/r-r:r%r&�
splitlinesZget_cfg_option_boolrZnormalize_users_groupsZextract_defaultr'r!�rand_user_password�append�re�compile�split�matchr9�	ExceptionZlogexc�len�joinr
Z	multi_logrZEXPIRE_APPLIES_TO_HASHED_USERSZ
expire_passwdr5r)rr6r7r8r"rr=ZplistrZchfgZ	multiliner;Z_groupsr@Z_user_config�errorsZplist_inZhashed_plist_inZhashed_usersZrandlistrA�prog�line�u�pr(ZblurbZusers_to_expireZ
expired_usersrrr�handle~s��
�






�
�
�
�

(
rX�cCs�|dkrtd��t�tj�t�tj�t�tj�t�tj�g}|�t	t
j|t|�tjtjtjtjd���t�
|�d�|�S)N�z.Password length must be at least 4 characters.)�select_from�)�
ValueError�random�choice�string�digitsZascii_lowercaseZascii_uppercaseZpunctuation�extendr:rZrand_strrQZshufflerR)ZpwlenZ
res_rand_listrrrrJs.



�
������
rJ)rY)(�__doc__Zloggingr^rLr`�typingrZ	cloudinitrrrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemar	Zcloudinit.distrosr
rrZ
cloudinit.logr
Zcloudinit.settingsrZcloudinit.ssh_utilrr�__annotations__Z	getLogger�__name__r%r:r.r!r)r5rXrJrrrr�<module>s2�

B	

Zerion Mini Shell 1.0