diff options
-rwxr-xr-x | func/certmaster.py | 18 | ||||
-rw-r--r-- | modules/copyfile.py | 15 | ||||
-rwxr-xr-x | scripts/certmaster | 7 |
3 files changed, 28 insertions, 12 deletions
diff --git a/func/certmaster.py b/func/certmaster.py index 59bfd36..b12ecdb 100755 --- a/func/certmaster.py +++ b/func/certmaster.py @@ -61,12 +61,22 @@ class CertMaster(object): else: self.cfg.autosign = False self.cfg.listen_port = int(self.cfg.listen_port) + self.ca_key_file = '%s/funcmaster.key' % self.cfg.cadir + self.ca_cert_file = '%s/funcmaster.crt' % self.cfg.cadir + try: + if not os.path.exists(self.cfg.cadir): + os.makedirs(self.cfg.cadir) + # fixme - should we creating these separately? + if not os.path.exists(self.ca_key_file) and not os.path.exists(self.ca_cert_file): + func.certs.create_ca(ca_key_file=self.ca_key_file, ca_cert_file=self.ca_cert_file) + except (IOError, OsError), e: + print 'Cannot make certmaster certificate authority keys/certs, aborting: %s' % e + sys.exit(1) + # open up the cakey and cacert so we have them available - ca_key_file = '%s/funcmaster.key' % self.cfg.cadir - ca_cert_file = '%s/funcmaster.crt' % self.cfg.cadir - self.cakey = func.certs.retrieve_key_from_file(ca_key_file) - self.cacert = func.certs.retrieve_cert_from_file(ca_cert_file) + self.cakey = func.certs.retrieve_key_from_file(self.ca_key_file) + self.cacert = func.certs.retrieve_cert_from_file(self.ca_cert_file) for dirpath in [self.cfg.cadir, self.cfg.certroot, self.cfg.csrroot]: if not os.path.exists(dirpath): diff --git a/modules/copyfile.py b/modules/copyfile.py index 7d04abf..58b5ea4 100644 --- a/modules/copyfile.py +++ b/modules/copyfile.py @@ -47,10 +47,13 @@ class CopyFile(func_module.FuncModule): return thissum.hexdigest() - def copyfile(self, filepath, filebuf): + def copyfile(self, filepath, filebuf, mode=0644, uid=0, gid=0, force=None): # -1 = problem file was not copied # 1 = file was copied # 0 = file was not copied b/c file is unchanged + + + # we should probably verify mode,uid,gid are valid as well dirpath = os.path.dirname(filepath) basepath = os.path.basename(filepath) @@ -62,7 +65,7 @@ class CopyFile(func_module.FuncModule): if os.path.exists(filepath): local_sum = self.checksum(filepath) - if remote_sum != local_sum: + if remote_sum != local_sum or force is not None: # back up the localone if os.path.exists(filepath): if not self._backuplocal(filepath): @@ -79,6 +82,14 @@ class CopyFile(func_module.FuncModule): return -1 else: return 0 + + # hmm, need to figure out proper exceptions -akl + try: + # we could intify the mode here if it's a string + os.chmod(filepath, mode) + os.chown(filepath, uid, gid) + except (IOError, OSError), e: + return -1 return 1 diff --git a/scripts/certmaster b/scripts/certmaster index 1be4c58..f4bcf53 100755 --- a/scripts/certmaster +++ b/scripts/certmaster @@ -1,11 +1,6 @@ #!/usr/bin/python -import sys -import distutils.sysconfig - -sys.path.append("%s/func" % distutils.sysconfig.get_python_lib()) - -import certmaster +from func import certmaster defaults = { 'listen_addr': 'localhost', 'listen_port': '51235', |