
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\mev	                 @   s<   d dl Z d dlZd dlmZmZ e jeZG dd dZdS )    N)atomic_helpersubpc               @   s    e Zd ZdZdd Zdd ZdS )PasswordConfiguratorzv
    Class for changing configurations related to passwords in a VM. Includes
    setting and expiring passwords.
    c             C   s   t jd |rtj|}g }x8tddD ]*}|jdd dkr(|j|jdd  q(W g }x2tddD ]$}|jdd }||krf|j| qfW |rt jd	 |jd
| |r| j| t jd dS )a+  
        Main method to perform all functionalities based on configuration file
        inputs.
        @param passwd: encoded admin password.
        @param resetPasswd: boolean to determine if password needs to be reset.
        @return cfg: dict to be used by cloud-init set_passwd code.
        zStarting password configurationz/etc/passwdr:   0r   z/etc/shadowzSetting admin passwordrootzConfigure Password completed!N)	LOGinfor   Zb64dopensplitappendZ
set_passwdreset_password)selfpasswdZresetPasswdZdistroZallRootUserslineZuidUsersListuser r   #/usr/lib/python3.6/config_passwd.py	configure   s$    



zPasswordConfigurator.configurec             C   s   t jd xt|D ]l}ytjdd|g W q tjk
rz } z4tjjdr\tjddd|g nt jd|| W Y d	d	}~X qX qW d	S )
z
        Method to reset password. Use passwd --expire command. Use chage if
        not succeeded using passwd command. Log failure message otherwise.
        @param: list of users for which to expire password.
        zExpiring password.r   z--expirez/usr/bin/chageZchagez-dr   z/Failed to expire password for %s with error: %sN)r
   r   r   ZProcessExecutionErrorospathexistsZwarning)r   ZuidUserListr   er   r   r   r   3   s    

z#PasswordConfigurator.reset_passwordN)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   r   )	Zloggingr   Z	cloudinitr   r   Z	getLoggerr   r
   r   r   r   r   r   <module>	   s   
