Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

245 lines
5.3 KiB

//+---------------------------------------------------------------------------
//
// Microsoft Windows
// Copyright (C) Microsoft Corporation, 1992 - 1995.
//
// File: libmain.cxx
//
// Contents: LibMain for nds.dll
//
// Functions: LibMain, DllGetClassObject
//
// History: 25-Oct-94 KrishnaG Created.
//
//----------------------------------------------------------------------------
#include "nds.hxx"
#pragma hdrstop
HRESULT
ConvertNDSAclVArrayToSecDesVar(
PVARIANT pVarArrayNDSAcl,
PVARIANT pVarSecDes
)
{
HRESULT hr = S_OK;
IADsSecurityDescriptor * pSecDes = NULL;
IDispatch * pDispatch = NULL;
VARIANT varDACL;
VariantInit(pVarSecDes);
memset(&varDACL, 0, sizeof(VARIANT));
hr = ConvertNDSAclVArrayToAclVariant(
pVarArrayNDSAcl,
&varDACL
);
BAIL_ON_FAILURE(hr);
hr = CoCreateInstance(
CLSID_SecurityDescriptor,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsSecurityDescriptor,
(void **)&pSecDes
);
BAIL_ON_FAILURE(hr);
hr = pSecDes->put_DiscretionaryAcl(V_DISPATCH(&varDACL));
BAIL_ON_FAILURE(hr);
hr = pSecDes->QueryInterface(IID_IDispatch, (void**)&pDispatch);
BAIL_ON_FAILURE(hr);
V_VT(pVarSecDes) = VT_DISPATCH;
V_DISPATCH(pVarSecDes) = pDispatch;
error:
if (pSecDes) {
pSecDes->Release();
}
RRETURN(hr);
}
HRESULT
ConvertNDSAclVArrayToAclVariant(
PVARIANT pVarArrayNDSACL,
PVARIANT pVarACL
)
{
IADsAccessControlList *pAccessControlList = NULL;
IDispatch *pDispatch = NULL;
VARIANT *pVarArray = NULL;
VARIANT varAce;
DWORD i = 0;
HRESULT hr = S_OK;
DWORD dwNumValues;
DWORD dwNewAceCount = 0;
VariantInit(pVarACL);
hr = CoCreateInstance(
CLSID_AccessControlList,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsAccessControlList,
(void **)&pAccessControlList
);
BAIL_ON_FAILURE(hr);
hr = ConvertSafeArrayToVariantArray(
*pVarArrayNDSACL,
&pVarArray,
&dwNumValues
);
BAIL_ON_FAILURE(hr);
for (i = 0; i < dwNumValues; i++) {
hr = ConvertNDSAclVariantToAceVariant(
&(pVarArray[i]),
(PVARIANT)&varAce
);
hr = pAccessControlList->AddAce(V_DISPATCH(&varAce));
if (SUCCEEDED(hr)) {
dwNewAceCount++;
}
VariantClear(&varAce);
}
pAccessControlList->put_AceCount(dwNewAceCount);
hr = pAccessControlList->QueryInterface(
IID_IDispatch,
(void **)&pDispatch
);
V_VT(pVarACL) = VT_DISPATCH;
V_DISPATCH(pVarACL) = pDispatch;
error:
if (pAccessControlList) {
pAccessControlList->Release();
}
if (pVarArray)
{
DWORD i = 0;
for (i = 0; i < dwNumValues; i++) {
VariantClear(pVarArray + i);
}
FreeADsMem(pVarArray);
}
RRETURN(hr);
}
HRESULT
ConvertNDSAclVariantToAceVariant(
PVARIANT pvarNDSAce,
PVARIANT pvarAce
)
{
HRESULT hr = S_OK;
IADsAccessControlEntry *pAccessControlEntry = NULL;
IDispatch *pDispatch = NULL;
IADsAcl *pSecDes = NULL;
DWORD dwPrivileges = 0;
BSTR bstrProtectedAttrName = NULL;
BSTR bstrSubjectName = NULL;
if (V_VT(pvarNDSAce) != VT_DISPATCH){
hr = E_FAIL;
BAIL_ON_FAILURE(hr);
}
pDispatch = V_DISPATCH(pvarNDSAce);
hr = pDispatch->QueryInterface(
IID_IADsAcl,
(void **)&pSecDes
);
BAIL_ON_FAILURE(hr);
hr = pSecDes->get_ProtectedAttrName(
&bstrProtectedAttrName
);
BAIL_ON_FAILURE(hr);
hr = pSecDes->get_SubjectName(
&bstrSubjectName
);
BAIL_ON_FAILURE(hr);
hr = pSecDes->get_Privileges(
(LONG *)&dwPrivileges);
BAIL_ON_FAILURE(hr);
VariantInit(pvarAce);
hr = CoCreateInstance(
CLSID_AccessControlEntry,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsAccessControlEntry,
(void **)&pAccessControlEntry
);
BAIL_ON_FAILURE(hr);
hr = pAccessControlEntry->put_AccessMask(dwPrivileges);
BAIL_ON_FAILURE(hr);
hr = pAccessControlEntry->put_Trustee(bstrSubjectName);
BAIL_ON_FAILURE(hr);
hr = pAccessControlEntry->put_ObjectType(bstrProtectedAttrName);
BAIL_ON_FAILURE(hr);
hr = pAccessControlEntry->QueryInterface(
IID_IDispatch,
(void **)&pDispatch
);
BAIL_ON_FAILURE(hr);
V_DISPATCH(pvarAce) = pDispatch;
V_VT(pvarAce) = VT_DISPATCH;
cleanup:
if (pSecDes) {
pSecDes->Release();
}
if (pAccessControlEntry) {
pAccessControlEntry->Release();
}
RRETURN(hr);
error:
if (pDispatch) {
pDispatch->Release();
}
if (pSecDes) {
pSecDes->Release();
}
if (pAccessControlEntry) {
pAccessControlEntry->Release();
}
goto cleanup;
}