diff options
author | Jonathan Cave <jonathan.cave@canonical.com> | 2020-02-07 10:19:49 +0000 |
---|---|---|
committer | Jonathan Cave <jonathan.cave@canonical.com> | 2020-02-07 10:19:49 +0000 |
commit | 6259dc5b8e43f811b3d9174d3381331cfd7ed423 (patch) | |
tree | aa6883b541495450e2feb555269381660aa9f7d3 | |
parent | 42c65f8ab5810e3d8299974318bd9136532efafc (diff) |
tpm-sysfs-resource: remove guacamole use
-rwxr-xr-x | bin/tpm-sysfs-resource | 98 |
1 files changed, 46 insertions, 52 deletions
diff --git a/bin/tpm-sysfs-resource b/bin/tpm-sysfs-resource index 34f81b57..2f8c256a 100755 --- a/bin/tpm-sysfs-resource +++ b/bin/tpm-sysfs-resource @@ -1,68 +1,62 @@ #!/usr/bin/env python3 -# Copyright 2015 Canonical Ltd. +# Copyright 2015-2020 Canonical Ltd. # All rights reserved. # # Written by: # Zygmunt Krynicki <zygmunt.krynicki@canonical.com> +# Jonathan Cave <jonathan.cave@canonical.com> +""" +Collect information about all sysfs attributes related to TPM. -"""Collect information about all sysfs attributes related to TPM.""" +This program traverses all the TPM device nodes found in /sys/class/tpm/. +Each present device is subsequently inspected by reading all readable files +in /sys/class/tpm/*/device/* and presenting the data present there as +subsequent RFC822 records. There is one record per TPM chip. In order to +differentiate each chip, each record contains the field x-sysfs-device-name +that stores the full sysfs directory name of the chip. -import os - -import guacamole - - -class tpm_sysfs_resource(guacamole.Command): +@EPILOG@ - """ - Collect information about all sysfs attributes related to TPM. +Unreadable files (typically due to permissions) are silently skipped. +""" - This program traverses all the TPM device nodes found in /sys/class/tpm/. - Each present device is subsequently inspected by reading all readable files - in /sys/class/tpm/*/device/* and presenting the data present there as - subsequent RFC822 records. There is one record per TPM chip. In order to - differentiate each chip, each record contains the field x-sysfs-device-name - that stores the full sysfs directory name of the chip. - - @EPILOG@ +import os - Unreadable files (typically due to permissions) are silently skipped. - """ - def invoked(self, ctx): - # This is found on 4.2 kernels - sysfs_root_tpm = '/sys/class/tpm/' - # This is found on 3.19 kernels - sysfs_root_misc = '/sys/class/misc/' - if os.path.isdir(sysfs_root_tpm): - sysfs_root = sysfs_root_tpm - elif os.path.isdir(sysfs_root_misc): - sysfs_root = sysfs_root_misc - else: - return - for tpm_id in sorted(os.listdir(sysfs_root)): - if sysfs_root == sysfs_root_misc and not tpm_id.startswith('tpm'): +def main(): + # This is found on 4.2 kernels + sysfs_root_tpm = '/sys/class/tpm/' + # This is found on 3.19 kernels + sysfs_root_misc = '/sys/class/misc/' + if os.path.isdir(sysfs_root_tpm): + sysfs_root = sysfs_root_tpm + elif os.path.isdir(sysfs_root_misc): + sysfs_root = sysfs_root_misc + else: + return + for tpm_id in sorted(os.listdir(sysfs_root)): + if sysfs_root == sysfs_root_misc and not tpm_id.startswith('tpm'): + continue + print("x-sysfs-device-name: {}".format(tpm_id)) + tpm_dirname = os.path.join(sysfs_root, tpm_id, 'device') + for tpm_attr in sorted(os.listdir(tpm_dirname)): + tpm_filename = os.path.join(tpm_dirname, tpm_attr) + if not os.path.isfile(tpm_filename): + continue + if not os.access(tpm_filename, os.R_OK): continue - print("x-sysfs-device-name: {}".format(tpm_id)) - tpm_dirname = os.path.join(sysfs_root, tpm_id, 'device') - for tpm_attr in sorted(os.listdir(tpm_dirname)): - tpm_filename = os.path.join(tpm_dirname, tpm_attr) - if not os.path.isfile(tpm_filename): - continue - if not os.access(tpm_filename, os.R_OK): - continue - with open(tpm_filename, 'rt', encoding='utf-8') as stream: - tpm_data = stream.read() - tpm_data = tpm_data.rstrip() - if '\n' in tpm_data: - print("{}:".format(tpm_attr)) - for tpm_data_chunk in tpm_data.splitlines(): - print(" {}".format(tpm_data_chunk)) - else: - print("{}: {}".format(tpm_attr, tpm_data)) - print() + with open(tpm_filename, 'rt', encoding='utf-8') as stream: + tpm_data = stream.read() + tpm_data = tpm_data.rstrip() + if '\n' in tpm_data: + print("{}:".format(tpm_attr)) + for tpm_data_chunk in tpm_data.splitlines(): + print(" {}".format(tpm_data_chunk)) + else: + print("{}: {}".format(tpm_attr, tpm_data)) + print() if __name__ == "__main__": - tpm_sysfs_resource().main() + main() |