1 // Licensed under the Apache License, Version 2.0
2 // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
4 // All files in the project carrying such notice may not be copied, modified, or distributed
5 // except according to those terms.
6 use shared::guiddef::GUID;
7 use shared::minwindef::{DWORD, ULONG};
8 use um::winbase::LocalFree;
9 use um::winnt::{HANDLE, LONG, LPSTR, LPWSTR, PVOID, SID};
10 #[inline]
AccFree(p: PVOID) -> PVOID11 pub unsafe fn AccFree(p: PVOID) -> PVOID {
12     LocalFree(p)
13 }
14 ENUM!{enum SE_OBJECT_TYPE {
15     SE_UNKNOWN_OBJECT_TYPE = 0,
16     SE_FILE_OBJECT,
17     SE_SERVICE,
18     SE_PRINTER,
19     SE_REGISTRY_KEY,
20     SE_LMSHARE,
21     SE_KERNEL_OBJECT,
22     SE_WINDOW_OBJECT,
23     SE_DS_OBJECT,
24     SE_DS_OBJECT_ALL,
25     SE_PROVIDER_DEFINED_OBJECT,
26     SE_WMIGUID_OBJECT,
27     SE_REGISTRY_WOW64_32KEY,
28     SE_REGISTRY_WOW64_64KEY,
29 }}
30 ENUM!{enum TRUSTEE_TYPE {
31     TRUSTEE_IS_UNKNOWN,
32     TRUSTEE_IS_USER,
33     TRUSTEE_IS_GROUP,
34     TRUSTEE_IS_DOMAIN,
35     TRUSTEE_IS_ALIAS,
36     TRUSTEE_IS_WELL_KNOWN_GROUP,
37     TRUSTEE_IS_DELETED,
38     TRUSTEE_IS_INVALID,
39     TRUSTEE_IS_COMPUTER,
40 }}
41 ENUM!{enum TRUSTEE_FORM {
42     TRUSTEE_IS_SID,
43     TRUSTEE_IS_NAME,
44     TRUSTEE_BAD_FORM,
45     TRUSTEE_IS_OBJECTS_AND_SID,
46     TRUSTEE_IS_OBJECTS_AND_NAME,
47 }}
48 ENUM!{enum MULTIPLE_TRUSTEE_OPERATION {
49     NO_MULTIPLE_TRUSTEE,
50     TRUSTEE_IS_IMPERSONATE,
51 }}
52 STRUCT!{struct OBJECTS_AND_SID {
53     ObjectsPresent: DWORD,
54     ObjectTypeGuid: GUID,
55     InheritedObjectTypeGuid: GUID,
56     pSid: *mut SID,
57 }}
58 pub type POBJECTS_AND_SID = *mut OBJECTS_AND_SID;
59 STRUCT!{struct OBJECTS_AND_NAME_A {
60     ObjectsPresent: DWORD,
61     ObjectType: SE_OBJECT_TYPE,
62     ObjectTypeName: LPSTR,
63     InheritedObjectTypeName: LPSTR,
64     ptstrName: LPSTR,
65 }}
66 pub type POBJECTS_AND_NAME_A = *mut OBJECTS_AND_NAME_A;
67 STRUCT!{struct OBJECTS_AND_NAME_W {
68     ObjectsPresent: DWORD,
69     ObjectType: SE_OBJECT_TYPE,
70     ObjectTypeName: LPWSTR,
71     InheritedObjectTypeName: LPWSTR,
72     ptstrName: LPWSTR,
73 }}
74 pub type POBJECTS_AND_NAME_W = *mut OBJECTS_AND_NAME_W;
75 STRUCT!{struct TRUSTEE_A {
76     pMultipleTrustee: *mut TRUSTEE_A,
77     MultipleTrusteeOperation: MULTIPLE_TRUSTEE_OPERATION,
78     TrusteeForm: TRUSTEE_FORM,
79     TrusteeType: TRUSTEE_TYPE,
80     ptstrName: LPSTR,
81 }}
82 pub type PTRUSTEE_A = *mut TRUSTEE_A;
83 pub type TRUSTEEA = TRUSTEE_A;
84 pub type PTRUSTEEA = PTRUSTEE_A;
85 STRUCT!{struct TRUSTEE_W {
86     pMultipleTrustee: *mut TRUSTEE_W,
87     MultipleTrusteeOperation: MULTIPLE_TRUSTEE_OPERATION,
88     TrusteeForm: TRUSTEE_FORM,
89     TrusteeType: TRUSTEE_TYPE,
90     ptstrName: LPWSTR,
91 }}
92 pub type PTRUSTEE_W = *mut TRUSTEE_W;
93 pub type TRUSTEEW = TRUSTEE_W;
94 pub type PTRUSTEEW = PTRUSTEE_W;
95 ENUM!{enum ACCESS_MODE {
96     NOT_USED_ACCESS = 0,
97     GRANT_ACCESS,
98     SET_ACCESS,
99     DENY_ACCESS,
100     REVOKE_ACCESS,
101     SET_AUDIT_SUCCESS,
102     SET_AUDIT_FAILURE,
103 }}
104 pub const NO_INHERITANCE: DWORD = 0x0;
105 pub const SUB_OBJECTS_ONLY_INHERIT: DWORD = 0x1;
106 pub const SUB_CONTAINERS_ONLY_INHERIT: DWORD = 0x2;
107 pub const SUB_CONTAINERS_AND_OBJECTS_INHERIT: DWORD = 0x3;
108 pub const INHERIT_NO_PROPAGATE: DWORD = 0x4;
109 pub const INHERIT_ONLY: DWORD = 0x8;
110 pub const INHERITED_ACCESS_ENTRY: DWORD = 0x10;
111 pub const INHERITED_PARENT: DWORD = 0x10000000;
112 pub const INHERITED_GRANDPARENT: DWORD = 0x20000000;
113 STRUCT!{struct EXPLICIT_ACCESS_A {
114     grfAccessPermissions: DWORD,
115     grfAccessMode: ACCESS_MODE,
116     grfInheritance: DWORD,
117     Trustee: TRUSTEE_A,
118 }}
119 pub type PEXPLICIT_ACCESS_A = *mut EXPLICIT_ACCESS_A;
120 pub type EXPLICIT_ACCESSA = EXPLICIT_ACCESS_A;
121 pub type PEXPLICIT_ACCESSA = PEXPLICIT_ACCESS_A;
122 STRUCT!{struct EXPLICIT_ACCESS_W {
123     grfAccessPermissions: DWORD,
124     grfAccessMode: ACCESS_MODE,
125     grfInheritance: DWORD,
126     Trustee: TRUSTEE_W,
127 }}
128 pub type PEXPLICIT_ACCESS_W = *mut EXPLICIT_ACCESS_W;
129 pub type EXPLICIT_ACCESSW = EXPLICIT_ACCESS_W;
130 pub type PEXPLICIT_ACCESSW = PEXPLICIT_ACCESS_W;
131 pub const ACCCTRL_DEFAULT_PROVIDER: &'static str = "Windows NT Access Provider";
132 pub type ACCESS_RIGHTS = ULONG;
133 pub type PACCESS_RIGHTS = *mut ACCESS_RIGHTS;
134 pub type INHERIT_FLAGS = ULONG;
135 pub type PINHERIT_FLAGS = *mut INHERIT_FLAGS;
136 STRUCT!{struct ACTRL_ACCESS_ENTRYA {
137     Trustee: TRUSTEE_A,
138     fAccessFlags: ULONG,
139     Access: ACCESS_RIGHTS,
140     ProvSpecificAccess: ACCESS_RIGHTS,
141     Inheritance: INHERIT_FLAGS,
142     lpInheritProperty: LPSTR,
143 }}
144 pub type PACTRL_ACCESS_ENTRYA = *mut ACTRL_ACCESS_ENTRYA;
145 STRUCT!{struct ACTRL_ACCESS_ENTRYW {
146     Trustee: TRUSTEE_W,
147     fAccessFlags: ULONG,
148     Access: ACCESS_RIGHTS,
149     ProvSpecificAccess: ACCESS_RIGHTS,
150     Inheritance: INHERIT_FLAGS,
151     lpInheritProperty: LPWSTR,
152 }}
153 pub type PACTRL_ACCESS_ENTRYW = *mut ACTRL_ACCESS_ENTRYW;
154 STRUCT!{struct ACTRL_ACCESS_ENTRY_LISTA {
155     cEntries: ULONG,
156     pAccessList: *mut ACTRL_ACCESS_ENTRYA,
157 }}
158 pub type PACTRL_ACCESS_ENTRY_LISTA = *mut ACTRL_ACCESS_ENTRY_LISTA;
159 STRUCT!{struct ACTRL_ACCESS_ENTRY_LISTW {
160     cEntries: ULONG,
161     pAccessList: *mut ACTRL_ACCESS_ENTRYW,
162 }}
163 pub type PACTRL_ACCESS_ENTRY_LISTW = *mut ACTRL_ACCESS_ENTRY_LISTW;
164 STRUCT!{struct ACTRL_PROPERTY_ENTRYA {
165     lpProperty: LPSTR,
166     pAccessEntryList: PACTRL_ACCESS_ENTRY_LISTA,
167     fListFlags: ULONG,
168 }}
169 pub type PACTRL_PROPERTY_ENTRYA = *mut ACTRL_PROPERTY_ENTRYA;
170 STRUCT!{struct ACTRL_PROPERTY_ENTRYW {
171     lpProperty: LPWSTR,
172     pAccessEntryList: PACTRL_ACCESS_ENTRY_LISTW,
173     fListFlags: ULONG,
174 }}
175 pub type PACTRL_PROPERTY_ENTRYW = *mut ACTRL_PROPERTY_ENTRYW;
176 STRUCT!{struct ACTRL_ACCESSA {
177     cEntries: ULONG,
178     pPropertyAccessList: PACTRL_PROPERTY_ENTRYA,
179 }}
180 pub type PACTRL_ACCESSA = *mut ACTRL_ACCESSA;
181 pub type ACTRL_AUDITA = ACTRL_ACCESSA;
182 pub type PACTRL_AUDITA = *mut ACTRL_AUDITA;
183 STRUCT!{struct ACTRL_ACCESSW {
184     cEntries: ULONG,
185     pPropertyAccessList: PACTRL_PROPERTY_ENTRYW,
186 }}
187 pub type PACTRL_ACCESSW = *mut ACTRL_ACCESSW;
188 pub type ACTRL_AUDITW = ACTRL_ACCESSW;
189 pub type PACTRL_AUDITW = *mut ACTRL_AUDITW;
190 pub const TRUSTEE_ACCESS_ALLOWED: ULONG = 0x00000001;
191 pub const TRUSTEE_ACCESS_READ: ULONG = 0x00000002;
192 pub const TRUSTEE_ACCESS_WRITE: ULONG = 0x00000004;
193 pub const TRUSTEE_ACCESS_EXPLICIT: ULONG = 0x00000001;
194 pub const TRUSTEE_ACCESS_READ_WRITE: ULONG = TRUSTEE_ACCESS_READ | TRUSTEE_ACCESS_WRITE;
195 pub const TRUSTEE_ACCESS_ALL: ULONG = 0xFFFFFFFF;
196 STRUCT!{struct TRUSTEE_ACCESSA {
197     lpProperty: LPSTR,
198     Access: ACCESS_RIGHTS,
199     fAccessFlags: ULONG,
200     fReturnedAccess: ULONG,
201 }}
202 pub type PTRUSTEE_ACCESSA = *mut TRUSTEE_ACCESSA;
203 STRUCT!{struct TRUSTEE_ACCESSW {
204     lpProperty: LPWSTR,
205     Access: ACCESS_RIGHTS,
206     fAccessFlags: ULONG,
207     fReturnedAccess: ULONG,
208 }}
209 pub type PTRUSTEE_ACCESSW = *mut TRUSTEE_ACCESSW;
210 pub const ACTRL_RESERVED: ULONG = 0x00000000;
211 pub const ACTRL_PERM_1: ULONG = 0x00000001;
212 pub const ACTRL_PERM_2: ULONG = 0x00000002;
213 pub const ACTRL_PERM_3: ULONG = 0x00000004;
214 pub const ACTRL_PERM_4: ULONG = 0x00000008;
215 pub const ACTRL_PERM_5: ULONG = 0x00000010;
216 pub const ACTRL_PERM_6: ULONG = 0x00000020;
217 pub const ACTRL_PERM_7: ULONG = 0x00000040;
218 pub const ACTRL_PERM_8: ULONG = 0x00000080;
219 pub const ACTRL_PERM_9: ULONG = 0x00000100;
220 pub const ACTRL_PERM_10: ULONG = 0x00000200;
221 pub const ACTRL_PERM_11: ULONG = 0x00000400;
222 pub const ACTRL_PERM_12: ULONG = 0x00000800;
223 pub const ACTRL_PERM_13: ULONG = 0x00001000;
224 pub const ACTRL_PERM_14: ULONG = 0x00002000;
225 pub const ACTRL_PERM_15: ULONG = 0x00004000;
226 pub const ACTRL_PERM_16: ULONG = 0x00008000;
227 pub const ACTRL_PERM_17: ULONG = 0x00010000;
228 pub const ACTRL_PERM_18: ULONG = 0x00020000;
229 pub const ACTRL_PERM_19: ULONG = 0x00040000;
230 pub const ACTRL_PERM_20: ULONG = 0x00080000;
231 pub const ACTRL_ACCESS_ALLOWED: ULONG = 0x00000001;
232 pub const ACTRL_ACCESS_DENIED: ULONG = 0x00000002;
233 pub const ACTRL_AUDIT_SUCCESS: ULONG = 0x00000004;
234 pub const ACTRL_AUDIT_FAILURE: ULONG = 0x00000008;
235 pub const ACTRL_ACCESS_PROTECTED: ULONG = 0x00000001;
236 pub const ACTRL_SYSTEM_ACCESS: ULONG = 0x04000000;
237 pub const ACTRL_DELETE: ULONG = 0x08000000;
238 pub const ACTRL_READ_CONTROL: ULONG = 0x10000000;
239 pub const ACTRL_CHANGE_ACCESS: ULONG = 0x20000000;
240 pub const ACTRL_CHANGE_OWNER: ULONG = 0x40000000;
241 pub const ACTRL_SYNCHRONIZE: ULONG = 0x80000000;
242 pub const ACTRL_STD_RIGHTS_ALL: ULONG = 0xf8000000;
243 pub const ACTRL_STD_RIGHT_REQUIRED: ULONG = ACTRL_STD_RIGHTS_ALL & !ACTRL_SYNCHRONIZE;
244 pub const ACTRL_DS_OPEN: ULONG = ACTRL_RESERVED;
245 pub const ACTRL_DS_CREATE_CHILD: ULONG = ACTRL_PERM_1;
246 pub const ACTRL_DS_DELETE_CHILD: ULONG = ACTRL_PERM_2;
247 pub const ACTRL_DS_LIST: ULONG = ACTRL_PERM_3;
248 pub const ACTRL_DS_SELF: ULONG = ACTRL_PERM_4;
249 pub const ACTRL_DS_READ_PROP: ULONG = ACTRL_PERM_5;
250 pub const ACTRL_DS_WRITE_PROP: ULONG = ACTRL_PERM_6;
251 pub const ACTRL_DS_DELETE_TREE: ULONG = ACTRL_PERM_7;
252 pub const ACTRL_DS_LIST_OBJECT: ULONG = ACTRL_PERM_8;
253 pub const ACTRL_DS_CONTROL_ACCESS: ULONG = ACTRL_PERM_9;
254 pub const ACTRL_FILE_READ: ULONG = ACTRL_PERM_1;
255 pub const ACTRL_FILE_WRITE: ULONG = ACTRL_PERM_2;
256 pub const ACTRL_FILE_APPEND: ULONG = ACTRL_PERM_3;
257 pub const ACTRL_FILE_READ_PROP: ULONG = ACTRL_PERM_4;
258 pub const ACTRL_FILE_WRITE_PROP: ULONG = ACTRL_PERM_5;
259 pub const ACTRL_FILE_EXECUTE: ULONG = ACTRL_PERM_6;
260 pub const ACTRL_FILE_READ_ATTRIB: ULONG = ACTRL_PERM_8;
261 pub const ACTRL_FILE_WRITE_ATTRIB: ULONG = ACTRL_PERM_9;
262 pub const ACTRL_FILE_CREATE_PIPE: ULONG = ACTRL_PERM_10;
263 pub const ACTRL_DIR_LIST: ULONG = ACTRL_PERM_1;
264 pub const ACTRL_DIR_CREATE_OBJECT: ULONG = ACTRL_PERM_2;
265 pub const ACTRL_DIR_CREATE_CHILD: ULONG = ACTRL_PERM_3;
266 pub const ACTRL_DIR_DELETE_CHILD: ULONG = ACTRL_PERM_7;
267 pub const ACTRL_DIR_TRAVERSE: ULONG = ACTRL_PERM_6;
268 pub const ACTRL_KERNEL_TERMINATE: ULONG = ACTRL_PERM_1;
269 pub const ACTRL_KERNEL_THREAD: ULONG = ACTRL_PERM_2;
270 pub const ACTRL_KERNEL_VM: ULONG = ACTRL_PERM_3;
271 pub const ACTRL_KERNEL_VM_READ: ULONG = ACTRL_PERM_4;
272 pub const ACTRL_KERNEL_VM_WRITE: ULONG = ACTRL_PERM_5;
273 pub const ACTRL_KERNEL_DUP_HANDLE: ULONG = ACTRL_PERM_6;
274 pub const ACTRL_KERNEL_PROCESS: ULONG = ACTRL_PERM_7;
275 pub const ACTRL_KERNEL_SET_INFO: ULONG = ACTRL_PERM_8;
276 pub const ACTRL_KERNEL_GET_INFO: ULONG = ACTRL_PERM_9;
277 pub const ACTRL_KERNEL_CONTROL: ULONG = ACTRL_PERM_10;
278 pub const ACTRL_KERNEL_ALERT: ULONG = ACTRL_PERM_11;
279 pub const ACTRL_KERNEL_GET_CONTEXT: ULONG = ACTRL_PERM_12;
280 pub const ACTRL_KERNEL_SET_CONTEXT: ULONG = ACTRL_PERM_13;
281 pub const ACTRL_KERNEL_TOKEN: ULONG = ACTRL_PERM_14;
282 pub const ACTRL_KERNEL_IMPERSONATE: ULONG = ACTRL_PERM_15;
283 pub const ACTRL_KERNEL_DIMPERSONATE: ULONG = ACTRL_PERM_16;
284 pub const ACTRL_PRINT_SADMIN: ULONG = ACTRL_PERM_1;
285 pub const ACTRL_PRINT_SLIST: ULONG = ACTRL_PERM_2;
286 pub const ACTRL_PRINT_PADMIN: ULONG = ACTRL_PERM_3;
287 pub const ACTRL_PRINT_PUSE: ULONG = ACTRL_PERM_4;
288 pub const ACTRL_PRINT_JADMIN: ULONG = ACTRL_PERM_5;
289 pub const ACTRL_SVC_GET_INFO: ULONG = ACTRL_PERM_1;
290 pub const ACTRL_SVC_SET_INFO: ULONG = ACTRL_PERM_2;
291 pub const ACTRL_SVC_STATUS: ULONG = ACTRL_PERM_3;
292 pub const ACTRL_SVC_LIST: ULONG = ACTRL_PERM_4;
293 pub const ACTRL_SVC_START: ULONG = ACTRL_PERM_5;
294 pub const ACTRL_SVC_STOP: ULONG = ACTRL_PERM_6;
295 pub const ACTRL_SVC_PAUSE: ULONG = ACTRL_PERM_7;
296 pub const ACTRL_SVC_INTERROGATE: ULONG = ACTRL_PERM_8;
297 pub const ACTRL_SVC_UCONTROL: ULONG = ACTRL_PERM_9;
298 pub const ACTRL_REG_QUERY: ULONG = ACTRL_PERM_1;
299 pub const ACTRL_REG_SET: ULONG = ACTRL_PERM_2;
300 pub const ACTRL_REG_CREATE_CHILD: ULONG = ACTRL_PERM_3;
301 pub const ACTRL_REG_LIST: ULONG = ACTRL_PERM_4;
302 pub const ACTRL_REG_NOTIFY: ULONG = ACTRL_PERM_5;
303 pub const ACTRL_REG_LINK: ULONG = ACTRL_PERM_6;
304 pub const ACTRL_WIN_CLIPBRD: ULONG = ACTRL_PERM_1;
305 pub const ACTRL_WIN_GLOBAL_ATOMS: ULONG = ACTRL_PERM_2;
306 pub const ACTRL_WIN_CREATE: ULONG = ACTRL_PERM_3;
307 pub const ACTRL_WIN_LIST_DESK: ULONG = ACTRL_PERM_4;
308 pub const ACTRL_WIN_LIST: ULONG = ACTRL_PERM_5;
309 pub const ACTRL_WIN_READ_ATTRIBS: ULONG = ACTRL_PERM_6;
310 pub const ACTRL_WIN_WRITE_ATTRIBS: ULONG = ACTRL_PERM_7;
311 pub const ACTRL_WIN_SCREEN: ULONG = ACTRL_PERM_8;
312 pub const ACTRL_WIN_EXIT: ULONG = ACTRL_PERM_9;
313 UNION!{union ACTRL_OVERLAPPED_u {
314     [u32; 1] [u64; 1],
315     Provider Provider_mut: PVOID,
316     Reserved1 Reserved1_mut: ULONG,
317 }}
318 STRUCT!{struct ACTRL_OVERLAPPED {
319     u: ACTRL_OVERLAPPED_u,
320     Reserved2: ULONG,
321     hEvent: HANDLE,
322 }}
323 pub type PACTRL_OVERLAPPED = *mut ACTRL_OVERLAPPED;
324 STRUCT!{struct ACTRL_ACCESS_INFOA {
325     fAccessPermission: ULONG,
326     lpAccessPermissionName: LPSTR,
327 }}
328 pub type PACTRL_ACCESS_INFOA = *mut ACTRL_ACCESS_INFOA;
329 STRUCT!{struct ACTRL_ACCESS_INFOW {
330     fAccessPermission: ULONG,
331     lpAccessPermissionName: LPWSTR,
332 }}
333 pub type PACTRL_ACCESS_INFOW = *mut ACTRL_ACCESS_INFOW;
334 STRUCT!{struct ACTRL_CONTROL_INFOA {
335     lpControlId: LPSTR,
336     lpControlName: LPSTR,
337 }}
338 pub type PACTRL_CONTROL_INFOA = *mut ACTRL_CONTROL_INFOA;
339 STRUCT!{struct ACTRL_CONTROL_INFOW {
340     lpControlId: LPWSTR,
341     lpControlName: LPWSTR,
342 }}
343 pub type PACTRL_CONTROL_INFOW = *mut ACTRL_CONTROL_INFOW;
344 pub const ACTRL_ACCESS_NO_OPTIONS: DWORD = 0x00000000;
345 pub const ACTRL_ACCESS_SUPPORTS_OBJECT_ENTRIES: DWORD = 0x00000001;
346 pub const TREE_SEC_INFO_SET: DWORD = 0x00000001;
347 pub const TREE_SEC_INFO_RESET: DWORD = 0x00000002;
348 pub const TREE_SEC_INFO_RESET_KEEP_EXPLICIT: DWORD = 0x00000003;
349 ENUM!{enum PROG_INVOKE_SETTING {
350     ProgressInvokeNever = 1,
351     ProgressInvokeEveryObject,
352     ProgressInvokeOnError,
353     ProgressCancelOperation,
354     ProgressRetryOperation,
355     ProgressInvokePrePostError,
356 }}
357 pub type PPROG_INVOKE_SETTING = *mut PROG_INVOKE_SETTING;
358 STRUCT!{struct FN_OBJECT_MGR_FUNCTS {
359     Placeholder: ULONG,
360 }}
361 pub type PFN_OBJECT_MGR_FUNCTS = *mut FN_OBJECT_MGR_FUNCTS;
362 STRUCT!{struct INHERITED_FROMA {
363     GenerationGap: LONG,
364     AncestorName: LPSTR,
365 }}
366 pub type PINHERITED_FROMA = *mut INHERITED_FROMA;
367 STRUCT!{struct INHERITED_FROMW {
368     GenerationGap: LONG,
369     AncestorName: LPWSTR,
370 }}
371 pub type PINHERITED_FROMW = *mut INHERITED_FROMW;
372