mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 21:14:15 +02:00
fix: ubuntu root password check
This commit is contained in:
@@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
### Fixes:
|
### Fixes:
|
||||||
- cached Flatpak app current version
|
- cached Flatpak app current version
|
||||||
- disk loader not filling all requested cached data from the disk
|
- 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)
|
- [Ubuntu 19.04 pip3 install issue] (https://github.com/vinifmor/bauh/issues/3)
|
||||||
|
|
||||||
### Code
|
### Code
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import io
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
|
|
||||||
from PyQt5.QtGui import QIcon
|
from PyQt5.QtGui import QIcon
|
||||||
from PyQt5.QtWidgets import QInputDialog, QLineEdit
|
from PyQt5.QtWidgets import QInputDialog, QLineEdit
|
||||||
|
|
||||||
from bauh.api.abstract.view import MessageType
|
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.qt.dialog import show_message
|
||||||
|
from bauh.view.util import resource
|
||||||
|
|
||||||
|
|
||||||
def is_root():
|
def is_root():
|
||||||
@@ -38,13 +37,19 @@ def ask_root_password(locale_keys: dict):
|
|||||||
|
|
||||||
|
|
||||||
def validate_password(password: str) -> bool:
|
def validate_password(password: str) -> bool:
|
||||||
proc = subprocess.Popen('sudo -k && echo {} | sudo -S whoami'.format(password),
|
clean = new_subprocess(['sudo', '-k']).stdout
|
||||||
shell=True,
|
echo = new_subprocess(['echo', password], stdin=clean).stdout
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.DEVNULL,
|
|
||||||
bufsize=-1)
|
|
||||||
stream = os._wrap_close(io.TextIOWrapper(proc.stdout), proc)
|
|
||||||
res = stream.read()
|
|
||||||
stream.close()
|
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user