Skip to content

Commit

Permalink
Improved
Browse files Browse the repository at this point in the history
  • Loading branch information
cecinestpasunepipe committed Aug 5, 2024
1 parent 1eac540 commit deb58c5
Showing 1 changed file with 9 additions and 5 deletions.
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

from dissect.target import Target
from dissect.target.helpers.record import TargetRecordDescriptor
Expand All @@ -28,7 +28,9 @@ 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: Union[ConfigurationEntry, dict], entry: Path, orig_path: Path, pattern: str
) -> Iterator[UnixConfigTreeRecord]:
index = 0
config_entry = items
if not isinstance(items, dict):
Expand All @@ -39,7 +41,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)

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 @@ 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 if hasattr(config_entry,"entry") else path),
"source": self.target.fs.path(
config_entry.entry.path if hasattr(config_entry, "entry") else orig_path
),
"path": path,
"key": key,
"value": value,
Expand All @@ -68,7 +72,7 @@ def etc(self, pattern: str) -> Iterator[UnixConfigTreeRecord]:
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
except Exception:
self.target.log.warning("Could not open configuration item: %s", item)
pass

0 comments on commit deb58c5

Please sign in to comment.