mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
*: Use action_utils.run instead of subprocess.check_output
- This is to capture stdout and stderr and transmit that from privileged daemon back to the service to be displayed in HTML. Tests: - Unit tests and code checks pass. - Some of the modified actions work as expected. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
1 parent
bf9005ac48
commit
b253166f6d
17 files changed
+101
-72
No files matched your search
@@ -9,6 +9,7 @@ from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth import app as app_module
|
||||
from plinth import cfg, menu
|
||||
from plinth.config import DropinConfigs
|
||||
@@ -127,8 +128,9 @@ def _diagnose_ldap_entry(search_item: str) -> DiagnosticCheck:
|
||||
result = Result.FAILED
|
||||
|
||||
try:
|
||||
output = subprocess.check_output(
|
||||
['ldapsearch', '-LLL', '-x', '-b', 'dc=thisbox', search_item])
|
||||
output = action_utils.run(
|
||||
['ldapsearch', '-LLL', '-x', '-b', 'dc=thisbox', search_item],
|
||||
check=True).stdout
|
||||
if search_item in output.decode():
|
||||
result = Result.PASSED
|
||||
except subprocess.CalledProcessError:
|
||||
|
||||
@@ -331,8 +331,8 @@ def get_nslcd_config() -> dict[str, str]:
|
||||
def _get_samba_users():
|
||||
"""Get users from the Samba user database."""
|
||||
# 'pdbedit -L' is better for listing users but is installed only with samba
|
||||
stdout = subprocess.check_output(
|
||||
['tdbdump', '/var/lib/samba/private/passdb.tdb']).decode()
|
||||
stdout = action_utils.run(['tdbdump', '/var/lib/samba/private/passdb.tdb'],
|
||||
check=True).stdout.decode()
|
||||
return re.findall(r'USER_(.*)\\0', stdout)
|
||||
|
||||
|
||||
@@ -354,7 +354,8 @@ def _disconnect_samba_user(username):
|
||||
|
||||
def _get_user_home(username):
|
||||
"""Return the user home directory."""
|
||||
output = subprocess.check_output(['getent', 'passwd', username], text=True)
|
||||
output = action_utils.run(['getent', 'passwd', username],
|
||||
check=True).stdout.decode()
|
||||
return pathlib.Path(output.split(':')[5])
|
||||
|
||||
|
||||
@@ -491,11 +492,11 @@ def _get_admin_users():
|
||||
admin_users = []
|
||||
|
||||
try:
|
||||
output = subprocess.check_output([
|
||||
output = action_utils.run([
|
||||
'ldapsearch', '-LLL', '-Q', '-Y', 'EXTERNAL', '-H', 'ldapi:///',
|
||||
'-o', 'ldif-wrap=no', '-s', 'base', '-b',
|
||||
'cn=admin,ou=groups,dc=thisbox', 'memberUid'
|
||||
]).decode()
|
||||
], check=True).stdout.decode()
|
||||
except subprocess.CalledProcessError as error:
|
||||
if error.returncode == 32:
|
||||
# no entries found
|
||||
|
||||
Reference in new issue
Block a user