Skip to content
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
12 changes: 6 additions & 6 deletions acquire/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@

def misc_windows_user_homes(target: Target) -> Iterator[fsutil.TargetPath]:
misc_dirs = {
("windows/serviceprofiles/localservice", False),
("windows/serviceprofiles/networkservice", False),
("windows/system32/config/systemprofile", False),
("users", True),
("documents and settings", True),
("Windows/ServiceProfiles/LocalService", False),
("Windows/ServiceProfiles/NetworkService", False),
("Windows/System32/config/systemprofile", False),
("Users", True),
("Documents and Settings", True),
}

for fs in target.fs.path().iterdir():
Expand Down Expand Up @@ -146,7 +146,7 @@ def misc_osx_user_homes(target: Target) -> Iterator[fsutil.TargetPath]:
def from_user_home(target: Target, path: str) -> Iterator[str]:
try:
for user_details in target.user_details.all_with_home():
yield normalize_path(target, user_details.home_path.joinpath(path))
yield normalize_path(target, user_details.home_path.joinpath(path), lower_case=False)
except Exception as e:
log.warning("Error occurred when requesting all user homes")
log.debug("", exc_info=e)
Expand Down
10 changes: 8 additions & 2 deletions acquire/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ def serialize_path(path: Any) -> str:

# Naive way to serialize TargetPath filesystem's metadata is
# to rely on uniqueness of `path._fs` object
fs_id = id(path._fs)
return f"{path._fs.__type__}:{fs_id}:{path}"
fs = path._fs
fs_id = id(fs)
fs_type = fs.__type__
path = str(path)
if not fs.case_sensitive:
path = path.lower()

return f"{fs_type}:{fs_id}:{path}"


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions acquire/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,13 @@ def persist_execution_report(path: Path, report_data: dict) -> Path:
SYSVOL_SUBST = re.compile(r"^(/\?\?/)?[cC]:")


def normalize_path(target: Target, path: Path, resolve: bool = False) -> str:
def normalize_path(target: Target, path: Path, resolve: bool = False, lower_case: bool = True) -> str:
if resolve:
path = path.resolve()

path = path.as_posix()

if not target.fs.case_sensitive:
if not target.fs.case_sensitive and lower_case:
path = path.lower()

if target.os == "windows":
Expand Down
47 changes: 33 additions & 14 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,94 +296,113 @@ def test_check_and_set_acquire_args_cagent():


@pytest.mark.parametrize(
"path, resolve, norm_path, case_sensitive, os",
"path, resolve, lower_case, case_sensitive, os, result",
[
(
pathlib.Path("/foo/bar"),
False,
"/foo/bar",
True,
True,
"dummy",
"/foo/bar",
),
(
pathlib.Path("/foo/BAR"),
False,
"/foo/bar",
True,
False,
"dummy",
"/foo/bar",
),
(
pathlib.Path("/foo/BAR"),
False,
"/foo/BAR",
True,
True,
"dummy",
"/foo/BAR",
),
(
pathlib.Path("/foo/../bar"),
False,
"/foo/../bar",
True,
True,
"dummy",
"/foo/../bar",
),
(
pathlib.Path("/foo/../foo/bar"),
True,
"/foo/bar",
True,
True,
"dummy",
"/foo/bar",
),
(
pathlib.PureWindowsPath("c:\\foo\\bar"),
False,
"sysvol/foo/bar",
True,
False,
"windows",
"sysvol/foo/bar",
),
(
pathlib.PureWindowsPath("C:\\foo\\bar"),
False,
"sysvol/foo/bar",
True,
False,
"windows",
"sysvol/foo/bar",
),
(
pathlib.PureWindowsPath("\\??\\C:\\foo\\bar"),
False,
"sysvol/foo/bar",
True,
False,
"windows",
"sysvol/foo/bar",
),
(
pathlib.PureWindowsPath("\\??\\c:\\foo\\bar"),
False,
"sysvol/foo/bar",
True,
False,
"windows",
"sysvol/foo/bar",
),
(
pathlib.PureWindowsPath("D:\\foo\\bar"),
False,
True,
False,
"windows",
"d:/foo/bar",
),
(
pathlib.PureWindowsPath("D:\\Foo\\BAR"),
False,
False,
False,
"windows",
"D:/Foo/BAR",
),
],
)
def test_utils_normalize_path(
mock_target: Target,
path: pathlib.Path,
resolve: bool,
norm_path: str,
lower_case: bool,
case_sensitive: bool,
os: str,
result: str,
) -> None:
with patch.object(mock_target, "os", new=os), patch.object(mock_target.fs, "_case_sensitive", new=case_sensitive):
resolved_path = normalize_path(mock_target, path, resolve=resolve)
resolved_path = normalize_path(mock_target, path, resolve=resolve, lower_case=lower_case)

if platform.system() == "Windows":
# A resolved path on windows adds a C:\ prefix. So we check if it ends with our expected
# path string
assert resolved_path.endswith(norm_path)
assert resolved_path.endswith(result)
else:
assert resolved_path == norm_path
assert resolved_path == result