Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Parse SSSD group listings #3406

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions insights/core/ls_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ def parse_rhel8_selinux(parts):
return result


def parse_sssd(parts):
links, owner, group, domain, last = parts
size, rest = last.split(None, 1)
result = {
"links": int(links),
"owner": owner,
"group": group + " " + domain,
"size": int(size),
"date": rest[:12],
"name": rest[13:]
}

return result


PASS_KEYS = set(["name", "total"])
DELAYED_KEYS = ["entries", "files", "dirs", "specials"]

Expand Down Expand Up @@ -195,6 +210,9 @@ def _load(self):
# always have at least two pieces separated by ':'.
if ":" in line.split()[4]:
rest = parse_rhel8_selinux(parts[1:])
elif line.split()[4].startswith("users") or "@" in line.split()[4]:
parts = line.split(None, 5)
rest = parse_sssd(parts[1:])
else:
rest = parse_non_selinux(parts[1:])
else:
Expand Down
27 changes: 27 additions & 0 deletions insights/tests/test_ls_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@
adsf
"""

SSSD_LISTINGS_1 = """
/var/log:
total 20
-rw-r--r--. 1 root domain [email protected] 36548 Jan 13 10:43 Xorg.1.log
-rw-r--r--. 1 root domain [email protected] 28245 Jan 13 10:38 Xorg.1.log.old
-rw-------. 1 root root 52756 Jun 28 10:26 X.log
"""

SSSD_LISTINGS_2 = """
/var/log:
total 20
-rw-r--r--. 1 root domain users 40893 Jan 31 16:34 Xorg.1.log
-rw-r--r--. 1 root domain users 36911 Dec 20 09:49 Xorg.1.log.old
"""


def test_parse_selinux():
results = parse(SELINUX_DIRECTORY.splitlines(), "/boot")
Expand Down Expand Up @@ -312,3 +327,15 @@ def test_rhel8_selinux():
assert res["date"] == "Apr 8 16:41"
assert res["name"] == "abcd-efgh-ijkl-mnop"
assert res["dir"] == "/var/lib/nova/instances"


def test_sssd_listing():
results = parse(SSSD_LISTINGS_1.splitlines(), "/var/log")
assert len(results) == 1
assert results["/var/log"]["entries"]['Xorg.1.log']['group'] == "domain [email protected]"
assert len(results["/var/log"]["entries"]) == 3

results = parse(SSSD_LISTINGS_2.splitlines(), "/var/log")
assert len(results) == 1
assert results["/var/log"]["entries"]['Xorg.1.log']['group'] == "domain users"
assert len(results["/var/log"]["entries"]) == 2