Current File : //lib/python2.7/site-packages/cloudinit/config/cc_set_passwords.pyc |
�
�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: <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...
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"