Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmisc.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * WINE COPYRIGHT: 00004 * Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net> 00005 * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla) 00006 * Copyright 2006 Robert Reif 00007 * 00008 * PROJECT: ReactOS system libraries 00009 * FILE: dll/win32/advapi32/sec/misc.c 00010 * PURPOSE: Miscellaneous security functions (some ported from Wine) 00011 */ 00012 00013 #include <advapi32.h> 00014 WINE_DEFAULT_DEBUG_CHANNEL(advapi); 00015 00016 00017 /* Interface to ntmarta.dll ***************************************************/ 00018 00019 NTMARTA NtMartaStatic = { 0 }; 00020 static PNTMARTA NtMarta = NULL; 00021 00022 #define FindNtMartaProc(Name) \ 00023 NtMartaStatic.Name = (PVOID)GetProcAddress(NtMartaStatic.hDllInstance, \ 00024 "Acc" # Name ); \ 00025 if (NtMartaStatic.Name == NULL) \ 00026 { \ 00027 return GetLastError(); \ 00028 } 00029 00030 00031 static DWORD 00032 LoadAndInitializeNtMarta(VOID) 00033 { 00034 /* this code may be executed simultaneously by multiple threads in case they're 00035 trying to initialize the interface at the same time, but that's no problem 00036 because the pointers returned by GetProcAddress will be the same. However, 00037 only one of the threads will change the NtMarta pointer to the NtMartaStatic 00038 structure, the others threads will detect that there were other threads 00039 initializing the structure faster and will release the reference to the 00040 DLL */ 00041 00042 NtMartaStatic.hDllInstance = LoadLibraryW(L"ntmarta.dll"); 00043 if (NtMartaStatic.hDllInstance == NULL) 00044 { 00045 return GetLastError(); 00046 } 00047 00048 #if 0 00049 FindNtMartaProc(LookupAccountTrustee); 00050 FindNtMartaProc(LookupAccountName); 00051 FindNtMartaProc(LookupAccountSid); 00052 FindNtMartaProc(SetEntriesInAList); 00053 FindNtMartaProc(ConvertAccessToSecurityDescriptor); 00054 FindNtMartaProc(ConvertSDToAccess); 00055 FindNtMartaProc(ConvertAclToAccess); 00056 FindNtMartaProc(GetAccessForTrustee); 00057 FindNtMartaProc(GetExplicitEntries); 00058 #endif 00059 FindNtMartaProc(RewriteGetNamedRights); 00060 FindNtMartaProc(RewriteSetNamedRights); 00061 FindNtMartaProc(RewriteGetHandleRights); 00062 FindNtMartaProc(RewriteSetHandleRights); 00063 FindNtMartaProc(RewriteSetEntriesInAcl); 00064 FindNtMartaProc(RewriteGetExplicitEntriesFromAcl); 00065 FindNtMartaProc(TreeResetNamedSecurityInfo); 00066 FindNtMartaProc(GetInheritanceSource); 00067 FindNtMartaProc(FreeIndexArray); 00068 00069 return ERROR_SUCCESS; 00070 } 00071 00072 00073 DWORD 00074 CheckNtMartaPresent(VOID) 00075 { 00076 DWORD ErrorCode; 00077 00078 if (InterlockedCompareExchangePointer((PVOID)&NtMarta, 00079 NULL, 00080 NULL) == NULL) 00081 { 00082 /* we're the first one trying to use ntmarta, initialize it and change 00083 the pointer after initialization */ 00084 ErrorCode = LoadAndInitializeNtMarta(); 00085 00086 if (ErrorCode == ERROR_SUCCESS) 00087 { 00088 /* try change the NtMarta pointer */ 00089 if (InterlockedCompareExchangePointer((PVOID)&NtMarta, 00090 &NtMartaStatic, 00091 NULL) != NULL) 00092 { 00093 /* another thread initialized ntmarta in the meanwhile, release 00094 the reference of the dll loaded. */ 00095 FreeLibrary(NtMartaStatic.hDllInstance); 00096 } 00097 } 00098 #if DBG 00099 else 00100 { 00101 ERR("Failed to initialize ntmarta.dll! Error: 0x%x", ErrorCode); 00102 } 00103 #endif 00104 } 00105 else 00106 { 00107 /* ntmarta was already initialized */ 00108 ErrorCode = ERROR_SUCCESS; 00109 } 00110 00111 return ErrorCode; 00112 } 00113 00114 00115 VOID 00116 UnloadNtMarta(VOID) 00117 { 00118 if (InterlockedExchangePointer((PVOID)&NtMarta, 00119 NULL) != NULL) 00120 { 00121 FreeLibrary(NtMartaStatic.hDllInstance); 00122 } 00123 } 00124 00125 00126 /******************************************************************************/ 00127 00128 /* 00129 * @implemented 00130 */ 00131 BOOL 00132 WINAPI 00133 AreAllAccessesGranted(DWORD GrantedAccess, 00134 DWORD DesiredAccess) 00135 { 00136 return (BOOL)RtlAreAllAccessesGranted(GrantedAccess, 00137 DesiredAccess); 00138 } 00139 00140 00141 /* 00142 * @implemented 00143 */ 00144 BOOL 00145 WINAPI 00146 AreAnyAccessesGranted(DWORD GrantedAccess, 00147 DWORD DesiredAccess) 00148 { 00149 return (BOOL)RtlAreAnyAccessesGranted(GrantedAccess, 00150 DesiredAccess); 00151 } 00152 00153 00154 /************************************************************ 00155 * ADVAPI_IsLocalComputer 00156 * 00157 * Checks whether the server name indicates local machine. 00158 */ 00159 BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName) 00160 { 00161 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1; 00162 BOOL Result; 00163 LPWSTR buf; 00164 00165 if (!ServerName || !ServerName[0]) 00166 return TRUE; 00167 00168 buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR)); 00169 Result = GetComputerNameW(buf, &dwSize); 00170 if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\')) 00171 ServerName += 2; 00172 Result = Result && !lstrcmpW(ServerName, buf); 00173 HeapFree(GetProcessHeap(), 0, buf); 00174 00175 return Result; 00176 } 00177 00178 00179 /****************************************************************************** 00180 * GetFileSecurityA [ADVAPI32.@] 00181 * 00182 * Obtains Specified information about the security of a file or directory. 00183 * 00184 * PARAMS 00185 * lpFileName [I] Name of the file to get info for 00186 * RequestedInformation [I] SE_ flags from "winnt.h" 00187 * pSecurityDescriptor [O] Destination for security information 00188 * nLength [I] Length of pSecurityDescriptor 00189 * lpnLengthNeeded [O] Destination for length of returned security information 00190 * 00191 * RETURNS 00192 * Success: TRUE. pSecurityDescriptor contains the requested information. 00193 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info. 00194 * 00195 * NOTES 00196 * The information returned is constrained by the callers access rights and 00197 * privileges. 00198 * 00199 * @implemented 00200 */ 00201 BOOL 00202 WINAPI 00203 GetFileSecurityA(LPCSTR lpFileName, 00204 SECURITY_INFORMATION RequestedInformation, 00205 PSECURITY_DESCRIPTOR pSecurityDescriptor, 00206 DWORD nLength, 00207 LPDWORD lpnLengthNeeded) 00208 { 00209 UNICODE_STRING FileName; 00210 NTSTATUS Status; 00211 BOOL bResult; 00212 00213 Status = RtlCreateUnicodeStringFromAsciiz(&FileName, 00214 (LPSTR)lpFileName); 00215 if (!NT_SUCCESS(Status)) 00216 { 00217 SetLastError(RtlNtStatusToDosError(Status)); 00218 return FALSE; 00219 } 00220 00221 bResult = GetFileSecurityW(FileName.Buffer, 00222 RequestedInformation, 00223 pSecurityDescriptor, 00224 nLength, 00225 lpnLengthNeeded); 00226 00227 RtlFreeUnicodeString(&FileName); 00228 00229 return bResult; 00230 } 00231 00232 00233 /* 00234 * @implemented 00235 */ 00236 BOOL 00237 WINAPI 00238 GetFileSecurityW(LPCWSTR lpFileName, 00239 SECURITY_INFORMATION RequestedInformation, 00240 PSECURITY_DESCRIPTOR pSecurityDescriptor, 00241 DWORD nLength, 00242 LPDWORD lpnLengthNeeded) 00243 { 00244 OBJECT_ATTRIBUTES ObjectAttributes; 00245 IO_STATUS_BLOCK StatusBlock; 00246 UNICODE_STRING FileName; 00247 ULONG AccessMask = 0; 00248 HANDLE FileHandle; 00249 NTSTATUS Status; 00250 00251 TRACE("GetFileSecurityW() called\n"); 00252 00253 QuerySecurityAccessMask(RequestedInformation, &AccessMask); 00254 00255 if (!RtlDosPathNameToNtPathName_U(lpFileName, 00256 &FileName, 00257 NULL, 00258 NULL)) 00259 { 00260 ERR("Invalid path\n"); 00261 SetLastError(ERROR_INVALID_NAME); 00262 return FALSE; 00263 } 00264 00265 InitializeObjectAttributes(&ObjectAttributes, 00266 &FileName, 00267 OBJ_CASE_INSENSITIVE, 00268 NULL, 00269 NULL); 00270 00271 Status = NtOpenFile(&FileHandle, 00272 AccessMask, 00273 &ObjectAttributes, 00274 &StatusBlock, 00275 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 00276 0); 00277 00278 RtlFreeHeap(RtlGetProcessHeap(), 00279 0, 00280 FileName.Buffer); 00281 00282 if (!NT_SUCCESS(Status)) 00283 { 00284 ERR("NtOpenFile() failed (Status %lx)\n", Status); 00285 SetLastError(RtlNtStatusToDosError(Status)); 00286 return FALSE; 00287 } 00288 00289 Status = NtQuerySecurityObject(FileHandle, 00290 RequestedInformation, 00291 pSecurityDescriptor, 00292 nLength, 00293 lpnLengthNeeded); 00294 NtClose(FileHandle); 00295 if (!NT_SUCCESS(Status)) 00296 { 00297 ERR("NtQuerySecurityObject() failed (Status %lx)\n", Status); 00298 SetLastError(RtlNtStatusToDosError(Status)); 00299 return FALSE; 00300 } 00301 00302 return TRUE; 00303 } 00304 00305 00306 /* 00307 * @implemented 00308 */ 00309 BOOL 00310 WINAPI 00311 GetKernelObjectSecurity(HANDLE Handle, 00312 SECURITY_INFORMATION RequestedInformation, 00313 PSECURITY_DESCRIPTOR pSecurityDescriptor, 00314 DWORD nLength, 00315 LPDWORD lpnLengthNeeded) 00316 { 00317 NTSTATUS Status; 00318 00319 Status = NtQuerySecurityObject(Handle, 00320 RequestedInformation, 00321 pSecurityDescriptor, 00322 nLength, 00323 lpnLengthNeeded); 00324 if (!NT_SUCCESS(Status)) 00325 { 00326 SetLastError(RtlNtStatusToDosError(Status)); 00327 return FALSE; 00328 } 00329 00330 return TRUE; 00331 } 00332 00333 00334 /****************************************************************************** 00335 * SetFileSecurityA [ADVAPI32.@] 00336 * Sets the security of a file or directory 00337 * 00338 * @implemented 00339 */ 00340 BOOL 00341 WINAPI 00342 SetFileSecurityA(LPCSTR lpFileName, 00343 SECURITY_INFORMATION SecurityInformation, 00344 PSECURITY_DESCRIPTOR pSecurityDescriptor) 00345 { 00346 UNICODE_STRING FileName; 00347 NTSTATUS Status; 00348 BOOL bResult; 00349 00350 Status = RtlCreateUnicodeStringFromAsciiz(&FileName, 00351 (LPSTR)lpFileName); 00352 if (!NT_SUCCESS(Status)) 00353 { 00354 SetLastError(RtlNtStatusToDosError(Status)); 00355 return FALSE; 00356 } 00357 00358 bResult = SetFileSecurityW(FileName.Buffer, 00359 SecurityInformation, 00360 pSecurityDescriptor); 00361 00362 RtlFreeUnicodeString(&FileName); 00363 00364 return bResult; 00365 } 00366 00367 00368 /****************************************************************************** 00369 * SetFileSecurityW [ADVAPI32.@] 00370 * Sets the security of a file or directory 00371 * 00372 * @implemented 00373 */ 00374 BOOL 00375 WINAPI 00376 SetFileSecurityW(LPCWSTR lpFileName, 00377 SECURITY_INFORMATION SecurityInformation, 00378 PSECURITY_DESCRIPTOR pSecurityDescriptor) 00379 { 00380 OBJECT_ATTRIBUTES ObjectAttributes; 00381 IO_STATUS_BLOCK StatusBlock; 00382 UNICODE_STRING FileName; 00383 ULONG AccessMask = 0; 00384 HANDLE FileHandle; 00385 NTSTATUS Status; 00386 00387 TRACE("SetFileSecurityW() called\n"); 00388 00389 SetSecurityAccessMask(SecurityInformation, &AccessMask); 00390 00391 if (!RtlDosPathNameToNtPathName_U(lpFileName, 00392 &FileName, 00393 NULL, 00394 NULL)) 00395 { 00396 ERR("Invalid path\n"); 00397 SetLastError(ERROR_INVALID_NAME); 00398 return FALSE; 00399 } 00400 00401 InitializeObjectAttributes(&ObjectAttributes, 00402 &FileName, 00403 OBJ_CASE_INSENSITIVE, 00404 NULL, 00405 NULL); 00406 00407 Status = NtOpenFile(&FileHandle, 00408 AccessMask, 00409 &ObjectAttributes, 00410 &StatusBlock, 00411 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 00412 0); 00413 00414 RtlFreeHeap(RtlGetProcessHeap(), 00415 0, 00416 FileName.Buffer); 00417 00418 if (!NT_SUCCESS(Status)) 00419 { 00420 ERR("NtOpenFile() failed (Status %lx)\n", Status); 00421 SetLastError(RtlNtStatusToDosError(Status)); 00422 return FALSE; 00423 } 00424 00425 Status = NtSetSecurityObject(FileHandle, 00426 SecurityInformation, 00427 pSecurityDescriptor); 00428 NtClose(FileHandle); 00429 00430 if (!NT_SUCCESS(Status)) 00431 { 00432 ERR("NtSetSecurityObject() failed (Status %lx)\n", Status); 00433 SetLastError(RtlNtStatusToDosError(Status)); 00434 return FALSE; 00435 } 00436 00437 return TRUE; 00438 } 00439 00440 00441 /* 00442 * @implemented 00443 */ 00444 BOOL 00445 WINAPI 00446 SetKernelObjectSecurity(HANDLE Handle, 00447 SECURITY_INFORMATION SecurityInformation, 00448 PSECURITY_DESCRIPTOR SecurityDescriptor) 00449 { 00450 NTSTATUS Status; 00451 00452 Status = NtSetSecurityObject(Handle, 00453 SecurityInformation, 00454 SecurityDescriptor); 00455 if (!NT_SUCCESS(Status)) 00456 { 00457 SetLastError(RtlNtStatusToDosError(Status)); 00458 return FALSE; 00459 } 00460 00461 return TRUE; 00462 } 00463 00464 00465 /* 00466 * @implemented 00467 */ 00468 BOOL 00469 WINAPI 00470 ImpersonateAnonymousToken(IN HANDLE ThreadHandle) 00471 { 00472 NTSTATUS Status; 00473 00474 Status = NtImpersonateAnonymousToken(ThreadHandle); 00475 if (!NT_SUCCESS(Status)) 00476 { 00477 SetLastError(RtlNtStatusToDosError(Status)); 00478 return FALSE; 00479 } 00480 00481 return TRUE; 00482 } 00483 00484 00485 /* 00486 * @implemented 00487 */ 00488 BOOL 00489 WINAPI 00490 ImpersonateLoggedOnUser(HANDLE hToken) 00491 { 00492 SECURITY_QUALITY_OF_SERVICE Qos; 00493 OBJECT_ATTRIBUTES ObjectAttributes; 00494 HANDLE NewToken; 00495 TOKEN_TYPE Type; 00496 ULONG ReturnLength; 00497 BOOL Duplicated; 00498 NTSTATUS Status; 00499 00500 /* Get the token type */ 00501 Status = NtQueryInformationToken(hToken, 00502 TokenType, 00503 &Type, 00504 sizeof(TOKEN_TYPE), 00505 &ReturnLength); 00506 if (!NT_SUCCESS(Status)) 00507 { 00508 SetLastError(RtlNtStatusToDosError(Status)); 00509 return FALSE; 00510 } 00511 00512 if (Type == TokenPrimary) 00513 { 00514 /* Create a duplicate impersonation token */ 00515 Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE); 00516 Qos.ImpersonationLevel = SecurityImpersonation; 00517 Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING; 00518 Qos.EffectiveOnly = FALSE; 00519 00520 ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); 00521 ObjectAttributes.RootDirectory = NULL; 00522 ObjectAttributes.ObjectName = NULL; 00523 ObjectAttributes.Attributes = 0; 00524 ObjectAttributes.SecurityDescriptor = NULL; 00525 ObjectAttributes.SecurityQualityOfService = &Qos; 00526 00527 Status = NtDuplicateToken(hToken, 00528 TOKEN_IMPERSONATE | TOKEN_QUERY, 00529 &ObjectAttributes, 00530 FALSE, 00531 TokenImpersonation, 00532 &NewToken); 00533 if (!NT_SUCCESS(Status)) 00534 { 00535 SetLastError(RtlNtStatusToDosError(Status)); 00536 return FALSE; 00537 } 00538 00539 Duplicated = TRUE; 00540 } 00541 else 00542 { 00543 /* User the original impersonation token */ 00544 NewToken = hToken; 00545 Duplicated = FALSE; 00546 } 00547 00548 /* Impersonate the the current thread */ 00549 Status = NtSetInformationThread(NtCurrentThread(), 00550 ThreadImpersonationToken, 00551 &NewToken, 00552 sizeof(HANDLE)); 00553 00554 if (Duplicated == TRUE) 00555 { 00556 NtClose(NewToken); 00557 } 00558 00559 if (!NT_SUCCESS(Status)) 00560 { 00561 SetLastError(RtlNtStatusToDosError(Status)); 00562 return FALSE; 00563 } 00564 00565 return TRUE; 00566 } 00567 00568 00569 /* 00570 * @implemented 00571 */ 00572 BOOL 00573 WINAPI 00574 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel) 00575 { 00576 NTSTATUS Status; 00577 00578 Status = RtlImpersonateSelf(ImpersonationLevel); 00579 if (!NT_SUCCESS(Status)) 00580 { 00581 SetLastError(RtlNtStatusToDosError(Status)); 00582 return FALSE; 00583 } 00584 00585 return TRUE; 00586 } 00587 00588 00589 /* 00590 * @implemented 00591 */ 00592 BOOL 00593 WINAPI 00594 RevertToSelf(VOID) 00595 { 00596 NTSTATUS Status; 00597 HANDLE Token = NULL; 00598 00599 Status = NtSetInformationThread(NtCurrentThread(), 00600 ThreadImpersonationToken, 00601 &Token, 00602 sizeof(HANDLE)); 00603 if (!NT_SUCCESS(Status)) 00604 { 00605 SetLastError(RtlNtStatusToDosError(Status)); 00606 return FALSE; 00607 } 00608 00609 return TRUE; 00610 } 00611 00612 00613 /****************************************************************************** 00614 * GetUserNameA [ADVAPI32.@] 00615 * 00616 * Get the current user name. 00617 * 00618 * PARAMS 00619 * lpszName [O] Destination for the user name. 00620 * lpSize [I/O] Size of lpszName. 00621 * 00622 * 00623 * @implemented 00624 */ 00625 BOOL 00626 WINAPI 00627 GetUserNameA(LPSTR lpszName, 00628 LPDWORD lpSize) 00629 { 00630 UNICODE_STRING NameW; 00631 ANSI_STRING NameA; 00632 BOOL Ret; 00633 00634 /* apparently Win doesn't check whether lpSize is valid at all! */ 00635 00636 NameW.MaximumLength = (*lpSize) * sizeof(WCHAR); 00637 NameW.Buffer = LocalAlloc(LMEM_FIXED, NameW.MaximumLength); 00638 if(NameW.Buffer == NULL) 00639 { 00640 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 00641 return FALSE; 00642 } 00643 00644 NameA.Length = 0; 00645 NameA.MaximumLength = ((*lpSize) < 0xFFFF ? (USHORT)(*lpSize) : 0xFFFF); 00646 NameA.Buffer = lpszName; 00647 00648 Ret = GetUserNameW(NameW.Buffer, 00649 lpSize); 00650 if(Ret) 00651 { 00652 NameW.Length = (*lpSize - 1) * sizeof(WCHAR); 00653 RtlUnicodeStringToAnsiString(&NameA, &NameW, FALSE); 00654 00655 *lpSize = NameA.Length + 1; 00656 } 00657 00658 LocalFree(NameW.Buffer); 00659 00660 return Ret; 00661 } 00662 00663 00664 /****************************************************************************** 00665 * GetUserNameW [ADVAPI32.@] 00666 * 00667 * See GetUserNameA. 00668 * 00669 * @implemented 00670 */ 00671 BOOL 00672 WINAPI 00673 GetUserNameW(LPWSTR lpszName, 00674 LPDWORD lpSize) 00675 { 00676 HANDLE hToken = INVALID_HANDLE_VALUE; 00677 DWORD tu_len = 0; 00678 char* tu_buf = NULL; 00679 TOKEN_USER* token_user = NULL; 00680 DWORD an_len = 0; 00681 SID_NAME_USE snu = SidTypeUser; 00682 WCHAR* domain_name = NULL; 00683 DWORD dn_len = 0; 00684 00685 if (!OpenThreadToken (GetCurrentThread(), TOKEN_QUERY, FALSE, &hToken)) 00686 { 00687 DWORD dwLastError = GetLastError(); 00688 if (dwLastError != ERROR_NO_TOKEN 00689 && dwLastError != ERROR_NO_IMPERSONATION_TOKEN) 00690 { 00691 /* don't call SetLastError(), 00692 as OpenThreadToken() ought to have set one */ 00693 return FALSE; 00694 } 00695 00696 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) 00697 { 00698 /* don't call SetLastError(), 00699 as OpenProcessToken() ought to have set one */ 00700 return FALSE; 00701 } 00702 } 00703 00704 tu_buf = LocalAlloc(LMEM_FIXED, 36); 00705 if (!tu_buf) 00706 { 00707 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 00708 CloseHandle(hToken); 00709 return FALSE; 00710 } 00711 00712 if (!GetTokenInformation(hToken, TokenUser, tu_buf, 36, &tu_len) || tu_len > 36) 00713 { 00714 LocalFree(tu_buf); 00715 tu_buf = LocalAlloc(LMEM_FIXED, tu_len); 00716 if (!tu_buf) 00717 { 00718 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 00719 CloseHandle(hToken); 00720 return FALSE; 00721 } 00722 00723 if (!GetTokenInformation(hToken, TokenUser, tu_buf, tu_len, &tu_len)) 00724 { 00725 /* don't call SetLastError(), 00726 as GetTokenInformation() ought to have set one */ 00727 LocalFree(tu_buf); 00728 CloseHandle(hToken); 00729 return FALSE; 00730 } 00731 } 00732 00733 CloseHandle(hToken); 00734 token_user = (TOKEN_USER*)tu_buf; 00735 00736 an_len = *lpSize; 00737 dn_len = 32; 00738 domain_name = LocalAlloc(LMEM_FIXED, dn_len * sizeof(WCHAR)); 00739 if (!domain_name) 00740 { 00741 LocalFree(tu_buf); 00742 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 00743 return FALSE; 00744 } 00745 00746 if (!LookupAccountSidW(NULL, token_user->User.Sid, lpszName, &an_len, domain_name, &dn_len, &snu) 00747 || dn_len > 32) 00748 { 00749 if (dn_len > 32) 00750 { 00751 LocalFree(domain_name); 00752 domain_name = LocalAlloc(LMEM_FIXED, dn_len * sizeof(WCHAR)); 00753 if (!domain_name) 00754 { 00755 LocalFree(tu_buf); 00756 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 00757 return FALSE; 00758 } 00759 } 00760 00761 an_len = *lpSize; 00762 if (!LookupAccountSidW(NULL, token_user->User.Sid, lpszName, &an_len, domain_name, &dn_len, &snu)) 00763 { 00764 /* don't call SetLastError(), 00765 as LookupAccountSid() ought to have set one */ 00766 LocalFree(domain_name); 00767 LocalFree(tu_buf); 00768 *lpSize = an_len; 00769 return FALSE; 00770 } 00771 } 00772 00773 LocalFree(domain_name); 00774 LocalFree(tu_buf); 00775 *lpSize = an_len + 1; 00776 return TRUE; 00777 } 00778 00779 00780 /****************************************************************************** 00781 * LookupAccountSidA [ADVAPI32.@] 00782 * 00783 * @implemented 00784 */ 00785 BOOL 00786 WINAPI 00787 LookupAccountSidA(LPCSTR lpSystemName, 00788 PSID lpSid, 00789 LPSTR lpName, 00790 LPDWORD cchName, 00791 LPSTR lpReferencedDomainName, 00792 LPDWORD cchReferencedDomainName, 00793 PSID_NAME_USE peUse) 00794 { 00795 UNICODE_STRING NameW, ReferencedDomainNameW, SystemNameW; 00796 LPWSTR NameBuffer = NULL; 00797 LPWSTR ReferencedDomainNameBuffer = NULL; 00798 DWORD dwName, dwReferencedDomainName; 00799 BOOL Ret; 00800 00801 /* 00802 * save the buffer sizes the caller passed to us, as they may get modified and 00803 * we require the original values when converting back to ansi 00804 */ 00805 dwName = *cchName; 00806 dwReferencedDomainName = *cchReferencedDomainName; 00807 00808 /* allocate buffers for the unicode strings to receive */ 00809 if (dwName > 0) 00810 { 00811 NameBuffer = LocalAlloc(LMEM_FIXED, dwName * sizeof(WCHAR)); 00812 if (NameBuffer == NULL) 00813 { 00814 SetLastError(ERROR_OUTOFMEMORY); 00815 return FALSE; 00816 } 00817 } 00818 else 00819 NameBuffer = NULL; 00820 00821 if (dwReferencedDomainName > 0) 00822 { 00823 ReferencedDomainNameBuffer = LocalAlloc(LMEM_FIXED, dwReferencedDomainName * sizeof(WCHAR)); 00824 if (ReferencedDomainNameBuffer == NULL) 00825 { 00826 if (dwName > 0) 00827 { 00828 LocalFree(NameBuffer); 00829 } 00830 00831 SetLastError(ERROR_OUTOFMEMORY); 00832 return FALSE; 00833 } 00834 } 00835 else 00836 ReferencedDomainNameBuffer = NULL; 00837 00838 00839 /* convert the system name to unicode - if present */ 00840 if (lpSystemName != NULL) 00841 { 00842 ANSI_STRING SystemNameA; 00843 00844 RtlInitAnsiString(&SystemNameA, lpSystemName); 00845 RtlAnsiStringToUnicodeString(&SystemNameW, &SystemNameA, TRUE); 00846 } 00847 else 00848 SystemNameW.Buffer = NULL; 00849 00850 /* it's time to call the unicode version */ 00851 Ret = LookupAccountSidW(SystemNameW.Buffer, 00852 lpSid, 00853 NameBuffer, 00854 cchName, 00855 ReferencedDomainNameBuffer, 00856 cchReferencedDomainName, 00857 peUse); 00858 if (Ret) 00859 { 00860 /* 00861 * convert unicode strings back to ansi, don't forget that we can't convert 00862 * more than 0xFFFF (USHORT) characters! Also don't forget to explicitly 00863 * terminate the converted string, the Rtl functions don't do that! 00864 */ 00865 if (lpName != NULL) 00866 { 00867 ANSI_STRING NameA; 00868 00869 NameA.Length = 0; 00870 NameA.MaximumLength = ((dwName <= 0xFFFF) ? (USHORT)dwName : 0xFFFF); 00871 NameA.Buffer = lpName; 00872 00873 RtlInitUnicodeString(&NameW, NameBuffer); 00874 RtlUnicodeStringToAnsiString(&NameA, &NameW, FALSE); 00875 NameA.Buffer[NameA.Length] = '\0'; 00876 } 00877 00878 if (lpReferencedDomainName != NULL) 00879 { 00880 ANSI_STRING ReferencedDomainNameA; 00881 00882 ReferencedDomainNameA.Length = 0; 00883 ReferencedDomainNameA.MaximumLength = ((dwReferencedDomainName <= 0xFFFF) ? 00884 (USHORT)dwReferencedDomainName : 0xFFFF); 00885 ReferencedDomainNameA.Buffer = lpReferencedDomainName; 00886 00887 RtlInitUnicodeString(&ReferencedDomainNameW, ReferencedDomainNameBuffer); 00888 RtlUnicodeStringToAnsiString(&ReferencedDomainNameA, &ReferencedDomainNameW, FALSE); 00889 ReferencedDomainNameA.Buffer[ReferencedDomainNameA.Length] = '\0'; 00890 } 00891 } 00892 00893 /* free previously allocated buffers */ 00894 if (SystemNameW.Buffer != NULL) 00895 { 00896 RtlFreeUnicodeString(&SystemNameW); 00897 } 00898 00899 if (NameBuffer != NULL) 00900 { 00901 LocalFree(NameBuffer); 00902 } 00903 00904 if (ReferencedDomainNameBuffer != NULL) 00905 { 00906 LocalFree(ReferencedDomainNameBuffer); 00907 } 00908 00909 return Ret; 00910 } 00911 00912 00913 /****************************************************************************** 00914 * LookupAccountSidW [ADVAPI32.@] 00915 * 00916 * @implemented 00917 */ 00918 BOOL WINAPI 00919 LookupAccountSidW(LPCWSTR pSystemName, 00920 PSID pSid, 00921 LPWSTR pAccountName, 00922 LPDWORD pdwAccountName, 00923 LPWSTR pDomainName, 00924 LPDWORD pdwDomainName, 00925 PSID_NAME_USE peUse) 00926 { 00927 LSA_UNICODE_STRING SystemName; 00928 LSA_OBJECT_ATTRIBUTES ObjectAttributes = {0}; 00929 LSA_HANDLE PolicyHandle = NULL; 00930 NTSTATUS Status; 00931 PLSA_REFERENCED_DOMAIN_LIST ReferencedDomain = NULL; 00932 PLSA_TRANSLATED_NAME TranslatedName = NULL; 00933 BOOL ret; 00934 DWORD dwAccountName, dwDomainName; 00935 00936 RtlInitUnicodeString(&SystemName, pSystemName); 00937 Status = LsaOpenPolicy(&SystemName, &ObjectAttributes, POLICY_LOOKUP_NAMES, &PolicyHandle); 00938 if (!NT_SUCCESS(Status)) 00939 { 00940 SetLastError(LsaNtStatusToWinError(Status)); 00941 return FALSE; 00942 } 00943 00944 Status = LsaLookupSids(PolicyHandle, 1, &pSid, &ReferencedDomain, &TranslatedName); 00945 00946 LsaClose(PolicyHandle); 00947 00948 if (!NT_SUCCESS(Status) || Status == STATUS_SOME_NOT_MAPPED) 00949 { 00950 SetLastError(LsaNtStatusToWinError(Status)); 00951 ret = FALSE; 00952 } 00953 else 00954 { 00955 ret = TRUE; 00956 00957 dwAccountName = TranslatedName->Name.Length / sizeof(WCHAR); 00958 if (ReferencedDomain && ReferencedDomain->Entries > 0) 00959 dwDomainName = ReferencedDomain->Domains[0].Name.Length / sizeof(WCHAR); 00960 else 00961 dwDomainName = 0; 00962 00963 if (*pdwAccountName <= dwAccountName || *pdwDomainName <= dwDomainName) 00964 { 00965 /* One or two buffers are insufficient, add up a char for NULL termination */ 00966 *pdwAccountName = dwAccountName + 1; 00967 *pdwDomainName = dwDomainName + 1; 00968 ret = FALSE; 00969 } 00970 else 00971 { 00972 /* Lengths are sufficient, copy the data */ 00973 if (dwAccountName) 00974 RtlCopyMemory(pAccountName, TranslatedName->Name.Buffer, dwAccountName * sizeof(WCHAR)); 00975 pAccountName[dwAccountName] = L'\0'; 00976 00977 if (dwDomainName) 00978 RtlCopyMemory(pDomainName, ReferencedDomain->Domains[0].Name.Buffer, dwDomainName * sizeof(WCHAR)); 00979 pDomainName[dwDomainName] = L'\0'; 00980 00981 *pdwAccountName = dwAccountName; 00982 *pdwDomainName = dwDomainName; 00983 00984 if (peUse) 00985 *peUse = TranslatedName->Use; 00986 } 00987 00988 if (!ret) 00989 SetLastError(ERROR_INSUFFICIENT_BUFFER); 00990 } 00991 00992 if (ReferencedDomain) 00993 LsaFreeMemory(ReferencedDomain); 00994 00995 if (TranslatedName) 00996 LsaFreeMemory(TranslatedName); 00997 00998 return ret; 00999 } 01000 01001 01002 /****************************************************************************** 01003 * LookupAccountNameA [ADVAPI32.@] 01004 * 01005 * @implemented 01006 */ 01007 BOOL 01008 WINAPI 01009 LookupAccountNameA(LPCSTR SystemName, 01010 LPCSTR AccountName, 01011 PSID Sid, 01012 LPDWORD SidLength, 01013 LPSTR ReferencedDomainName, 01014 LPDWORD hReferencedDomainNameLength, 01015 PSID_NAME_USE SidNameUse) 01016 { 01017 BOOL ret; 01018 UNICODE_STRING lpSystemW; 01019 UNICODE_STRING lpAccountW; 01020 LPWSTR lpReferencedDomainNameW = NULL; 01021 01022 RtlCreateUnicodeStringFromAsciiz(&lpSystemW, SystemName); 01023 RtlCreateUnicodeStringFromAsciiz(&lpAccountW, AccountName); 01024 01025 if (ReferencedDomainName) 01026 lpReferencedDomainNameW = HeapAlloc(GetProcessHeap(), 01027 0, 01028 *hReferencedDomainNameLength * sizeof(WCHAR)); 01029 01030 ret = LookupAccountNameW(lpSystemW.Buffer, 01031 lpAccountW.Buffer, 01032 Sid, 01033 SidLength, 01034 lpReferencedDomainNameW, 01035 hReferencedDomainNameLength, 01036 SidNameUse); 01037 01038 if (ret && lpReferencedDomainNameW) 01039 { 01040 WideCharToMultiByte(CP_ACP, 01041 0, 01042 lpReferencedDomainNameW, 01043 *hReferencedDomainNameLength + 1, 01044 ReferencedDomainName, 01045 *hReferencedDomainNameLength + 1, 01046 NULL, 01047 NULL); 01048 } 01049 01050 RtlFreeUnicodeString(&lpSystemW); 01051 RtlFreeUnicodeString(&lpAccountW); 01052 HeapFree(GetProcessHeap(), 0, lpReferencedDomainNameW); 01053 01054 return ret; 01055 } 01056 01057 01058 /****************************************************************************** 01059 * LookupAccountNameW [ADVAPI32.@] 01060 * 01061 * @implemented 01062 */ 01063 BOOL 01064 WINAPI 01065 LookupAccountNameW(LPCWSTR lpSystemName, 01066 LPCWSTR lpAccountName, 01067 PSID Sid, 01068 LPDWORD cbSid, 01069 LPWSTR ReferencedDomainName, 01070 LPDWORD cchReferencedDomainName, 01071 PSID_NAME_USE peUse) 01072 { 01073 OBJECT_ATTRIBUTES ObjectAttributes = {0}; 01074 UNICODE_STRING SystemName; 01075 UNICODE_STRING AccountName; 01076 LSA_HANDLE PolicyHandle = NULL; 01077 PLSA_REFERENCED_DOMAIN_LIST ReferencedDomains = NULL; 01078 PLSA_TRANSLATED_SID TranslatedSid = NULL; 01079 PSID pDomainSid; 01080 DWORD dwDomainNameLength; 01081 DWORD dwSidLength; 01082 UCHAR nSubAuthorities; 01083 BOOL bResult; 01084 NTSTATUS Status; 01085 01086 TRACE("%s %s %p %p %p %p %p\n", lpSystemName, lpAccountName, 01087 Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse); 01088 01089 RtlInitUnicodeString(&SystemName, 01090 lpSystemName); 01091 01092 Status = LsaOpenPolicy(lpSystemName ? &SystemName : NULL, 01093 &ObjectAttributes, 01094 POLICY_LOOKUP_NAMES, 01095 &PolicyHandle); 01096 if (!NT_SUCCESS(Status)) 01097 { 01098 SetLastError(LsaNtStatusToWinError(Status)); 01099 return FALSE; 01100 } 01101 01102 RtlInitUnicodeString(&AccountName, 01103 lpAccountName); 01104 01105 Status = LsaLookupNames(PolicyHandle, 01106 1, 01107 &AccountName, 01108 &ReferencedDomains, 01109 &TranslatedSid); 01110 01111 LsaClose(PolicyHandle); 01112 01113 if (!NT_SUCCESS(Status) || Status == STATUS_SOME_NOT_MAPPED) 01114 { 01115 SetLastError(LsaNtStatusToWinError(Status)); 01116 bResult = FALSE; 01117 } 01118 else 01119 { 01120 pDomainSid = ReferencedDomains->Domains[TranslatedSid->DomainIndex].Sid; 01121 nSubAuthorities = *GetSidSubAuthorityCount(pDomainSid); 01122 dwSidLength = GetSidLengthRequired(nSubAuthorities + 1); 01123 01124 dwDomainNameLength = ReferencedDomains->Domains->Name.Length / sizeof(WCHAR); 01125 01126 if (*cbSid < dwSidLength || 01127 *cchReferencedDomainName < dwDomainNameLength + 1) 01128 { 01129 *cbSid = dwSidLength; 01130 *cchReferencedDomainName = dwDomainNameLength + 1; 01131 01132 bResult = FALSE; 01133 } 01134 else 01135 { 01136 CopySid(*cbSid, Sid, pDomainSid); 01137 *GetSidSubAuthorityCount(Sid) = nSubAuthorities + 1; 01138 *GetSidSubAuthority(Sid, (DWORD)nSubAuthorities) = TranslatedSid->RelativeId; 01139 01140 RtlCopyMemory(ReferencedDomainName, ReferencedDomains->Domains->Name.Buffer, dwDomainNameLength * sizeof(WCHAR)); 01141 ReferencedDomainName[dwDomainNameLength] = L'\0'; 01142 01143 *cchReferencedDomainName = dwDomainNameLength; 01144 01145 *peUse = TranslatedSid->Use; 01146 01147 bResult = TRUE; 01148 } 01149 01150 if (bResult == FALSE) 01151 SetLastError(ERROR_INSUFFICIENT_BUFFER); 01152 } 01153 01154 if (ReferencedDomains != NULL) 01155 LsaFreeMemory(ReferencedDomains); 01156 01157 if (TranslatedSid != NULL) 01158 LsaFreeMemory(TranslatedSid); 01159 01160 return bResult; 01161 } 01162 01163 01164 /********************************************************************** 01165 * LookupPrivilegeValueA EXPORTED 01166 * 01167 * @implemented 01168 */ 01169 BOOL 01170 WINAPI 01171 LookupPrivilegeValueA(LPCSTR lpSystemName, 01172 LPCSTR lpName, 01173 PLUID lpLuid) 01174 { 01175 UNICODE_STRING SystemName; 01176 UNICODE_STRING Name; 01177 BOOL Result; 01178 01179 /* Remote system? */ 01180 if (lpSystemName != NULL) 01181 { 01182 RtlCreateUnicodeStringFromAsciiz(&SystemName, 01183 (LPSTR)lpSystemName); 01184 } 01185 else 01186 SystemName.Buffer = NULL; 01187 01188 /* Check the privilege name is not NULL */ 01189 if (lpName == NULL) 01190 { 01191 SetLastError(ERROR_NO_SUCH_PRIVILEGE); 01192 return FALSE; 01193 } 01194 01195 RtlCreateUnicodeStringFromAsciiz(&Name, 01196 (LPSTR)lpName); 01197 01198 Result = LookupPrivilegeValueW(SystemName.Buffer, 01199 Name.Buffer, 01200 lpLuid); 01201 01202 RtlFreeUnicodeString(&Name); 01203 01204 /* Remote system? */ 01205 if (SystemName.Buffer != NULL) 01206 { 01207 RtlFreeUnicodeString(&SystemName); 01208 } 01209 01210 return Result; 01211 } 01212 01213 01214 /********************************************************************** 01215 * LookupPrivilegeValueW 01216 * 01217 * @implemented 01218 */ 01219 BOOL 01220 WINAPI 01221 LookupPrivilegeValueW(LPCWSTR lpSystemName, 01222 LPCWSTR lpPrivilegeName, 01223 PLUID lpLuid) 01224 { 01225 OBJECT_ATTRIBUTES ObjectAttributes = {0}; 01226 UNICODE_STRING SystemName; 01227 UNICODE_STRING PrivilegeName; 01228 LSA_HANDLE PolicyHandle = NULL; 01229 NTSTATUS Status; 01230 01231 TRACE("%S,%S,%p\n", lpSystemName, lpPrivilegeName, lpLuid); 01232 01233 RtlInitUnicodeString(&SystemName, 01234 lpSystemName); 01235 01236 Status = LsaOpenPolicy(lpSystemName ? &SystemName : NULL, 01237 &ObjectAttributes, 01238 POLICY_LOOKUP_NAMES, 01239 &PolicyHandle); 01240 if (!NT_SUCCESS(Status)) 01241 { 01242 SetLastError(LsaNtStatusToWinError(Status)); 01243 return FALSE; 01244 } 01245 01246 RtlInitUnicodeString(&PrivilegeName, 01247 lpPrivilegeName); 01248 01249 Status = LsaLookupPrivilegeValue(PolicyHandle, 01250 &PrivilegeName, 01251 lpLuid); 01252 01253 LsaClose(PolicyHandle); 01254 01255 if (!NT_SUCCESS(Status)) 01256 { 01257 SetLastError(LsaNtStatusToWinError(Status)); 01258 return FALSE; 01259 } 01260 01261 return TRUE; 01262 } 01263 01264 01265 /********************************************************************** 01266 * LookupPrivilegeDisplayNameA EXPORTED 01267 * 01268 * @unimplemented 01269 */ 01270 BOOL 01271 WINAPI 01272 LookupPrivilegeDisplayNameA(LPCSTR lpSystemName, 01273 LPCSTR lpName, 01274 LPSTR lpDisplayName, 01275 LPDWORD cbDisplayName, 01276 LPDWORD lpLanguageId) 01277 { 01278 FIXME("%s() not implemented!\n", __FUNCTION__); 01279 SetLastError (ERROR_CALL_NOT_IMPLEMENTED); 01280 return FALSE; 01281 } 01282 01283 01284 /********************************************************************** 01285 * LookupPrivilegeDisplayNameW EXPORTED 01286 * 01287 * @unimplemented 01288 */ 01289 BOOL 01290 WINAPI 01291 LookupPrivilegeDisplayNameW(LPCWSTR lpSystemName, 01292 LPCWSTR lpName, 01293 LPWSTR lpDisplayName, 01294 LPDWORD cbDisplayName, 01295 LPDWORD lpLanguageId) 01296 { 01297 FIXME("%s() not implemented!\n", __FUNCTION__); 01298 SetLastError (ERROR_CALL_NOT_IMPLEMENTED); 01299 return FALSE; 01300 } 01301 01302 01303 /********************************************************************** 01304 * LookupPrivilegeNameA EXPORTED 01305 * 01306 * @implemented 01307 */ 01308 BOOL 01309 WINAPI 01310 LookupPrivilegeNameA(LPCSTR lpSystemName, 01311 PLUID lpLuid, 01312 LPSTR lpName, 01313 LPDWORD cchName) 01314 { 01315 UNICODE_STRING lpSystemNameW; 01316 BOOL ret; 01317 DWORD wLen = 0; 01318 01319 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName); 01320 01321 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName); 01322 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, NULL, &wLen); 01323 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER) 01324 { 01325 LPWSTR lpNameW = HeapAlloc(GetProcessHeap(), 0, wLen * sizeof(WCHAR)); 01326 01327 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, lpNameW, 01328 &wLen); 01329 if (ret) 01330 { 01331 /* Windows crashes if cchName is NULL, so will I */ 01332 unsigned int len = WideCharToMultiByte(CP_ACP, 0, lpNameW, -1, lpName, 01333 *cchName, NULL, NULL); 01334 01335 if (len == 0) 01336 { 01337 /* WideCharToMultiByte failed */ 01338 ret = FALSE; 01339 } 01340 else if (len > *cchName) 01341 { 01342 *cchName = len; 01343 SetLastError(ERROR_INSUFFICIENT_BUFFER); 01344 ret = FALSE; 01345 } 01346 else 01347 { 01348 /* WideCharToMultiByte succeeded, output length needs to be 01349 * length not including NULL terminator 01350 */ 01351 *cchName = len - 1; 01352 } 01353 } 01354 HeapFree(GetProcessHeap(), 0, lpNameW); 01355 } 01356 RtlFreeUnicodeString(&lpSystemNameW); 01357 return ret; 01358 } 01359 01360 01361 /********************************************************************** 01362 * LookupPrivilegeNameW EXPORTED 01363 * 01364 * @implemented 01365 */ 01366 BOOL 01367 WINAPI 01368 LookupPrivilegeNameW(LPCWSTR lpSystemName, 01369 PLUID lpLuid, 01370 LPWSTR lpName, 01371 LPDWORD cchName) 01372 { 01373 OBJECT_ATTRIBUTES ObjectAttributes = {0}; 01374 UNICODE_STRING SystemName; 01375 PUNICODE_STRING PrivilegeName = NULL; 01376 LSA_HANDLE PolicyHandle = NULL; 01377 NTSTATUS Status; 01378 01379 TRACE("%S,%p,%p,%p\n", lpSystemName, lpLuid, lpName, cchName); 01380 01381 RtlInitUnicodeString(&SystemName, 01382 lpSystemName); 01383 01384 Status = LsaOpenPolicy(lpSystemName ? &SystemName : NULL, 01385 &ObjectAttributes, 01386 POLICY_LOOKUP_NAMES, 01387 &PolicyHandle); 01388 if (!NT_SUCCESS(Status)) 01389 { 01390 SetLastError(LsaNtStatusToWinError(Status)); 01391 return FALSE; 01392 } 01393 01394 Status = LsaLookupPrivilegeName(PolicyHandle, 01395 lpLuid, 01396 &PrivilegeName); 01397 if (NT_SUCCESS(Status)) 01398 { 01399 if (PrivilegeName->Length + sizeof(WCHAR) > *cchName * sizeof(WCHAR)) 01400 { 01401 Status = STATUS_BUFFER_TOO_SMALL; 01402 01403 *cchName = (PrivilegeName->Length + sizeof(WCHAR)) / sizeof(WCHAR); 01404 } 01405 else 01406 { 01407 RtlMoveMemory(lpName, 01408 PrivilegeName->Buffer, 01409 PrivilegeName->Length); 01410 lpName[PrivilegeName->Length / sizeof(WCHAR)] = 0; 01411 01412 *cchName = PrivilegeName->Length / sizeof(WCHAR); 01413 } 01414 01415 LsaFreeMemory(PrivilegeName->Buffer); 01416 LsaFreeMemory(PrivilegeName); 01417 } 01418 01419 LsaClose(PolicyHandle); 01420 01421 if (!NT_SUCCESS(Status)) 01422 { 01423 SetLastError(LsaNtStatusToWinError(Status)); 01424 return FALSE; 01425 } 01426 01427 return TRUE; 01428 } 01429 01430 01431 static DWORD 01432 pGetSecurityInfoCheck(SECURITY_INFORMATION SecurityInfo, 01433 PSID *ppsidOwner, 01434 PSID *ppsidGroup, 01435 PACL *ppDacl, 01436 PACL *ppSacl, 01437 PSECURITY_DESCRIPTOR* ppSecurityDescriptor) 01438 { 01439 if ((SecurityInfo & (OWNER_SECURITY_INFORMATION | 01440 GROUP_SECURITY_INFORMATION | 01441 DACL_SECURITY_INFORMATION | 01442 SACL_SECURITY_INFORMATION)) && 01443 ppSecurityDescriptor == NULL) 01444 { 01445 /* if one of the SIDs or ACLs are present, the security descriptor 01446 most not be NULL */ 01447 return ERROR_INVALID_PARAMETER; 01448 } 01449 else 01450 { 01451 /* reset the pointers unless they're ignored */ 01452 if ((SecurityInfo & OWNER_SECURITY_INFORMATION) && 01453 ppsidOwner != NULL) 01454 { 01455 *ppsidOwner = NULL; 01456 } 01457 if ((SecurityInfo & GROUP_SECURITY_INFORMATION) && 01458 ppsidGroup != NULL) 01459 { 01460 *ppsidGroup = NULL; 01461 } 01462 if ((SecurityInfo & DACL_SECURITY_INFORMATION) && 01463 ppDacl != NULL) 01464 { 01465 *ppDacl = NULL; 01466 } 01467 if ((SecurityInfo & SACL_SECURITY_INFORMATION) && 01468 ppSacl != NULL) 01469 { 01470 *ppSacl = NULL; 01471 } 01472 01473 if (SecurityInfo & (OWNER_SECURITY_INFORMATION | 01474 GROUP_SECURITY_INFORMATION | 01475 DACL_SECURITY_INFORMATION | 01476 SACL_SECURITY_INFORMATION)) 01477 { 01478 *ppSecurityDescriptor = NULL; 01479 } 01480 01481 return ERROR_SUCCESS; 01482 } 01483 } 01484 01485 01486 static DWORD 01487 pSetSecurityInfoCheck(PSECURITY_DESCRIPTOR pSecurityDescriptor, 01488 SECURITY_INFORMATION SecurityInfo, 01489 PSID psidOwner, 01490 PSID psidGroup, 01491 PACL pDacl, 01492 PACL pSacl) 01493 { 01494 /* initialize a security descriptor on the stack */ 01495 if (!InitializeSecurityDescriptor(pSecurityDescriptor, 01496 SECURITY_DESCRIPTOR_REVISION)) 01497 { 01498 return GetLastError(); 01499 } 01500 01501 if (SecurityInfo & OWNER_SECURITY_INFORMATION) 01502 { 01503 if (RtlValidSid(psidOwner)) 01504 { 01505 if (!SetSecurityDescriptorOwner(pSecurityDescriptor, 01506 psidOwner, 01507 FALSE)) 01508 { 01509 return GetLastError(); 01510 } 01511 } 01512 else 01513 { 01514 return ERROR_INVALID_PARAMETER; 01515 } 01516 } 01517 01518 if (SecurityInfo & GROUP_SECURITY_INFORMATION) 01519 { 01520 if (RtlValidSid(psidGroup)) 01521 { 01522 if (!SetSecurityDescriptorGroup(pSecurityDescriptor, 01523 psidGroup, 01524 FALSE)) 01525 { 01526 return GetLastError(); 01527 } 01528 } 01529 else 01530 { 01531 return ERROR_INVALID_PARAMETER; 01532 } 01533 } 01534 01535 if (SecurityInfo & DACL_SECURITY_INFORMATION) 01536 { 01537 if (pDacl != NULL) 01538 { 01539 if (SetSecurityDescriptorDacl(pSecurityDescriptor, 01540 TRUE, 01541 pDacl, 01542 FALSE)) 01543 { 01544 /* check if the DACL needs to be protected from being 01545 modified by inheritable ACEs */ 01546 if (SecurityInfo & PROTECTED_DACL_SECURITY_INFORMATION) 01547 { 01548 goto ProtectDacl; 01549 } 01550 } 01551 else 01552 { 01553 return GetLastError(); 01554 } 01555 } 01556 else 01557 { 01558 ProtectDacl: 01559 /* protect the DACL from being modified by inheritable ACEs */ 01560 if (!SetSecurityDescriptorControl(pSecurityDescriptor, 01561 SE_DACL_PROTECTED, 01562 SE_DACL_PROTECTED)) 01563 { 01564 return GetLastError(); 01565 } 01566 } 01567 } 01568 01569 if (SecurityInfo & SACL_SECURITY_INFORMATION) 01570 { 01571 if (pSacl != NULL) 01572 { 01573 if (SetSecurityDescriptorSacl(pSecurityDescriptor, 01574 TRUE, 01575 pSacl, 01576 FALSE)) 01577 { 01578 /* check if the SACL needs to be protected from being 01579 modified by inheritable ACEs */ 01580 if (SecurityInfo & PROTECTED_SACL_SECURITY_INFORMATION) 01581 { 01582 goto ProtectSacl; 01583 } 01584 } 01585 else 01586 { 01587 return GetLastError(); 01588 } 01589 } 01590 else 01591 { 01592 ProtectSacl: 01593 /* protect the SACL from being modified by inheritable ACEs */ 01594 if (!SetSecurityDescriptorControl(pSecurityDescriptor, 01595 SE_SACL_PROTECTED, 01596 SE_SACL_PROTECTED)) 01597 { 01598 return GetLastError(); 01599 } 01600 } 01601 } 01602 01603 return ERROR_SUCCESS; 01604 } 01605 01606 01607 /********************************************************************** 01608 * GetNamedSecurityInfoW EXPORTED 01609 * 01610 * @implemented 01611 */ 01612 DWORD 01613 WINAPI 01614 GetNamedSecurityInfoW(LPWSTR pObjectName, 01615 SE_OBJECT_TYPE ObjectType, 01616 SECURITY_INFORMATION SecurityInfo, 01617 PSID *ppsidOwner, 01618 PSID *ppsidGroup, 01619 PACL *ppDacl, 01620 PACL *ppSacl, 01621 PSECURITY_DESCRIPTOR *ppSecurityDescriptor) 01622 { 01623 DWORD ErrorCode; 01624 01625 if (pObjectName != NULL) 01626 { 01627 ErrorCode = CheckNtMartaPresent(); 01628 if (ErrorCode == ERROR_SUCCESS) 01629 { 01630 ErrorCode = pGetSecurityInfoCheck(SecurityInfo, 01631 ppsidOwner, 01632 ppsidGroup, 01633 ppDacl, 01634 ppSacl, 01635 ppSecurityDescriptor); 01636 01637 if (ErrorCode == ERROR_SUCCESS) 01638 { 01639 /* call the MARTA provider */ 01640 ErrorCode = AccRewriteGetNamedRights(pObjectName, 01641 ObjectType, 01642 SecurityInfo, 01643 ppsidOwner, 01644 ppsidGroup, 01645 ppDacl, 01646 ppSacl, 01647 ppSecurityDescriptor); 01648 } 01649 } 01650 } 01651 else 01652 ErrorCode = ERROR_INVALID_PARAMETER; 01653 01654 return ErrorCode; 01655 } 01656 01657 01658 /********************************************************************** 01659 * GetNamedSecurityInfoA EXPORTED 01660 * 01661 * @implemented 01662 */ 01663 DWORD 01664 WINAPI 01665 GetNamedSecurityInfoA(LPSTR pObjectName, 01666 SE_OBJECT_TYPE ObjectType, 01667 SECURITY_INFORMATION SecurityInfo, 01668 PSID *ppsidOwner, 01669 PSID *ppsidGroup, 01670 PACL *ppDacl, 01671 PACL *ppSacl, 01672 PSECURITY_DESCRIPTOR *ppSecurityDescriptor) 01673 { 01674 DWORD len; 01675 LPWSTR wstr = NULL; 01676 DWORD r; 01677 01678 TRACE("%s %d %d %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo, 01679 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor); 01680 01681 if( pObjectName ) 01682 { 01683 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 ); 01684 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR)); 01685 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len ); 01686 } 01687 01688 r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner, 01689 ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor ); 01690 01691 HeapFree( GetProcessHeap(), 0, wstr ); 01692 01693 return r; 01694 } 01695 01696 01697 /********************************************************************** 01698 * SetNamedSecurityInfoW EXPORTED 01699 * 01700 * @implemented 01701 */ 01702 DWORD 01703 WINAPI 01704 SetNamedSecurityInfoW(LPWSTR pObjectName, 01705 SE_OBJECT_TYPE ObjectType, 01706 SECURITY_INFORMATION SecurityInfo, 01707 PSID psidOwner, 01708 PSID psidGroup, 01709 PACL pDacl, 01710 PACL pSacl) 01711 { 01712 DWORD ErrorCode; 01713 01714 if (pObjectName != NULL) 01715 { 01716 ErrorCode = CheckNtMartaPresent(); 01717 if (ErrorCode == ERROR_SUCCESS) 01718 { 01719 SECURITY_DESCRIPTOR SecurityDescriptor; 01720 01721 ErrorCode = pSetSecurityInfoCheck(&SecurityDescriptor, 01722 SecurityInfo, 01723 psidOwner, 01724 psidGroup, 01725 pDacl, 01726 pSacl); 01727 01728 if (ErrorCode == ERROR_SUCCESS) 01729 { 01730 /* call the MARTA provider */ 01731 ErrorCode = AccRewriteSetNamedRights(pObjectName, 01732 ObjectType, 01733 SecurityInfo, 01734 &SecurityDescriptor); 01735 } 01736 } 01737 } 01738 else 01739 ErrorCode = ERROR_INVALID_PARAMETER; 01740 01741 return ErrorCode; 01742 } 01743 01744 01745 /********************************************************************** 01746 * SetNamedSecurityInfoA EXPORTED 01747 * 01748 * @implemented 01749 */ 01750 DWORD 01751 WINAPI 01752 SetNamedSecurityInfoA(LPSTR pObjectName, 01753 SE_OBJECT_TYPE ObjectType, 01754 SECURITY_INFORMATION SecurityInfo, 01755 PSID psidOwner, 01756 PSID psidGroup, 01757 PACL pDacl, 01758 PACL pSacl) 01759 { 01760 UNICODE_STRING ObjectName; 01761 NTSTATUS Status; 01762 DWORD Ret; 01763 01764 Status = RtlCreateUnicodeStringFromAsciiz(&ObjectName, 01765 pObjectName); 01766 if (!NT_SUCCESS(Status)) 01767 { 01768 return RtlNtStatusToDosError(Status); 01769 } 01770 01771 Ret = SetNamedSecurityInfoW(ObjectName.Buffer, 01772 ObjectType, 01773 SecurityInfo, 01774 psidOwner, 01775 psidGroup, 01776 pDacl, 01777 pSacl); 01778 01779 RtlFreeUnicodeString(&ObjectName); 01780 01781 return Ret; 01782 } 01783 01784 01785 /********************************************************************** 01786 * GetSecurityInfo EXPORTED 01787 * 01788 * @implemented 01789 */ 01790 DWORD 01791 WINAPI 01792 GetSecurityInfo(HANDLE handle, 01793 SE_OBJECT_TYPE ObjectType, 01794 SECURITY_INFORMATION SecurityInfo, 01795 PSID *ppsidOwner, 01796 PSID *ppsidGroup, 01797 PACL *ppDacl, 01798 PACL *ppSacl, 01799 PSECURITY_DESCRIPTOR *ppSecurityDescriptor) 01800 { 01801 DWORD ErrorCode; 01802 01803 if (handle != NULL) 01804 { 01805 ErrorCode = CheckNtMartaPresent(); 01806 if (ErrorCode == ERROR_SUCCESS) 01807 { 01808 ErrorCode = pGetSecurityInfoCheck(SecurityInfo, 01809 ppsidOwner, 01810 ppsidGroup, 01811 ppDacl, 01812 ppSacl, 01813 ppSecurityDescriptor); 01814 01815 if (ErrorCode == ERROR_SUCCESS) 01816 { 01817 /* call the MARTA provider */ 01818 ErrorCode = AccRewriteGetHandleRights(handle, 01819 ObjectType, 01820 SecurityInfo, 01821 ppsidOwner, 01822 ppsidGroup, 01823 ppDacl, 01824 ppSacl, 01825 ppSecurityDescriptor); 01826 } 01827 } 01828 } 01829 else 01830 ErrorCode = ERROR_INVALID_HANDLE; 01831 01832 return ErrorCode; 01833 } 01834 01835 01836 /********************************************************************** 01837 * SetSecurityInfo EXPORTED 01838 * 01839 * @implemented 01840 */ 01841 DWORD 01842 WINAPI 01843 SetSecurityInfo(HANDLE handle, 01844 SE_OBJECT_TYPE ObjectType, 01845 SECURITY_INFORMATION SecurityInfo, 01846 PSID psidOwner, 01847 PSID psidGroup, 01848 PACL pDacl, 01849 PACL pSacl) 01850 { 01851 DWORD ErrorCode; 01852 01853 if (handle != NULL) 01854 { 01855 ErrorCode = CheckNtMartaPresent(); 01856 if (ErrorCode == ERROR_SUCCESS) 01857 { 01858 SECURITY_DESCRIPTOR SecurityDescriptor; 01859 01860 ErrorCode = pSetSecurityInfoCheck(&SecurityDescriptor, 01861 SecurityInfo, 01862 psidOwner, 01863 psidGroup, 01864 pDacl, 01865 pSacl); 01866 01867 if (ErrorCode == ERROR_SUCCESS) 01868 { 01869 /* call the MARTA provider */ 01870 ErrorCode = AccRewriteSetHandleRights(handle, 01871 ObjectType, 01872 SecurityInfo, 01873 &SecurityDescriptor); 01874 } 01875 } 01876 } 01877 else 01878 ErrorCode = ERROR_INVALID_HANDLE; 01879 01880 return ErrorCode; 01881 } 01882 01883 01884 /****************************************************************************** 01885 * GetSecurityInfoExW EXPORTED 01886 */ 01887 DWORD 01888 WINAPI 01889 GetSecurityInfoExA(HANDLE hObject, 01890 SE_OBJECT_TYPE ObjectType, 01891 SECURITY_INFORMATION SecurityInfo, 01892 LPCSTR lpProvider, 01893 LPCSTR lpProperty, 01894 PACTRL_ACCESSA *ppAccessList, 01895 PACTRL_AUDITA *ppAuditList, 01896 LPSTR *lppOwner, 01897 LPSTR *lppGroup) 01898 { 01899 FIXME("%s() not implemented!\n", __FUNCTION__); 01900 return ERROR_BAD_PROVIDER; 01901 } 01902 01903 01904 /****************************************************************************** 01905 * GetSecurityInfoExW EXPORTED 01906 */ 01907 DWORD 01908 WINAPI 01909 GetSecurityInfoExW(HANDLE hObject, 01910 SE_OBJECT_TYPE ObjectType, 01911 SECURITY_INFORMATION SecurityInfo, 01912 LPCWSTR lpProvider, 01913 LPCWSTR lpProperty, 01914 PACTRL_ACCESSW *ppAccessList, 01915 PACTRL_AUDITW *ppAuditList, 01916 LPWSTR *lppOwner, 01917 LPWSTR *lppGroup) 01918 { 01919 FIXME("%s() not implemented!\n", __FUNCTION__); 01920 return ERROR_BAD_PROVIDER; 01921 } 01922 01923 01924 /********************************************************************** 01925 * ImpersonateNamedPipeClient EXPORTED 01926 * 01927 * @implemented 01928 */ 01929 BOOL 01930 WINAPI 01931 ImpersonateNamedPipeClient(HANDLE hNamedPipe) 01932 { 01933 IO_STATUS_BLOCK StatusBlock; 01934 NTSTATUS Status; 01935 01936 TRACE("ImpersonateNamedPipeClient() called\n"); 01937 01938 Status = NtFsControlFile(hNamedPipe, 01939 NULL, 01940 NULL, 01941 NULL, 01942 &StatusBlock, 01943 FSCTL_PIPE_IMPERSONATE, 01944 NULL, 01945 0, 01946 NULL, 01947 0); 01948 if (!NT_SUCCESS(Status)) 01949 { 01950 SetLastError(RtlNtStatusToDosError(Status)); 01951 return FALSE; 01952 } 01953 01954 return TRUE; 01955 } 01956 01957 01958 /* 01959 * @implemented 01960 */ 01961 BOOL 01962 WINAPI 01963 CreatePrivateObjectSecurity(PSECURITY_DESCRIPTOR ParentDescriptor, 01964 PSECURITY_DESCRIPTOR CreatorDescriptor, 01965 PSECURITY_DESCRIPTOR *NewDescriptor, 01966 BOOL IsDirectoryObject, 01967 HANDLE Token, 01968 PGENERIC_MAPPING GenericMapping) 01969 { 01970 NTSTATUS Status; 01971 01972 Status = RtlNewSecurityObject(ParentDescriptor, 01973 CreatorDescriptor, 01974 NewDescriptor, 01975 IsDirectoryObject, 01976 Token, 01977 GenericMapping); 01978 if (!NT_SUCCESS(Status)) 01979 { 01980 SetLastError(RtlNtStatusToDosError(Status)); 01981 return FALSE; 01982 } 01983 01984 return TRUE; 01985 } 01986 01987 01988 /* 01989 * @unimplemented 01990 */ 01991 BOOL 01992 WINAPI 01993 CreatePrivateObjectSecurityEx(PSECURITY_DESCRIPTOR ParentDescriptor, 01994 PSECURITY_DESCRIPTOR CreatorDescriptor, 01995 PSECURITY_DESCRIPTOR* NewDescriptor, 01996 GUID* ObjectType, 01997 BOOL IsContainerObject, 01998 ULONG AutoInheritFlags, 01999 HANDLE Token, 02000 PGENERIC_MAPPING GenericMapping) 02001 { 02002 FIXME("%s() not implemented!\n", __FUNCTION__); 02003 return FALSE; 02004 } 02005 02006 02007 /* 02008 * @unimplemented 02009 */ 02010 BOOL 02011 WINAPI 02012 CreatePrivateObjectSecurityWithMultipleInheritance(PSECURITY_DESCRIPTOR ParentDescriptor, 02013 PSECURITY_DESCRIPTOR CreatorDescriptor, 02014 PSECURITY_DESCRIPTOR* NewDescriptor, 02015 GUID** ObjectTypes, 02016 ULONG GuidCount, 02017 BOOL IsContainerObject, 02018 ULONG AutoInheritFlags, 02019 HANDLE Token, 02020 PGENERIC_MAPPING GenericMapping) 02021 { 02022 FIXME("%s() not implemented!\n", __FUNCTION__); 02023 return FALSE; 02024 } 02025 02026 02027 /* 02028 * @implemented 02029 */ 02030 BOOL 02031 WINAPI 02032 DestroyPrivateObjectSecurity(PSECURITY_DESCRIPTOR *ObjectDescriptor) 02033 { 02034 NTSTATUS Status; 02035 02036 Status = RtlDeleteSecurityObject(ObjectDescriptor); 02037 if (!NT_SUCCESS(Status)) 02038 { 02039 SetLastError(RtlNtStatusToDosError(Status)); 02040 return FALSE; 02041 } 02042 02043 return TRUE; 02044 } 02045 02046 02047 /* 02048 * @implemented 02049 */ 02050 BOOL 02051 WINAPI 02052 GetPrivateObjectSecurity(IN PSECURITY_DESCRIPTOR ObjectDescriptor, 02053 IN SECURITY_INFORMATION SecurityInformation, 02054 OUT PSECURITY_DESCRIPTOR ResultantDescriptor OPTIONAL, 02055 IN DWORD DescriptorLength, 02056 OUT PDWORD ReturnLength) 02057 { 02058 NTSTATUS Status; 02059 02060 /* Call RTL */ 02061 Status = RtlQuerySecurityObject(ObjectDescriptor, 02062 SecurityInformation, 02063 ResultantDescriptor, 02064 DescriptorLength, 02065 ReturnLength); 02066 if (!NT_SUCCESS(Status)) 02067 { 02068 /* Fail */ 02069 SetLastError(RtlNtStatusToDosError(Status)); 02070 return FALSE; 02071 } 02072 02073 /* Success */ 02074 return TRUE; 02075 } 02076 02077 02078 /* 02079 * @implemented 02080 */ 02081 BOOL 02082 WINAPI 02083 SetPrivateObjectSecurity(SECURITY_INFORMATION SecurityInformation, 02084 PSECURITY_DESCRIPTOR ModificationDescriptor, 02085 PSECURITY_DESCRIPTOR *ObjectsSecurityDescriptor, 02086 PGENERIC_MAPPING GenericMapping, 02087 HANDLE Token) 02088 { 02089 NTSTATUS Status; 02090 02091 Status = RtlSetSecurityObject(SecurityInformation, 02092 ModificationDescriptor, 02093 ObjectsSecurityDescriptor, 02094 GenericMapping, 02095 Token); 02096 if (!NT_SUCCESS(Status)) 02097 { 02098 SetLastError(RtlNtStatusToDosError(Status)); 02099 return FALSE; 02100 } 02101 02102 return TRUE; 02103 } 02104 02105 02106 /* 02107 * @implemented 02108 */ 02109 DWORD 02110 WINAPI 02111 TreeResetNamedSecurityInfoW(LPWSTR pObjectName, 02112 SE_OBJECT_TYPE ObjectType, 02113 SECURITY_INFORMATION SecurityInfo, 02114 PSID pOwner, 02115 PSID pGroup, 02116 PACL pDacl, 02117 PACL pSacl, 02118 BOOL KeepExplicit, 02119 FN_PROGRESSW fnProgress, 02120 PROG_INVOKE_SETTING ProgressInvokeSetting, 02121 PVOID Args) 02122 { 02123 DWORD ErrorCode; 02124 02125 if (pObjectName != NULL) 02126 { 02127 ErrorCode = CheckNtMartaPresent(); 02128 if (ErrorCode == ERROR_SUCCESS) 02129 { 02130 switch (ObjectType) 02131 { 02132 case SE_FILE_OBJECT: 02133 case SE_REGISTRY_KEY: 02134 { 02135 /* check the SecurityInfo flags for sanity (both, the protected 02136 and unprotected dacl/sacl flag must not be passed together) */ 02137 if (((SecurityInfo & DACL_SECURITY_INFORMATION) && 02138 (SecurityInfo & (PROTECTED_DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION)) == 02139 (PROTECTED_DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION)) 02140 02141 || 02142 02143 ((SecurityInfo & SACL_SECURITY_INFORMATION) && 02144 (SecurityInfo & (PROTECTED_SACL_SECURITY_INFORMATION | UNPROTECTED_SACL_SECURITY_INFORMATION)) == 02145 (PROTECTED_SACL_SECURITY_INFORMATION | UNPROTECTED_SACL_SECURITY_INFORMATION))) 02146 { 02147 ErrorCode = ERROR_INVALID_PARAMETER; 02148 break; 02149 } 02150 02151 /* call the MARTA provider */ 02152 ErrorCode = AccTreeResetNamedSecurityInfo(pObjectName, 02153 ObjectType, 02154 SecurityInfo, 02155 pOwner, 02156 pGroup, 02157 pDacl, 02158 pSacl, 02159 KeepExplicit, 02160 fnProgress, 02161 ProgressInvokeSetting, 02162 Args); 02163 break; 02164 } 02165 02166 default: 02167 /* object type not supported */ 02168 ErrorCode = ERROR_INVALID_PARAMETER; 02169 break; 02170 } 02171 } 02172 } 02173 else 02174 ErrorCode = ERROR_INVALID_PARAMETER; 02175 02176 return ErrorCode; 02177 } 02178 02179 #ifdef HAS_FN_PROGRESSW 02180 02181 typedef struct _INERNAL_FNPROGRESSW_DATA 02182 { 02183 FN_PROGRESSA fnProgress; 02184 PVOID Args; 02185 } INERNAL_FNPROGRESSW_DATA, *PINERNAL_FNPROGRESSW_DATA; 02186 02187 static VOID WINAPI 02188 InternalfnProgressW(LPWSTR pObjectName, 02189 DWORD Status, 02190 PPROG_INVOKE_SETTING pInvokeSetting, 02191 PVOID Args, 02192 BOOL SecuritySet) 02193 { 02194 PINERNAL_FNPROGRESSW_DATA pifnProgressData = (PINERNAL_FNPROGRESSW_DATA)Args; 02195 INT ObjectNameSize; 02196 LPSTR pObjectNameA; 02197 02198 ObjectNameSize = WideCharToMultiByte(CP_ACP, 02199 0, 02200 pObjectName, 02201 -1, 02202 NULL, 02203 0, 02204 NULL, 02205 NULL); 02206 02207 if (ObjectNameSize > 0) 02208 { 02209 pObjectNameA = RtlAllocateHeap(RtlGetProcessHeap(), 02210 0, 02211 ObjectNameSize); 02212 if (pObjectNameA != NULL) 02213 { 02214 pObjectNameA[0] = '\0'; 02215 WideCharToMultiByte(CP_ACP, 02216 0, 02217 pObjectName, 02218 -1, 02219 pObjectNameA, 02220 ObjectNameSize, 02221 NULL, 02222 NULL); 02223 02224 pifnProgressData->fnProgress((LPWSTR)pObjectNameA, /* FIXME: wrong cast!! */ 02225 Status, 02226 pInvokeSetting, 02227 pifnProgressData->Args, 02228 SecuritySet); 02229 02230 RtlFreeHeap(RtlGetProcessHeap(), 02231 0, 02232 pObjectNameA); 02233 } 02234 } 02235 } 02236 #endif 02237 02238 02239 /* 02240 * @implemented 02241 */ 02242 DWORD 02243 WINAPI 02244 TreeResetNamedSecurityInfoA(LPSTR pObjectName, 02245 SE_OBJECT_TYPE ObjectType, 02246 SECURITY_INFORMATION SecurityInfo, 02247 PSID pOwner, 02248 PSID pGroup, 02249 PACL pDacl, 02250 PACL pSacl, 02251 BOOL KeepExplicit, 02252 FN_PROGRESSA fnProgress, 02253 PROG_INVOKE_SETTING ProgressInvokeSetting, 02254 PVOID Args) 02255 { 02256 #ifndef HAS_FN_PROGRESSW 02257 /* That's all this function does, at least up to w2k3... Even MS was too 02258 lazy to implement it... */ 02259 return ERROR_CALL_NOT_IMPLEMENTED; 02260 #else 02261 INERNAL_FNPROGRESSW_DATA ifnProgressData; 02262 UNICODE_STRING ObjectName; 02263 NTSTATUS Status; 02264 DWORD Ret; 02265 02266 Status = RtlCreateUnicodeStringFromAsciiz(&ObjectName, 02267 pObjectName); 02268 if (!NT_SUCCESS(Status)) 02269 { 02270 return RtlNtStatusToDosError(Status); 02271 } 02272 02273 ifnProgressData.fnProgress = fnProgress; 02274 ifnProgressData.Args = Args; 02275 02276 Ret = TreeResetNamedSecurityInfoW(ObjectName.Buffer, 02277 ObjectType, 02278 SecurityInfo, 02279 pOwner, 02280 pGroup, 02281 pDacl, 02282 pSacl, 02283 KeepExplicit, 02284 (fnProgress != NULL ? InternalfnProgressW : NULL), 02285 ProgressInvokeSetting, 02286 &ifnProgressData); 02287 02288 RtlFreeUnicodeString(&ObjectName); 02289 02290 return Ret; 02291 #endif 02292 } 02293 02294 /****************************************************************************** 02295 * SaferCreateLevel [ADVAPI32.@] 02296 */ 02297 BOOL WINAPI SaferCreateLevel(DWORD ScopeId, DWORD LevelId, DWORD OpenFlags, 02298 SAFER_LEVEL_HANDLE* LevelHandle, LPVOID lpReserved) 02299 { 02300 FIXME("(%u, %x, %u, %p, %p) stub\n", ScopeId, LevelId, OpenFlags, LevelHandle, lpReserved); 02301 return FALSE; 02302 } 02303 02304 /****************************************************************************** 02305 * SaferGetPolicyInformation [ADVAPI32.@] 02306 */ 02307 BOOL WINAPI SaferGetPolicyInformation(DWORD scope, SAFER_POLICY_INFO_CLASS class, DWORD size, 02308 PVOID buffer, PDWORD required, LPVOID lpReserved) 02309 { 02310 FIXME("(%u %u %u %p %p %p) stub\n", scope, class, size, buffer, required, lpReserved); 02311 return FALSE; 02312 } 02313 02314 /****************************************************************************** 02315 * QueryWindows31FilesMigration [ADVAPI32.@] 02316 * 02317 * PARAMS 02318 * x1 [] 02319 */ 02320 BOOL WINAPI 02321 QueryWindows31FilesMigration( DWORD x1 ) 02322 { 02323 FIXME("(%d):stub\n",x1); 02324 return TRUE; 02325 } 02326 02327 /****************************************************************************** 02328 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@] 02329 * 02330 * PARAMS 02331 * x1 [] 02332 * x2 [] 02333 * x3 [] 02334 * x4 [] 02335 */ 02336 BOOL WINAPI 02337 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3, 02338 DWORD x4 ) 02339 { 02340 FIXME("(0x%08x,0x%08x,0x%08x,0x%08x):stub\n",x1,x2,x3,x4); 02341 return TRUE; 02342 } 02343 02344 /* EOF */ Generated on Fri May 25 2012 04:15:08 for ReactOS by
1.7.6.1
|