diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index a92f134c..2694d3ef 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -196,12 +196,15 @@ class FilesystemController(ControllerPolicy): def show_disk_information(self, device): """ Show disk information, requires sudo/root """ - out = utils.run_command("hdparm -i {}".format(device)) - log.debug(out) - if out['status'] != 0: - result = out['err'] + if not utils.is_root(): + result = "hdparm requires root permission." else: - result = out['output'] + out = utils.run_command("hdparm -i {}".format(device)) + log.debug(out) + if out['status'] != 0: + result = out['err'] + else: + result = out['output'] disk_info_view = DiskInfoView(self.model, self.signal, result) @@ -212,4 +215,3 @@ class FilesystemController(ControllerPolicy): log.debug('forcing is_uefi True beacuse of options') return True return os.path.exists('/sys/firmware/efi') - diff --git a/subiquity/utils.py b/subiquity/utils.py index 2bbb4513..4f123f2b 100644 --- a/subiquity/utils.py +++ b/subiquity/utils.py @@ -113,3 +113,13 @@ def crypt_password(passwd, algo='SHA-512'): salt = 16 * ' ' salt = ''.join([random.choice(salt_set) for c in salt]) return crypt.crypt(passwd, algos[algo] + salt) + + +def is_root(): + """ Returns root or if sudo user exists + """ + sudo_user = os.getenv('SUDO_USER', None) + + if os.geteuid() != 0 or not sudo_user: + return False + return True