From 638319217bad0817553d4afe2886019c5121c567 Mon Sep 17 00:00:00 2001 From: James Bromberger Date: Fri, 16 Aug 2013 17:37:56 +0000 Subject: [PATCH 1/2] Chmod the seded file back to being executable. --- plugins/admin_user/tasks.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/admin_user/tasks.py b/plugins/admin_user/tasks.py index 387894f..2183b93 100644 --- a/plugins/admin_user/tasks.py +++ b/plugins/admin_user/tasks.py @@ -52,6 +52,11 @@ class AdminUserCredentials(Task): getcreds_path = os.path.join(info.root, 'etc/init.d/ec2-get-credentials') username = info.manifest.plugins['admin_user']['username'] sed_i(getcreds_path, 'username=\'root\'', 'username=\'{username}\''.format(username=username)) + import stat + rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | + stat.S_IRGRP | stat.S_IXGRP | + stat.S_IROTH | stat.S_IXOTH) + os.chmod(getcreds_path, rwxr_xr_x) class DisableRootLogin(Task): From d716baadfb964481063eb60b33a3d28248294c35 Mon Sep 17 00:00:00 2001 From: James Bromberger Date: Sat, 17 Aug 2013 08:23:51 +0000 Subject: [PATCH 2/2] Do permissions changes in a nicer way for sed_i. --- common/tools.py | 3 +++ plugins/admin_user/tasks.py | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/common/tools.py b/common/tools.py index 4a89c47..b7988cb 100644 --- a/common/tools.py +++ b/common/tools.py @@ -50,10 +50,13 @@ def sed_i(file_path, pattern, subst): from tempfile import mkstemp from shutil import move from os import close + import os temp_fd, temp_path = mkstemp() + mode = os.stat(file_path).st_mode with open(temp_path, 'w') as new_file: with open(file_path) as old_file: for line in old_file: new_file.write(line.replace(pattern, subst)) close(temp_fd) + os.chmod(temp_path, mode) move(temp_path, file_path) diff --git a/plugins/admin_user/tasks.py b/plugins/admin_user/tasks.py index 2183b93..387894f 100644 --- a/plugins/admin_user/tasks.py +++ b/plugins/admin_user/tasks.py @@ -52,11 +52,6 @@ class AdminUserCredentials(Task): getcreds_path = os.path.join(info.root, 'etc/init.d/ec2-get-credentials') username = info.manifest.plugins['admin_user']['username'] sed_i(getcreds_path, 'username=\'root\'', 'username=\'{username}\''.format(username=username)) - import stat - rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | - stat.S_IRGRP | stat.S_IXGRP | - stat.S_IROTH | stat.S_IXOTH) - os.chmod(getcreds_path, rwxr_xr_x) class DisableRootLogin(Task):