source: trunk/src/advapi32/security.cpp@ 2348

Last change on this file since 2348 was 2348, checked in by sandervl, 26 years ago

compile fix

File size: 18.7 KB
Line 
1/* $Id: security.cpp,v 1.4 2000-01-06 20:23:47 sandervl Exp $ */
2/*
3 * Win32 security API functions for OS/2
4 *
5 * Copyright 1998 Sander van Leeuwen (OS/2 Port)
6 *
7 * Based on Wine code (dlls\advapi32\security.c)
8 *
9 * Copyright original Wine author(s) (????)
10 *
11 * dlls/advapi32/security.c
12 * FIXME: for all functions thunking down to Rtl* functions: implement SetLastError()
13 */
14#ifdef __WIN32OS2__
15#include <os2win.h>
16#include <heapstring.h>
17#endif
18
19#include <string.h>
20
21#include "windef.h"
22#include "winerror.h"
23#include "heap.h"
24#include "ntddk.h"
25#include "ntsecapi.h"
26#include "debugtools.h"
27
28DECLARE_DEBUG_CHANNEL(advapi-security)
29
30static BOOL fInitSecurity = FALSE;
31static BOOL fHasSecurity = FALSE;
32
33static BOOL Wine_HasSecurity(void)
34{
35 //SvL: Let's not check this for every single call please...
36 if(!fInitSecurity)
37 {
38 OSVERSIONINFOA osi;
39 osi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
40 GetVersionExA(&osi);
41 if (osi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
42 fHasSecurity = TRUE;
43 }
44 fInitSecurity = TRUE;
45 }
46 if(!fHasSecurity) {
47 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
48 return FALSE;
49 }
50 return TRUE;
51}
52
53
54#define CallWin32ToNt(func) \
55 { NTSTATUS ret; \
56 ret = (func); \
57 if (ret !=STATUS_SUCCESS) \
58 { SetLastError (RtlNtStatusToDosError(ret)); return FALSE; } \
59 return TRUE; \
60 }
61
62/* ##############################
63 ###### TOKEN FUNCTIONS ######
64 ##############################
65*/
66
67/******************************************************************************
68 * OpenProcessToken [ADVAPI32.109]
69 * Opens the access token associated with a process
70 *
71 * PARAMS
72 * ProcessHandle [I] Handle to process
73 * DesiredAccess [I] Desired access to process
74 * TokenHandle [O] Pointer to handle of open access token
75 *
76 * RETURNS STD
77 */
78BOOL WINAPI
79OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess,
80 HANDLE *TokenHandle )
81{
82 if (!Wine_HasSecurity()) return FALSE;
83 CallWin32ToNt(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
84}
85
86/******************************************************************************
87 * OpenThreadToken [ADVAPI32.114]
88 *
89 * PARAMS
90 * thread []
91 * desiredaccess []
92 * openasself []
93 * thandle []
94 */
95BOOL WINAPI
96OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess,
97 BOOL OpenAsSelf, HANDLE *TokenHandle)
98{
99 if (!Wine_HasSecurity()) return FALSE;
100 CallWin32ToNt (NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
101}
102
103/*************************************************************************
104 * SetThreadToken [ADVAPI32.231]
105 *
106 * Assigns an "impersonation token" to a thread so it can assume the
107 * security privledges of another thread or process. Can also remove
108 * a previously assigned token. Only supported on NT - it's a stub
109 * exactly like this one on Win9X.
110 *
111 */
112
113BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
114{
115 FIXME(__FUNCTION__"(%p, %x): stub\n", thread, token);
116
117 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
118
119 return FALSE;
120}
121
122/******************************************************************************
123 * AdjustTokenPrivileges [ADVAPI32.10]
124 *
125 * PARAMS
126 * TokenHandle []
127 * DisableAllPrivileges []
128 * NewState []
129 * BufferLength []
130 * PreviousState []
131 * ReturnLength []
132 */
133BOOL WINAPI
134AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
135 PTOKEN_PRIVILEGES NewState, DWORD BufferLength,
136 PTOKEN_PRIVILEGES PreviousState, LPDWORD ReturnLength )
137{
138 CallWin32ToNt(NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength));
139}
140
141/******************************************************************************
142 * GetTokenInformation [ADVAPI32.66]
143 *
144 * PARAMS
145 * token []
146 * tokeninfoclass []
147 * tokeninfo []
148 * tokeninfolength []
149 * retlen []
150 *
151 */
152BOOL WINAPI
153GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
154 LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
155{
156 CallWin32ToNt (NtQueryInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength, retlen));
157}
158
159/* ##############################
160 ###### SID FUNCTIONS ######
161 ##############################
162*/
163
164/******************************************************************************
165 * CopySid [ADVAPI32.24]
166 *
167 * PARAMS
168 * nDestinationSidLength []
169 * pDestinationSid []
170 * pSourceSid []
171 */
172BOOL WINAPI
173CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
174{
175 CallWin32ToNt (RtlCopySid( nDestinationSidLength, pDestinationSid, pSourceSid));
176}
177
178/******************************************************************************
179 * IsValidSid [ADVAPI32.80]
180 *
181 * PARAMS
182 * pSid []
183 */
184BOOL WINAPI
185IsValidSid( PSID pSid )
186{
187 CallWin32ToNt (RtlValidSid( pSid));
188}
189
190/******************************************************************************
191 * EqualSid [ADVAPI32.40]
192 *
193 * PARAMS
194 * pSid1 []
195 * pSid2 []
196 */
197BOOL WINAPI
198EqualSid( PSID pSid1, PSID pSid2 )
199{
200 CallWin32ToNt (RtlEqualSid( pSid1, pSid2));
201}
202
203/******************************************************************************
204 * EqualPrefixSid [ADVAPI32.39]
205 */
206BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2)
207{
208 CallWin32ToNt (RtlEqualPrefixSid( pSid1, pSid2));
209}
210
211/******************************************************************************
212 * InitializeSid [ADVAPI32.74]
213 *
214 * PARAMS
215 * pIdentifierAuthority []
216 */
217BOOL WINAPI
218InitializeSid (PSID pSid, PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
219 BYTE nSubAuthorityCount)
220{
221 CallWin32ToNt (RtlInitializeSid( pSid, pIdentifierAuthority, nSubAuthorityCount));
222}
223
224/* ##############################################
225 ###### SECURITY DESCRIPTOR FUNCTIONS ######
226 ##############################################
227*/
228
229/******************************************************************************
230 * InitializeSecurityDescriptor [ADVAPI32.73]
231 *
232 * PARAMS
233 * pDescr []
234 * revision []
235 */
236BOOL WINAPI
237InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr, DWORD revision )
238{
239 CallWin32ToNt (RtlCreateSecurityDescriptor(pDescr, revision ));
240}
241
242/******************************************************************************
243 * GetSecurityDescriptorLength [ADVAPI32.55]
244 */
245DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)
246{
247 return (RtlLengthSecurityDescriptor(pDescr));
248}
249
250/******************************************************************************
251 * GetSecurityDescriptorOwner [ADVAPI32.56]
252 *
253 * PARAMS
254 * pOwner []
255 * lpbOwnerDefaulted []
256 */
257BOOL WINAPI
258GetSecurityDescriptorOwner( SECURITY_DESCRIPTOR *pDescr, PSID *pOwner,
259 LPBOOL lpbOwnerDefaulted )
260{
261 CallWin32ToNt (RtlGetOwnerSecurityDescriptor( pDescr, pOwner, (PBOOLEAN)lpbOwnerDefaulted ));
262}
263
264/******************************************************************************
265 * SetSecurityDescriptorOwner [ADVAPI32]
266 *
267 * PARAMS
268 */
269BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor,
270 PSID pOwner, BOOL bOwnerDefaulted)
271{
272 CallWin32ToNt (RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
273}
274/******************************************************************************
275 * GetSecurityDescriptorGroup [ADVAPI32.54]
276 */
277BOOL WINAPI GetSecurityDescriptorGroup(
278 PSECURITY_DESCRIPTOR SecurityDescriptor,
279 PSID *Group,
280 LPBOOL GroupDefaulted)
281{
282 CallWin32ToNt (RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, (PBOOLEAN)GroupDefaulted));
283}
284/******************************************************************************
285 * SetSecurityDescriptorGroup
286 */
287BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
288 PSID Group, BOOL GroupDefaulted)
289{
290 CallWin32ToNt (RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
291}
292
293/******************************************************************************
294 * IsValidSecurityDescriptor [ADVAPI32.79]
295 *
296 * PARAMS
297 * lpsecdesc []
298 */
299BOOL WINAPI
300IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
301{
302 CallWin32ToNt (RtlValidSecurityDescriptor(SecurityDescriptor));
303}
304
305/******************************************************************************
306 * GetSecurityDescriptorDacl [ADVAPI.91]
307 */
308BOOL WINAPI GetSecurityDescriptorDacl(
309 IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
310 OUT LPBOOL lpbDaclPresent,
311 OUT PACL *pDacl,
312 OUT LPBOOL lpbDaclDefaulted)
313{
314 CallWin32ToNt (RtlGetDaclSecurityDescriptor(pSecurityDescriptor, (PBOOLEAN)lpbDaclPresent,
315 pDacl, (PBOOLEAN)lpbDaclDefaulted));
316}
317
318/******************************************************************************
319 * SetSecurityDescriptorDacl [ADVAPI.224]
320 */
321BOOL WINAPI
322SetSecurityDescriptorDacl (
323 PSECURITY_DESCRIPTOR lpsd,
324 BOOL daclpresent,
325 PACL dacl,
326 BOOL dacldefaulted )
327{
328 CallWin32ToNt (RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ));
329}
330/******************************************************************************
331 * GetSecurityDescriptorSacl [ADVAPI.]
332 */
333BOOL WINAPI GetSecurityDescriptorSacl(
334 IN PSECURITY_DESCRIPTOR lpsd,
335 OUT LPBOOL lpbSaclPresent,
336 OUT PACL *pSacl,
337 OUT LPBOOL lpbSaclDefaulted)
338{
339 CallWin32ToNt (RtlGetSaclSecurityDescriptor(lpsd, (PBOOLEAN)lpbSaclPresent,
340 pSacl, (PBOOLEAN)lpbSaclDefaulted));
341}
342
343/**************************************************************************
344 * SetSecurityDescriptorSacl [NTDLL.488]
345 */
346BOOL WINAPI SetSecurityDescriptorSacl (
347 PSECURITY_DESCRIPTOR lpsd,
348 BOOL saclpresent,
349 PACL lpsacl,
350 BOOL sacldefaulted)
351{
352 CallWin32ToNt (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
353}
354/******************************************************************************
355 * MakeSelfRelativeSD [ADVAPI32.95]
356 *
357 * PARAMS
358 * lpabssecdesc []
359 * lpselfsecdesc []
360 * lpbuflen []
361 */
362BOOL WINAPI
363MakeSelfRelativeSD( PSECURITY_DESCRIPTOR lpabssecdesc,
364 PSECURITY_DESCRIPTOR lpselfsecdesc, LPDWORD lpbuflen )
365{
366 FIXME(__FUNCTION__"(%p,%p,%p),stub!\n",lpabssecdesc,lpselfsecdesc,lpbuflen);
367 return TRUE;
368}
369
370/******************************************************************************
371 * GetSecurityDescriptorControl32 [ADVAPI32]
372 */
373
374BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor,
375 PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
376{ FIXME(__FUNCTION__"(%p,%p,%p),stub!\n",pSecurityDescriptor,pControl,lpdwRevision);
377 return 1;
378}
379
380/* ##############################
381 ###### MISC FUNCTIONS ######
382 ##############################
383*/
384
385/******************************************************************************
386 * LookupPrivilegeValue32W [ADVAPI32.93]
387 * Retrieves LUID used on a system to represent the privilege name.
388 *
389 * NOTES
390 * lpLuid should be PLUID
391 *
392 * PARAMS
393 * lpSystemName [I] Address of string specifying the system
394 * lpName [I] Address of string specifying the privilege
395 * lpLuid [I] Address of locally unique identifier
396 *
397 * RETURNS STD
398 */
399BOOL WINAPI
400LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, LPVOID lpLuid )
401{
402 FIXME(__FUNCTION__"(%s,%s,%p): stub\n",debugstr_w(lpSystemName),
403 debugstr_w(lpName), lpLuid);
404 return TRUE;
405}
406
407/******************************************************************************
408 * LookupPrivilegeValue32A [ADVAPI32.92]
409 */
410BOOL WINAPI
411LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, LPVOID lpLuid )
412{
413 LPWSTR lpSystemNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpSystemName);
414 LPWSTR lpNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpName);
415 BOOL ret = LookupPrivilegeValueW( lpSystemNameW, lpNameW, lpLuid);
416 HeapFree(GetProcessHeap(), 0, lpNameW);
417 HeapFree(GetProcessHeap(), 0, lpSystemNameW);
418 return ret;
419}
420
421/******************************************************************************
422 * GetFileSecurity32A [ADVAPI32.45]
423 *
424 * Obtains Specified information about the security of a file or directory
425 * The information obtained is constrained by the callers access rights and
426 * privileges
427 */
428BOOL WINAPI
429GetFileSecurityA( LPCSTR lpFileName,
430 SECURITY_INFORMATION RequestedInformation,
431 PSECURITY_DESCRIPTOR pSecurityDescriptor,
432 DWORD nLength, LPDWORD lpnLengthNeeded )
433{
434 FIXME(__FUNCTION__"(%s) : stub\n", debugstr_a(lpFileName));
435 return TRUE;
436}
437
438/******************************************************************************
439 * GetFileSecurity32W [ADVAPI32.46]
440 *
441 * Obtains Specified information about the security of a file or directory
442 * The information obtained is constrained by the callers access rights and
443 * privileges
444 *
445 * PARAMS
446 * lpFileName []
447 * RequestedInformation []
448 * pSecurityDescriptor []
449 * nLength []
450 * lpnLengthNeeded []
451 */
452BOOL WINAPI
453GetFileSecurityW( LPCWSTR lpFileName,
454 SECURITY_INFORMATION RequestedInformation,
455 PSECURITY_DESCRIPTOR pSecurityDescriptor,
456 DWORD nLength, LPDWORD lpnLengthNeeded )
457{
458 FIXME(__FUNCTION__"(%s) : stub\n", debugstr_w(lpFileName) );
459 return TRUE;
460}
461
462/******************************************************************************
463 * SetFileSecurity32A [ADVAPI32.182]
464 * Sets the security of a file or directory
465 */
466BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
467 SECURITY_INFORMATION RequestedInformation,
468 PSECURITY_DESCRIPTOR pSecurityDescriptor)
469{
470 FIXME(__FUNCTION__"(%s) : stub\n", debugstr_a(lpFileName));
471 return TRUE;
472}
473
474/******************************************************************************
475 * SetFileSecurity32W [ADVAPI32.183]
476 * Sets the security of a file or directory
477 *
478 * PARAMS
479 * lpFileName []
480 * RequestedInformation []
481 * pSecurityDescriptor []
482 */
483BOOL WINAPI
484SetFileSecurityW( LPCWSTR lpFileName,
485 SECURITY_INFORMATION RequestedInformation,
486 PSECURITY_DESCRIPTOR pSecurityDescriptor )
487{
488 FIXME(__FUNCTION__"(%s) : stub\n", debugstr_w(lpFileName) );
489 return TRUE;
490}
491
492/******************************************************************************
493 * LookupAccountSid32A [ADVAPI32.86]
494 */
495BOOL WINAPI
496LookupAccountSidA( LPCSTR system, PSID sid, LPCSTR account,
497 LPDWORD accountSize, LPCSTR domain, LPDWORD domainSize,
498 PSID_NAME_USE name_use )
499{
500 FIXME(__FUNCTION__"(%s,%p,%p,%p,%p,%p,%p): stub\n",
501 system,sid,account,accountSize,domain,domainSize,name_use);
502 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
503 return FALSE;
504}
505
506/******************************************************************************
507 * LookupAccountSid32W [ADVAPI32.87]
508 *
509 * PARAMS
510 * system []
511 * sid []
512 * account []
513 * accountSize []
514 * domain []
515 * domainSize []
516 * name_use []
517 */
518BOOL WINAPI
519LookupAccountSidW( LPCWSTR system, PSID sid, LPCWSTR account,
520 LPDWORD accountSize, LPCWSTR domain, LPDWORD domainSize,
521 PSID_NAME_USE name_use )
522{
523 FIXME(__FUNCTION__"(%p,%p,%p,%p,%p,%p,%p): stub\n",
524 system,sid,account,accountSize,domain,domainSize,name_use);
525 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
526 return FALSE;
527}
528
529/******************************************************************************
530 * QueryWindows31FilesMigration [ADVAPI32.266]
531 *
532 * PARAMS
533 * x1 []
534 */
535BOOL WINAPI
536QueryWindows31FilesMigration( DWORD x1 )
537{
538 FIXME(__FUNCTION__"(%ld):stub\n",x1);
539 return TRUE;
540}
541
542/******************************************************************************
543 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.265]
544 *
545 * PARAMS
546 * x1 []
547 * x2 []
548 * x3 []
549 * x4 []
550 */
551BOOL WINAPI
552SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
553 DWORD x4 )
554{
555 FIXME(__FUNCTION__"(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
556 return TRUE;
557}
558
559/******************************************************************************
560 * LsaOpenPolicy [ADVAPI32.200]
561 *
562 * PARAMS
563 * x1 []
564 * x2 []
565 * x3 []
566 * x4 []
567 */
568NTSTATUS WINAPI
569LsaOpenPolicy(PLSA_UNICODE_STRING SystemName,
570 PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
571 ACCESS_MASK DesiredAccess,
572 PLSA_HANDLE PolicyHandle)
573{
574 FIXME(__FUNCTION__"(%p,%p,0x%08lx,%p):stub\n",
575 SystemName, ObjectAttributes,
576 DesiredAccess, PolicyHandle);
577 return 0xc0000000; /* generic error */
578}
579
580/******************************************************************************
581 * NotifyBootConfigStatus [ADVAPI32.97]
582 *
583 * PARAMS
584 * x1 []
585 */
586BOOL WINAPI
587NotifyBootConfigStatus( DWORD x1 )
588{
589 FIXME(__FUNCTION__"(0x%08lx):stub\n",x1);
590 return 1;
591}
592
593/******************************************************************************
594 * RevertToSelf [ADVAPI32.180]
595 *
596 * PARAMS
597 * void []
598 */
599BOOL WINAPI
600RevertToSelf( void )
601{
602 FIXME(__FUNCTION__"(), stub\n");
603 return TRUE;
604}
605
606/******************************************************************************
607 * ImpersonateSelf [ADVAPI32.71]
608 */
609BOOL WINAPI
610ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
611{
612 FIXME(__FUNCTION__"(%08x), stub\n", ImpersonationLevel);
613 return TRUE;
614}
615
616/******************************************************************************
617 * AccessCheck32 [ADVAPI32.71]
618 */
619BOOL WINAPI
620AccessCheck(PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken,
621 DWORD DesiredAccess, PGENERIC_MAPPING GenericMapping, PPRIVILEGE_SET PrivilegeSet,
622 LPDWORD PrivilegeSetLength, LPDWORD GrantedAccess, LPBOOL AccessStatus)
623{
624 FIXME(__FUNCTION__"(%p, %04x, %08lx, %p, %p, %p, %p, %p), stub\n",
625 pSecurityDescriptor, ClientToken, DesiredAccess, GenericMapping,
626 PrivilegeSet, PrivilegeSetLength, GrantedAccess, AccessStatus);
627 *AccessStatus = TRUE;
628 return TRUE;
629}
630
631/*****************************************************************************
632 * Name : InitializeAcl
633 * Purpose : The InitializeAcl function creates a new ACL structure.
634 * An ACL is an access-control list.
635 * Parameters: PACL pAcl address of access-control list
636 * DWORD nAclLength size of access-control list
637 * DWORD dwAclRevision revision level of access-control list
638 * Variables :
639 * Result :
640 * Remark :
641 * Status : UNTESTED STUB
642 *
643 * Author : Patrick Haller [Tue, 1998/06/16 23:00]
644 *****************************************************************************/
645
646BOOL WIN32API InitializeAcl(PACL pAcl,
647 DWORD nAclLength,
648 DWORD dwAclRevision)
649{
650 dprintf(("ADVAPI32: InitializeAcl(%08xh,%08xh,%08xh)",
651 pAcl,
652 nAclLength,
653 dwAclRevision));
654
655 CallWin32ToNt (RtlCreateAcl(pAcl, nAclLength, dwAclRevision));
656}
Note: See TracBrowser for help on using the repository browser.