1
- using gsudo . Native ;
2
- using System ;
1
+ using System ;
3
2
using System . Runtime . ConstrainedExecution ;
4
3
using System . Runtime . InteropServices ;
5
4
using System . Security . Principal ;
6
5
using static gsudo . Native . TokensApi ;
7
6
8
- namespace gsudo . Tokens
7
+ namespace gsudo . Native
9
8
{
10
9
internal static partial class NativeMethods
11
10
{
@@ -21,19 +20,19 @@ internal static partial class NativeMethods
21
20
internal const int SE_PRIVILEGE_DISABLED = 0x00000000 ;
22
21
internal const int ERROR_NOT_ALL_ASSIGNED = 0x00000514 ;
23
22
24
- internal const UInt32 STANDARD_RIGHTS_REQUIRED = 0x000F0000 ;
25
- internal const UInt32 STANDARD_RIGHTS_READ = 0x00020000 ;
26
- internal const UInt32 TOKEN_ASSIGN_PRIMARY = 0x0001 ;
27
- internal const UInt32 TOKEN_DUPLICATE = 0x0002 ;
28
- internal const UInt32 TOKEN_IMPERSONATE = 0x0004 ;
29
- internal const UInt32 TOKEN_QUERY = 0x0008 ;
30
- internal const UInt32 TOKEN_QUERY_SOURCE = 0x0010 ;
31
- internal const UInt32 TOKEN_ADJUST_PRIVILEGES = 0x0020 ;
32
- internal const UInt32 TOKEN_ADJUST_GROUPS = 0x0040 ;
33
- internal const UInt32 TOKEN_ADJUST_DEFAULT = 0x0080 ;
34
- internal const UInt32 TOKEN_ADJUST_SESSIONID = 0x0100 ;
35
- internal const UInt32 TOKEN_READ = ( STANDARD_RIGHTS_READ | TOKEN_QUERY ) ;
36
- internal const UInt32 TOKEN_ALL_ACCESS = ( STANDARD_RIGHTS_REQUIRED |
23
+ internal const uint STANDARD_RIGHTS_REQUIRED = 0x000F0000 ;
24
+ internal const uint STANDARD_RIGHTS_READ = 0x00020000 ;
25
+ internal const uint TOKEN_ASSIGN_PRIMARY = 0x0001 ;
26
+ internal const uint TOKEN_DUPLICATE = 0x0002 ;
27
+ internal const uint TOKEN_IMPERSONATE = 0x0004 ;
28
+ internal const uint TOKEN_QUERY = 0x0008 ;
29
+ internal const uint TOKEN_QUERY_SOURCE = 0x0010 ;
30
+ internal const uint TOKEN_ADJUST_PRIVILEGES = 0x0020 ;
31
+ internal const uint TOKEN_ADJUST_GROUPS = 0x0040 ;
32
+ internal const uint TOKEN_ADJUST_DEFAULT = 0x0080 ;
33
+ internal const uint TOKEN_ADJUST_SESSIONID = 0x0100 ;
34
+ internal const uint TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY ;
35
+ internal const uint TOKEN_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED |
37
36
TOKEN_ASSIGN_PRIMARY |
38
37
TOKEN_DUPLICATE |
39
38
TOKEN_IMPERSONATE |
@@ -42,7 +41,7 @@ internal static partial class NativeMethods
42
41
TOKEN_ADJUST_PRIVILEGES |
43
42
TOKEN_ADJUST_GROUPS |
44
43
TOKEN_ADJUST_DEFAULT |
45
- TOKEN_ADJUST_SESSIONID ) ;
44
+ TOKEN_ADJUST_SESSIONID ;
46
45
47
46
[ DllImport ( "kernel32.dll" , CharSet = CharSet . Auto , SetLastError = true ) ]
48
47
internal static extern IntPtr GetCurrentProcess ( ) ;
@@ -65,7 +64,13 @@ internal static extern bool OpenProcessToken(IntPtr processHandle,
65
64
66
65
[ DllImport ( "kernel32.dll" , CharSet = CharSet . Auto , SetLastError = true ) ]
67
66
[ return : MarshalAs ( UnmanagedType . Bool ) ]
68
- internal static extern Boolean CloseHandle ( IntPtr hObject ) ;
67
+ internal static extern bool CloseHandle ( IntPtr hObject ) ;
68
+
69
+ [ DllImport ( "advapi32.dll" , SetLastError = true ) ]
70
+ internal static extern bool GetKernelObjectSecurity ( IntPtr Handle , uint securityInformation , IntPtr pSecurityDescriptor , uint nLength , out uint lpnLengthNeeded ) ;
71
+
72
+ [ DllImport ( "advapi32.dll" , SetLastError = true ) ]
73
+ internal static extern bool SetKernelObjectSecurity ( IntPtr Handle , uint securityInformation , IntPtr pSecurityDescriptor ) ;
69
74
70
75
[ StructLayout ( LayoutKind . Sequential ) ]
71
76
public struct LUID
@@ -100,5 +105,20 @@ public struct TOKEN_PRIVILEGES
100
105
101
106
public LUID_AND_ATTRIBUTES [ ] Privileges { get => privileges ; set => privileges = value ; }
102
107
}
108
+
103
109
}
110
+
111
+ [ Flags ]
112
+ internal enum SECURITY_INFORMATION : uint
113
+ {
114
+ OWNER_SECURITY_INFORMATION = 0x00000001 ,
115
+ GROUP_SECURITY_INFORMATION = 0x00000002 ,
116
+ DACL_SECURITY_INFORMATION = 0x00000004 ,
117
+ SACL_SECURITY_INFORMATION = 0x00000008 ,
118
+ UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000 ,
119
+ UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000 ,
120
+ PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000 ,
121
+ PROTECTED_DACL_SECURITY_INFORMATION = 0x80000000
122
+ }
123
+
104
124
}
0 commit comments