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

Fix issue with pathless config items #785

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
16 changes: 11 additions & 5 deletions dissect/target/plugins/os/unix/etc/etc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import fnmatch
import re
from pathlib import Path
Expand Down Expand Up @@ -28,9 +30,10 @@
def __init__(self, target: Target):
super().__init__(target, "/etc")

def _sub(self, items: ConfigurationEntry, entry: Path, pattern: str) -> Iterator[UnixConfigTreeRecord]:
def _sub(
self, items: ConfigurationEntry | dict, entry: Path, orig_path: Path, pattern: str
) -> Iterator[UnixConfigTreeRecord]:
index = 0
config_entry = items
if not isinstance(items, dict):
items = items.as_dict()

Expand All @@ -39,7 +42,7 @@
path = Path(entry) / Path(key)

if isinstance(value, dict):
yield from self._sub(value, path, pattern)
yield from self._sub(value, path, orig_path, pattern)

Check warning on line 45 in dissect/target/plugins/os/unix/etc/etc.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/os/unix/etc/etc.py#L45

Added line #L45 was not covered by tests
continue

if not isinstance(value, list):
Expand All @@ -48,7 +51,7 @@
if fnmatch.fnmatch(path, pattern):
data = {
"_target": self.target,
"source": self.target.fs.path(config_entry.entry.path),
"source": self.target.fs.path(orig_path),
"path": path,
"key": key,
"value": value,
Expand All @@ -68,7 +71,10 @@
for item in items:
try:
config_object = self.get(str(Path(entry) / Path(item)))
yield from self._sub(config_object, Path(entry) / Path(item), pattern)

if isinstance(config_object, ConfigurationEntry):
path = Path(entry) / Path(item)
Comment on lines 73 to +76
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path = Path(entry) / item
config_object = self.get(str(path))

yield from self._sub(config_object, path, orig_path=path, pattern=pattern)

Check warning on line 77 in dissect/target/plugins/os/unix/etc/etc.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/os/unix/etc/etc.py#L75-L77

Added lines #L75 - L77 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orig_path will not contain the root. aka, /etc. I think it might be a good idea to add that to it.

except Exception:
self.target.log.warning("Could not open configuration item: %s", item)
pass