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
14 changes: 9 additions & 5 deletions dissect/target/plugins/os/unix/etc/etc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fnmatch
import re
from pathlib import Path
from typing import Iterator
from typing import Iterator, Union
cecinestpasunepipe marked this conversation as resolved.
Show resolved Hide resolved

from dissect.target import Target
from dissect.target.helpers.record import TargetRecordDescriptor
Expand All @@ -28,7 +28,9 @@
def __init__(self, target: Target):
super().__init__(target, "/etc")

def _sub(self, items: ConfigurationEntry, entry: Path, pattern: str) -> Iterator[UnixConfigTreeRecord]:
def _sub(
self, items: Union[ConfigurationEntry, dict], entry: Path, orig_path: Path, pattern: str
cecinestpasunepipe marked this conversation as resolved.
Show resolved Hide resolved
) -> Iterator[UnixConfigTreeRecord]:
index = 0
config_entry = items
if not isinstance(items, dict):
Expand All @@ -39,7 +41,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 44 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#L44

Added line #L44 was not covered by tests
continue

if not isinstance(value, list):
Expand All @@ -48,7 +50,9 @@
if fnmatch.fnmatch(path, pattern):
data = {
"_target": self.target,
"source": self.target.fs.path(config_entry.entry.path),
"source": self.target.fs.path(
config_entry.entry.path if hasattr(config_entry, "entry") else orig_path
),
cecinestpasunepipe marked this conversation as resolved.
Show resolved Hide resolved
"path": path,
"key": key,
"value": value,
Expand All @@ -68,7 +72,7 @@
try:
config_object = self.get(str(Path(entry) / Path(item)))
if isinstance(config_object, ConfigurationEntry):
yield from self._sub(config_object, Path(entry) / Path(item), pattern)
yield from self._sub(config_object, Path(entry) / Path(item), Path(entry) / Path(item), pattern)

Check warning on line 75 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

Added line #L75 was not covered by tests
cecinestpasunepipe marked this conversation as resolved.
Show resolved Hide resolved
except Exception:
self.target.log.warning("Could not open configuration item: %s", item)
pass