diff --git a/dissect/target/plugins/os/unix/etc/etc.py b/dissect/target/plugins/os/unix/etc/etc.py index 2c836ece3..f7ce28fb1 100644 --- a/dissect/target/plugins/os/unix/etc/etc.py +++ b/dissect/target/plugins/os/unix/etc/etc.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import fnmatch import re from pathlib import Path @@ -28,9 +30,10 @@ class EtcTree(ConfigurationTreePlugin): 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() @@ -39,7 +42,7 @@ def _sub(self, items: ConfigurationEntry, entry: Path, pattern: str) -> Iterator 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) continue if not isinstance(value, list): @@ -48,7 +51,7 @@ def _sub(self, items: ConfigurationEntry, entry: Path, pattern: str) -> Iterator 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, @@ -68,7 +71,10 @@ def etc(self, pattern: str, root: str) -> Iterator[UnixConfigTreeRecord]: 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) + yield from self._sub(config_object, path, orig_path=path, pattern=pattern) except Exception: self.target.log.warning("Could not open configuration item: %s", item) pass