summaryrefslogtreecommitdiff
path: root/src/vm/securityattributes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm/securityattributes.cpp')
-rw-r--r--src/vm/securityattributes.cpp1282
1 files changed, 0 insertions, 1282 deletions
diff --git a/src/vm/securityattributes.cpp b/src/vm/securityattributes.cpp
index 0facbbbfb3..1f8e3e1d4d 100644
--- a/src/vm/securityattributes.cpp
+++ b/src/vm/securityattributes.cpp
@@ -21,133 +21,6 @@ HRESULT BlobToAttributeSet(BYTE* pBuffer, ULONG cbBuffer, CORSEC_ATTRSET* pAttrS
#ifndef CROSSGEN_COMPILE
-OBJECTREF SecurityAttributes::CreatePermissionSet(BOOL fTrusted)
-{
- CONTRACTL {
- THROWS;
- GC_TRIGGERS;
- MODE_COOPERATIVE;
- } CONTRACTL_END;
-
- OBJECTREF pPermSet = NULL;
- GCPROTECT_BEGIN(pPermSet);
-
- MethodTable* pMT = MscorlibBinder::GetClass(CLASS__PERMISSION_SET);
- pPermSet = (OBJECTREF) AllocateObject(pMT);
-
- ARG_SLOT fStatus = (fTrusted) ? 1 : 0;
-
- MethodDescCallSite ctor(METHOD__PERMISSION_SET__CTOR);
-
- ARG_SLOT arg[2] = {
- ObjToArgSlot(pPermSet),
- BoolToArgSlot(fStatus)
- };
- ctor.Call(arg);
-
- GCPROTECT_END();
-
- return pPermSet;
-}
-
-#ifdef FEATURE_CAS_POLICY
-
-// todo: remove the non-cas parameters (because they're bogus now anyway)
-void SecurityAttributes::XmlToPermissionSet(PBYTE pbXmlBlob,
- DWORD cbXmlBlob,
- OBJECTREF* pPermSet,
- OBJECTREF* pEncoding,
- PBYTE pbNonCasXmlBlob,
- DWORD cbNonCasXmlBlob,
- OBJECTREF* pNonCasPermSet,
- OBJECTREF* pNonCasEncoding)
-{
- CONTRACTL {
- THROWS;
- GC_TRIGGERS;
- MODE_COOPERATIVE;
- PRECONDITION(IsProtectedByGCFrame (pPermSet));
- PRECONDITION(IsProtectedByGCFrame (pEncoding));
- PRECONDITION(IsProtectedByGCFrame (pNonCasPermSet));
- PRECONDITION(IsProtectedByGCFrame (pNonCasEncoding));
- } CONTRACTL_END;
-
- // Get Host Protection Flags
- EApiCategories eProtectedCategories = GetHostProtectionManager()->GetProtectedCategories();
-
- MethodDescCallSite decodeXML(METHOD__PERMISSION_SET__DECODE_XML, pPermSet); // can trigger GC
-
- // Deserialize the CAS PermissionSet
- if(pbXmlBlob && cbXmlBlob > 0)
- {
- _ASSERTE(*pbXmlBlob != LAZY_DECL_SEC_FLAG);
-
- // Create a new (empty) permission set.
- *pPermSet = SecurityAttributes::CreatePermissionSet(FALSE);
-
- // Buffer in managed space.
- SecurityAttributes::CopyEncodingToByteArray(pbXmlBlob, cbXmlBlob, pEncoding);
-
- ARG_SLOT args[] = {
- ObjToArgSlot(*pPermSet),
- ObjToArgSlot(*pEncoding),
- (ARG_SLOT)eProtectedCategories,
- (ARG_SLOT)0,
- };
-
- // Deserialize into a managed object.
- BOOL success = FALSE;
- EX_TRY
- {
- // Elevate thread's allowed loading level. This can cause load failures if assemblies loaded from this point on require
- // any assemblies currently being loaded.
- OVERRIDE_LOAD_LEVEL_LIMIT(FILE_ACTIVE);
- OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED);
- success = decodeXML.Call_RetBool(args);
- }
- EX_SWALLOW_NONTERMINAL
-
- if (!success)
- COMPlusThrow(kSecurityException, IDS_ENCODEDPERMSET_DECODEFAILURE);
- }
-
- // Deserialize the non-CAS PermissionSet
- if(pbNonCasXmlBlob && cbNonCasXmlBlob > 0)
- {
- _ASSERTE(*pbNonCasXmlBlob != LAZY_DECL_SEC_FLAG);
-
- // Create a new (empty) permission set.
- *pNonCasPermSet = SecurityAttributes::CreatePermissionSet(FALSE);
-
- // Buffer in managed space.
- SecurityAttributes::CopyEncodingToByteArray(pbNonCasXmlBlob, cbNonCasXmlBlob, pNonCasEncoding);
-
- ARG_SLOT args[] = {
- ObjToArgSlot(*pNonCasPermSet),
- ObjToArgSlot(*pNonCasEncoding),
- (ARG_SLOT)eProtectedCategories,
- (ARG_SLOT)0,
- };
-
- // Deserialize into a managed object.
- BOOL success = FALSE;
- EX_TRY
- {
- // Elevate thread's allowed loading level. This can cause load failures if assemblies loaded from this point on require
- // any assemblies currently being loaded.
- OVERRIDE_LOAD_LEVEL_LIMIT(FILE_ACTIVE);
- OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED);
- success = decodeXML.Call_RetBool(args);
- }
- EX_SWALLOW_NONTERMINAL
-
- if (!success)
- COMPlusThrow(kSecurityException, IDS_ENCODEDPERMSET_DECODEFAILURE);
- }
-}
-
-#endif // FEATURE_CAS_POLICY
-
//
// Determine if a security action allows an optimization where an empty permission set can be represented as
// NULL. Some VM optimizations kick in if an empty permission set can be represented as NULL; however since
@@ -177,70 +50,6 @@ bool SecurityAttributes::ActionAllowsNullPermissionSet(CorDeclSecurity action)
return action != dclPermitOnly && action != dclRequestOptional;
}
-#ifdef FEATURE_CAS_POLICY
-
-PsetCacheEntry* SecurityAttributes::MergePermissionSets(IN PsetCacheEntry *pPCE1, IN PsetCacheEntry *pPCE2, IN bool fIntersect, DWORD dwAction)
-{
- CONTRACTL {
- THROWS;
- GC_TRIGGERS;
- MODE_COOPERATIVE;
- } CONTRACTL_END;
-
- SecurityDeclarativeCache *pSDC;
- PsetCacheEntry* pMergedPCE;
-
- struct _gc {
- OBJECTREF orSet1;
- OBJECTREF orSet2;
- OBJECTREF orMergedSet;
- } gc;
- memset(&gc, '\0', sizeof(gc));
- GCPROTECT_BEGIN(gc);
- {
- // Union or Intersect the two PermissionSets
- gc.orSet1 = pPCE1->CreateManagedPsetObject (dwAction);
-
- if(gc.orSet1 == NULL)
- pMergedPCE = fIntersect ? pPCE1 : pPCE2;
- else
- {
- gc.orSet2 = pPCE2->CreateManagedPsetObject (dwAction);
- if(gc.orSet2 == NULL)
- pMergedPCE = fIntersect ? pPCE2 : pPCE1;
- else
- {
- BinderMethodID methID = (fIntersect ? METHOD__PERMISSION_SET__INTERSECT : METHOD__PERMISSION_SET__UNION);
- MethodDescCallSite mergeMethod(methID, &gc.orSet1);
-
- ARG_SLOT args[2] = {
- ObjToArgSlot(gc.orSet1),
- ObjToArgSlot(gc.orSet2),
- };
- gc.orMergedSet = mergeMethod.Call_RetOBJECTREF(args);
-
- if(gc.orMergedSet == NULL)
- gc.orMergedSet = CreatePermissionSet(false);
-
- // Convert to XML blob
- PBYTE pbData;
- DWORD cbData;
- EncodePermissionSet(&gc.orMergedSet, &pbData, &cbData);
-
- // Store XML blob and obtain an index to reference it
- pSDC = &(GetAppDomain()->m_pSecContext->m_pSecurityDeclarativeCache);
- pMergedPCE = pSDC->CreateAndCachePset (pbData, cbData);
-
- }
- }
- }
- GCPROTECT_END();
-
- return pMergedPCE;
-}
-
-#endif // FEATURE_CAS_POLICY
-
void SecurityAttributes::CopyEncodingToByteArray(IN PBYTE pbData,
IN DWORD cbData,
OUT OBJECTREF* pArray)
@@ -280,1077 +89,6 @@ void SecurityAttributes::CopyByteArrayToEncoding(IN U1ARRAYREF* pArray,
CopyMemory(*ppbData, (*pArray)->GetDirectPointerToNonObjectElements(), size);
}
-#ifdef FEATURE_CAS_POLICY
-void SecurityAttributes::EncodePermissionSet(IN OBJECTREF* pRef,
- OUT PBYTE* ppbData,
- OUT DWORD* pcbData)
-{
- CONTRACTL {
- THROWS;
- GC_TRIGGERS;
- MODE_COOPERATIVE;
- PRECONDITION(IsProtectedByGCFrame (pRef));
- } CONTRACTL_END;
-
- MethodDescCallSite encodeXML(METHOD__PERMISSION_SET__ENCODE_XML);
-
- // Encode up the result
- ARG_SLOT args1[1];
- args1[0] = ObjToArgSlot(*pRef);
- OBJECTREF pByteArray = NULL;
- pByteArray = encodeXML.Call_RetOBJECTREF(args1);
-
- SecurityAttributes::CopyByteArrayToEncoding((U1ARRAYREF*) &pByteArray,
- ppbData,
- pcbData);
-}
-
-static void SetupRestrictSecAttributes()
-{
- CONTRACTL {
- THROWS;
- GC_TRIGGERS;
- MODE_COOPERATIVE;
- } CONTRACTL_END;
-
- EX_TRY
- {
- MethodDescCallSite setupSecurity(METHOD__PERMISSION_SET__SETUP_SECURITY);
-
- setupSecurity.Call(NULL);
- }
- EX_CATCH
- {
- // There is a possibility that we've already set the appdomain policy
- // level for this process. In that case we'll get a policy exception
- // that we are free to ignore.
- OBJECTREF pThrowable = GET_THROWABLE();
- DefineFullyQualifiedNameForClassOnStack();
- LPCUTF8 szClass = GetFullyQualifiedNameForClass(pThrowable->GetMethodTable());
- if (strcmp(g_PolicyExceptionClassName, szClass) != 0)
- COMPlusThrow(pThrowable);
- }
- EX_END_CATCH(RethrowTerminalExceptions)
-}
-
-Assembly* SecurityAttributes::LoadAssemblyFromToken(IMetaDataAssemblyImport *pImport, mdAssemblyRef tkAssemblyRef)
-{
- CONTRACTL
- {
- THROWS;
- GC_TRIGGERS;
- MODE_ANY;
- }
- CONTRACTL_END;
-
- _ASSERTE(TypeFromToken(tkAssemblyRef) == mdtAssemblyRef);
-
- // Find all the details needed to name an assembly for loading.
- ASSEMBLYMETADATA sContext;
- BYTE *pbPublicKeyOrToken;
- DWORD cbPublicKeyOrToken;
- DWORD dwFlags;
- LPWSTR wszName;
- DWORD cchName;
-
- // Initialize ASSEMBLYMETADATA structure.
- ZeroMemory(&sContext, sizeof(ASSEMBLYMETADATA));
-
- // Retrieve size of assembly name.
- HRESULT hr = pImport->GetAssemblyRefProps(tkAssemblyRef, // [IN] The AssemblyRef for which to get the properties.
- NULL, // [OUT] Pointer to the public key or token.
- NULL, // [OUT] Count of bytes in the public key or token.
- NULL, // [OUT] Buffer to fill with name.
- NULL, // [IN] Size of buffer in wide chars.
- &cchName, // [OUT] Actual # of wide chars in name.
- &sContext, // [OUT] Assembly MetaData.
- NULL, // [OUT] Hash blob.
- NULL, // [OUT] Count of bytes in the hash blob.
- NULL); // [OUT] Flags.
- _ASSERTE(SUCCEEDED(hr));
-
- // Allocate the necessary buffers.
- wszName = (LPWSTR)_alloca(cchName * sizeof(WCHAR));
- sContext.szLocale = (LPWSTR)_alloca(sContext.cbLocale * sizeof(WCHAR));
- sContext.rProcessor = (DWORD *)_alloca(sContext.ulProcessor * sizeof(DWORD));
- sContext.rOS = (OSINFO *)_alloca(sContext.ulOS * sizeof(OSINFO));
-
- // Get the assembly name and rest of naming properties.
- hr = pImport->GetAssemblyRefProps(tkAssemblyRef,
- (const void **)&pbPublicKeyOrToken,
- &cbPublicKeyOrToken,
- wszName,
- cchName,
- &cchName,
- &sContext,
- NULL,
- NULL,
- &dwFlags);
- _ASSERTE(SUCCEEDED(hr));
-
- // We've got the details of the assembly, just need to load it.
-
- // Convert assembly name to UTF8.
- MAKE_UTF8PTR_FROMWIDE(uszAssemblyName, wszName);
-
- // Unfortunately we've got an ASSEMBLYMETADATA structure, but we need
- // an AssemblyMetaDataInternal
- AssemblyMetaDataInternal internalContext;
-
- // Initialize the structure.
- ZeroMemory(&internalContext, sizeof(AssemblyMetaDataInternal));
-
- internalContext.usMajorVersion = sContext.usMajorVersion;
- internalContext.usMinorVersion = sContext.usMinorVersion;
- internalContext.usBuildNumber = sContext.usBuildNumber;
- internalContext.usRevisionNumber = sContext.usRevisionNumber;
- internalContext.rProcessor = sContext.rProcessor;
- internalContext.ulProcessor = sContext.ulProcessor;
- internalContext.rOS = sContext.rOS;
- internalContext.ulOS = sContext.ulOS;
- if(sContext.cbLocale)
- {
- MAKE_UTF8PTR_FROMWIDE(pLocale, sContext.szLocale);
- internalContext.szLocale = pLocale;
- }
- else
- {
- internalContext.szLocale = "";
- }
-
- Assembly* pAssembly = NULL;
- {
- // Elevate thread's allowed loading level. This can cause load failures if assemblies loaded from this point on require
- // any assemblies currently being loaded.
- OVERRIDE_LOAD_LEVEL_LIMIT(FILE_ACTIVE);
- pAssembly = AssemblySpec::LoadAssembly(uszAssemblyName,
- &internalContext,
- pbPublicKeyOrToken,
- cbPublicKeyOrToken,
- dwFlags);
- }
-
- // @todo: Add CORSECATTR_E_ASSEMBLY_LOAD_FAILED_EX context to this exception path?
-
- return pAssembly;
-}
-
-TypeHandle FindSecurityAttributeHandle(LPCWSTR wszTypeName)
-{
- CONTRACTL {
- THROWS;
- GC_TRIGGERS;
- } CONTRACTL_END;
-
- TypeHandle hType;
- MethodDescCallSite findSecurityAttributeTypeHandle(METHOD__SECURITY_ATTRIBUTE__FIND_SECURITY_ATTRIBUTE_TYPE_HANDLE);
-
- struct _gc {
- STRINGREF str;
- } gc;
-
- ZeroMemory(&gc, sizeof(gc));
-
- GCPROTECT_BEGIN(gc);
- gc.str = StringObject::NewString(wszTypeName);
- ARG_SLOT arg[1] = {
- ObjToArgSlot(gc.str)
- };
-
- TypeHandle th = TypeHandle::FromPtr(findSecurityAttributeTypeHandle.Call_RetLPVOID(arg));
- hType = th;
- GCPROTECT_END();
-
- return hType;
-}
-
-// @TODO: replace this method with a call to the reflection code that decodes CA blobs
-// and instantiates managed attribute objects. Currently the most significant perf
-// cost of this method is due to TypeName::GetTypeWorker which it calls via
-// GetTypeFromAssemblyQualifiedName, and GetTypeUsingCASearchRules
-HRESULT SecurityAttributes::AttributeSetToManaged(OBJECTREF* /*OUT*/obj, CORSEC_ATTRSET* pAttrSet, OBJECTREF* pThrowable, DWORD* pdwErrorIndex, bool bLazy)
-{
- CONTRACTL {
- THROWS;
- GC_TRIGGERS;
- // Assumption: if the first obj is protected, the whole array is protected
- if (pAttrSet->dwAttrCount > 0) {PRECONDITION(IsProtectedByGCFrame (obj));}
- } CONTRACTL_END;
-
- HRESULT hr = S_OK;
- DWORD i;
- TypeHandle hType;
- MethodTable *pMT = NULL;
- MethodDesc *pMD = NULL;
-
- // Elevate the allowed loading level
- // Elevate thread's allowed loading level. This can cause load failures if assemblies loaded from this point on require any assemblies currently being loaded.
- OVERRIDE_LOAD_LEVEL_LIMIT(FILE_ACTIVE);
- OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED);
-
- for (i = 0; i < pAttrSet->dwAttrCount; i++)
- {
- CORSEC_ATTRIBUTE *pAttr = &pAttrSet->pAttrs[i];
-
- if (pdwErrorIndex)
- *pdwErrorIndex = pAttr->dwIndex;
-
- // Find the assembly that contains the security attribute class.
- _ASSERTE(pAttr->pName);
- Assembly *pAssembly;
-
- if (bLazy)
- {
- // Convert type name to Unicode
- MAKE_WIDEPTR_FROMUTF8(wszTypeName, pAttr->pName);
-
- {
- // Load the type
- {
- DWORD error = (DWORD)-1;
- NewHolder<TypeName> pTypeName = new TypeName(wszTypeName, &error);
-
- if (error == (DWORD)(-1) && !(pTypeName->GetAssembly()->IsEmpty()))
- {
- hType = pTypeName->GetTypeFromAsm(FALSE);
- }
- else
- {
- hType = TypeName::GetTypeFromAssembly(wszTypeName, SystemDomain::SystemAssembly());
- }
- }
-
- // Special workaround for if the compile-time version of the attribute is no longer available
- if (hType.IsNull() || hType.GetMethodTable() == NULL)
- hType = FindSecurityAttributeHandle(wszTypeName);
- }
- }
- else
- {
- if (!IsNilToken(pAttr->tkAssemblyRef) && TypeFromToken(pAttr->tkAssemblyRef) == mdtAssemblyRef)
- {
- // Load from AssemblyRef token stored in the CORSEC_ATTRSET
- pAssembly = LoadAssemblyFromToken(pAttrSet->pImport, pAttr->tkAssemblyRef);
- }
- else
- {
- // Load from MSCORLIB.
- pAssembly = SystemDomain::SystemAssembly();
- }
- _ASSERTE(pAssembly && "Failed to find assembly with declarative attribute");
-
- EX_TRY
- {
- hType = ClassLoader::LoadTypeByNameThrowing(pAssembly, NULL, pAttr->pName);
- }
- EX_CATCH_THROWABLE(pThrowable);
- }
-
- // Load the security attribute class.
- if (hType.IsNull() || (pMT = hType.GetMethodTable()) == NULL)
- {
- MAKE_WIDEPTR_FROMUTF8(wszTemp, pAttr->pName);
- SString sMessage;
- GetExceptionMessage(*pThrowable, sMessage);
- if (!sMessage.IsEmpty())
- hr = VMPostError(CORSECATTR_E_TYPE_LOAD_FAILED_EX, wszTemp, sMessage.GetUnicode());
- else
- hr = VMPostError(CORSECATTR_E_TYPE_LOAD_FAILED, wszTemp);
- return hr;
- }
-
- // Make sure it's not abstract.
- if (pMT->IsAbstract())
- return VMPostError(CORSECATTR_E_ABSTRACT);
-
-#ifdef _DEBUG
- // Make sure it's really a security attribute class
- /*{
- MethodTable *pParentMT = pMT->GetParentMethodTable();
- CHAR *szClass;
- DefineFullyQualifiedNameForClassOnStack();
- while (pParentMT) {
- szClass = GetFullyQualifiedNameForClass(pParentMT->GetClass());
- if (stricmpUTF8(szClass, COR_BASE_SECURITY_ATTRIBUTE_CLASS_ANSI) == 0)
- break;
- pParentMT = pParentMT->GetParentMethodTable();
- }
- _ASSERTE(pParentMT && "Security attribute not derived from COR_BASE_SECURITY_ATTRIBUTE_CLASS");
- }*/
-#endif
-
- // Instantiate an instance.
- obj[i] = pMT->Allocate();
-
- // Find and call the constructor.
- pMD = MemberLoader::FindConstructor(pMT, &gsig_IM_SecurityAction_RetVoid);
- if (pMD == NULL)
- return VMPostError(CORSECATTR_E_MISSING_CONSTRUCTOR);
- MethodDescCallSite ctor(pMD);
- ARG_SLOT args[] = {
- ObjToArgSlot(obj[i]),
- (ARG_SLOT)pAttrSet->dwAction
- };
- ctor.Call(args);
-
- // Set the attributes and properties
- hr = SetAttrFieldsAndProperties(pAttr, pThrowable, pMT, &obj[i]);
- if (FAILED(hr))
- return hr;
- }
-
- return hr;
-}
-
-
-HRESULT SecurityAttributes::SetAttrFieldsAndProperties(CORSEC_ATTRIBUTE *pAttr, OBJECTREF* pThrowable, MethodTable* pMT, OBJECTREF* pObj)
-{
- // Setup fields and properties on the object, as specified by the
- // serialized data passed to us.
- BYTE *pbBuffer = pAttr->pbValues;
- SIZE_T cbBuffer = pAttr->cbValues;
- BYTE *pbBufferEnd = pbBuffer + cbBuffer;
- DWORD j;
- HRESULT hr = S_OK;
-
- EX_TRY
- {
- for (j = 0; j < pAttr->wValues; j++)
- {
- DWORD dwType = 0;
- BOOL bIsField = FALSE;
- BYTE *pbName;
- DWORD cbName;
- DWORD dwLength;
- NewArrayHolder<CHAR> szName(NULL);
- TypeHandle hEnum;
- CorElementType eEnumType = ELEMENT_TYPE_END;
-
- // Check we've got at least the field/property specifier and the
- // type code.
- if(cbBuffer < (sizeof(BYTE) + sizeof(BYTE)))
- {
- hr = VMPostError(CORSECATTR_E_TRUNCATED);
- goto Error;
- }
-
- // Grab the field/property specifier.
- bIsField = *(BYTE*)pbBuffer == SERIALIZATION_TYPE_FIELD;
- if(!bIsField && *(BYTE*)pbBuffer != SERIALIZATION_TYPE_PROPERTY)
- {
- hr = VMPostError(CORSECATTR_E_TRUNCATED);
- goto Error;
- }
- pbBuffer += sizeof(BYTE);
- cbBuffer -= sizeof(BYTE);
-
- // Grab the value type.
- dwType = *(BYTE*)pbBuffer;
- pbBuffer += sizeof(BYTE);
- cbBuffer -= sizeof(BYTE);
-
- // If it's a type that needs further specification, get that information
- switch (dwType)
- {
- case SERIALIZATION_TYPE_ENUM:
- // Immediately after the enum type token is the fully
- // qualified name of the value type used to represent
- // the enum.
- if (FAILED(CPackedLen::SafeGetData((BYTE const *)pbBuffer,
- (BYTE const *)pbBufferEnd,
- &cbName,
- (BYTE const **)&pbName)))
- {
- hr = VMPostError(CORSECATTR_E_TRUNCATED);
- goto Error;
- }
-
- // SafeGetData ensured that the name is within the buffer
- _ASSERTE(FitsIn<DWORD>((pbName - pbBuffer) + cbName));
- dwLength = static_cast<DWORD>((pbName - pbBuffer) + cbName);
- pbBuffer += dwLength;
- cbBuffer -= dwLength;
-
- // Buffer the name and nul terminate it.
- szName = new (nothrow) CHAR[cbName + 1];
- if (szName == NULL)
- {
- hr = E_OUTOFMEMORY;
- goto Error;
- }
- memcpy(szName, pbName, cbName);
- szName[cbName] = '\0';
-
- // Lookup the type (possibly loading an assembly containing
- // the type).
- hEnum = TypeName::GetTypeUsingCASearchRules(szName, NULL);
-
- //If we couldn't find the type, post an error
- if (hEnum.IsNull())
- {
- MAKE_WIDEPTR_FROMUTF8(wszTemp, szName);
- SString sMessage;
- GetExceptionMessage(*pThrowable, sMessage);
- if (!sMessage.IsEmpty())
- hr = VMPostError(CORSECATTR_E_TYPE_LOAD_FAILED_EX, wszTemp, sMessage.GetUnicode());
- else
- hr = VMPostError(CORSECATTR_E_TYPE_LOAD_FAILED, wszTemp);
- goto Error;
- }
-
- // Calculate the underlying primitive type of the
- // enumeration.
- eEnumType = hEnum.GetInternalCorElementType();
- break;
- case SERIALIZATION_TYPE_SZARRAY:
- case SERIALIZATION_TYPE_TYPE:
- // Can't deal with these yet.
- hr = VMPostError(CORSECATTR_E_UNSUPPORTED_TYPE);
- goto Error;
- }
-
- // Grab the field/property name and length.
- if (FAILED(CPackedLen::SafeGetData((BYTE const *)pbBuffer,
- (BYTE const *)pbBufferEnd,
- &cbName,
- (BYTE const **)&pbName)))
- {
- hr = VMPostError(CORSECATTR_E_TRUNCATED);
- goto Error;
- }
-
- // SafeGetData ensured that the name is within the buffer
- _ASSERTE(FitsIn<DWORD>((pbName - pbBuffer) + cbName));
- dwLength = static_cast<DWORD>((pbName - pbBuffer) + cbName);
- pbBuffer += dwLength;
- cbBuffer -= dwLength;
-
- // Buffer the name and null terminate it.
- szName = new (nothrow) CHAR[cbName + 1];
- if (szName == NULL)
- {
- hr = E_OUTOFMEMORY;
- goto Error;
- }
- memcpy(szName, pbName, cbName);
- szName[cbName] = '\0';
-
- // Set the field or property
- if (bIsField)
- hr = SetAttrField(&pbBuffer, &cbBuffer, dwType, hEnum, pMT, szName, pObj, dwLength, pbName, cbName, eEnumType);
- else
- hr = SetAttrProperty(&pbBuffer, &cbBuffer, pMT, dwType, szName, pObj, dwLength, pbName, cbName, eEnumType);
- }
- }
-Error:;
- EX_CATCH
- {
- hr = GET_EXCEPTION()->GetHR();
- if (pThrowable)
- {
- *pThrowable = GET_THROWABLE();
- }
- }
- EX_END_CATCH(SwallowAllExceptions);
- return hr;
-}
-
-HRESULT SecurityAttributes::SetAttrField(BYTE** ppbBuffer, SIZE_T* pcbBuffer, DWORD dwType, TypeHandle hEnum, MethodTable* pMT, __in_z LPSTR szName, OBJECTREF* pObj, DWORD dwLength, BYTE* pbName, DWORD cbName, CorElementType eEnumType)
-{
- DWORD cbSig = 0;
- NewArrayHolder<BYTE> pbSig(new (nothrow) BYTE[128]);
- if (pbSig == NULL)
- return E_OUTOFMEMORY;
-
- BYTE *pbBufferEnd = *ppbBuffer + *pcbBuffer;
-
- // Build the field signature.
- cbSig += CorSigCompressData((ULONG)IMAGE_CEE_CS_CALLCONV_FIELD, &pbSig[cbSig]);
- switch (dwType)
- {
- case SERIALIZATION_TYPE_BOOLEAN:
- case SERIALIZATION_TYPE_I1:
- case SERIALIZATION_TYPE_I2:
- case SERIALIZATION_TYPE_I4:
- case SERIALIZATION_TYPE_I8:
- case SERIALIZATION_TYPE_U1:
- case SERIALIZATION_TYPE_U2:
- case SERIALIZATION_TYPE_U4:
- case SERIALIZATION_TYPE_U8:
- case SERIALIZATION_TYPE_R4:
- case SERIALIZATION_TYPE_R8:
- case SERIALIZATION_TYPE_CHAR:
- static_assert_no_msg(SERIALIZATION_TYPE_BOOLEAN == (CorSerializationType)ELEMENT_TYPE_BOOLEAN);
- static_assert_no_msg(SERIALIZATION_TYPE_I1 == (CorSerializationType)ELEMENT_TYPE_I1);
- static_assert_no_msg(SERIALIZATION_TYPE_I2 == (CorSerializationType)ELEMENT_TYPE_I2);
- static_assert_no_msg(SERIALIZATION_TYPE_I4 == (CorSerializationType)ELEMENT_TYPE_I4);
- static_assert_no_msg(SERIALIZATION_TYPE_I8 == (CorSerializationType)ELEMENT_TYPE_I8);
- static_assert_no_msg(SERIALIZATION_TYPE_U1 == (CorSerializationType)ELEMENT_TYPE_U1);
- static_assert_no_msg(SERIALIZATION_TYPE_U2 == (CorSerializationType)ELEMENT_TYPE_U2);
- static_assert_no_msg(SERIALIZATION_TYPE_U4 == (CorSerializationType)ELEMENT_TYPE_U4);
- static_assert_no_msg(SERIALIZATION_TYPE_U8 == (CorSerializationType)ELEMENT_TYPE_U8);
- static_assert_no_msg(SERIALIZATION_TYPE_R4 == (CorSerializationType)ELEMENT_TYPE_R4);
- static_assert_no_msg(SERIALIZATION_TYPE_R8 == (CorSerializationType)ELEMENT_TYPE_R8);
- static_assert_no_msg(SERIALIZATION_TYPE_CHAR == (CorSerializationType)ELEMENT_TYPE_CHAR);
- cbSig += CorSigCompressData(dwType, &pbSig[cbSig]);
- break;
- case SERIALIZATION_TYPE_STRING:
- cbSig += CorSigCompressData((ULONG)ELEMENT_TYPE_STRING, &pbSig[cbSig]);
- break;
- case SERIALIZATION_TYPE_ENUM:
- // To avoid problems when the field and enum are defined
- // in different scopes (we'd have to go hunting for
- // typerefs), we build a signature with a special type
- // (ELEMENT_TYPE_INTERNAL, which contains a TypeHandle).
- // This compares loaded types for indentity.
- cbSig += CorSigCompressData((ULONG)ELEMENT_TYPE_INTERNAL, &pbSig[cbSig]);
- cbSig += CorSigCompressPointer(hEnum.AsPtr(), &pbSig[cbSig]);
- break;
- default:
- return VMPostError(CORSECATTR_E_UNSUPPORTED_TYPE);
- }
-
-
- // Locate a field desc.
- FieldDesc* pFD = MemberLoader::FindField(pMT, szName, (PCCOR_SIGNATURE)pbSig,
- cbSig, pMT->GetModule());
- if (pFD == NULL)
- {
- MAKE_WIDEPTR_FROMUTF8(wszTemp, szName);
- return VMPostError(CORSECATTR_E_NO_FIELD, wszTemp);
- }
-
- // Set the field value.
- LPSTR szString;
- switch (dwType)
- {
- case SERIALIZATION_TYPE_BOOLEAN:
- case SERIALIZATION_TYPE_I1:
- case SERIALIZATION_TYPE_U1:
- if(*pcbBuffer < sizeof(BYTE))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- pFD->SetValue8(*pObj, *(BYTE*)(*ppbBuffer));
- (*ppbBuffer) += sizeof(BYTE);
- (*pcbBuffer) -= sizeof(BYTE);
- break;
- case SERIALIZATION_TYPE_CHAR:
- case SERIALIZATION_TYPE_I2:
- case SERIALIZATION_TYPE_U2:
- if(*pcbBuffer < sizeof(WORD))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- pFD->SetValue16(*pObj, GET_UNALIGNED_VAL16(*ppbBuffer));
- (*ppbBuffer) += sizeof(WORD);
- (*pcbBuffer) -= sizeof(WORD);
- break;
- case SERIALIZATION_TYPE_I4:
- case SERIALIZATION_TYPE_U4:
- case SERIALIZATION_TYPE_R4:
- if(*pcbBuffer < sizeof(DWORD))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- pFD->SetValue32(*pObj, GET_UNALIGNED_VAL32(*ppbBuffer));
- (*ppbBuffer) += sizeof(DWORD);
- (*pcbBuffer) -= sizeof(DWORD);
- break;
- case SERIALIZATION_TYPE_I8:
- case SERIALIZATION_TYPE_U8:
- case SERIALIZATION_TYPE_R8:
- if(*pcbBuffer < sizeof(INT64))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- pFD->SetValue64(*pObj, GET_UNALIGNED_VAL64(*ppbBuffer));
- (*ppbBuffer) += sizeof(INT64);
- (*pcbBuffer) -= sizeof(INT64);
- break;
- case SERIALIZATION_TYPE_STRING:
- // Ensures special case 'null' check below does not overrun buffer
- if(*ppbBuffer >= pbBufferEnd) {
- return VMPostError(CORSECATTR_E_TRUNCATED);
- }
- // Special case 'null' (represented as a length byte of '0xFF').
- if (*(*ppbBuffer) == 0xFF) {
- szString = NULL;
- dwLength = sizeof(BYTE);
- } else {
- if (FAILED(CPackedLen::SafeGetData((BYTE const *)*ppbBuffer,
- (BYTE const *)pbBufferEnd,
- &cbName,
- (BYTE const **)&pbName)))
- {
- return VMPostError(CORSECATTR_E_TRUNCATED);
- }
-
- // SafeGetData will ensure the name is within the buffer
- _ASSERTE(FitsIn<DWORD>((pbName - *ppbBuffer) + cbName));
- dwLength = static_cast<DWORD>((pbName - *ppbBuffer) + cbName);
-
- DWORD allocLen = cbName + 1;
- // Buffer and nul terminate it.
- szString = (LPSTR)_alloca(allocLen);
- memcpy(szString, pbName, cbName);
- szString[cbName] = '\0';
-
- }
-
- // Allocate and initialize a managed version of the string.
- {
- STRINGREF orString;
- if (szString)
- {
- orString = StringObject::NewString(szString, cbName);
- if (orString == NULL)
- COMPlusThrowOM();
- }
- else
- orString = NULL;
-
- pFD->SetRefValue(*pObj, (OBJECTREF)orString);
- }
-
- (*ppbBuffer) += dwLength;
- (*pcbBuffer) -= dwLength;
- break;
- case SERIALIZATION_TYPE_ENUM:
- // Get the underlying primitive type.
- switch (eEnumType)
- {
- case ELEMENT_TYPE_I1:
- case ELEMENT_TYPE_U1:
- if(*pcbBuffer < sizeof(BYTE))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- pFD->SetValue8(*pObj, *(BYTE*)(*ppbBuffer));
- (*ppbBuffer) += sizeof(BYTE);
- (*pcbBuffer) -= sizeof(BYTE);
- break;
- case ELEMENT_TYPE_I2:
- case ELEMENT_TYPE_U2:
- if(*pcbBuffer < sizeof(WORD))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- pFD->SetValue16(*pObj, GET_UNALIGNED_VAL16(*ppbBuffer));
- (*ppbBuffer) += sizeof(WORD);
- (*pcbBuffer) -= sizeof(WORD);
- break;
- case ELEMENT_TYPE_I4:
- case ELEMENT_TYPE_U4:
- if(*pcbBuffer < sizeof(DWORD))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- pFD->SetValue32(*pObj, GET_UNALIGNED_VAL32(*ppbBuffer));
- (*ppbBuffer) += sizeof(DWORD);
- (*pcbBuffer) -= sizeof(DWORD);
- break;
- default:
- return VMPostError(CORSECATTR_E_UNSUPPORTED_ENUM_TYPE);
- }
- break;
- default:
- return VMPostError(CORSECATTR_E_UNSUPPORTED_TYPE);
- }
- return S_OK;
-}
-
-HRESULT SecurityAttributes::SetAttrProperty(BYTE** ppbBuffer, SIZE_T* pcbBuffer, MethodTable* pMT, DWORD dwType, __in_z LPSTR szName, OBJECTREF* pObj, DWORD dwLength, BYTE* pbName, DWORD cbName, CorElementType eEnumType)
-{
- CONTRACTL {
- THROWS;
- GC_TRIGGERS;
- PRECONDITION(IsProtectedByGCFrame (pObj));
- } CONTRACTL_END;
-
- // Locate the property setter.
- MethodDesc* pMD = MemberLoader::FindPropertyMethod(pMT, szName, PropertySet);
- if (pMD == NULL)
- {
- MAKE_WIDEPTR_FROMUTF8(wszTemp, szName);
- return VMPostError(CORSECATTR_E_NO_PROPERTY, wszTemp);
- }
-
- MethodDescCallSite propSet(pMD);
-
- // Build the argument list.
- ARG_SLOT args[2] = { NULL, NULL };
- LPSTR szString;
- NewHolder<BYTE> tmpLargeStringHolder (NULL);
-
- switch (dwType)
- {
- case SERIALIZATION_TYPE_BOOLEAN:
- case SERIALIZATION_TYPE_I1:
- case SERIALIZATION_TYPE_U1:
- if(*pcbBuffer < sizeof(BYTE))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- args[1] = (ARG_SLOT)*(BYTE*)(*ppbBuffer);
- (*ppbBuffer) += sizeof(BYTE);
- (*pcbBuffer) -= sizeof(BYTE);
- break;
- case SERIALIZATION_TYPE_CHAR:
- case SERIALIZATION_TYPE_I2:
- case SERIALIZATION_TYPE_U2:
- if(*pcbBuffer < sizeof(WORD))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- args[1] = (ARG_SLOT)GET_UNALIGNED_VAL16(*ppbBuffer);
- (*ppbBuffer) += sizeof(WORD);
- (*pcbBuffer) -= sizeof(WORD);
- break;
- case SERIALIZATION_TYPE_I4:
- case SERIALIZATION_TYPE_U4:
- case SERIALIZATION_TYPE_R4:
- if(*pcbBuffer < sizeof(DWORD))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- args[1] = (ARG_SLOT)GET_UNALIGNED_VAL32(*ppbBuffer);
- (*ppbBuffer) += sizeof(DWORD);
- (*pcbBuffer) -= sizeof(DWORD);
- break;
- case SERIALIZATION_TYPE_I8:
- case SERIALIZATION_TYPE_U8:
- case SERIALIZATION_TYPE_R8:
- if(*pcbBuffer < sizeof(INT64))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- args[1] = (ARG_SLOT)GET_UNALIGNED_VAL64(*ppbBuffer);
- (*ppbBuffer) += sizeof(INT64);
- (*pcbBuffer) -= sizeof(INT64);
- break;
- case SERIALIZATION_TYPE_STRING:
- // Ensures special case 'null' check below does not overrun buffer
- if(*pcbBuffer < sizeof(BYTE)) {
- return VMPostError(CORSECATTR_E_TRUNCATED);
- }
- // Special case 'null' (represented as a length byte of '0xFF').
- if (*(*ppbBuffer) == 0xFF) {
- szString = NULL;
- dwLength = sizeof(BYTE);
- if(*pcbBuffer < sizeof(BYTE))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- } else {
-
- if (FAILED(CPackedLen::SafeGetData((BYTE const *)(*ppbBuffer),
- (BYTE const *)(*ppbBuffer + *pcbBuffer),
- &cbName,
- (BYTE const **)&pbName)))
- {
- return VMPostError(CORSECATTR_E_TRUNCATED);
- }
-
- // Used below - SafeGetData ensures that name is within the buffer
- _ASSERTE(FitsIn<DWORD>((pbName - *ppbBuffer) + cbName));
- dwLength = static_cast<DWORD>((pbName - *ppbBuffer) + cbName);
-
- DWORD allocLen = cbName + 1;
-
- //
- // For smaller size strings allocate from stack, use heap otherwise
- //
-
- if ((pbName - *ppbBuffer) < 4) {
- // Buffer and nul terminate it.
- szString = (LPSTR)_alloca(allocLen);
- } else {
- tmpLargeStringHolder = new BYTE[allocLen];
- szString = (LPSTR) ((BYTE*)tmpLargeStringHolder);
- }
-
- memcpy(szString, pbName, cbName);
- szString[cbName] = '\0';
- }
-
- // Allocate and initialize a managed version of the string.
- {
- STRINGREF orString;
-
- if (szString) {
- orString = StringObject::NewString(szString, cbName);
- if (orString == NULL)
- COMPlusThrowOM();
- } else
- orString = NULL;
-
- args[1] = ObjToArgSlot(orString);
- }
-
- (*ppbBuffer) += dwLength;
- (*pcbBuffer) -= dwLength;
- break;
- case SERIALIZATION_TYPE_ENUM:
- // Get the underlying primitive type.
- switch (eEnumType)
- {
- case ELEMENT_TYPE_I1:
- case ELEMENT_TYPE_U1:
- if(*pcbBuffer < sizeof(BYTE))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- args[1] = (ARG_SLOT)*(BYTE*)(*ppbBuffer);
- (*ppbBuffer) += sizeof(BYTE);
- (*pcbBuffer) -= sizeof(BYTE);
- break;
- case ELEMENT_TYPE_I2:
- case ELEMENT_TYPE_U2:
- if(*pcbBuffer < sizeof(WORD))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- args[1] = (ARG_SLOT)GET_UNALIGNED_VAL16(*ppbBuffer);
- (*ppbBuffer) += sizeof(WORD);
- (*pcbBuffer) -= sizeof(WORD);
- break;
- case ELEMENT_TYPE_I4:
- case ELEMENT_TYPE_U4:
- if(*pcbBuffer < sizeof(DWORD))
- return VMPostError(CORSECATTR_E_TRUNCATED);
- args[1] = (ARG_SLOT)GET_UNALIGNED_VAL32(*ppbBuffer);
- (*ppbBuffer) += sizeof(DWORD);
- (*pcbBuffer) -= sizeof(DWORD);
- break;
- default:
- return VMPostError(CORSECATTR_E_UNSUPPORTED_ENUM_TYPE);
- }
- break;
- default:
- return VMPostError(CORSECATTR_E_UNSUPPORTED_TYPE);
- }
-
-
- // ! don't move this up, StringObject::NewString
- // ! inside the switch causes a GC
- args[0] = ObjToArgSlot(*pObj);
-
- // Call the setter.
- propSet.Call(args);
-
- return S_OK;
-}
-
-
-void SecurityAttributes::AttrSetBlobToPermissionSets(
- IN BYTE* pbRawPermissions,
- IN DWORD cbRawPermissions,
- OUT OBJECTREF* pObj,
- DWORD dwAction)
-{
- CONTRACTL {
- THROWS;
- GC_TRIGGERS;
- } CONTRACTL_END;
-
- _ASSERTE(pbRawPermissions);
- _ASSERTE(cbRawPermissions > 0);
- _ASSERTE(pbRawPermissions[0] == LAZY_DECL_SEC_FLAG);
-
- HRESULT hr = S_OK;
- CORSEC_ATTRSET pset;
-
- // Deserialize the CORSEC_ATTRSET
- hr = BlobToAttributeSet(pbRawPermissions, cbRawPermissions, &pset, dwAction);
- if(FAILED(hr))
- COMPlusThrowHR(hr);
-
- OBJECTREF throwable = NULL;
- GCPROTECT_BEGIN(throwable);
- {
- // allocate and GC-protect an array of objectrefs to reference the permissions
- OBJECTREF* attrArray = (OBJECTREF*)_alloca(pset.dwAttrCount * sizeof(OBJECTREF));
- memset(attrArray, 0, pset.dwAttrCount * sizeof(OBJECTREF));
- GCPROTECT_ARRAY_BEGIN(*attrArray, pset.dwAttrCount);
- {
- // Convert to a managed array of attribute objects
- DWORD dwErrorIndex;
- hr = AttributeSetToManaged(/*OUT*/attrArray, &pset, &throwable, &dwErrorIndex, true);
-
- // Convert the array of attribute objects to a serialized PermissionSet
- if (SUCCEEDED(hr))
- {
- BYTE* pbXmlBlob = NULL;
- DWORD cbXmlBlob = 0;
- BYTE* pbNonCasXmlBlob = NULL;
- DWORD cbNonCasXmlBlob = 0;
-
- AttrArrayToPermissionSet(attrArray,
- false,
- pset.dwAttrCount,
- &pbXmlBlob,
- &cbXmlBlob,
- &pbNonCasXmlBlob,
- &cbNonCasXmlBlob,
- ActionAllowsNullPermissionSet(static_cast<CorDeclSecurity>(dwAction)),
- pObj);
-
- _ASSERTE(pbXmlBlob == NULL && cbXmlBlob == 0 && pbNonCasXmlBlob == NULL && cbNonCasXmlBlob == 0);
- }
- }
- GCPROTECT_END();
- }
- GCPROTECT_END();
-
- if(FAILED(hr))
- COMPlusThrowHR(hr);
-}
-
-HRESULT SecurityAttributes::TranslateSecurityAttributesHelper(
- CORSEC_ATTRSET *pAttrSet,
- BYTE **ppbOutput,
- DWORD *pcbOutput,
- BYTE **ppbNonCasOutput,
- DWORD *pcbNonCasOutput,
- DWORD *pdwErrorIndex)
-{
- CONTRACTL {
- NOTHROW;
- GC_TRIGGERS;
- MODE_COOPERATIVE;
- } CONTRACTL_END;
-
- HRESULT hr = S_OK;
- OBJECTREF *attrArray;
- DWORD dwGlobalError = 0;
-
- EX_TRY
- {
- if (pdwErrorIndex)
- dwGlobalError = *pdwErrorIndex;
-
- // Get into the context of the special compilation appdomain (which has an
- // AppBase set to the current directory).
- ComCallWrapper *pWrap = ComCallWrapper::GetWrapperFromIP(pAttrSet->pAppDomain);
-
- ENTER_DOMAIN_ID(pWrap->GetDomainID())
- {
- struct _gc {
- OBJECTREF throwable;
- OBJECTREF orPermSet;
- } gc;
- ZeroMemory(&gc, sizeof(gc));
- GCPROTECT_BEGIN(gc);
- {
- // we need to setup special security settings that we use during compilation
- SetupRestrictSecAttributes();
-
- // allocate and protect an array of objectrefs to reference the permissions
- attrArray = (OBJECTREF*)_alloca(pAttrSet->dwAttrCount * sizeof(OBJECTREF));
- memset(attrArray, 0, pAttrSet->dwAttrCount * sizeof(OBJECTREF));
- GCPROTECT_ARRAY_BEGIN(*attrArray, pAttrSet->dwAttrCount);
- {
- // Convert to an array of attributes, and then serialize to XML
- hr = AttributeSetToManaged(/*OUT*/attrArray, pAttrSet, &gc.throwable, pdwErrorIndex, false);
- if (SUCCEEDED(hr))
- {
- if (pdwErrorIndex)
- *pdwErrorIndex = dwGlobalError;
-
- // Convert the array of attribute objects to a serialized PermissionSet or PermissionSetCollection
- AttrArrayToPermissionSet(attrArray,
- true,
- pAttrSet->dwAttrCount,
- ppbOutput,
- pcbOutput,
- ppbNonCasOutput,
- pcbNonCasOutput,
- ActionAllowsNullPermissionSet(static_cast<CorDeclSecurity>(pAttrSet->dwAction)),
- &gc.orPermSet);
- }
- }
- GCPROTECT_END();
- }
- GCPROTECT_END(); // for throwable
- }
- END_DOMAIN_TRANSITION;
- }
- EX_CATCH_HRESULT(hr);
- return hr;
-}
-
-// Call into managed code to group permissions into a PermissionSet and serialize it to XML
-void SecurityAttributes::AttrArrayToPermissionSet(OBJECTREF* attrArray,
- bool fSerialize,
- DWORD attrCount,
- BYTE **ppbOutput,
- DWORD *pcbOutput,
- BYTE **ppbNonCasOutput,
- DWORD *pcbNonCasOutput,
- bool fAllowEmptyPermissionSet,
- OBJECTREF* pPermSet)
-{
- CONTRACTL {
- THROWS;
- GC_TRIGGERS;
- MODE_COOPERATIVE;
- } CONTRACTL_END;
-
- EApiCategories eProtectedCategories = (EApiCategories)(GetHostProtectionManager()->GetProtectedCategories());
-
- MethodDescCallSite createSerialized(METHOD__PERMISSION_SET__CREATE_SERIALIZED);
-
- // Allocate a managed array of security attribute objects for input to the function.
- PTRARRAYREF orInput = (PTRARRAYREF) AllocateObjectArray(attrCount, g_pObjectClass);
-
- // Copy over the permission objects references.
- DWORD i;
- for (i = 0; i < attrCount; i++)
- {
- orInput->SetAt(i, attrArray[i]);
- }
-
- // Call the routine.
- struct _gc {
- U1ARRAYREF orNonCasOutput;
- } gc;
- ZeroMemory(&gc, sizeof(gc));
- GCPROTECT_BEGIN(gc);
-
- ARG_SLOT args[] = {
- ObjToArgSlot(orInput),
- BoolToArgSlot(fSerialize),
- PtrToArgSlot(&gc.orNonCasOutput),
- PtrToArgSlot(pPermSet),
- (ARG_SLOT)eProtectedCategories,
- BoolToArgSlot(fAllowEmptyPermissionSet)
- };
- U1ARRAYREF orOutput = NULL;
-
- {
- // Elevate the allowed loading level
- // Elevate thread's allowed loading level. This can cause load failures if assemblies loaded from this point on require any assemblies currently being loaded.
- OVERRIDE_LOAD_LEVEL_LIMIT(FILE_ACTIVE);
- OVERRIDE_TYPE_LOAD_LEVEL_LIMIT(CLASS_LOADED);
-
- orOutput = (U1ARRAYREF) createSerialized.Call_RetOBJECTREF(args);
- }
-
- // Buffer the managed output in a native binary blob.
- // Special case the empty blob. We might get a second blob output if
- // there were any non-CAS permissions present.
- NewArrayHolder<BYTE> TempOutput(NULL);
- NewArrayHolder<BYTE> TempNonCasOutput(NULL);
-
- if (orOutput == NULL)
- {
- *pcbOutput = 0;
- }
- else
- {
- BYTE *pbArray = orOutput->GetDataPtr();
- DWORD cbArray = orOutput->GetNumComponents();
- TempOutput = new BYTE[cbArray];
- memcpy(TempOutput, pbArray, cbArray);
- *pcbOutput = cbArray;
- }
-
- if (gc.orNonCasOutput == NULL)
- {
- *pcbNonCasOutput = 0;
- }
- else
- {
- BYTE *pbArray = gc.orNonCasOutput->GetDataPtr();
- DWORD cbArray = gc.orNonCasOutput->GetNumComponents();
- TempNonCasOutput = new BYTE[cbArray];
- memcpy(TempNonCasOutput, pbArray, cbArray);
- *pcbNonCasOutput = cbArray;
- }
-
- *ppbOutput = TempOutput;
- *ppbNonCasOutput = TempNonCasOutput;
-
- TempOutput.SuppressRelease();
- TempNonCasOutput.SuppressRelease();
-
- GCPROTECT_END();
-}
-#endif // FEATURE_CAS_POLICY
-
//
// This is a public exported method
//
@@ -1363,27 +101,7 @@ HRESULT STDMETHODCALLTYPE TranslateSecurityAttributes(CORSEC_ATTRSET *pAttrSe
DWORD *pcbNonCasOutput,
DWORD *pdwErrorIndex)
{
-#ifdef FEATURE_CAS_POLICY
- CONTRACTL {
- NOTHROW;
- GC_TRIGGERS;
- ENTRY_POINT;
- MODE_ANY;
- } CONTRACTL_END;
- HRESULT hr = S_OK;
-
- BEGIN_ENTRYPOINT_NOTHROW;
-
- GCX_COOP(); // because it calls into managed code to instantiate the PermissionSet objects
- hr = SecurityAttributes::TranslateSecurityAttributesHelper(pAttrSet, ppbOutput, pcbOutput,
- ppbNonCasOutput, pcbNonCasOutput, pdwErrorIndex);
-
- END_ENTRYPOINT_NOTHROW;
-
- return hr;
-#else
return E_NOTIMPL;
-#endif
}