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