File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -30,3 +30,10 @@ features = [
30
30
" Win32_NetworkManagement_IpHelper" ,
31
31
" Win32_NetworkManagement_Ndis" ,
32
32
]
33
+
34
+ [target .'cfg(windows)' .dev-dependencies .windows-sys ]
35
+ workspace = true
36
+ features = [
37
+ " Win32_Storage" ,
38
+ " Win32_Storage_FileSystem"
39
+ ]
Original file line number Diff line number Diff line change @@ -45,3 +45,34 @@ pub fn is_admin_owned<T: AsRawHandle>(handle: T) -> io::Result<bool> {
45
45
46
46
Ok ( is_system_owned || is_admin_owned)
47
47
}
48
+
49
+ #[ cfg( test) ]
50
+ mod test {
51
+ use std:: os:: windows:: fs:: OpenOptionsExt ;
52
+ use windows_sys:: Win32 :: Storage :: FileSystem :: FILE_FLAG_BACKUP_SEMANTICS ;
53
+
54
+ use super :: is_admin_owned;
55
+
56
+ #[ test]
57
+ pub fn test_is_admin_owned ( ) {
58
+ // The kernel image is owned by "TrustedInstaller", so we expect the function to return 'false'
59
+ let path = std:: fs:: File :: open ( r"C:\Windows\System32\ntoskrnl.exe" ) . unwrap ( ) ;
60
+ let result = is_admin_owned ( path) ;
61
+ assert ! (
62
+ matches!( result, Ok ( false ) ) ,
63
+ "expected ntoskrnl.exe to be owned by TrustedInstaller (false), got {result:?}"
64
+ ) ;
65
+
66
+ // The Windows system temp directory is owned by SYSTEM, so we expect 'true'
67
+ let path = std:: fs:: File :: options ( )
68
+ . read ( true )
69
+ . custom_flags ( FILE_FLAG_BACKUP_SEMANTICS )
70
+ . open ( r"C:\Windows\Temp" )
71
+ . unwrap ( ) ;
72
+ let result = is_admin_owned ( path) ;
73
+ assert ! (
74
+ matches!( result, Ok ( true ) ) ,
75
+ "expected TEMP to be owned by SYSTEM (true), got {result:?}"
76
+ ) ;
77
+ }
78
+ }
You can’t perform that action at this time.
0 commit comments