mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
users: Avoid error when user's groups cannot be parsed
Add log warnings to help debug if there is a related issue. May help #1834. Tested: - Run action command with valid and invalid username. Warning is printed for invalid username. - Modify the output to remove '='. Warning is printed instead of exception. - Ensure that warnings messages are output to stderr and not stdout. - On frontpage.py change the call to get user groups and ensure that that output warning messages are not parsed groups. Signed-off-by: James Valleroy <jvalleroy@mailbox.org> [sunil: Drop module logger as root logger is at use] [sunil: Use %s formatting for logging API] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
b524cbe399
commit
1aaf5efb52
@ -5,6 +5,7 @@ Configuration helper for the LDAP user directory
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
@ -12,6 +13,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import augeas
|
import augeas
|
||||||
|
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
|
|
||||||
ACCESS_CONF = '/etc/security/access.conf'
|
ACCESS_CONF = '/etc/security/access.conf'
|
||||||
@ -200,8 +202,8 @@ def configure_ldapscripts():
|
|||||||
# modify a copy of the config file
|
# modify a copy of the config file
|
||||||
shutil.copy('/etc/ldapscripts/ldapscripts.conf', LDAPSCRIPTS_CONF)
|
shutil.copy('/etc/ldapscripts/ldapscripts.conf', LDAPSCRIPTS_CONF)
|
||||||
|
|
||||||
aug = augeas.Augeas(
|
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||||
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
|
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||||
aug.set('/augeas/load/Shellvars/lens', 'Shellvars.lns')
|
aug.set('/augeas/load/Shellvars/lens', 'Shellvars.lns')
|
||||||
aug.set('/augeas/load/Shellvars/incl[last() + 1]', LDAPSCRIPTS_CONF)
|
aug.set('/augeas/load/Shellvars/incl[last() + 1]', LDAPSCRIPTS_CONF)
|
||||||
aug.load()
|
aug.load()
|
||||||
@ -325,13 +327,20 @@ def get_user_groups(username):
|
|||||||
output = process.stdout.decode().strip()
|
output = process.stdout.decode().strip()
|
||||||
if output:
|
if output:
|
||||||
groups_part = output.split(' ')[2]
|
groups_part = output.split(' ')[2]
|
||||||
groups = groups_part.split('=')[1]
|
try:
|
||||||
|
groups = groups_part.split('=')[1]
|
||||||
|
except IndexError:
|
||||||
|
logging.warning('Could not read groups for user %s: \n%s',
|
||||||
|
username, output)
|
||||||
|
return []
|
||||||
|
|
||||||
group_names = [
|
group_names = [
|
||||||
user.strip('()') for user in re.findall(r'\(.*?\)', groups)
|
user.strip('()') for user in re.findall(r'\(.*?\)', groups)
|
||||||
]
|
]
|
||||||
group_names.remove('users')
|
group_names.remove('users')
|
||||||
return group_names
|
return group_names
|
||||||
|
|
||||||
|
logging.warning('User %s not found in LDAP', username)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user