From 4aec5a436a394cdd7eab7f5a6dd88aca7e2c9ca1 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 18 Sep 2019 13:30:46 -0300 Subject: [PATCH] fix: ubuntu root password check --- CHANGELOG.md | 1 + bauh/view/qt/root.py | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0e94c93..9f04e0ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixes: - cached Flatpak app current version - disk loader not filling all requested cached data from the disk +- Ubuntu root password check - [Ubuntu 19.04 pip3 install issue] (https://github.com/vinifmor/bauh/issues/3) ### Code diff --git a/bauh/view/qt/root.py b/bauh/view/qt/root.py index 477c604e..f3250253 100644 --- a/bauh/view/qt/root.py +++ b/bauh/view/qt/root.py @@ -1,13 +1,12 @@ -import io import os -import subprocess from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QInputDialog, QLineEdit from bauh.api.abstract.view import MessageType -from bauh.view.util import resource +from bauh.commons.system import new_subprocess from bauh.view.qt.dialog import show_message +from bauh.view.util import resource def is_root(): @@ -38,13 +37,19 @@ def ask_root_password(locale_keys: dict): def validate_password(password: str) -> bool: - proc = subprocess.Popen('sudo -k && echo {} | sudo -S whoami'.format(password), - shell=True, - stdout=subprocess.PIPE, - stderr=subprocess.DEVNULL, - bufsize=-1) - stream = os._wrap_close(io.TextIOWrapper(proc.stdout), proc) - res = stream.read() - stream.close() + clean = new_subprocess(['sudo', '-k']).stdout + echo = new_subprocess(['echo', password], stdin=clean).stdout - return bool(res.strip()) + validate = new_subprocess(['sudo', '-S', '-v'], stdin=echo) + + for o in validate.stdout: + pass + + for o in validate.stderr: + if o: + line = o.decode() + + if 'incorrect password attempt' in line: + return False + + return True