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 for using the correct volume name to mount filesystems in Unix #677

Merged
merged 5 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dissect/target/plugins/os/unix/_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ def _add_mounts(self) -> None:
fs_id = None
fs_subvol = None
fs_subvolid = None
fs_volume_name = fs.volume.name if fs.volume and not isinstance(fs.volume, list) else None
fs_last_mount = None
fs_volume_name = None
vol_volume_name = fs.volume.name if fs.volume and not isinstance(fs.volume, list) else None

if fs.__type__ == "xfs":
fs_id = fs.xfs.uuid
Expand All @@ -224,8 +225,9 @@ def _add_mounts(self) -> None:

if (
(fs_id and (fs_id == dev_id and (subvol == fs_subvol or subvolid == fs_subvolid)))
or (fs_volume_name and (fs_volume_name == volume_name))
or (fs_last_mount and (fs_last_mount == mount_point))
or (fs_volume_name and (fs_volume_name == volume_name))
or (vol_volume_name and (vol_volume_name == volume_name))
):
self.target.log.debug("Mounting %s (%s) at %s", fs, fs.volume, mount_point)
self.target.fs.mount(mount_point, fs)
Expand Down
28 changes: 26 additions & 2 deletions tests/plugins/os/unix/test__os.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import tempfile
from io import BytesIO
from pathlib import Path
from unittest.mock import Mock, patch
from uuid import UUID

import pytest

from dissect.target.filesystem import VirtualFilesystem
from dissect.target.plugins.os.unix._os import parse_fstab
from dissect.target.plugins.os.unix._os import UnixPlugin, parse_fstab
from dissect.target.target import Target

FSTAB_CONTENT = """
Expand Down Expand Up @@ -44,7 +45,7 @@
""" # noqa


def test_parse_fstab(tmp_path):
def test_parse_fstab(tmp_path: Path) -> None:
with tempfile.NamedTemporaryFile(dir=tmp_path, delete=False) as tf:
tf.write(FSTAB_CONTENT.encode("ascii"))
tf.close()
Expand All @@ -71,6 +72,29 @@ def test_parse_fstab(tmp_path):
}


def test_mount_volume_name_regression(fs_unix: VirtualFilesystem) -> None:
mock_fs = Mock()
mock_vol = Mock()

mock_vol.name = "test-volume"

mock_fs.__type__ = "ext"
mock_fs.extfs.volume_name = "ext-volume"
mock_fs.volume = mock_vol
mock_fs.exists.return_value = False

for expected_volume_name in ["test-volume", "ext-volume"]:
with patch(
"dissect.target.plugins.os.unix._os.parse_fstab",
return_value=[(None, expected_volume_name, "/mnt", "auto", "default")],
):
target = Target()
target.filesystems.add(mock_fs)
UnixPlugin.create(target, fs_unix)

assert target.fs.mounts["/mnt"] == mock_fs


@pytest.mark.parametrize(
"path, expected_hostname, expected_domain, file_content",
[
Expand Down
Loading