44import re
55import uuid
66from struct import unpack
7- from typing import Iterator , Optional , Union
7+ from typing import Iterator
8+
9+ from flow .record .fieldtypes import posix_path
810
911from dissect .target .filesystem import Filesystem
1012from dissect .target .helpers .fsutil import TargetPath
@@ -25,7 +27,7 @@ def __init__(self, target: Target):
2527 self ._os_release = self ._parse_os_release ()
2628
2729 @classmethod
28- def detect (cls , target : Target ) -> Optional [ Filesystem ] :
30+ def detect (cls , target : Target ) -> Filesystem | None :
2931 for fs in target .filesystems :
3032 if fs .exists ("/var" ) and fs .exists ("/etc" ):
3133 return fs
@@ -71,7 +73,7 @@ def users(self, sessions: bool = False) -> Iterator[UnixUserRecord]:
7173 uid = pwent .get (2 ),
7274 gid = pwent .get (3 ),
7375 gecos = pwent .get (4 ),
74- home = self . target . fs . path (pwent .get (5 )),
76+ home = posix_path (pwent .get (5 )),
7577 shell = pwent .get (6 ),
7678 source = passwd_file ,
7779 _target = self .target ,
@@ -115,23 +117,23 @@ def users(self, sessions: bool = False) -> Iterator[UnixUserRecord]:
115117
116118 yield UnixUserRecord (
117119 name = user ["name" ],
118- home = user ["home" ],
120+ home = posix_path ( user ["home" ]) ,
119121 shell = user ["shell" ],
120122 source = "/var/log/syslog" ,
121123 _target = self .target ,
122124 )
123125
124126 @export (property = True )
125- def architecture (self ) -> Optional [ str ] :
127+ def architecture (self ) -> str | None :
126128 return self ._get_architecture (self .os )
127129
128130 @export (property = True )
129- def hostname (self ) -> Optional [ str ] :
131+ def hostname (self ) -> str | None :
130132 hosts_string = self ._hosts_dict .get ("hostname" , "localhost" )
131133 return self ._hostname_dict .get ("hostname" , hosts_string )
132134
133135 @export (property = True )
134- def domain (self ) -> Optional [ str ] :
136+ def domain (self ) -> str | None :
135137 domain = self ._hostname_dict .get ("domain" , "localhost" )
136138 if domain == "localhost" :
137139 domain = self ._hosts_dict ["hostname" , "localhost" ]
@@ -152,7 +154,7 @@ def _parse_rh_legacy(self, path):
152154 _ , _ , hostname = line .rstrip ().partition ("=" )
153155 return hostname
154156
155- def _parse_hostname_string (self , paths : Optional [ list [str ]] = None ) -> Optional [ dict [str , str ]] :
157+ def _parse_hostname_string (self , paths : list [str ] | None = None ) -> dict [str , str ] | None :
156158 """
157159 Returns a dict containing the hostname and domain name portion of the path(s) specified
158160
@@ -184,7 +186,7 @@ def _parse_hostname_string(self, paths: Optional[list[str]] = None) -> Optional[
184186 break # break whenever a valid hostname is found
185187 return hostname_dict
186188
187- def _parse_hosts_string (self , paths : Optional [ list [str ]] = None ) -> dict [str , str ]:
189+ def _parse_hosts_string (self , paths : list [str ] | None = None ) -> dict [str , str ]:
188190 paths = paths or ["/etc/hosts" ]
189191 hosts_string = {"ip" : None , "hostname" : None }
190192
@@ -244,7 +246,7 @@ def _add_mounts(self) -> None:
244246 self .target .log .debug ("Mounting %s (%s) at %s" , fs , fs .volume , mount_point )
245247 self .target .fs .mount (mount_point , fs )
246248
247- def _parse_os_release (self , glob : Optional [ str ] = None ) -> dict [str , str ]:
249+ def _parse_os_release (self , glob : str | None = None ) -> dict [str , str ]:
248250 """Parse files containing Unix version information.
249251
250252 Not all these files are equal. Generally speaking these files are
@@ -286,7 +288,7 @@ def _parse_os_release(self, glob: Optional[str] = None) -> dict[str, str]:
286288 continue
287289 return os_release
288290
289- def _get_architecture (self , os : str = "unix" , path : str = "/bin/ls" ) -> Optional [ str ] :
291+ def _get_architecture (self , os : str = "unix" , path : str = "/bin/ls" ) -> str | None :
290292 arch_strings = {
291293 0x00 : "Unknown" ,
292294 0x02 : "SPARC" ,
@@ -322,7 +324,7 @@ def _get_architecture(self, os: str = "unix", path: str = "/bin/ls") -> Optional
322324def parse_fstab (
323325 fstab : TargetPath ,
324326 log : logging .Logger = log ,
325- ) -> Iterator [tuple [Union [ uuid .UUID , str ] , str , str , str , str ]]:
327+ ) -> Iterator [tuple [uuid .UUID | str , str , str , str , str ]]:
326328 """Parse fstab file and return a generator that streams the details of entries,
327329 with unsupported FS types and block devices filtered away.
328330 """
0 commit comments