Skip to content

Commit

Permalink
Parse SSSD group listings
Browse files Browse the repository at this point in the history
The SSSD group listings breaks the present implementation by parsing the domain
group as the file-size.

Resolves: #3395

Signed-off-by: Sachin Patil <[email protected]>
  • Loading branch information
Sachin Patil committed May 10, 2022
1 parent 57a3cd8 commit 438b570
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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, group1, group2, last = parts
size, rest = last.split(None, 1)
result = {
"links": int(links),
"owner": owner,
"group": group1 + " " + group2,
"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 "@" in line.split()[4]:
parts = line.split(None, 5)
rest = parse_sssd(parts[1:])
else:
rest = parse_non_selinux(parts[1:])
else:
Expand Down
15 changes: 15 additions & 0 deletions insights/tests/test_ls_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@
adsf
"""

SSSD_LISTINGS = """
/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
"""


def test_parse_selinux():
results = parse(SELINUX_DIRECTORY.splitlines(), "/boot")
Expand Down Expand Up @@ -312,3 +320,10 @@ 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.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

0 comments on commit 438b570

Please sign in to comment.