OS : Linux
PHP Version : 7.4.33
Software : Apache/2.4.6 (CentOS) PHP/7.4.33
Information System : Linux apprendre2 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
Disable Function : ó
ƒjbc @ sé d Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l m
Z
d d l m Z m
Z
e j e ƒ Z d j g e e
D] Z e d k r” e ^ q” ƒ Z d d
d „ Z d „ Z d
d „ Z e d „ Z d S( sã
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:
password: password1
chpasswd:
expire:
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...
iÿÿÿÿN( t ug_util( t log( t update_ssh_config( t util( t
ascii_letterst digitst t loLOI01t sshc C s) d } | d k r d g } n t j | ƒ r6 d } nm t j | ƒ rN d } nU d | } | d k sv | j ƒ d k rŒ t j d | | ƒ n t j d | | ƒ d St i | | 6ƒ } | sÐ t j d
| ƒ d Sd | k rõ t | ƒ d | g } n t | ƒ | d g } t j
| ƒ t j d
ƒ d S( s5 Apply sshd PasswordAuthentication changes.
@param pw_auth: config setting from 'pw_auth'.
Best given as True, False, or "unchanged".
@param service_cmd: The service command list (['service'])
@param service_name: The name of the sshd service for the system.
@return: Nonet PasswordAuthenticationt servicet yest nos" Leaving ssh config '%s' unchanged.t unchangeds %s ssh_pwauth=%ss$ %s Unrecognized value: ssh_pwauth=%sNs/ No need to restart ssh service, %s not updated.t systemctlt restarts Restarted the ssh daemon.( t NoneR t is_truet is_falset lowert LOGt debugt warningR t listt subp( t pw_autht service_cmdt service_namet cfg_namet cfg_valt bmsgt updatedt cmd( ( sE /usr/lib/python2.7/site-packages/cloudinit/config/cc_set_passwords.pyt handle_ssh_pwautha s*
c C s¬ t | ƒ d k rI | d } d | k r^ d | d k r^ | d d =q^ n t j | d d ƒ } t } d } d | k r | d } d | k r| d rt | d t ƒ rÎ | j d ƒ t j | d | ƒ } q| j d ƒ t j | d | ƒ } | r| j ƒ } qn t j
| d | ƒ } n | r‰| r‰t j | | j
ƒ \ } }
t j | ƒ \ } } | ryd | | f g } q‰| j d ƒ n g }
| rEg } g } g } g } g } t j d
ƒ } xà | D]» } | j d d ƒ \ } } | j | ƒ d k r%d | k r%| j | ƒ | j | ƒ qÉ| d
k s=| d k r`t ƒ } | j d | | f ƒ n | j d | | f ƒ | j | ƒ qÉWd j | ƒ d } | rþy$ | j d | ƒ t | j
| ƒ Wqþt k
rú} |
j | ƒ t j | d | ƒ qþXn d j | ƒ d } | rzy* | j d | ƒ t | j
| d t ƒWqzt k
rv} |
j | ƒ t j | d | ƒ qzXn t | ƒ r²d d j | ƒ f } t j j d | ƒ n | rEg } xe | D]] } y! | j
j | ƒ | j | ƒ WqÅt k
r!} |
j | ƒ t j | d | ƒ qÅXqÅW| rB| j d | ƒ qBqEn t | j d ƒ d | j
j d | j
j! d d ƒ ƒt |
ƒ r¨| j d t |
ƒ ƒ |
d ‚ n d S( Ni t chpasswdR t passwords$ Handling input for chpasswd as list.s0 Handling input for chpasswd as multiline string.t expires %s:%ss2 No default or defined user to change password for.s \$(1|2a|2y|5|6)(\$.+){2}t :i t Rt RANDOMs
s Changing password for %s:s, Failed to set passwords with chpasswd for %ss Setting hashed password for %s:t hasheds3 Failed to set hashed passwords with chpasswd for %ss% Set the following 'random' passwords
s %s
%s
s Failed to set 'expire' for %ss Expired passwords for: %s userst
ssh_pwauthR R t ssh_svcnameR s* %s errors occured, re-raising the last oneiÿÿÿÿ(" t lenR t get_cfg_option_strR t Truet
isinstanceR R t get_cfg_option_listt
splitlinest get_cfg_option_boolR t normalize_users_groupst distrot extract_defaultR t ret compilet splitt matcht appendt rand_user_passwordt joinR" t Exceptiont logexct syst stderrt writet
expire_passwdR! t gett init_cmdt
get_option( t _namet cfgt cloudR t argsR# R$ t plistt chfgt userst _groupst usert _user_configt errorst plist_int hashed_plist_int hashed_userst randlistt progt linet ut pt ch_int et hashed_ch_int blurbt
expired_users( ( sE /usr/lib/python2.7/site-packages/cloudinit/config/cc_set_passwords.pyt handle‡ s¤
!
i c C s t j | d t ƒS( Nt select_from( R t rand_strt PW_SET( t pwlen( ( sE /usr/lib/python2.7/site-packages/cloudinit/config/cc_set_passwords.pyR: ï s c C s t j ƒ rQ xn | j ƒ D]1 } | j d ƒ \ } } | j | | d | ƒq Wn, d g | rf d g n g } t j | | ƒ d S( NR% R( R" s -e( R t
is_FreeBSDR0 R7 t
set_passwdR ( R3 RP R( t pentryRV RW R ( ( sE /usr/lib/python2.7/site-packages/cloudinit/config/cc_set_passwords.pyR" ó s ( t __doc__R5 R> t cloudinit.distrosR t cloudinitR t loggingt cloudinit.ssh_utilR R t stringR R t getLoggert __name__R R; t xR` R R! R] R: t FalseR" ( ( ( sE /usr/lib/python2.7/site-packages/cloudinit/config/cc_set_passwords.pyt N s & h