IADsAccessControlList::CopyAccessList 方法 (iads.h)
IADsAccessControlList::CopyAccessList方法會將存取控制專案 (ACE) 複製到呼叫端的進程空間 (ACL) 。
語法
HRESULT CopyAccessList(
[out] IDispatch **ppAccessControlList
);
參數
[out] ppAccessControlList
ACL 的 IDispatch介面指標位址,做為原始存取清單的複本。 如果此參數在傳回時為 Null ,則無法建立 ACL 的複本。
傳回值
這個方法會傳回標準傳回值。
如需其他傳回值的詳細資訊,請參閱 ADSI 錯誤碼。
備註
呼叫端必須透過其 IDispatch指標,在 ACE 複本上呼叫Release。
範例
下列程式碼範例示範如何將 ACL 從一個 ADSI 物件複製到另一個物件。
Dim x As IADs
Dim sd As IADsSecurityDescriptor
Dim Dacl As IADsAccessControlList
Dim CopyDacl As IADsAccessControlList
' Get the ACL from one object.
Set x = GetObject("LDAP://OU=Sales, DC=activeD,DC=mydomain,DC=fabrikam,DC=com")
Set sd = x.Get("ntSecurityDescriptor")
Set Dacl = sd.DiscretionaryAcl
Set CopyDacl = Dacl.CopyAccessList()
' Copy the ACL to another object in the Directory.
Set x = GetObject("LDAP://OU=Sales, DC=Fabrikam,DC=com")
Set sd = x.Get("ntSecurityDescriptor")
sd.DiscretionaryAcl = CopyDacl
x.Put "ntSecurityDescriptor", Array(sd)
x.SetInfo
Cleanup:
If (Err.Number<>0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
Set x = Nothing
Set sd = Nothing
Set Dacl = Nothing
Set CopyDacl = Nothing
下列程式碼範例會將 ACL 從來源物件複製到目標物件。
HRESULT CopyACL(IADs *pSource, IADs *pTarget)
{
IADsSecurityDescriptor *pSourceSD = NULL;
IADsSecurityDescriptor *pTargetSD = NULL;
IDispatch *pDisp = NULL;
HRESULT hr = S_OK;
VARIANT varSource, varTarget;
VariantInit(&varSource);
VariantInit(&varTarget);
if((pSource==NULL) || (pTarget==NULL))
{
return E_FAIL;
}
hr = pSource->Get(CComBSTR("ntSecurityDescriptor"), &varSource);
if(FAILED(hr))
{
goto Cleanup;
}
hr = pTarget->Get(CComBSTR("ntSecurityDescriptor"), &varTarget);
if(FAILED(hr))
{
goto Cleanup;
}
hr = V_DISPATCH(&varSource)->QueryInterface(IID_IADsSecurityDescriptor,
(void**)&pSourceSD);
if(FAILED(hr))
{
goto Cleanup;
}
hr = V_DISPATCH(&varTarget)->QueryInterface(IID_IADsSecurityDescriptor,
(void**)&pTargetSD);
if(FAILED(hr))
{
goto Cleanup;
}
hr = pSourceSD->get_DiscretionaryAcl(&pDisp);
if(FAILED(hr))
{
goto Cleanup;
}
hr = pTargetSD->put_DiscretionaryAcl(pDisp);
if(FAILED(hr))
{
goto Cleanup;
}
hr = pTarget->SetInfo();
Cleanup:
VariantClear(&varSource);
VariantClear(&varTarget);
if(pSourceSD)
{
pSourceSD->Release();
}
if(pTargetSD)
{
pTargetSD->Release();
}
if(pDisp)
{
pDisp->Release();
}
return hr;
}
需求
最低支援的用戶端 | Windows Vista |
最低支援的伺服器 | Windows Server 2008 |
目標平台 | Windows |
標頭 | iads.h |
Dll | Activeds.dll |