Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenac.c
Go to the documentation of this file.
00001 /* $Id: ac.c 53225 2011-08-14 11:31:23Z akhaldi $ 00002 * 00003 * COPYRIGHT: See COPYING in the top level directory 00004 * PROJECT: ReactOS system libraries 00005 * FILE: lib/advapi32/sec/ac.c 00006 * PURPOSE: ACL/ACE functions 00007 */ 00008 00009 #include <advapi32.h> 00010 WINE_DEFAULT_DEBUG_CHANNEL(advapi); 00011 00012 /* --- ACL --- */ 00013 00014 /* 00015 * @implemented 00016 */ 00017 BOOL 00018 WINAPI 00019 GetAclInformation(PACL pAcl, 00020 LPVOID pAclInformation, 00021 DWORD nAclInformationLength, 00022 ACL_INFORMATION_CLASS dwAclInformationClass) 00023 { 00024 NTSTATUS Status; 00025 00026 Status = RtlQueryInformationAcl(pAcl, 00027 pAclInformation, 00028 nAclInformationLength, 00029 dwAclInformationClass); 00030 if (!NT_SUCCESS(Status)) 00031 { 00032 SetLastError(RtlNtStatusToDosError(Status)); 00033 return FALSE; 00034 } 00035 00036 return TRUE; 00037 } 00038 00039 00040 /* 00041 * @implemented 00042 */ 00043 BOOL 00044 WINAPI 00045 InitializeAcl(PACL pAcl, 00046 DWORD nAclLength, 00047 DWORD dwAclRevision) 00048 { 00049 NTSTATUS Status; 00050 00051 Status = RtlCreateAcl(pAcl, 00052 nAclLength, 00053 dwAclRevision); 00054 if (!NT_SUCCESS(Status)) 00055 { 00056 SetLastError(RtlNtStatusToDosError(Status)); 00057 return FALSE; 00058 } 00059 00060 return TRUE; 00061 } 00062 00063 00064 /* 00065 * @implemented 00066 */ 00067 BOOL 00068 WINAPI 00069 IsValidAcl(PACL pAcl) 00070 { 00071 return RtlValidAcl (pAcl); 00072 } 00073 00074 00075 /* 00076 * @implemented 00077 */ 00078 BOOL 00079 WINAPI 00080 SetAclInformation(PACL pAcl, 00081 LPVOID pAclInformation, 00082 DWORD nAclInformationLength, 00083 ACL_INFORMATION_CLASS dwAclInformationClass) 00084 { 00085 NTSTATUS Status; 00086 00087 Status = RtlSetInformationAcl(pAcl, 00088 pAclInformation, 00089 nAclInformationLength, 00090 dwAclInformationClass); 00091 if (!NT_SUCCESS(Status)) 00092 { 00093 SetLastError(RtlNtStatusToDosError(Status)); 00094 return FALSE; 00095 } 00096 00097 return TRUE; 00098 } 00099 00100 00101 /* --- ACE --- */ 00102 00103 /* 00104 * @implemented 00105 */ 00106 BOOL 00107 WINAPI 00108 AddAccessAllowedAce(PACL pAcl, 00109 DWORD dwAceRevision, 00110 DWORD AccessMask, 00111 PSID pSid) 00112 { 00113 NTSTATUS Status; 00114 00115 Status = RtlAddAccessAllowedAce(pAcl, 00116 dwAceRevision, 00117 AccessMask, 00118 pSid); 00119 if (!NT_SUCCESS(Status)) 00120 { 00121 SetLastError(RtlNtStatusToDosError(Status)); 00122 return FALSE; 00123 } 00124 00125 return TRUE; 00126 } 00127 00128 00129 /* 00130 * @implemented 00131 */ 00132 BOOL WINAPI 00133 AddAccessAllowedAceEx(PACL pAcl, 00134 DWORD dwAceRevision, 00135 DWORD AceFlags, 00136 DWORD AccessMask, 00137 PSID pSid) 00138 { 00139 NTSTATUS Status; 00140 00141 Status = RtlAddAccessAllowedAceEx(pAcl, 00142 dwAceRevision, 00143 AceFlags, 00144 AccessMask, 00145 pSid); 00146 if (!NT_SUCCESS(Status)) 00147 { 00148 SetLastError(RtlNtStatusToDosError(Status)); 00149 return FALSE; 00150 } 00151 00152 return TRUE; 00153 } 00154 00155 00156 /* 00157 * @implemented 00158 */ 00159 BOOL 00160 WINAPI 00161 AddAccessAllowedObjectAce(PACL pAcl, 00162 DWORD dwAceRevision, 00163 DWORD AceFlags, 00164 DWORD AccessMask, 00165 GUID *ObjectTypeGuid, 00166 GUID *InheritedObjectTypeGuid, 00167 PSID pSid) 00168 { 00169 NTSTATUS Status; 00170 00171 Status = RtlAddAccessAllowedObjectAce(pAcl, 00172 dwAceRevision, 00173 AceFlags, 00174 AccessMask, 00175 ObjectTypeGuid, 00176 InheritedObjectTypeGuid, 00177 pSid); 00178 if (!NT_SUCCESS(Status)) 00179 { 00180 SetLastError(RtlNtStatusToDosError(Status)); 00181 return FALSE; 00182 } 00183 00184 return TRUE; 00185 } 00186 00187 00188 /* 00189 * @implemented 00190 */ 00191 BOOL 00192 WINAPI 00193 AddAccessDeniedAce(PACL pAcl, 00194 DWORD dwAceRevision, 00195 DWORD AccessMask, 00196 PSID pSid) 00197 { 00198 NTSTATUS Status; 00199 00200 Status = RtlAddAccessDeniedAce(pAcl, 00201 dwAceRevision, 00202 AccessMask, 00203 pSid); 00204 if (!NT_SUCCESS(Status)) 00205 { 00206 SetLastError(RtlNtStatusToDosError(Status)); 00207 return FALSE; 00208 } 00209 00210 return TRUE; 00211 } 00212 00213 00214 /* 00215 * @implemented 00216 */ 00217 BOOL WINAPI 00218 AddAccessDeniedAceEx(PACL pAcl, 00219 DWORD dwAceRevision, 00220 DWORD AceFlags, 00221 DWORD AccessMask, 00222 PSID pSid) 00223 { 00224 NTSTATUS Status; 00225 00226 Status = RtlAddAccessDeniedAceEx(pAcl, 00227 dwAceRevision, 00228 AceFlags, 00229 AccessMask, 00230 pSid); 00231 if (!NT_SUCCESS(Status)) 00232 { 00233 SetLastError(RtlNtStatusToDosError(Status)); 00234 return FALSE; 00235 } 00236 00237 return TRUE; 00238 } 00239 00240 00241 /* 00242 * @implemented 00243 */ 00244 BOOL 00245 WINAPI 00246 AddAccessDeniedObjectAce(PACL pAcl, 00247 DWORD dwAceRevision, 00248 DWORD AceFlags, 00249 DWORD AccessMask, 00250 GUID* ObjectTypeGuid, 00251 GUID* InheritedObjectTypeGuid, 00252 PSID pSid) 00253 { 00254 NTSTATUS Status; 00255 00256 Status = RtlAddAccessDeniedObjectAce(pAcl, 00257 dwAceRevision, 00258 AceFlags, 00259 AccessMask, 00260 ObjectTypeGuid, 00261 InheritedObjectTypeGuid, 00262 pSid); 00263 if (!NT_SUCCESS(Status)) 00264 { 00265 SetLastError(RtlNtStatusToDosError(Status)); 00266 return FALSE; 00267 } 00268 00269 return TRUE; 00270 } 00271 00272 00273 /* 00274 * @implemented 00275 */ 00276 BOOL 00277 WINAPI 00278 AddAce(PACL pAcl, 00279 DWORD dwAceRevision, 00280 DWORD dwStartingAceIndex, 00281 LPVOID pAceList, 00282 DWORD nAceListLength) 00283 { 00284 NTSTATUS Status; 00285 00286 Status = RtlAddAce(pAcl, 00287 dwAceRevision, 00288 dwStartingAceIndex, 00289 pAceList, 00290 nAceListLength); 00291 if (!NT_SUCCESS(Status)) 00292 { 00293 SetLastError(RtlNtStatusToDosError(Status)); 00294 return FALSE; 00295 } 00296 00297 return TRUE; 00298 } 00299 00300 00301 /* 00302 * @implemented 00303 */ 00304 BOOL 00305 WINAPI 00306 AddAuditAccessAce(PACL pAcl, 00307 DWORD dwAceRevision, 00308 DWORD dwAccessMask, 00309 PSID pSid, 00310 BOOL bAuditSuccess, 00311 BOOL bAuditFailure) 00312 { 00313 NTSTATUS Status; 00314 00315 Status = RtlAddAuditAccessAce(pAcl, 00316 dwAceRevision, 00317 dwAccessMask, 00318 pSid, 00319 bAuditSuccess, 00320 bAuditFailure); 00321 if (!NT_SUCCESS(Status)) 00322 { 00323 SetLastError(RtlNtStatusToDosError(Status)); 00324 return FALSE; 00325 } 00326 00327 return TRUE; 00328 } 00329 00330 00331 /* 00332 * @implemented 00333 */ 00334 BOOL WINAPI 00335 AddAuditAccessAceEx(PACL pAcl, 00336 DWORD dwAceRevision, 00337 DWORD AceFlags, 00338 DWORD dwAccessMask, 00339 PSID pSid, 00340 BOOL bAuditSuccess, 00341 BOOL bAuditFailure) 00342 { 00343 NTSTATUS Status; 00344 00345 Status = RtlAddAuditAccessAceEx(pAcl, 00346 dwAceRevision, 00347 AceFlags, 00348 dwAccessMask, 00349 pSid, 00350 bAuditSuccess, 00351 bAuditFailure); 00352 if (!NT_SUCCESS(Status)) 00353 { 00354 SetLastError(RtlNtStatusToDosError(Status)); 00355 return FALSE; 00356 } 00357 00358 return TRUE; 00359 } 00360 00361 00362 /* 00363 * @implemented 00364 */ 00365 BOOL 00366 WINAPI 00367 AddAuditAccessObjectAce(PACL pAcl, 00368 DWORD dwAceRevision, 00369 DWORD AceFlags, 00370 DWORD AccessMask, 00371 GUID *ObjectTypeGuid, 00372 GUID *InheritedObjectTypeGuid, 00373 PSID pSid, 00374 BOOL bAuditSuccess, 00375 BOOL bAuditFailure) 00376 { 00377 NTSTATUS Status; 00378 00379 Status = RtlAddAuditAccessObjectAce(pAcl, 00380 dwAceRevision, 00381 AceFlags, 00382 AccessMask, 00383 ObjectTypeGuid, 00384 InheritedObjectTypeGuid, 00385 pSid, 00386 bAuditSuccess, 00387 bAuditFailure); 00388 if (!NT_SUCCESS(Status)) 00389 { 00390 SetLastError(RtlNtStatusToDosError(Status)); 00391 return FALSE; 00392 } 00393 00394 return TRUE; 00395 } 00396 00397 00398 /* 00399 * @implemented 00400 */ 00401 BOOL 00402 WINAPI 00403 AddMandatoryAce(IN OUT PACL pAcl, 00404 IN DWORD dwAceRevision, 00405 IN DWORD AceFlags, 00406 IN DWORD MandatoryPolicy, 00407 IN PSID pLabelSid) 00408 { 00409 NTSTATUS Status; 00410 00411 Status = RtlAddMandatoryAce(pAcl, 00412 dwAceRevision, 00413 AceFlags, 00414 MandatoryPolicy, 00415 SYSTEM_MANDATORY_LABEL_ACE_TYPE, 00416 pLabelSid); 00417 if (!NT_SUCCESS(Status)) 00418 { 00419 SetLastError(RtlNtStatusToDosError(Status)); 00420 return FALSE; 00421 } 00422 00423 return TRUE; 00424 } 00425 00426 00427 /* 00428 * @implemented 00429 */ 00430 BOOL 00431 WINAPI 00432 DeleteAce(PACL pAcl, 00433 DWORD dwAceIndex) 00434 { 00435 NTSTATUS Status; 00436 00437 Status = RtlDeleteAce(pAcl, 00438 dwAceIndex); 00439 if (!NT_SUCCESS(Status)) 00440 { 00441 SetLastError(RtlNtStatusToDosError(Status)); 00442 return FALSE; 00443 } 00444 00445 return TRUE; 00446 } 00447 00448 00449 /* 00450 * @implemented 00451 */ 00452 BOOL 00453 WINAPI 00454 FindFirstFreeAce(PACL pAcl, 00455 LPVOID *pAce) 00456 { 00457 return RtlFirstFreeAce(pAcl, 00458 (PACE*)pAce); 00459 } 00460 00461 00462 /* 00463 * @implemented 00464 */ 00465 BOOL 00466 WINAPI 00467 GetAce(PACL pAcl, 00468 DWORD dwAceIndex, 00469 LPVOID *pAce) 00470 { 00471 NTSTATUS Status; 00472 00473 Status = RtlGetAce(pAcl, 00474 dwAceIndex, 00475 pAce); 00476 if (!NT_SUCCESS(Status)) 00477 { 00478 SetLastError(RtlNtStatusToDosError(Status)); 00479 return FALSE; 00480 } 00481 00482 return TRUE; 00483 } 00484 00485 00486 /* 00487 * @implemented 00488 */ 00489 DWORD 00490 WINAPI 00491 GetInheritanceSourceW(LPWSTR pObjectName, 00492 SE_OBJECT_TYPE ObjectType, 00493 SECURITY_INFORMATION SecurityInfo, 00494 BOOL Container, 00495 GUID **pObjectClassGuids OPTIONAL, 00496 DWORD GuidCount, 00497 PACL pAcl, 00498 PFN_OBJECT_MGR_FUNCTS pfnArray OPTIONAL, 00499 PGENERIC_MAPPING pGenericMapping, 00500 PINHERITED_FROMW pInheritArray) 00501 { 00502 DWORD ErrorCode; 00503 00504 ErrorCode = CheckNtMartaPresent(); 00505 if (ErrorCode == ERROR_SUCCESS) 00506 { 00507 /* call the MARTA provider */ 00508 ErrorCode = AccGetInheritanceSource(pObjectName, 00509 ObjectType, 00510 SecurityInfo, 00511 Container, 00512 pObjectClassGuids, 00513 GuidCount, 00514 pAcl, 00515 pfnArray, 00516 pGenericMapping, 00517 pInheritArray); 00518 } 00519 00520 return ErrorCode; 00521 } 00522 00523 00524 /* 00525 * @unimplemented 00526 */ 00527 DWORD 00528 WINAPI 00529 GetInheritanceSourceA(LPSTR pObjectName, 00530 SE_OBJECT_TYPE ObjectType, 00531 SECURITY_INFORMATION SecurityInfo, 00532 BOOL Container, 00533 GUID **pObjectClassGuids OPTIONAL, 00534 DWORD GuidCount, 00535 PACL pAcl, 00536 PFN_OBJECT_MGR_FUNCTS pfnArray OPTIONAL, 00537 PGENERIC_MAPPING pGenericMapping, 00538 PINHERITED_FROMA pInheritArray) 00539 { 00540 /* That's all this function does, at least up to w2k3... Even MS was too 00541 lazy to implement it... */ 00542 return ERROR_CALL_NOT_IMPLEMENTED; 00543 } 00544 00545 00546 /* 00547 * @implemented 00548 */ 00549 DWORD 00550 WINAPI 00551 FreeInheritedFromArray(PINHERITED_FROMW pInheritArray, 00552 USHORT AceCnt, 00553 PFN_OBJECT_MGR_FUNCTS pfnArray OPTIONAL) 00554 { 00555 DWORD ErrorCode; 00556 00557 ErrorCode = CheckNtMartaPresent(); 00558 if (ErrorCode == ERROR_SUCCESS) 00559 { 00560 /* call the MARTA provider */ 00561 ErrorCode = AccFreeIndexArray(pInheritArray, 00562 AceCnt, 00563 pfnArray); 00564 } 00565 00566 return ErrorCode; 00567 } 00568 00569 00570 /* 00571 * @implemented 00572 */ 00573 DWORD 00574 WINAPI 00575 SetEntriesInAclW(ULONG cCountOfExplicitEntries, 00576 PEXPLICIT_ACCESS_W pListOfExplicitEntries, 00577 PACL OldAcl, 00578 PACL *NewAcl) 00579 { 00580 DWORD ErrorCode; 00581 00582 if (!NewAcl) 00583 { 00584 return ERROR_INVALID_PARAMETER; 00585 } 00586 00587 ErrorCode = CheckNtMartaPresent(); 00588 if (ErrorCode == ERROR_SUCCESS) 00589 { 00590 /* call the MARTA provider */ 00591 ErrorCode = AccRewriteSetEntriesInAcl(cCountOfExplicitEntries, 00592 pListOfExplicitEntries, 00593 OldAcl, 00594 NewAcl); 00595 } 00596 00597 return ErrorCode; 00598 } 00599 00600 00601 static DWORD 00602 InternalTrusteeAToW(IN PTRUSTEE_A pTrusteeA, 00603 OUT PTRUSTEE_W *pTrusteeW) 00604 { 00605 TRUSTEE_FORM TrusteeForm; 00606 INT BufferSize = 0; 00607 PSTR lpStr; 00608 DWORD ErrorCode = ERROR_SUCCESS; 00609 00610 //ASSERT(sizeof(TRUSTEE_W) == sizeof(TRUSTEE_A)); 00611 00612 TrusteeForm = GetTrusteeFormA(pTrusteeA); 00613 switch (TrusteeForm) 00614 { 00615 case TRUSTEE_IS_NAME: 00616 { 00617 /* directly copy the array, this works as the size of the EXPLICIT_ACCESS_A 00618 structure matches the size of the EXPLICIT_ACCESS_W version */ 00619 lpStr = GetTrusteeNameA(pTrusteeA); 00620 if (lpStr != NULL) 00621 BufferSize = strlen(lpStr) + 1; 00622 00623 *pTrusteeW = RtlAllocateHeap(RtlGetProcessHeap(), 00624 0, 00625 sizeof(TRUSTEE_W) + (BufferSize * sizeof(WCHAR))); 00626 if (*pTrusteeW != NULL) 00627 { 00628 RtlCopyMemory(*pTrusteeW, 00629 pTrusteeA, 00630 FIELD_OFFSET(TRUSTEE_A, 00631 ptstrName)); 00632 00633 if (lpStr != NULL) 00634 { 00635 (*pTrusteeW)->ptstrName = (PWSTR)((*pTrusteeW) + 1); 00636 00637 /* convert the trustee's name */ 00638 if (MultiByteToWideChar(CP_ACP, 00639 0, 00640 lpStr, 00641 -1, 00642 (*pTrusteeW)->ptstrName, 00643 BufferSize) == 0) 00644 { 00645 goto ConvertErr; 00646 } 00647 } 00648 else 00649 { 00650 RtlFreeHeap(RtlGetProcessHeap(), 00651 0, 00652 *pTrusteeW); 00653 goto NothingToConvert; 00654 } 00655 } 00656 else 00657 ErrorCode = ERROR_NOT_ENOUGH_MEMORY; 00658 break; 00659 } 00660 00661 case TRUSTEE_IS_OBJECTS_AND_NAME: 00662 { 00663 POBJECTS_AND_NAME_A oanA = (POBJECTS_AND_NAME_A)GetTrusteeNameA(pTrusteeA); 00664 POBJECTS_AND_NAME_W oan; 00665 PWSTR StrBuf; 00666 00667 /* calculate the size needed */ 00668 if ((oanA->ObjectsPresent & ACE_INHERITED_OBJECT_TYPE_PRESENT) && 00669 oanA->InheritedObjectTypeName != NULL) 00670 { 00671 BufferSize = strlen(oanA->InheritedObjectTypeName) + 1; 00672 } 00673 if (oanA->ptstrName != NULL) 00674 { 00675 BufferSize += strlen(oanA->ptstrName) + 1; 00676 } 00677 00678 *pTrusteeW = RtlAllocateHeap(RtlGetProcessHeap(), 00679 0, 00680 sizeof(TRUSTEE_W) + sizeof(OBJECTS_AND_NAME_W) + 00681 (BufferSize * sizeof(WCHAR))); 00682 00683 if (*pTrusteeW != NULL) 00684 { 00685 oan = (POBJECTS_AND_NAME_W)((*pTrusteeW) + 1); 00686 StrBuf = (PWSTR)(oan + 1); 00687 00688 /* copy over the parts of the TRUSTEE structure that don't need 00689 to be touched */ 00690 RtlCopyMemory(*pTrusteeW, 00691 pTrusteeA, 00692 FIELD_OFFSET(TRUSTEE_A, 00693 ptstrName)); 00694 00695 (*pTrusteeW)->ptstrName = (LPWSTR)oan; 00696 00697 /* convert the OBJECTS_AND_NAME_A structure */ 00698 oan->ObjectsPresent = oanA->ObjectsPresent; 00699 oan->ObjectType = oanA->ObjectType; 00700 00701 if ((oanA->ObjectsPresent & ACE_INHERITED_OBJECT_TYPE_PRESENT) && 00702 oanA->InheritedObjectTypeName != NULL) 00703 { 00704 /* convert inherited object type name */ 00705 BufferSize = strlen(oanA->InheritedObjectTypeName) + 1; 00706 00707 if (MultiByteToWideChar(CP_ACP, 00708 0, 00709 oanA->InheritedObjectTypeName, 00710 -1, 00711 StrBuf, 00712 BufferSize) == 0) 00713 { 00714 goto ConvertErr; 00715 } 00716 oan->InheritedObjectTypeName = StrBuf; 00717 00718 StrBuf += BufferSize; 00719 } 00720 else 00721 oan->InheritedObjectTypeName = NULL; 00722 00723 if (oanA->ptstrName != NULL) 00724 { 00725 /* convert the trustee name */ 00726 BufferSize = strlen(oanA->ptstrName) + 1; 00727 00728 if (MultiByteToWideChar(CP_ACP, 00729 0, 00730 oanA->ptstrName, 00731 -1, 00732 StrBuf, 00733 BufferSize) == 0) 00734 { 00735 goto ConvertErr; 00736 } 00737 oan->ptstrName = StrBuf; 00738 } 00739 else 00740 oan->ptstrName = NULL; 00741 } 00742 else 00743 ErrorCode = ERROR_NOT_ENOUGH_MEMORY; 00744 break; 00745 } 00746 00747 default: 00748 { 00749 NothingToConvert: 00750 /* no need to convert anything to unicode */ 00751 *pTrusteeW = (PTRUSTEE_W)pTrusteeA; 00752 break; 00753 } 00754 } 00755 00756 return ErrorCode; 00757 00758 ConvertErr: 00759 ErrorCode = GetLastError(); 00760 00761 /* cleanup */ 00762 RtlFreeHeap(RtlGetProcessHeap(), 00763 0, 00764 *pTrusteeW); 00765 00766 return ErrorCode; 00767 } 00768 00769 00770 static __inline VOID 00771 InternalFreeConvertedTrustee(IN PTRUSTEE_W pTrusteeW, 00772 IN PTRUSTEE_A pTrusteeA) 00773 { 00774 if ((PVOID)pTrusteeW != (PVOID)pTrusteeA) 00775 { 00776 RtlFreeHeap(RtlGetProcessHeap(), 00777 0, 00778 pTrusteeW); 00779 } 00780 } 00781 00782 00783 static DWORD 00784 InternalExplicitAccessAToW(IN ULONG cCountOfExplicitEntries, 00785 IN PEXPLICIT_ACCESS_A pListOfExplicitEntriesA, 00786 OUT PEXPLICIT_ACCESS_W *pListOfExplicitEntriesW) 00787 { 00788 TRUSTEE_FORM TrusteeForm; 00789 SIZE_T Size; 00790 ULONG i; 00791 ULONG ObjectsAndNameCount = 0; 00792 PEXPLICIT_ACCESS_W peaw = NULL; 00793 DWORD ErrorCode = ERROR_SUCCESS; 00794 LPSTR lpStr; 00795 00796 /* NOTE: This code assumes that the size of the TRUSTEE_A and TRUSTEE_W structure matches! */ 00797 //ASSERT(sizeof(TRUSTEE_A) == sizeof(TRUSTEE_W)); 00798 00799 if (cCountOfExplicitEntries != 0) 00800 { 00801 /* calculate the size needed */ 00802 Size = cCountOfExplicitEntries * sizeof(EXPLICIT_ACCESS_W); 00803 for (i = 0; i != cCountOfExplicitEntries; i++) 00804 { 00805 TrusteeForm = GetTrusteeFormA(&pListOfExplicitEntriesA[i].Trustee); 00806 00807 switch (TrusteeForm) 00808 { 00809 case TRUSTEE_IS_NAME: 00810 { 00811 lpStr = GetTrusteeNameA(&pListOfExplicitEntriesA[i].Trustee); 00812 if (lpStr != NULL) 00813 Size += (strlen(lpStr) + 1) * sizeof(WCHAR); 00814 break; 00815 } 00816 00817 case TRUSTEE_IS_OBJECTS_AND_NAME: 00818 { 00819 POBJECTS_AND_NAME_A oan = (POBJECTS_AND_NAME_A)GetTrusteeNameA(&pListOfExplicitEntriesA[i].Trustee); 00820 00821 if ((oan->ObjectsPresent & ACE_INHERITED_OBJECT_TYPE_PRESENT) && 00822 oan->InheritedObjectTypeName != NULL) 00823 { 00824 Size += (strlen(oan->InheritedObjectTypeName) + 1) * sizeof(WCHAR); 00825 } 00826 00827 if (oan->ptstrName != NULL) 00828 Size += (strlen(oan->ptstrName) + 1) * sizeof(WCHAR); 00829 00830 ObjectsAndNameCount++; 00831 break; 00832 } 00833 00834 default: 00835 break; 00836 } 00837 } 00838 00839 /* allocate the array */ 00840 peaw = RtlAllocateHeap(RtlGetProcessHeap(), 00841 0, 00842 Size); 00843 if (peaw != NULL) 00844 { 00845 INT BufferSize; 00846 POBJECTS_AND_NAME_W oan = (POBJECTS_AND_NAME_W)(peaw + cCountOfExplicitEntries); 00847 LPWSTR StrBuf = (LPWSTR)(oan + ObjectsAndNameCount); 00848 00849 /* convert the array to unicode */ 00850 for (i = 0; i != cCountOfExplicitEntries; i++) 00851 { 00852 peaw[i].grfAccessPermissions = pListOfExplicitEntriesA[i].grfAccessPermissions; 00853 peaw[i].grfAccessMode = pListOfExplicitEntriesA[i].grfAccessMode; 00854 peaw[i].grfInheritance = pListOfExplicitEntriesA[i].grfInheritance; 00855 00856 /* convert or copy the TRUSTEE structure */ 00857 TrusteeForm = GetTrusteeFormA(&pListOfExplicitEntriesA[i].Trustee); 00858 switch (TrusteeForm) 00859 { 00860 case TRUSTEE_IS_NAME: 00861 { 00862 lpStr = GetTrusteeNameA(&pListOfExplicitEntriesA[i].Trustee); 00863 if (lpStr != NULL) 00864 { 00865 /* convert the trustee name */ 00866 BufferSize = strlen(lpStr) + 1; 00867 00868 if (MultiByteToWideChar(CP_ACP, 00869 0, 00870 lpStr, 00871 -1, 00872 StrBuf, 00873 BufferSize) == 0) 00874 { 00875 goto ConvertErr; 00876 } 00877 peaw[i].Trustee.ptstrName = StrBuf; 00878 00879 StrBuf += BufferSize; 00880 } 00881 else 00882 goto RawTrusteeCopy; 00883 00884 break; 00885 } 00886 00887 case TRUSTEE_IS_OBJECTS_AND_NAME: 00888 { 00889 POBJECTS_AND_NAME_A oanA = (POBJECTS_AND_NAME_A)GetTrusteeNameA(&pListOfExplicitEntriesA[i].Trustee); 00890 00891 /* copy over the parts of the TRUSTEE structure that don't need 00892 to be touched */ 00893 RtlCopyMemory(&peaw[i].Trustee, 00894 &pListOfExplicitEntriesA[i].Trustee, 00895 FIELD_OFFSET(TRUSTEE_A, 00896 ptstrName)); 00897 00898 peaw[i].Trustee.ptstrName = (LPWSTR)oan; 00899 00900 /* convert the OBJECTS_AND_NAME_A structure */ 00901 oan->ObjectsPresent = oanA->ObjectsPresent; 00902 oan->ObjectType = oanA->ObjectType; 00903 00904 if ((oanA->ObjectsPresent & ACE_INHERITED_OBJECT_TYPE_PRESENT) && 00905 oanA->InheritedObjectTypeName != NULL) 00906 { 00907 /* convert inherited object type name */ 00908 BufferSize = strlen(oanA->InheritedObjectTypeName) + 1; 00909 00910 if (MultiByteToWideChar(CP_ACP, 00911 0, 00912 oanA->InheritedObjectTypeName, 00913 -1, 00914 StrBuf, 00915 BufferSize) == 0) 00916 { 00917 goto ConvertErr; 00918 } 00919 oan->InheritedObjectTypeName = StrBuf; 00920 00921 StrBuf += BufferSize; 00922 } 00923 else 00924 oan->InheritedObjectTypeName = NULL; 00925 00926 if (oanA->ptstrName != NULL) 00927 { 00928 /* convert the trustee name */ 00929 BufferSize = strlen(oanA->ptstrName) + 1; 00930 00931 if (MultiByteToWideChar(CP_ACP, 00932 0, 00933 oanA->ptstrName, 00934 -1, 00935 StrBuf, 00936 BufferSize) == 0) 00937 { 00938 goto ConvertErr; 00939 } 00940 oan->ptstrName = StrBuf; 00941 00942 StrBuf += BufferSize; 00943 } 00944 else 00945 oan->ptstrName = NULL; 00946 00947 /* move on to the next OBJECTS_AND_NAME_A structure */ 00948 oan++; 00949 break; 00950 } 00951 00952 default: 00953 { 00954 RawTrusteeCopy: 00955 /* just copy over the TRUSTEE structure, they don't contain any 00956 ansi/unicode specific data */ 00957 RtlCopyMemory(&peaw[i].Trustee, 00958 &pListOfExplicitEntriesA[i].Trustee, 00959 sizeof(TRUSTEE_A)); 00960 break; 00961 } 00962 } 00963 } 00964 00965 ASSERT(ErrorCode == ERROR_SUCCESS); 00966 *pListOfExplicitEntriesW = peaw; 00967 } 00968 else 00969 ErrorCode = ERROR_NOT_ENOUGH_MEMORY; 00970 } 00971 00972 return ErrorCode; 00973 00974 ConvertErr: 00975 ErrorCode = GetLastError(); 00976 00977 /* cleanup */ 00978 RtlFreeHeap(RtlGetProcessHeap(), 00979 0, 00980 peaw); 00981 00982 return ErrorCode; 00983 } 00984 00985 00986 /* 00987 * @implemented 00988 */ 00989 DWORD 00990 WINAPI 00991 SetEntriesInAclA(ULONG cCountOfExplicitEntries, 00992 PEXPLICIT_ACCESS_A pListOfExplicitEntries, 00993 PACL OldAcl, 00994 PACL *NewAcl) 00995 { 00996 PEXPLICIT_ACCESS_W ListOfExplicitEntriesW = NULL; 00997 DWORD ErrorCode; 00998 00999 ErrorCode = InternalExplicitAccessAToW(cCountOfExplicitEntries, 01000 pListOfExplicitEntries, 01001 &ListOfExplicitEntriesW); 01002 if (ErrorCode == ERROR_SUCCESS) 01003 { 01004 ErrorCode = SetEntriesInAclW(cCountOfExplicitEntries, 01005 ListOfExplicitEntriesW, 01006 OldAcl, 01007 NewAcl); 01008 01009 /* free the allocated array */ 01010 RtlFreeHeap(RtlGetProcessHeap(), 01011 0, 01012 ListOfExplicitEntriesW); 01013 } 01014 01015 return ErrorCode; 01016 } 01017 01018 01019 /* 01020 * @implemented 01021 */ 01022 DWORD 01023 WINAPI 01024 GetExplicitEntriesFromAclW(PACL pacl, 01025 PULONG pcCountOfExplicitEntries, 01026 PEXPLICIT_ACCESS_W *pListOfExplicitEntries) 01027 { 01028 DWORD ErrorCode; 01029 01030 ErrorCode = CheckNtMartaPresent(); 01031 if (ErrorCode == ERROR_SUCCESS) 01032 { 01033 /* call the MARTA provider */ 01034 ErrorCode = AccRewriteGetExplicitEntriesFromAcl(pacl, 01035 pcCountOfExplicitEntries, 01036 pListOfExplicitEntries); 01037 } 01038 01039 return ErrorCode; 01040 } 01041 01042 01043 /* 01044 * @unimplemented 01045 */ 01046 DWORD 01047 WINAPI 01048 GetEffectiveRightsFromAclW(IN PACL pacl, 01049 IN PTRUSTEE_W pTrustee, 01050 OUT PACCESS_MASK pAccessRights) 01051 { 01052 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights); 01053 01054 *pAccessRights = STANDARD_RIGHTS_ALL | SPECIFIC_RIGHTS_ALL; 01055 return ERROR_SUCCESS; 01056 } 01057 01058 01059 /* 01060 * @implemented 01061 */ 01062 DWORD 01063 WINAPI 01064 GetEffectiveRightsFromAclA(IN PACL pacl, 01065 IN PTRUSTEE_A pTrustee, 01066 OUT PACCESS_MASK pAccessRights) 01067 { 01068 PTRUSTEE_W pTrusteeW = NULL; 01069 DWORD ErrorCode; 01070 01071 ErrorCode = InternalTrusteeAToW(pTrustee, 01072 &pTrusteeW); 01073 if (ErrorCode == ERROR_SUCCESS) 01074 { 01075 ErrorCode = GetEffectiveRightsFromAclW(pacl, 01076 pTrusteeW, 01077 pAccessRights); 01078 01079 InternalFreeConvertedTrustee(pTrusteeW, 01080 pTrustee); 01081 } 01082 else 01083 ErrorCode = ERROR_NOT_ENOUGH_MEMORY; 01084 01085 return ErrorCode; 01086 } 01087 01088 01089 /* 01090 * @unimplemented 01091 */ 01092 DWORD 01093 WINAPI 01094 GetAuditedPermissionsFromAclW(IN PACL pacl, 01095 IN PTRUSTEE_W pTrustee, 01096 OUT PACCESS_MASK pSuccessfulAuditedRights, 01097 OUT PACCESS_MASK pFailedAuditRights) 01098 { 01099 FIXME("%s() not implemented!\n", __FUNCTION__); 01100 return ERROR_CALL_NOT_IMPLEMENTED; 01101 } 01102 01103 01104 /* 01105 * @implemented 01106 */ 01107 DWORD 01108 WINAPI 01109 GetAuditedPermissionsFromAclA(IN PACL pacl, 01110 IN PTRUSTEE_A pTrustee, 01111 OUT PACCESS_MASK pSuccessfulAuditedRights, 01112 OUT PACCESS_MASK pFailedAuditRights) 01113 { 01114 PTRUSTEE_W pTrusteeW = NULL; 01115 DWORD ErrorCode; 01116 01117 ErrorCode = InternalTrusteeAToW(pTrustee, 01118 &pTrusteeW); 01119 if (ErrorCode == ERROR_SUCCESS) 01120 { 01121 ErrorCode = GetAuditedPermissionsFromAclW(pacl, 01122 pTrusteeW, 01123 pSuccessfulAuditedRights, 01124 pFailedAuditRights); 01125 01126 InternalFreeConvertedTrustee(pTrusteeW, 01127 pTrustee); 01128 } 01129 else 01130 ErrorCode = ERROR_NOT_ENOUGH_MEMORY; 01131 01132 return ErrorCode; 01133 } 01134 01135 /* EOF */ Generated on Sun May 27 2012 04:22:41 for ReactOS by
1.7.6.1
|