added stubs for SetSecurityInfo(), GetInheritanceSourceA/W() and FreeInheritedFromArray()
[reactos.git] / reactos / lib / advapi32 / sec / misc.c
1 /* $Id: misc.c,v 1.30 2004/12/13 19:06:28 weiden Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/advapi32/sec/misc.c
6 * PURPOSE: Miscellaneous security functions
7 */
8
9 #include "advapi32.h"
10 #include <accctrl.h>
11 #include <malloc.h>
12
13 #define NDEBUG
14 #include <debug.h>
15
16
17 /*
18 * @implemented
19 */
20 BOOL STDCALL
21 AreAllAccessesGranted(DWORD GrantedAccess,
22 DWORD DesiredAccess)
23 {
24 return((BOOL)RtlAreAllAccessesGranted(GrantedAccess,
25 DesiredAccess));
26 }
27
28
29 /*
30 * @implemented
31 */
32 BOOL STDCALL
33 AreAnyAccessesGranted(DWORD GrantedAccess,
34 DWORD DesiredAccess)
35 {
36 return((BOOL)RtlAreAnyAccessesGranted(GrantedAccess,
37 DesiredAccess));
38 }
39
40
41 /******************************************************************************
42 * GetFileSecurityA [ADVAPI32.@]
43 *
44 * Obtains Specified information about the security of a file or directory.
45 *
46 * PARAMS
47 * lpFileName [I] Name of the file to get info for
48 * RequestedInformation [I] SE_ flags from "winnt.h"
49 * pSecurityDescriptor [O] Destination for security information
50 * nLength [I] Length of pSecurityDescriptor
51 * lpnLengthNeeded [O] Destination for length of returned security information
52 *
53 * RETURNS
54 * Success: TRUE. pSecurityDescriptor contains the requested information.
55 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
56 *
57 * NOTES
58 * The information returned is constrained by the callers access rights and
59 * privileges.
60 *
61 * @implemented
62 */
63 BOOL WINAPI
64 GetFileSecurityA(LPCSTR lpFileName,
65 SECURITY_INFORMATION RequestedInformation,
66 PSECURITY_DESCRIPTOR pSecurityDescriptor,
67 DWORD nLength,
68 LPDWORD lpnLengthNeeded)
69 {
70 UNICODE_STRING FileName;
71 NTSTATUS Status;
72 BOOL bResult;
73
74 Status = RtlCreateUnicodeStringFromAsciiz(&FileName,
75 (LPSTR)lpFileName);
76 if (!NT_SUCCESS(Status))
77 {
78 SetLastError(RtlNtStatusToDosError(Status));
79 return FALSE;
80 }
81
82 bResult = GetFileSecurityW(FileName.Buffer,
83 RequestedInformation,
84 pSecurityDescriptor,
85 nLength,
86 lpnLengthNeeded);
87
88 RtlFreeUnicodeString(&FileName);
89
90 return bResult;
91 }
92
93
94 /*
95 * @implemented
96 */
97 BOOL WINAPI
98 GetFileSecurityW(LPCWSTR lpFileName,
99 SECURITY_INFORMATION RequestedInformation,
100 PSECURITY_DESCRIPTOR pSecurityDescriptor,
101 DWORD nLength,
102 LPDWORD lpnLengthNeeded)
103 {
104 OBJECT_ATTRIBUTES ObjectAttributes;
105 IO_STATUS_BLOCK StatusBlock;
106 UNICODE_STRING FileName;
107 ULONG AccessMask = 0;
108 HANDLE FileHandle;
109 NTSTATUS Status;
110
111 DPRINT("GetFileSecurityW() called\n");
112
113 if (RequestedInformation &
114 (OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION))
115 {
116 AccessMask |= STANDARD_RIGHTS_READ;
117 }
118
119 if (RequestedInformation & SACL_SECURITY_INFORMATION)
120 {
121 AccessMask |= ACCESS_SYSTEM_SECURITY;
122 }
123
124 if (!RtlDosPathNameToNtPathName_U((LPWSTR)lpFileName,
125 &FileName,
126 NULL,
127 NULL))
128 {
129 DPRINT("Invalid path\n");
130 SetLastError(ERROR_INVALID_NAME);
131 return FALSE;
132 }
133
134 InitializeObjectAttributes(&ObjectAttributes,
135 &FileName,
136 OBJ_CASE_INSENSITIVE,
137 NULL,
138 NULL);
139
140 Status = NtOpenFile(&FileHandle,
141 AccessMask,
142 &ObjectAttributes,
143 &StatusBlock,
144 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
145 0);
146 if (!NT_SUCCESS(Status))
147 {
148 DPRINT("NtOpenFile() failed (Status %lx)\n", Status);
149 SetLastError(RtlNtStatusToDosError(Status));
150 return FALSE;
151 }
152
153 RtlFreeUnicodeString(&FileName);
154
155 Status = NtQuerySecurityObject(FileHandle,
156 RequestedInformation,
157 pSecurityDescriptor,
158 nLength,
159 lpnLengthNeeded);
160 NtClose(FileHandle);
161
162 if (!NT_SUCCESS(Status))
163 {
164 DPRINT("NtQuerySecurityObject() failed (Status %lx)\n", Status);
165 SetLastError(RtlNtStatusToDosError(Status));
166 return FALSE;
167 }
168
169 return TRUE;
170 }
171
172
173 /*
174 * @implemented
175 */
176 BOOL STDCALL
177 GetKernelObjectSecurity(HANDLE Handle,
178 SECURITY_INFORMATION RequestedInformation,
179 PSECURITY_DESCRIPTOR pSecurityDescriptor,
180 DWORD nLength,
181 LPDWORD lpnLengthNeeded)
182 {
183 NTSTATUS Status;
184
185 Status = NtQuerySecurityObject(Handle,
186 RequestedInformation,
187 pSecurityDescriptor,
188 nLength,
189 lpnLengthNeeded);
190 if (!NT_SUCCESS(Status))
191 {
192 SetLastError(RtlNtStatusToDosError(Status));
193 return(FALSE);
194 }
195 return(TRUE);
196 }
197
198
199 /******************************************************************************
200 * SetFileSecurityA [ADVAPI32.@]
201 * Sets the security of a file or directory
202 *
203 * @implemented
204 */
205 BOOL STDCALL
206 SetFileSecurityA (LPCSTR lpFileName,
207 SECURITY_INFORMATION SecurityInformation,
208 PSECURITY_DESCRIPTOR pSecurityDescriptor)
209 {
210 UNICODE_STRING FileName;
211 NTSTATUS Status;
212 BOOL bResult;
213
214 Status = RtlCreateUnicodeStringFromAsciiz(&FileName,
215 (LPSTR)lpFileName);
216 if (!NT_SUCCESS(Status))
217 {
218 SetLastError(RtlNtStatusToDosError(Status));
219 return FALSE;
220 }
221
222 bResult = SetFileSecurityW(FileName.Buffer,
223 SecurityInformation,
224 pSecurityDescriptor);
225
226 RtlFreeUnicodeString(&FileName);
227
228 return bResult;
229 }
230
231
232 /******************************************************************************
233 * SetFileSecurityW [ADVAPI32.@]
234 * Sets the security of a file or directory
235 *
236 * @implemented
237 */
238 BOOL STDCALL
239 SetFileSecurityW (LPCWSTR lpFileName,
240 SECURITY_INFORMATION SecurityInformation,
241 PSECURITY_DESCRIPTOR pSecurityDescriptor)
242 {
243 OBJECT_ATTRIBUTES ObjectAttributes;
244 IO_STATUS_BLOCK StatusBlock;
245 UNICODE_STRING FileName;
246 ULONG AccessMask = 0;
247 HANDLE FileHandle;
248 NTSTATUS Status;
249
250 DPRINT("SetFileSecurityW() called\n");
251
252 if (SecurityInformation &
253 (OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION))
254 {
255 AccessMask |= WRITE_OWNER;
256 }
257
258 if (SecurityInformation & DACL_SECURITY_INFORMATION)
259 {
260 AccessMask |= WRITE_DAC;
261 }
262
263 if (SecurityInformation & SACL_SECURITY_INFORMATION)
264 {
265 AccessMask |= ACCESS_SYSTEM_SECURITY;
266 }
267
268 if (!RtlDosPathNameToNtPathName_U((LPWSTR)lpFileName,
269 &FileName,
270 NULL,
271 NULL))
272 {
273 DPRINT("Invalid path\n");
274 SetLastError(ERROR_INVALID_NAME);
275 return FALSE;
276 }
277
278 InitializeObjectAttributes(&ObjectAttributes,
279 &FileName,
280 OBJ_CASE_INSENSITIVE,
281 NULL,
282 NULL);
283
284 Status = NtOpenFile(&FileHandle,
285 AccessMask,
286 &ObjectAttributes,
287 &StatusBlock,
288 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
289 0);
290 if (!NT_SUCCESS(Status))
291 {
292 DPRINT("NtOpenFile() failed (Status %lx)\n", Status);
293 SetLastError(RtlNtStatusToDosError(Status));
294 return FALSE;
295 }
296
297 RtlFreeUnicodeString(&FileName);
298
299 Status = NtSetSecurityObject(FileHandle,
300 SecurityInformation,
301 pSecurityDescriptor);
302 NtClose(FileHandle);
303
304 if (!NT_SUCCESS(Status))
305 {
306 DPRINT("NtSetSecurityObject() failed (Status %lx)\n", Status);
307 SetLastError(RtlNtStatusToDosError(Status));
308 return FALSE;
309 }
310
311 return TRUE;
312 }
313
314
315 /*
316 * @implemented
317 */
318 BOOL STDCALL
319 SetKernelObjectSecurity(HANDLE Handle,
320 SECURITY_INFORMATION SecurityInformation,
321 PSECURITY_DESCRIPTOR SecurityDescriptor)
322 {
323 NTSTATUS Status;
324
325 Status = NtSetSecurityObject(Handle,
326 SecurityInformation,
327 SecurityDescriptor);
328 if (!NT_SUCCESS(Status))
329 {
330 SetLastError(RtlNtStatusToDosError(Status));
331 return FALSE;
332 }
333 return TRUE;
334 }
335
336
337 /*
338 * @implemented
339 */
340 VOID STDCALL
341 MapGenericMask(PDWORD AccessMask,
342 PGENERIC_MAPPING GenericMapping)
343 {
344 RtlMapGenericMask(AccessMask,
345 GenericMapping);
346 }
347
348
349 /*
350 * @implemented
351 */
352 BOOL STDCALL
353 ImpersonateLoggedOnUser(HANDLE hToken)
354 {
355 SECURITY_QUALITY_OF_SERVICE Qos;
356 OBJECT_ATTRIBUTES ObjectAttributes;
357 HANDLE NewToken;
358 TOKEN_TYPE Type;
359 ULONG ReturnLength;
360 BOOL Duplicated;
361 NTSTATUS Status;
362
363 /* Get the token type */
364 Status = NtQueryInformationToken (hToken,
365 TokenType,
366 &Type,
367 sizeof(TOKEN_TYPE),
368 &ReturnLength);
369 if (!NT_SUCCESS(Status))
370 {
371 SetLastError (RtlNtStatusToDosError (Status));
372 return FALSE;
373 }
374
375 if (Type == TokenPrimary)
376 {
377 /* Create a duplicate impersonation token */
378 Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
379 Qos.ImpersonationLevel = SecurityImpersonation;
380 Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
381 Qos.EffectiveOnly = FALSE;
382
383 ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
384 ObjectAttributes.RootDirectory = NULL;
385 ObjectAttributes.ObjectName = NULL;
386 ObjectAttributes.Attributes = 0;
387 ObjectAttributes.SecurityDescriptor = NULL;
388 ObjectAttributes.SecurityQualityOfService = &Qos;
389
390 Status = NtDuplicateToken (hToken,
391 TOKEN_IMPERSONATE | TOKEN_QUERY,
392 &ObjectAttributes,
393 FALSE,
394 TokenImpersonation,
395 &NewToken);
396 if (!NT_SUCCESS(Status))
397 {
398 SetLastError (RtlNtStatusToDosError (Status));
399 return FALSE;
400 }
401
402 Duplicated = TRUE;
403 }
404 else
405 {
406 /* User the original impersonation token */
407 NewToken = hToken;
408 Duplicated = FALSE;
409 }
410
411 /* Impersonate the the current thread */
412 Status = NtSetInformationThread (NtCurrentThread (),
413 ThreadImpersonationToken,
414 &NewToken,
415 sizeof(HANDLE));
416
417 if (Duplicated == TRUE)
418 {
419 NtClose (NewToken);
420 }
421
422 if (!NT_SUCCESS(Status))
423 {
424 SetLastError (RtlNtStatusToDosError (Status));
425 return FALSE;
426 }
427
428 return TRUE;
429 }
430
431
432 /*
433 * @implemented
434 */
435 BOOL STDCALL
436 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
437 {
438 NTSTATUS Status;
439
440 Status = RtlImpersonateSelf(ImpersonationLevel);
441 if (!NT_SUCCESS(Status))
442 {
443 SetLastError(RtlNtStatusToDosError(Status));
444 return FALSE;
445 }
446 return TRUE;
447 }
448
449
450 /*
451 * @implemented
452 */
453 BOOL STDCALL
454 RevertToSelf(VOID)
455 {
456 NTSTATUS Status;
457 HANDLE Token = NULL;
458
459 Status = NtSetInformationThread(NtCurrentThread(),
460 ThreadImpersonationToken,
461 &Token,
462 sizeof(HANDLE));
463 if (!NT_SUCCESS(Status))
464 {
465 SetLastError(RtlNtStatusToDosError(Status));
466 return FALSE;
467 }
468 return TRUE;
469 }
470
471
472 /******************************************************************************
473 * GetUserNameA [ADVAPI32.@]
474 *
475 * Get the current user name.
476 *
477 * PARAMS
478 * lpszName [O] Destination for the user name.
479 * lpSize [I/O] Size of lpszName.
480 *
481 *
482 * @implemented
483 */
484 BOOL WINAPI
485 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
486 {
487 WCHAR* lpszNameW = NULL;
488 DWORD len = 0;
489
490 if ( !lpSize )
491 {
492 SetLastError(ERROR_INVALID_PARAMETER);
493 return FALSE;
494 }
495
496 len = *lpSize;
497 lpszNameW = LocalAlloc ( LMEM_FIXED, len * sizeof(WCHAR) );
498
499 if ( !GetUserNameW ( lpszNameW, &len ) )
500 {
501 LocalFree ( lpszNameW );
502 return FALSE;
503 }
504
505 len = wcstombs ( lpszName, lpszNameW, len );
506
507 LocalFree ( lpszNameW );
508
509 if ( len > *lpSize )
510 {
511 SetLastError(ERROR_INSUFFICIENT_BUFFER);
512 return FALSE;
513 }
514
515 *lpSize = len;
516 return TRUE;
517 }
518
519 /******************************************************************************
520 * GetUserNameW [ADVAPI32.@]
521 *
522 * See GetUserNameA.
523 *
524 * @implemented
525 */
526 BOOL WINAPI
527 GetUserNameW ( LPWSTR lpszName, LPDWORD lpSize )
528 {
529 HANDLE hToken = INVALID_HANDLE_VALUE;
530 DWORD tu_len = 0;
531 char* tu_buf = NULL;
532 TOKEN_USER* token_user = NULL;
533 DWORD an_len = 0;
534 SID_NAME_USE snu = SidTypeUser;
535 WCHAR* domain_name = NULL;
536 DWORD dn_len = 0;
537
538 if ( !OpenThreadToken ( GetCurrentThread(), TOKEN_QUERY, FALSE, &hToken ) )
539 {
540 DWORD dwLastError = GetLastError();
541 if ( dwLastError != ERROR_NO_TOKEN
542 && dwLastError != ERROR_NO_IMPERSONATION_TOKEN )
543 {
544 /* don't call SetLastError(),
545 as OpenThreadToken() ought to have set one */
546 return FALSE;
547 }
548 if ( !OpenProcessToken ( GetCurrentProcess(), TOKEN_QUERY, &hToken ) )
549 {
550 /* don't call SetLastError(),
551 as OpenProcessToken() ought to have set one */
552 return FALSE;
553 }
554 }
555 tu_buf = LocalAlloc ( LMEM_FIXED, 36 );
556 if ( !tu_buf )
557 {
558 SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
559 return FALSE;
560 }
561 if ( !GetTokenInformation ( hToken, TokenUser, tu_buf, 36, &tu_len ) || tu_len > 36 )
562 {
563 LocalFree ( tu_buf );
564 tu_buf = LocalAlloc ( LMEM_FIXED, tu_len );
565 if ( !tu_buf )
566 {
567 SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
568 return FALSE;
569 }
570 if ( !GetTokenInformation ( hToken, TokenUser, tu_buf, tu_len, &tu_len ) )
571 {
572 /* don't call SetLastError(),
573 as GetTokenInformation() ought to have set one */
574 LocalFree ( tu_buf );
575 CloseHandle ( hToken );
576 return FALSE;
577 }
578 }
579 token_user = (TOKEN_USER*)tu_buf;
580
581 an_len = *lpSize;
582 dn_len = 32;
583 domain_name = LocalAlloc ( LMEM_FIXED, dn_len * sizeof(WCHAR) );
584 if ( !domain_name )
585 {
586 LocalFree ( tu_buf );
587 SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
588 return FALSE;
589 }
590 if ( !LookupAccountSidW ( NULL, token_user->User.Sid, lpszName, &an_len, domain_name, &dn_len, &snu )
591 || dn_len > 32 )
592 {
593 if ( dn_len > 32 )
594 {
595 LocalFree ( domain_name );
596 domain_name = LocalAlloc ( LMEM_FIXED, dn_len * sizeof(WCHAR) );
597 if ( !domain_name )
598 {
599 LocalFree ( tu_buf );
600 SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
601 return FALSE;
602 }
603 }
604 if ( !LookupAccountSidW ( NULL, token_user->User.Sid, lpszName, &an_len, domain_name, &dn_len, &snu ) )
605 {
606 /* don't call SetLastError(),
607 as LookupAccountSid() ought to have set one */
608 LocalFree ( domain_name );
609 CloseHandle ( hToken );
610 return FALSE;
611 }
612 }
613
614 LocalFree ( domain_name );
615 LocalFree ( tu_buf );
616 CloseHandle ( hToken );
617
618 if ( an_len > *lpSize )
619 {
620 *lpSize = an_len;
621 SetLastError(ERROR_INSUFFICIENT_BUFFER);
622 return FALSE;
623 }
624
625 return TRUE;
626 }
627
628
629 /******************************************************************************
630 * LookupAccountSidA [ADVAPI32.@]
631 *
632 * @unimplemented
633 */
634 BOOL STDCALL
635 LookupAccountSidA (LPCSTR lpSystemName,
636 PSID lpSid,
637 LPSTR lpName,
638 LPDWORD cchName,
639 LPSTR lpReferencedDomainName,
640 LPDWORD cchReferencedDomainName,
641 PSID_NAME_USE peUse)
642 {
643 DWORD NameLength;
644 DWORD DomainLength;
645
646 DPRINT1("LookupAccountSidA is unimplemented, but returns success\n");
647
648 /* Calculate length needed */
649 NameLength = strlen("Administrator") + 1;
650 DomainLength = strlen("BUILTIN") + 1;
651
652 if (*cchName < NameLength || *cchReferencedDomainName < DomainLength)
653 {
654 *cchName = NameLength;
655 *cchReferencedDomainName = DomainLength;
656 SetLastError(ERROR_INSUFFICIENT_BUFFER);
657 return FALSE;
658 }
659
660 if (lpName) lstrcpynA(lpName, "Administrator", *cchName);
661 if (lpReferencedDomainName) lstrcpynA(lpReferencedDomainName, "BUILTIN", *cchReferencedDomainName);
662 return TRUE;
663 }
664
665
666 /******************************************************************************
667 * LookupAccountSidW [ADVAPI32.@]
668 *
669 * @unimplemented
670 */
671 BOOL STDCALL
672 LookupAccountSidW (LPCWSTR lpSystemName,
673 PSID lpSid,
674 LPWSTR lpName,
675 LPDWORD cchName,
676 LPWSTR lpReferencedDomainName,
677 LPDWORD cchReferencedDomainName,
678 PSID_NAME_USE peUse)
679 {
680 DWORD NameLength;
681 DWORD DomainLength;
682
683 DPRINT1("LookupAccountSidW is unimplemented, but returns success\n");
684
685 /* Calculate length needed */
686 NameLength = wcslen(L"Administrator") + sizeof(WCHAR);
687 DomainLength = wcslen(L"BUILTIN") + sizeof(WCHAR);
688
689 if (*cchName < NameLength || *cchReferencedDomainName < DomainLength)
690 {
691 *cchName = NameLength;
692 *cchReferencedDomainName = DomainLength;
693 SetLastError(ERROR_INSUFFICIENT_BUFFER);
694 return FALSE;
695 }
696
697 if (lpName) lstrcpynW(lpName, L"Administrator", *cchName);
698 if (lpReferencedDomainName) lstrcpynW(lpReferencedDomainName, L"BUILTIN", *cchReferencedDomainName);
699 return TRUE;
700 }
701
702
703 /******************************************************************************
704 * LookupAccountNameA [ADVAPI32.@]
705 *
706 * @unimplemented
707 */
708 BOOL STDCALL
709 LookupAccountNameA (LPCSTR SystemName,
710 LPCSTR AccountName,
711 PSID Sid,
712 LPDWORD SidLength,
713 LPSTR ReferencedDomainName,
714 LPDWORD hReferencedDomainNameLength,
715 PSID_NAME_USE SidNameUse)
716 {
717 DPRINT1("LookupAccountNameA is unimplemented\n");
718 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
719 return FALSE;
720 }
721
722
723 /******************************************************************************
724 * LookupAccountNameW [ADVAPI32.@]
725 *
726 * @unimplemented
727 */
728 BOOL STDCALL
729 LookupAccountNameW (LPCWSTR SystemName,
730 LPCWSTR AccountName,
731 PSID Sid,
732 LPDWORD SidLength,
733 LPWSTR ReferencedDomainName,
734 LPDWORD hReferencedDomainNameLength,
735 PSID_NAME_USE SidNameUse)
736 {
737 DPRINT1("LookupAccountNameW is unimplemented\n");
738 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
739 return FALSE;
740 }
741
742
743 /**********************************************************************
744 * LookupPrivilegeValueA EXPORTED
745 *
746 * @implemented
747 */
748 BOOL STDCALL
749 LookupPrivilegeValueA (LPCSTR lpSystemName,
750 LPCSTR lpName,
751 PLUID lpLuid)
752 {
753 UNICODE_STRING SystemName;
754 UNICODE_STRING Name;
755 BOOL Result;
756
757 /* Remote system? */
758 if (lpSystemName != NULL)
759 {
760 RtlCreateUnicodeStringFromAsciiz (&SystemName,
761 (LPSTR)lpSystemName);
762 }
763
764 /* Check the privilege name is not NULL */
765 if (lpName == NULL)
766 {
767 SetLastError (ERROR_INVALID_PARAMETER);
768 return FALSE;
769 }
770
771 RtlCreateUnicodeStringFromAsciiz (&Name,
772 (LPSTR)lpName);
773
774 Result = LookupPrivilegeValueW ((lpSystemName != NULL) ? SystemName.Buffer : NULL,
775 Name.Buffer,
776 lpLuid);
777
778 RtlFreeUnicodeString (&Name);
779
780 /* Remote system? */
781 if (lpSystemName != NULL)
782 {
783 RtlFreeUnicodeString (&SystemName);
784 }
785
786 return Result;
787 }
788
789
790 /**********************************************************************
791 * LookupPrivilegeValueW EXPORTED
792 *
793 * @unimplemented
794 */
795 BOOL STDCALL
796 LookupPrivilegeValueW (LPCWSTR SystemName,
797 LPCWSTR PrivName,
798 PLUID Luid)
799 {
800 static const WCHAR * const DefaultPrivNames[] =
801 {
802 L"SeCreateTokenPrivilege",
803 L"SeAssignPrimaryTokenPrivilege",
804 L"SeLockMemoryPrivilege",
805 L"SeIncreaseQuotaPrivilege",
806 L"SeUnsolicitedInputPrivilege",
807 L"SeMachineAccountPrivilege",
808 L"SeTcbPrivilege",
809 L"SeSecurityPrivilege",
810 L"SeTakeOwnershipPrivilege",
811 L"SeLoadDriverPrivilege",
812 L"SeSystemProfilePrivilege",
813 L"SeSystemtimePrivilege",
814 L"SeProfileSingleProcessPrivilege",
815 L"SeIncreaseBasePriorityPrivilege",
816 L"SeCreatePagefilePrivilege",
817 L"SeCreatePermanentPrivilege",
818 L"SeBackupPrivilege",
819 L"SeRestorePrivilege",
820 L"SeShutdownPrivilege",
821 L"SeDebugPrivilege",
822 L"SeAuditPrivilege",
823 L"SeSystemEnvironmentPrivilege",
824 L"SeChangeNotifyPrivilege",
825 L"SeRemoteShutdownPrivilege",
826 L"SeUndockPrivilege",
827 L"SeSyncAgentPrivilege",
828 L"SeEnableDelegationPrivilege",
829 L"SeManageVolumePrivilege",
830 L"SeImpersonatePrivilege",
831 L"SeCreateGlobalPrivilege"
832 };
833 unsigned Priv;
834
835 if (NULL != SystemName && L'\0' != *SystemName)
836 {
837 DPRINT1("LookupPrivilegeValueW: not implemented for remote system\n");
838 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
839 return FALSE;
840 }
841
842 for (Priv = 0; Priv < sizeof(DefaultPrivNames) / sizeof(DefaultPrivNames[0]); Priv++)
843 {
844 if (0 == wcscmp(PrivName, DefaultPrivNames[Priv]))
845 {
846 Luid->LowPart = Priv + 1;
847 Luid->HighPart = 0;
848 return TRUE;
849 }
850 }
851
852 DPRINT1("LookupPrivilegeValueW: no such privilege %S\n", PrivName);
853 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
854 return FALSE;
855 }
856
857
858 /**********************************************************************
859 * LookupPrivilegeDisplayNameA EXPORTED
860 *
861 * @unimplemented
862 */
863 BOOL STDCALL
864 LookupPrivilegeDisplayNameA (LPCSTR lpSystemName,
865 LPCSTR lpName,
866 LPSTR lpDisplayName,
867 LPDWORD cbDisplayName,
868 LPDWORD lpLanguageId)
869 {
870 DPRINT1("LookupPrivilegeDisplayNameA: stub\n");
871 SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
872 return FALSE;
873 }
874
875
876 /**********************************************************************
877 * LookupPrivilegeDisplayNameW EXPORTED
878 *
879 * @unimplemented
880 */
881 BOOL STDCALL
882 LookupPrivilegeDisplayNameW (LPCWSTR lpSystemName,
883 LPCWSTR lpName,
884 LPWSTR lpDisplayName,
885 LPDWORD cbDisplayName,
886 LPDWORD lpLanguageId)
887 {
888 DPRINT1("LookupPrivilegeDisplayNameW: stub\n");
889 SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
890 return FALSE;
891 }
892
893
894 /**********************************************************************
895 * LookupPrivilegeNameA EXPORTED
896 *
897 * @unimplemented
898 */
899 BOOL STDCALL
900 LookupPrivilegeNameA (LPCSTR lpSystemName,
901 PLUID lpLuid,
902 LPSTR lpName,
903 LPDWORD cbName)
904 {
905 DPRINT1("LookupPrivilegeNameA: stub\n");
906 SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
907 return FALSE;
908 }
909
910
911 /**********************************************************************
912 * LookupPrivilegeNameW EXPORTED
913 *
914 * @unimplemented
915 */
916 BOOL STDCALL
917 LookupPrivilegeNameW (LPCWSTR lpSystemName,
918 PLUID lpLuid,
919 LPWSTR lpName,
920 LPDWORD cbName)
921 {
922 DPRINT1("LookupPrivilegeNameW: stub\n");
923 SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
924 return FALSE;
925 }
926
927
928 /**********************************************************************
929 * GetNamedSecurityInfoW EXPORTED
930 *
931 * @unimplemented
932 */
933 DWORD STDCALL
934 GetNamedSecurityInfoW(LPWSTR pObjectName,
935 SE_OBJECT_TYPE ObjectType,
936 SECURITY_INFORMATION SecurityInfo,
937 PSID *ppsidOwner,
938 PSID *ppsidGroup,
939 PACL *ppDacl,
940 PACL *ppSacl,
941 PSECURITY_DESCRIPTOR *ppSecurityDescriptor)
942 {
943 DPRINT1("GetNamedSecurityInfoW: stub\n");
944 return ERROR_CALL_NOT_IMPLEMENTED;
945 }
946
947
948 /**********************************************************************
949 * GetNamedSecurityInfoA EXPORTED
950 *
951 * @unimplemented
952 */
953 DWORD STDCALL
954 GetNamedSecurityInfoA(LPSTR pObjectName,
955 SE_OBJECT_TYPE ObjectType,
956 SECURITY_INFORMATION SecurityInfo,
957 PSID *ppsidOwner,
958 PSID *ppsidGroup,
959 PACL *ppDacl,
960 PACL *ppSacl,
961 PSECURITY_DESCRIPTOR *ppSecurityDescriptor)
962 {
963 DPRINT1("GetNamedSecurityInfoA: stub\n");
964 return ERROR_CALL_NOT_IMPLEMENTED;
965 }
966
967
968 /**********************************************************************
969 * SetNamedSecurityInfoW EXPORTED
970 *
971 * @unimplemented
972 */
973 DWORD STDCALL
974 SetNamedSecurityInfoW(LPWSTR pObjectName,
975 SE_OBJECT_TYPE ObjectType,
976 SECURITY_INFORMATION SecurityInfo,
977 PSID psidOwner,
978 PSID psidGroup,
979 PACL pDacl,
980 PACL pSacl)
981 {
982 DPRINT1("SetNamedSecurityInfoW: stub\n");
983 return ERROR_CALL_NOT_IMPLEMENTED;
984 }
985
986
987 /**********************************************************************
988 * SetNamedSecurityInfoA EXPORTED
989 *
990 * @unimplemented
991 */
992 DWORD STDCALL
993 SetNamedSecurityInfoA(LPSTR pObjectName,
994 SE_OBJECT_TYPE ObjectType,
995 SECURITY_INFORMATION SecurityInfo,
996 PSID psidOwner,
997 PSID psidGroup,
998 PACL pDacl,
999 PACL pSacl)
1000 {
1001 DPRINT1("SetNamedSecurityInfoA: stub\n");
1002 return ERROR_CALL_NOT_IMPLEMENTED;
1003 }
1004
1005
1006 /**********************************************************************
1007 * GetSecurityInfo EXPORTED
1008 *
1009 * @unimplemented
1010 */
1011 DWORD STDCALL
1012 GetSecurityInfo(HANDLE handle,
1013 SE_OBJECT_TYPE ObjectType,
1014 SECURITY_INFORMATION SecurityInfo,
1015 PSID* ppsidOwner,
1016 PSID* ppsidGroup,
1017 PACL* ppDacl,
1018 PACL* ppSacl,
1019 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
1020 {
1021 DPRINT1("GetSecurityInfo: stub\n");
1022 return ERROR_CALL_NOT_IMPLEMENTED;
1023 }
1024
1025
1026 /**********************************************************************
1027 * SetSecurityInfo EXPORTED
1028 *
1029 * @unimplemented
1030 */
1031 DWORD
1032 WINAPI
1033 SetSecurityInfo(HANDLE handle,
1034 SE_OBJECT_TYPE ObjectType,
1035 SECURITY_INFORMATION SecurityInfo,
1036 PSID psidOwner,
1037 PSID psidGroup,
1038 PACL pDacl,
1039 PACL pSacl)
1040 {
1041 DPRINT1("SetSecurityInfo: stub\n");
1042 return ERROR_CALL_NOT_IMPLEMENTED;
1043 }
1044
1045
1046 /******************************************************************************
1047 * GetSecurityInfoExW EXPORTED
1048 */
1049 DWORD WINAPI GetSecurityInfoExA(
1050 HANDLE hObject,
1051 SE_OBJECT_TYPE ObjectType,
1052 SECURITY_INFORMATION SecurityInfo,
1053 LPCSTR lpProvider,
1054 LPCSTR lpProperty,
1055 PACTRL_ACCESSA *ppAccessList,
1056 PACTRL_AUDITA *ppAuditList,
1057 LPSTR *lppOwner,
1058 LPSTR *lppGroup
1059 )
1060 {
1061 DPRINT1("GetSecurityInfoExA stub!\n");
1062 return ERROR_BAD_PROVIDER;
1063 }
1064
1065
1066 /******************************************************************************
1067 * GetSecurityInfoExW EXPORTED
1068 */
1069 DWORD WINAPI GetSecurityInfoExW(
1070 HANDLE hObject,
1071 SE_OBJECT_TYPE ObjectType,
1072 SECURITY_INFORMATION SecurityInfo,
1073 LPCWSTR lpProvider,
1074 LPCWSTR lpProperty,
1075 PACTRL_ACCESSW *ppAccessList,
1076 PACTRL_AUDITW *ppAuditList,
1077 LPWSTR *lppOwner,
1078 LPWSTR *lppGroup
1079 )
1080 {
1081 DPRINT1("GetSecurityInfoExW stub!\n");
1082 return ERROR_BAD_PROVIDER;
1083 }
1084
1085
1086 /**********************************************************************
1087 * ImpersonateNamedPipeClient EXPORTED
1088 *
1089 * @implemented
1090 */
1091 BOOL STDCALL
1092 ImpersonateNamedPipeClient(HANDLE hNamedPipe)
1093 {
1094 IO_STATUS_BLOCK StatusBlock;
1095 NTSTATUS Status;
1096
1097 DPRINT("ImpersonateNamedPipeClient() called\n");
1098
1099 Status = NtFsControlFile(hNamedPipe,
1100 NULL,
1101 NULL,
1102 NULL,
1103 &StatusBlock,
1104 FSCTL_PIPE_IMPERSONATE,
1105 NULL,
1106 0,
1107 NULL,
1108 0);
1109 if (!NT_SUCCESS(Status))
1110 {
1111 SetLastError(RtlNtStatusToDosError(Status));
1112 return FALSE;
1113 }
1114
1115 return TRUE;
1116 }
1117
1118 /* EOF */