4967065a |
import os
import crypt
import random
import string |
a5a8bd39 |
import commons |
4967065a |
install_phase = commons.POST_INSTALL
enabled = True
|
a5a8bd39 |
def execute(config, root): |
4967065a |
shadow_password = config['password']
passwd_filename = os.path.join(root, 'etc/passwd')
shadow_filename = os.path.join(root, 'etc/shadow') |
a5a8bd39 |
|
4967065a |
#replace root blank password in passwd file to point to shadow file |
a5a8bd39 |
commons.replace_string_in_file(passwd_filename, "root::", "root:x:") |
4967065a |
if os.path.isfile(shadow_filename) == False:
with open(shadow_filename, "w") as destination: |
a5a8bd39 |
destination.write("root:" + shadow_password + ":") |
4967065a |
else:
#add password hash in shadow file
commons.replace_string_in_file(shadow_filename, "root::", "root:"+shadow_password+":") |
4d53ba03 |
commons.replace_string_in_file(shadow_filename, "root:x:", "root:"+shadow_password+":") |