From 2ab488b89bd2d6b017a3798613e19bcb7661957e Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Thu, 28 May 2009 13:49:40 +0200 Subject: [PATCH] implement hardware hash generation and store --- libraries/entropy/const.py | 2 ++ libraries/entropy/core.py | 39 +++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/libraries/entropy/const.py b/libraries/entropy/const.py index 5fa03275c..499f77ea8 100644 --- a/libraries/entropy/const.py +++ b/libraries/entropy/const.py @@ -337,6 +337,8 @@ def const_default_settings(rootdir): # by equo inside triggerTools 'triggername': "trigger", 'trigger_sh_interpreter': "/usr/sbin/entropy.sh", + # entropy hardware hash generator executable + 'etp_hw_hash_gen': rootdir+"/usr/bin/entropy_hwgen.sh", # proxy configuration constants, used system wide 'proxy': { 'ftp': None, diff --git a/libraries/entropy/core.py b/libraries/entropy/core.py index bca5a4c4a..f880e37a4 100644 --- a/libraries/entropy/core.py +++ b/libraries/entropy/core.py @@ -292,6 +292,7 @@ class SystemSettings(Singleton): 'system_dirs': etpConst['confdir']+"/fsdirs.conf", 'system_dirs_mask': etpConst['confdir']+"/fsdirsmask.conf", 'system_rev_symlinks': etpConst['confdir']+"/fssymlinks.conf", + 'hw_hash': etpConst['confdir']+"/.hw.hash", 'socket_service': etpConst['socketconf'], 'system': etpConst['entropyconf'], 'repositories': etpConst['repositoriesconf'], @@ -302,7 +303,7 @@ class SystemSettings(Singleton): 'repos_license_whitelist', 'system_package_sets', 'conflicting_tagged_packages', 'system_dirs', 'system_dirs_mask', 'socket_service', 'system', - 'system_rev_symlinks' + 'system_rev_symlinks', 'hw_hash' ]) self.__setting_files_pre_run.extend(['repositories']) @@ -866,7 +867,43 @@ class SystemSettings(Singleton): """ return self.__generic_parser(self.__setting_files['system_dirs_mask']) + def hw_hash_parser(self): + """ + Hardware hash metadata parser and generator. It returns a theorically + unique SHA256 hash bound to the computer running this Framework. + + @return basestring containing SHA256 hexdigest + """ + hw_hash_file = self.__setting_files['hw_hash'] + if os.access(hw_hash_file, os.R_OK | os.F_OK): + hash_f = open(hw_hash_file, "r") + hash_data = hash_f.readline().strip() + hash_f.close() + return hash_data + + hash_file_dir = os.path.dirname(hw_hash_file) + hw_hash_exec = etpConst['etp_hw_hash_gen'] + if os.access(hash_file_dir, os.W_OK) and \ + os.access(hw_hash_exec, os.X_OK | os.F_OK | os.R_OK): + pipe = os.popen('{ ' + hw_hash_exec + '; } 2>&1', 'r') + hash_data = pipe.read().strip() + sts = pipe.close() + if sts != None: + return None + hash_f = open(hw_hash_file, "w") + hash_f.write(hash_data) + hash_f.flush() + hash_f.close() + return hash_data + def system_rev_symlinks_parser(self): + """ + Parser returning important system symlinks mapping. For example: + {'/usr/lib': ['/usr/lib64']} + Useful for reverse matching files belonging to packages. + + @return dict containing the mapping + """ setting_file = self.__setting_files['system_rev_symlinks'] raw_data = self.__generic_parser(setting_file) data = {}