diff --git a/letsencrypt/client/apache_configurator.py b/letsencrypt/client/apache_configurator.py index 904bf6ff8..8985bed06 100644 --- a/letsencrypt/client/apache_configurator.py +++ b/letsencrypt/client/apache_configurator.py @@ -124,14 +124,20 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): :ivar dict assoc: Mapping between domains and vhosts """ - def __init__(self, server_root=CONFIG.SERVER_ROOT, save_dir=None, version=None): + def __init__(self, server_root=CONFIG.SERVER_ROOT, dir=None, version=None): """Initialize an Apache Configurator.""" - if not save_dir: - save_dir={"backup": CONFIG.BACKUP_DIR, - "temp": CONFIG.TEMP_CHECKPOINT_DIR, - "progress": CONFIG.IN_PROGRESS_DIR} + # The top 3 are the only ones that need to be + # defined for Augeas Configurator + if dir: + self.dir = dir + else: + self.dir = {"backup": CONFIG.BACKUP_DIR, + "temp": CONFIG.TEMP_CHECKPOINT_DIR, + "progress": CONFIG.IN_PROGRESS_DIR, + "config": CONFIG.CONFIG_DIR, + "work": CONFIG.WORK_DIR} - super(ApacheConfigurator, self).__init__(save_dir) + super(ApacheConfigurator, self).__init__(dir) self.server_root = server_root @@ -167,7 +173,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator): # Add name_server association dict self.assoc = dict() # Verify that all directories and files exist with proper permissions - verify_setup() + self.verify_setup() # Enable mod_ssl if it isn't already enabled # This is Let's Encrypt... we enable mod_ssl on initialization :) @@ -1327,6 +1333,19 @@ LogLevel warn \n\ return tuple(matches[0].split('.')) + def verify_setup(self): + """Verify the setup to ensure safe operating environment. + + Make sure that files/directories are setup with appropriate permissions + Aim for defensive coding... make sure all input files + have permissions of root + + """ + uid = os.geteuid() + le_util.make_or_verify_dir(self.dir["config"], 0o755, uid) + le_util.make_or_verify_dir(self.dir["work"], 0o755, uid) + le_util.make_or_verify_dir(self.dir["backup"], 0o755, uid) + ########################################################################### # Challenges Section ########################################################################### @@ -1572,19 +1591,6 @@ def apache_restart(): return True -def verify_setup(): - """Verify the setup to ensure safe operating environment. - - Make sure that files/directories are setup with appropriate permissions - Aim for defensive coding... make sure all input files - have permissions of root - - """ - le_util.make_or_verify_dir(CONFIG.CONFIG_DIR, 0o755) - le_util.make_or_verify_dir(CONFIG.WORK_DIR, 0o755) - le_util.make_or_verify_dir(CONFIG.BACKUP_DIR, 0o755) - - def case_i(string): """Returns case insensitive regex. diff --git a/letsencrypt/client/augeas_configurator.py b/letsencrypt/client/augeas_configurator.py index 5a17d1f77..e69c0af1f 100644 --- a/letsencrypt/client/augeas_configurator.py +++ b/letsencrypt/client/augeas_configurator.py @@ -23,9 +23,9 @@ class AugeasConfigurator(configurator.Configurator): super(AugeasConfigurator, self).__init__() if not dir: - dir={"backup": CONFIG.BACKUP_DIR, - "temp": CONFIG.TEMP_CHECKPOINT_DIR, - "progress": CONFIG.IN_PROGRESS_DIR} + dir = {"backup": CONFIG.BACKUP_DIR, + "temp": CONFIG.TEMP_CHECKPOINT_DIR, + "progress": CONFIG.IN_PROGRESS_DIR} self.dir = dir # TODO: this instantiation can be optimized to only load diff --git a/letsencrypt/client/tests/apache_configurator_test.py b/letsencrypt/client/tests/apache_configurator_test.py index e63429bd5..c4f1ffa32 100644 --- a/letsencrypt/client/tests/apache_configurator_test.py +++ b/letsencrypt/client/tests/apache_configurator_test.py @@ -53,11 +53,14 @@ class TwoVhost80(unittest.TestCase): # Using a new configurator every time allows the Configurator to clean # up after itself - backup = os.path.join(TESTING_DIR, "backups") - temp = os.path.join(TESTING_DIR, "temp_checkpoint") - progress = os.path.join(backup, "IN_PROGRESS") self.config = apache_configurator.ApacheConfigurator( - self.config_path, {"backup": backup, "temp": temp, "progress": progress}, (2, 4, 7)) + self.config_path, + {"backup": os.path.join(TESTING_DIR, "backups"), + "temp": os.path.join(TESTING_DIR, "temp_checkpoint"), + "progress": os.path.join(TESTING_DIR, "backups", "IN_PROGRESS"), + "config": os.path.join(TESTING_DIR, "config"), + "work": os.path.join(TESTING_DIR, "work")}, + (2, 4, 7)) self.aug_path = "/files" + self.config_path