3 \¼mev ã@s<ddlZddlZddlmZmZejeƒZGdd„dƒZdS)éN)Ú atomic_helperÚsubpc@s eZdZdZdd„Zdd„ZdS)ÚPasswordConfiguratorzv Class for changing configurations related to passwords in a VM. Includes setting and expiring passwords. cCsÄtjdƒ|rtj|ƒ}g}x8tddƒD]*}|jdƒddkr(|j|jdƒdƒq(Wg}x2tddƒD]$}|jdƒd}||krf|j|ƒqfW|r¨tjd ƒ|jd |ƒ|r¶|j|ƒtjd ƒ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. zStarting password configurationz /etc/passwdÚrú:éÚ0rz /etc/shadowzSetting admin passwordÚrootzConfigure Password completed!N) ÚLOGÚinforZb64dÚopenÚsplitÚappendZ set_passwdÚreset_password)ÚselfÚpasswdZ resetPasswdZdistroZ allRootUsersÚlineZ uidUsersListÚuser©rú#/usr/lib/python3.6/config_passwd.pyÚ configures$     zPasswordConfigurator.configurecCs„tjdƒxt|D]l}ytjdd|gƒWqtjk rz}z4tjjdƒr\tjddd|gƒntjd||ƒWYd d }~XqXqWd 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. zExpiring password.rz--expirez/usr/bin/chageZchagez-drz/Failed to expire password for %s with error: %sN)r r rZProcessExecutionErrorÚosÚpathÚexistsZwarning)rZ uidUserListrÚerrrr3s   z#PasswordConfigurator.reset_passwordN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrrsr) ZloggingrZ cloudinitrrZ getLoggerrr rrrrrÚ s