Server IP : 23.254.227.96 / Your IP : 216.73.216.7 Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64 User : viralblo ( 1001) PHP Version : 8.1.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib/python3.6/site-packages/cloudinit/config/__pycache__/ |
Upload File : |
3 ��b� � @ s� d Z ddlZddlmZmZ ddlmZ ddlmZm Z ddl mZ ddlm Z eje�Zdjd d � ee D ��Zdd� Zd d� Zddd�Zddd�ZdS )a� Set Passwords ------------- **Summary:** Set user passwords and enable/disable SSH password authentication This module consumes three top-level config keys: ``ssh_pwauth``, ``chpasswd`` and ``password``. The ``ssh_pwauth`` config key determines whether or not sshd will be configured to accept password authentication. True values will enable password auth, false values will disable password auth, and the literal string ``unchanged`` will leave it unchanged. Setting no value will also leave the current setting on-disk unchanged. The ``chpasswd`` config key accepts a dictionary containing either or both of ``expire`` and ``list``. If the ``list`` key is provided, it should contain a list of ``username:password`` pairs. This can be either a YAML list (of strings), or a multi-line string with one pair per line. Each user will have the corresponding password set. A password can be randomly generated by specifying ``RANDOM`` or ``R`` as a user's password. A hashed password, created by a tool like ``mkpasswd``, can be specified; a regex (``r'\$(1|2a|2y|5|6)(\$.+){2}'``) is used to determine if a password value should be treated as a hash. .. note:: The users specified must already exist on the system. Users will have been created by the ``cc_users_groups`` module at this point. By default, all users on the system will have their passwords expired (meaning that they will have to be reset the next time the user logs in). To disable this behaviour, set ``expire`` under ``chpasswd`` to a false value. If a ``list`` of user/password pairs is not specified under ``chpasswd``, then the value of the ``password`` config key will be used to set the default user's password. **Internal name:** ``cc_set_passwords`` **Module frequency:** per instance **Supported distros:** all **Config keys**:: ssh_pwauth: <yes/no/unchanged> password: password1 chpasswd: expire: <true/false> chpasswd: list: | user1:password1 user2:RANDOM user3:password3 user4:R ## # or as yaml list ## chpasswd: list: - user1:password1 - user2:RANDOM - user3:password3 - user4:R - user4:$6$rL..$ej... � N)� ascii_letters�digits)�log)�subp�util)�ug_util)�update_ssh_config� c C s g | ]}|d kr|�qS )ZloLOI01� )�.0�xr r �&/usr/lib/python3.6/cc_set_passwords.py� <listcomp>[ s r c C s� d}t j| �rd}nNt j| �r$d}n>d| }| dks@| j� dkrPtjd|| � ntjd|| � dS t||i�}|s�tjd |� dS |jd |j dd�� tjd � dS )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: NoneZPasswordAuthentication�yes�noz"Leaving SSH config '%s' unchanged.NZ unchangedz%s ssh_pwauth=%sz$%s Unrecognized value: ssh_pwauth=%sz/No need to restart SSH service, %s not updated.ZrestartZssh_svcnameZsshzRestarted the SSH daemon.) r Zis_trueZis_false�lower�LOG�debug�warningr Zmanage_serviceZ get_option)Zpw_auth�distroZcfg_nameZcfg_valZbmsg�updatedr r r �handle_ssh_pwauth^ s r c - C s� |r,|d }d|kr:d|d kr:|d d= nt j|dd �}d}d }d|kr�|d }d|kr�|d r�t|d t�r�|jd� t j|d|�}n$|jd� t j|d|�}|r�|j� }t j|d|�}| o�|�rtj ||j �\} } tj| �\}}|r�d ||f g}n |jd � g } |�rVg }g }g }g }g } t jd�}x�|D ]�}|jdd �\}}|j|�d k �rxd|k�rx|j|� |j|� nH|dk�s�|dk�r�t� }|jd ||f � |jd ||f � | j|� �q4W dj|�d }| �r4y|jd| � t|j |� W n< tk �r2 } z| j|� t j|d| � W Y d d }~X nX dj|�d }|�r�y |jd|� t|j |dd� W n< tk �r� } z| j|� t j|d|� W Y d d }~X nX t|��r�ddj|�f}t jd| ddd� |�rVg }xf| D ]^}y|j j|� |j|� W n< tk �r< } z| j|� t j|d|� W Y d d }~X nX �q�W |�rV|jd|� t|jd�|j � t| ��r�|jdt| �� | d �d S )Nr �chpasswd�list�passwordTz$Handling input for chpasswd as list.z0Handling input for chpasswd as multiline string.�expirez%s:%sz2No default or defined user to change password for.z\$(1|2a|2y|5|6)(\$.+){2}�:� �RZRANDOM� zChanging password for %s:z,Failed to set passwords with chpasswd for %szSetting hashed password for %s:)�hashedz3Failed to set hashed passwords with chpasswd for %sz%Set the following 'random' passwords z%s %s F)�stderrZfallback_to_stdoutzFailed to set 'expire' for %szExpired passwords for: %s usersZ ssh_pwauthz*%s errors occured, re-raising the last one���)r Zget_cfg_option_str� isinstancer r Zget_cfg_option_list� splitlinesZget_cfg_option_boolr Znormalize_users_groupsr Zextract_defaultr �re�compile�split�match�append�rand_user_password�joinr � ExceptionZlogexc�lenZ multi_logZ expire_passwdr �get)�_nameZcfgZcloudr �argsr r ZplistZchfgZusersZ_groups�userZ_user_config�errors�plist_inZhashed_plist_inZhashed_usersZrandlist�prog�line�u�pZch_in�eZhashed_ch_inZblurbZ expired_usersr r r �handle} s� & r9 � c C s t j| td�S )N)Zselect_from)r Zrand_str�PW_SET)Zpwlenr r r r* � s r* Fc C s^ t j� r:xP|j� D ]"}|jd�\}}| j|||d� qW n dg|rHdgng }tj||� d S )Nr )r r z-e)r Zis_BSDr$ r'