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
7 changes: 3 additions & 4 deletions dissect/target/plugins/os/unix/_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def users(self, sessions: bool = False) -> Iterator[UnixUserRecord]:
# Yield users found in passwd files.
for passwd_file in PASSWD_FILES:
if (path := self.target.fs.path(passwd_file)).exists():
for line in path.open("rt"):
for line in path.open("rt", errors="surrogateescape"):
line = line.strip()
if not line or line.startswith("#"):
continue
Expand All @@ -85,13 +85,12 @@ def users(self, sessions: bool = False) -> Iterator[UnixUserRecord]:
current_user = (pwent.get(0), pwent.get(5), pwent.get(6))
if current_user in seen_users:
continue

seen_users.add(current_user)
yield UnixUserRecord(
name=pwent.get(0),
passwd=pwent.get(1),
uid=pwent.get(2),
gid=pwent.get(3),
uid=pwent.get(2) or None,
gid=pwent.get(3) or None,
gecos=pwent.get(4),
home=posix_path(pwent.get(5)),
shell=pwent.get(6),
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ def target_unix_users(target_unix: Target, fs_unix: Filesystem) -> Iterator[Targ
passwd = """
root:x:0:0:root:/root:/bin/bash
user:x:1000:1000:user:/home/user:/bin/bash
+@ngtest:x:::::
"""
fs_unix.map_file_fh("/etc/passwd", BytesIO(textwrap.dedent(passwd).encode()))
yield target_unix
Expand Down
8 changes: 7 additions & 1 deletion tests/plugins/os/unix/test__os.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_parse_hostname_string(
def test_users(target_unix_users: Target) -> None:
users = list(target_unix_users.users())

assert len(users) == 2
assert len(users) == 3

assert users[0].name == "root"
assert users[0].uid == 0
Expand All @@ -148,6 +148,12 @@ def test_users(target_unix_users: Target) -> None:
assert users[1].home == posix_path("/home/user")
assert users[1].shell == "/bin/bash"

assert users[2].name == "+@ngtest"
assert users[2].uid is None
assert users[2].gid is None
assert users[2].home == posix_path("")
assert users[2].shell == ""


@pytest.mark.parametrize(
"expected_arch, elf_buf",
Expand Down
Loading