HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_set_passwords.cpython-38.pyc
U

Ӈgp%�@sUdZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZddlmZmZmZdd	lmZdd
lmZddlmZdegegd
�Zeed<e�e�Z e!e"e!d�dd�Z#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��C/usr/lib/python3/dist-packages/cloudinit/config/cc_set_passwords.py�
<listcomp>(s�z%get_users_by_type.<locals>.<listcomp>r)rrrrr�get_users_by_type#s�
��r!c
CsPz|�d|�t�d�Wn0tjk
rJ}zt�d|�W5d}~XYnXdS)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)�distro�service�errr�_restart_ssh_daemon0s�r()r%cCs�|�dd�}d}t|t�r*tjdddd�t�|�r:d}nRt�|�rJd	}nBd
|�d�}|dksj|��d
krzt	�
d||�nt	�d||�dSt||i�}|s�t	�
d|�dS|�
�r�t�ddddd|g�j��}|��dkr�t||�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_messageZyesZnozLeaving 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	reloading)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<sD
�

��

r3)r�cfg�cloud�argsrcCs&|j}|r2|d}d|kr@d|dkr@|dd=nt�|dd�}d}g}g}d|kr�|d}	tj|	dgd�}d|	kr�|	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�\}}|�|�dk	�r&d|k�r&|�||f�|�|�nD|dk�s:|dk�rRt�}|�d||f�|�||f�|�|��q�|�r�zt�	d|�|j|dd �Wn<tk
�r�}z|�|�t�td!|�W5d}~XYnX|�r2zt�	d"|�|j|dd �Wn<tk
�r0}z|�|�t�td#|�W5d}~XYnXt|��r^d$d%�|�f}tjd&|ddd'�|�r�|}tj�rx||7}g}|D]\}z|� |�|�|�Wn<tk
�r�}z|�|�t�td(|�W5d}~XYnX�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 �szhandle.<locals>.<listcomp>rcSsg|]\}}|�qSrrr=rrrr �sr�: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+r8r"r#�
splitlinesZget_cfg_option_boolrZnormalize_users_groupsZextract_defaultr$r!�rand_user_password�append�re�compile�split�matchr7�	ExceptionZlogexc�len�joinr
Z	multi_logrZEXPIRE_APPLIES_TO_HASHED_USERSZ
expire_passwdr3r)rr4r5r6r%rr;ZplistrZchfgZ	multiliner9Z_groupsr>Z_user_config�errorsZplist_inZhashed_plist_inZhashed_usersZrandlistr?�prog�line�u�pr'ZblurbZusers_to_expireZ
expired_usersrrr�handleps��
�






�
�
��

$
rU�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.)Zselect_from�)�
ValueError�randomZchoice�stringZdigitsZascii_lowercaseZascii_uppercaseZpunctuation�extendr8rZrand_strrNZshufflerO)ZpwlenZ
res_rand_listrrrrG�s.



�
������
rG)rV)(�__doc__ZloggingrZrIr[�typingrZ	cloudinitrrrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemar	Zcloudinit.distrosr
rrZ
cloudinit.logr
Zcloudinit.settingsrZcloudinit.ssh_utilrr�__annotations__Z	getLogger�__name__r"r8r,r!r(r3rUrGrrrr�<module>s2�

4