
    x[hv	                     \    d dl Z d dlZd dlmZmZ  e j
                  e      Z G d d      Zy)    N)atomic_helpersubpc                       e Zd ZdZd Zd Zy)PasswordConfiguratorzv
    Class for changing configurations related to passwords in a VM. Includes
    setting and expiring passwords.
    c                    t         j                  d       |rt        j                  |      }g }t	        dd      D ]=  }|j                  d      d   dk(  s|j                  |j                  d      d          ? g }t	        dd      D ],  }|j                  d      d   }||v s|j                  |       . |r't         j                  d	       |j                  d
|       |r| j                  |       t         j                  d       y)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   b64dopensplitappend
set_passwdreset_password)selfpasswdresetPasswddistroallRootUserslineuidUsersListusers           T/usr/lib/python3/dist-packages/cloudinit/sources/helpers/vmware/imc/config_passwd.py	configurezPasswordConfigurator.configure   s     	23"''/F, 	8Dzz#q!S(##DJJsOA$67	8 , 	*D::c?1%D|###D)	* HH-.ff--01    c                 N   t         j                  d       |D ]  }	 t        j                  dd|g        y	# t        j                  $ rZ}t        j
                  j                  d      rt        j                  ddd|g       nt         j                  d||       Y d	}~d	}~ww xY w)
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/chagechagez-dr   z/Failed to expire password for %s with error: %sN)r   r   r   ProcessExecutionErrorospathexistswarning)r   uidUserListr   es       r   r   z#PasswordConfigurator.reset_password3   s     	%& 	D
		8Z67	 -- 77>>"23IIwc489KKI	s   7B$
ABB$N)__name__
__module____qualname____doc__r   r    r   r   r   r      s    
28r   r   )	loggingr#   	cloudinitr   r   	getLoggerr)   r   r   r-   r   r   <module>r1      s,     	 )g!4 4r   