diff options
-rw-r--r-- | src/lib/Client/Tools/POSIX.py | 23 | ||||
-rw-r--r-- | src/lib/Client/Tools/__init__.py | 8 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/lib/Client/Tools/POSIX.py b/src/lib/Client/Tools/POSIX.py index 7b0544a25..aea5e7f3c 100644 --- a/src/lib/Client/Tools/POSIX.py +++ b/src/lib/Client/Tools/POSIX.py @@ -47,7 +47,7 @@ def normGid(entry): log.error('GID normalization failed for %s' % (entry.get('name'))) return False -text_chars = "".join(map(chr, range(32, 127)) + list("\n\r\t\b")) +text_chars = "".join([chr(y) for y in range(32, 127)] + list("\n\r\t\b")) notrans = string.maketrans("", "") def isString(strng): @@ -278,6 +278,27 @@ class POSIX(Bcfg2.Client.Tools.Tool): self.logger.error('Permission fixup failed for %s' % (entry.get('name'))) return False + def gatherCurrentData(self, entry): + if entry.tag == 'ConfigFile': + try: + ondisk = os.stat(entry.get('name')) + except OSError: + entry.set('current_exists', 'false') + self.logger.debug("%s %s does not exist" % + (entry.tag, entry.get('name'))) + return False + try: + entry.set('current_owner', str(ondisk[ST_UID])) + entry.set('current_group', str(ondisk[ST_GID])) + except (OSError, KeyError): + pass + entry.set('perms', str(oct(ondisk[ST_MODE])[-4:])) + try: + content = open(entry.get('name')).read() + entry.set('current_bfile', binascii.b2a_base64(content)) + except IOError, error: + self.logger.error("Failed to read %s: %s" % (error.filename, error.strerror)) + def VerifyConfigFile(self, entry, _): '''Install ConfigFile Entry''' # configfile verify is permissions check + content check diff --git a/src/lib/Client/Tools/__init__.py b/src/lib/Client/Tools/__init__.py index ed8649082..663fa3433 100644 --- a/src/lib/Client/Tools/__init__.py +++ b/src/lib/Client/Tools/__init__.py @@ -152,6 +152,10 @@ class Tool: return [sentry.get('name') for sentry in struct if sentry.tag in \ ['ConfigFile', 'SymLink', 'Directory', 'Permissions']] + def gatherCurrentData(self, entry): + '''Default implementation of the information gathering routines''' + pass + def canVerify(self, entry): '''test if entry has enough information to be verified''' if not self.handlesEntry(entry): @@ -164,6 +168,10 @@ class Tool: % (entry.tag, entry.get('name'))) self.logger.error("\t... due to absense of %s attribute(s)" % \ (":".join(missing))) + try: + self.gatherCurrentData(entry) + except: + self.logger.error("Unexpected error in gatherCurrentData", exc_info=1) return False return True |