Changed some treeview related definitions.
[wine] / dlls / advapi32 / security.c
1 #include "windows.h"
2 #include "winerror.h"
3 #include "debug.h"
4 #include "heap.h"
5 #include "ntdll.h"
6
7 BOOL32 WINAPI IsValidSid (LPSID pSid);
8 BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2);
9 BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2);
10 DWORD  WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount);
11 BOOL32 WINAPI AllocateAndInitializeSid(LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3,    DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, LPSID *pSid);
12 VOID*  WINAPI FreeSid(LPSID pSid);
13 BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount);
14 LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority(LPSID pSid);
15 DWORD* WINAPI GetSidSubAuthority(LPSID pSid, DWORD nSubAuthority);
16 BYTE*  WINAPI GetSidSubAuthorityCount(LPSID pSid);
17 DWORD  WINAPI GetLengthSid(LPSID pSid);
18 BOOL32 WINAPI CopySid(DWORD nDestinationSidLength, LPSID pDestinationSid, LPSID pSourceSid);
19
20 /******************************************************************************
21  * OpenProcessToken [ADVAPI32.109]
22  * Opens the access token associated with a process
23  *
24  * PARAMS
25  *    ProcessHandle [I] Handle to process
26  *    DesiredAccess [I] Desired access to process
27  *    TokenHandle   [O] Pointer to handle of open access token
28  *
29  * RETURNS STD
30  */
31 BOOL32 WINAPI OpenProcessToken( HANDLE32 ProcessHandle, DWORD DesiredAccess,
32                                 HANDLE32 *TokenHandle )
33 {
34     FIXME(advapi,"(%08x,%08lx,%p): stub\n",ProcessHandle,DesiredAccess,
35           TokenHandle);
36     return TRUE;
37 }
38
39
40 /***********************************************************************
41  *      OpenThreadToken [ADVAPI32.114]
42  */
43 BOOL32 WINAPI OpenThreadToken( HANDLE32 thread,DWORD desiredaccess,
44                                BOOL32 openasself,HANDLE32 *thandle )
45 {
46         FIXME(advapi,"(%08x,%08lx,%d,%p): stub!\n",
47               thread,desiredaccess,openasself,thandle);
48         *thandle = 0; /* FIXME ... well, store something in there ;) */
49         return TRUE;
50 }
51
52
53 /******************************************************************************
54  *      LookupPrivilegeValue32A [ADVAPI32.92]
55  */
56 BOOL32 WINAPI LookupPrivilegeValue32A( LPCSTR lpSystemName, 
57                                        LPCSTR lpName, LPVOID lpLuid)
58 {
59     LPWSTR lpSystemNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpSystemName);
60     LPWSTR lpNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpName);
61     BOOL32 ret = LookupPrivilegeValue32W( lpSystemNameW, lpNameW, lpLuid);
62     HeapFree(GetProcessHeap(), 0, lpNameW);
63     HeapFree(GetProcessHeap(), 0, lpSystemNameW);
64     return ret;
65 }
66
67
68 /******************************************************************************
69  * LookupPrivilegeValue32W                                        [ADVAPI32.93]
70  * Retrieves LUID used on a system to represent the privilege name.
71  *
72  * NOTES
73  *    lpLuid should be PLUID
74  *
75  * PARAMS
76  *    lpSystemName [I] Address of string specifying the system
77  *    lpName       [I] Address of string specifying the privilege
78  *    lpLuid       [I] Address of locally unique identifier
79  *
80  * RETURNS STD
81  */
82 BOOL32 WINAPI LookupPrivilegeValue32W( LPCWSTR lpSystemName,
83                                        LPCWSTR lpName, LPVOID lpLuid )
84 {
85     FIXME(advapi,"(%s,%s,%p): stub\n",debugstr_w(lpSystemName), 
86                   debugstr_w(lpName), lpLuid);
87     return TRUE;
88 }
89 /******************************************************************************
90  *      GetFileSecurityA        [ADVAPI32.45]
91  * Obtains Specified information about the security of a file or directory
92  * The information obtained is constrained by the callers acces rights and
93  * priviliges
94  */
95
96 BOOL32 WINAPI GetFileSecurity32A( LPCSTR lpFileName,
97                                 SECURITY_INFORMATION RequestedInformation,
98                                 LPSECURITY_DESCRIPTOR pSecurityDescriptor,
99                                 DWORD nLength,
100                                 LPDWORD lpnLengthNeeded)
101 {
102   FIXME(advapi, "(%s) : stub\n", debugstr_a(lpFileName));
103   return TRUE;
104 }
105
106 /******************************************************************************
107  *      GetFileSecurityiW       [ADVAPI32.46]
108  * Obtains Specified information about the security of a file or directory
109  * The information obtained is constrained by the callers acces rights and
110  * priviliges
111  */
112
113 BOOL32 WINAPI GetFileSecurity32W( LPCWSTR lpFileName,
114                                 SECURITY_INFORMATION RequestedInformation,
115                                 LPSECURITY_DESCRIPTOR pSecurityDescriptor,
116                                 DWORD nLength,
117                                 LPDWORD lpnLengthNeeded)
118 {
119   FIXME(advapi, "(%s) : stub\n", debugstr_w(lpFileName) ); 
120   return TRUE;
121 }
122
123
124 /***********************************************************************
125  *           AdjustTokenPrivileges   [ADVAPI32.10]
126  */
127 BOOL32 WINAPI AdjustTokenPrivileges(HANDLE32 TokenHandle,BOOL32 DisableAllPrivileges,
128         LPVOID NewState,DWORD BufferLength,LPVOID PreviousState,
129         LPDWORD ReturnLength )
130 {
131         return TRUE;
132 }
133
134 /***********************************************************************
135  * CopySid                              [ADVAPI.24]
136  */
137 BOOL32 WINAPI CopySid (DWORD nDestinationSidLength, LPSID pDestinationSid,
138                        LPSID pSourceSid)
139 {
140
141     if (!IsValidSid(pSourceSid))
142         return FALSE;
143
144     if (nDestinationSidLength < GetLengthSid(pSourceSid))
145         return FALSE;
146
147     memcpy(pDestinationSid, pSourceSid, GetLengthSid(pSourceSid));
148
149     return TRUE;
150 }
151
152 /***********************************************************************
153  *           IsValidSid  (ADVAPI.80)
154  */
155 BOOL32 WINAPI IsValidSid (LPSID pSid) {
156     if (!pSid || pSid->Revision != SID_REVISION)
157         return FALSE;
158
159     return TRUE;
160 }
161
162 /***********************************************************************
163  *           EqualSid  (ADVAPI.40)
164  */
165 BOOL32 WINAPI EqualSid (LPSID pSid1, LPSID pSid2) {
166     if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
167         return FALSE;
168
169     if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
170         return FALSE;
171
172     if (memcmp(pSid1, pSid2, GetLengthSid(pSid1)) != 0)
173         return FALSE;
174
175     return TRUE;
176 }
177
178 /***********************************************************************
179  *           EqualPrefixSid  (ADVAPI.39)
180  */
181 BOOL32 WINAPI EqualPrefixSid (LPSID pSid1, LPSID pSid2) {
182     if (!IsValidSid(pSid1) || !IsValidSid(pSid2))
183         return FALSE;
184
185     if (*GetSidSubAuthorityCount(pSid1) != *GetSidSubAuthorityCount(pSid2))
186         return FALSE;
187
188     if (memcmp(pSid1, pSid2, GetSidLengthRequired(pSid1->SubAuthorityCount - 1))
189  != 0)
190         return FALSE;
191
192     return TRUE;
193 }
194
195 /***********************************************************************
196  *           GetSidLengthRequired  (ADVAPI.63)
197  */
198 DWORD WINAPI GetSidLengthRequired (BYTE nSubAuthorityCount) {
199     return sizeof (SID) + (nSubAuthorityCount - 1) * sizeof (DWORD);
200 }
201
202 /***********************************************************************
203  *           GetTokenInformation        [ADVAPI32.66]
204  */
205 BOOL32 WINAPI GetTokenInformation(
206         HANDLE32 token,/*TOKEN_INFORMATION_CLASS*/ DWORD tokeninfoclass,LPVOID tokeninfo,
207         DWORD tokeninfolength,LPDWORD retlen
208 ) {
209         FIXME(advapi,"(%08x,%ld,%p,%ld,%p): stub\n",
210               token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
211         return TRUE;
212 }
213
214 /***********************************************************************
215  *           AllocateAndInitializeSid  (ADVAPI.11)
216  */
217 BOOL32 WINAPI AllocateAndInitializeSid(LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
218     BYTE nSubAuthorityCount,
219     DWORD nSubAuthority0, DWORD nSubAuthority1,
220     DWORD nSubAuthority2, DWORD nSubAuthority3,
221     DWORD nSubAuthority4, DWORD nSubAuthority5,
222     DWORD nSubAuthority6, DWORD nSubAuthority7,
223     LPSID *pSid) {
224
225     if (!(*pSid = HeapAlloc( GetProcessHeap(), 0,
226                              GetSidLengthRequired(nSubAuthorityCount))))
227         return FALSE;
228     (*pSid)->Revision = SID_REVISION;
229     if (pIdentifierAuthority)
230         memcpy(&(*pSid)->IdentifierAuthority, pIdentifierAuthority,
231                sizeof (SID_IDENTIFIER_AUTHORITY));
232     *GetSidSubAuthorityCount(*pSid) = nSubAuthorityCount;
233
234     if (nSubAuthorityCount > 0)
235         *GetSidSubAuthority(*pSid, 0) = nSubAuthority0;
236     if (nSubAuthorityCount > 1)
237         *GetSidSubAuthority(*pSid, 1) = nSubAuthority1;
238     if (nSubAuthorityCount > 2)
239         *GetSidSubAuthority(*pSid, 2) = nSubAuthority2;
240     if (nSubAuthorityCount > 3)
241         *GetSidSubAuthority(*pSid, 3) = nSubAuthority3;
242     if (nSubAuthorityCount > 4)
243         *GetSidSubAuthority(*pSid, 4) = nSubAuthority4;
244     if (nSubAuthorityCount > 5)
245         *GetSidSubAuthority(*pSid, 5) = nSubAuthority5;
246     if (nSubAuthorityCount > 6)
247         *GetSidSubAuthority(*pSid, 6) = nSubAuthority6;
248     if (nSubAuthorityCount > 7)
249         *GetSidSubAuthority(*pSid, 7) = nSubAuthority7;
250
251     return TRUE;
252 }
253
254 /***********************************************************************
255  *           FreeSid  (ADVAPI.42)
256  */
257 VOID* WINAPI FreeSid(LPSID pSid)
258 {
259     HeapFree( GetProcessHeap(), 0, pSid );
260     return NULL;
261 }
262
263 /***********************************************************************
264  *           InitializeSecurityDescriptor  (ADVAPI.73)
265  */
266 BOOL32 WINAPI InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr,
267                                             DWORD revision )
268 {
269     FIXME(security, "(%p,%#lx): stub\n", pDescr, revision);
270     return TRUE;
271 }
272
273 /***********************************************************************
274  *           GetSecurityDescriptorLength  (ADVAPI.55)
275  */
276 DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)
277 {
278     FIXME(security, "(%p), stub\n", pDescr);
279     return 0;
280 }
281
282 /***********************************************************************
283  *           GetSecurityDescriptorOwner  (ADVAPI.56)
284  */
285 BOOL32 WINAPI GetSecurityDescriptorOwner (SECURITY_DESCRIPTOR *pDescr,LPSID *pOwner,LPBOOL32 lpbOwnerDefaulted)
286 {
287     FIXME(security, "(%p,%p,%p), stub\n", pDescr,pOwner,lpbOwnerDefaulted);
288     *lpbOwnerDefaulted = TRUE;
289     return 0;
290 }
291
292 /***********************************************************************
293  *           GetSecurityDescriptorGroup  (ADVAPI.54)
294  */
295 BOOL32 WINAPI GetSecurityDescriptorGroup(SECURITY_DESCRIPTOR *pDescr,LPSID *pGroup,LPBOOL32 lpbOwnerDefaulted)
296 {
297     FIXME(security, "(%p,%p,%p), stub\n", pDescr,pGroup,lpbOwnerDefaulted);
298     *lpbOwnerDefaulted = TRUE;
299     return 0;
300 }
301
302 /***********************************************************************
303  *           InitializeSid  (ADVAPI.74)
304  */
305 BOOL32 WINAPI InitializeSid (LPSID pSid, LPSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
306                     BYTE nSubAuthorityCount)
307 {
308     int i;
309
310     pSid->Revision = SID_REVISION;
311     if (pIdentifierAuthority)
312         memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority,
313                sizeof (SID_IDENTIFIER_AUTHORITY));
314     *GetSidSubAuthorityCount(pSid) = nSubAuthorityCount;
315
316     for (i = 0; i < nSubAuthorityCount; i++)
317         *GetSidSubAuthority(pSid, i) = 0;
318
319     return TRUE;
320 }
321
322 /***********************************************************************
323  *           GetSidIdentifierAuthority  (ADVAPI.62)
324  */
325 LPSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority (LPSID pSid)
326 {
327     return &pSid->IdentifierAuthority;
328 }
329
330 /***********************************************************************
331  *           GetSidSubAuthority  (ADVAPI.64)
332  */
333 DWORD * WINAPI GetSidSubAuthority (LPSID pSid, DWORD nSubAuthority)
334 {
335     return &pSid->SubAuthority[nSubAuthority];
336 }
337
338 /***********************************************************************
339  * GetSidSubAuthorityCount              [ADVAPI.65]
340  */
341 BYTE * WINAPI GetSidSubAuthorityCount (LPSID pSid)
342 {
343     return &pSid->SubAuthorityCount;
344 }
345
346 /***********************************************************************
347  * GetLengthSid                         [ADVAPI.48]
348  */
349 DWORD WINAPI GetLengthSid (LPSID pSid)
350 {
351     return GetSidLengthRequired(*GetSidSubAuthorityCount(pSid));
352 }
353
354 /******************************************************************************
355  * IsValidSecurityDescriptor                    [ADVAPI32]
356  */
357 BOOL32 WINAPI IsValidSecurityDescriptor(LPSECURITY_DESCRIPTOR lpsecdesc) {
358         FIXME(advapi,"(%p),stub!\n",lpsecdesc);
359         return TRUE;
360 }
361
362 /***********************************************************************
363  * LookupAccountSidA                    [ADVAPI32.86]
364  */
365 BOOL32 WINAPI LookupAccountSid32A(LPCSTR system,PSID sid,
366                                   LPCSTR account,LPDWORD accountSize,
367                                   LPCSTR domain, LPDWORD domainSize,
368                                   PSID_NAME_USE name_use)
369 {
370         FIXME(security,"(%s,%p,%p,%p,%p,%p,%p): stub\n",
371               system,sid,account,accountSize,domain,domainSize,name_use);
372         SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
373         return FALSE;
374 }
375
376 /***********************************************************************
377  * LookupAccountSidW            [ADVAPI32.86]
378  */
379 BOOL32 WINAPI LookupAccountSid32W(LPCWSTR system,PSID sid,
380                                   LPCWSTR account,LPDWORD accountSize,
381                                   LPCWSTR domain, LPDWORD domainSize,
382                                   PSID_NAME_USE name_use)
383 {
384         FIXME(security,"(%p,%p,%p,%p,%p,%p,%p): stub\n",
385               system,sid,account,accountSize,domain,domainSize,name_use);
386         SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
387         return FALSE;
388 }
389
390 /******************************************************************************
391  * SetFileSecurityA             [ADVAPI32.182]
392  * Sets the security of a file or directory
393  */
394
395 BOOL32 WINAPI SetFileSecurity32A( LPCSTR lpFileName,
396                                 SECURITY_INFORMATION RequestedInformation,
397                                 LPSECURITY_DESCRIPTOR pSecurityDescriptor)
398 {
399   FIXME(advapi, "(%s) : stub\n", debugstr_a(lpFileName));
400   return TRUE;
401 }
402
403 /******************************************************************************
404  * SetFileSecurityW             [ADVAPI32.183]
405  * Sets the security of a file or directory
406  */
407
408 BOOL32 WINAPI SetFileSecurity32W( LPCWSTR lpFileName,
409                                 SECURITY_INFORMATION RequestedInformation,
410                                 LPSECURITY_DESCRIPTOR pSecurityDescriptor)
411 {
412   FIXME(advapi, "(%s) : stub\n", debugstr_w(lpFileName) ); 
413   return TRUE;
414 }
415 /******************************************************************************
416  * MakeSelfRelativeSD                           [ADVAPI32]
417  */
418 BOOL32 WINAPI MakeSelfRelativeSD(
419         LPSECURITY_DESCRIPTOR lpabssecdesc,
420         LPSECURITY_DESCRIPTOR lpselfsecdesc,LPDWORD lpbuflen
421 ) {
422         FIXME(advapi,"(%p,%p,%p),stub!\n",lpabssecdesc,lpselfsecdesc,lpbuflen);
423         return TRUE;
424 }
425
426 /******************************************************************************
427  * QueryWindows31FilesMigration                 [ADVAPI32]
428  */
429 BOOL32 WINAPI QueryWindows31FilesMigration(DWORD x1) {
430         FIXME(advapi,"(%ld),stub!\n",x1);
431         return TRUE;
432 }
433
434 /******************************************************************************
435  * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32]
436  */
437 BOOL32 WINAPI SynchronizeWindows31FilesAndWindowsNTRegistry(DWORD x1,DWORD x2,DWORD x3,DWORD x4) {
438         FIXME(advapi,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
439         return TRUE;
440 }
441
442 /******************************************************************************
443  * LsaOpenPolicy                                [ADVAPI32]
444  */
445 BOOL32 WINAPI LsaOpenPolicy(DWORD x1,DWORD x2,DWORD x3,DWORD x4) {
446         FIXME(advapi,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
447         return 0xc0000000; /* generic error */
448 }
449
450 /******************************************************************************
451  * NotifyBootConfigStatus                       [ADVAPI32]
452  */
453 BOOL32 WINAPI NotifyBootConfigStatus(DWORD x1) {
454         FIXME(advapi,"(0x%08lx),stub!\n",x1);
455         return 1;
456 }
457
458 /******************************************************************************
459  * RevertToSelf                 [ADVAPI32]
460  */
461 BOOL32 WINAPI RevertToSelf(void) {
462         FIXME(advapi,"(), stub\n");
463         return TRUE;
464 }