Skip to content

Commit

Permalink
Fix issue with pathless config items (#785)
Browse files Browse the repository at this point in the history
Fix issue with pathless config items
  • Loading branch information
cecinestpasunepipe authored Nov 21, 2024
1 parent 6e6a546 commit 8785906
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 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 @@ -30,9 +32,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()

Expand All @@ -41,7 +44,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):
Expand All @@ -50,7 +53,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,
Expand All @@ -71,8 +74,11 @@ def etc(self, pattern: str, root: str) -> Iterator[UnixConfigTreeRecord]:
for entry, subs, items in self.config_fs.walk(root):
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)
path = Path(entry) / item
config_object = self.get(str(path))

if isinstance(config_object, ConfigurationEntry):
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

0 comments on commit 8785906

Please sign in to comment.