IADsAccessControlList::CopyAccessList 方法 (iads.h)

IADsAccessControlList::CopyAccessList 方法将访问控制列表中的每个访问控制项 (ACE) 复制到调用方的进程空间 (ACL) 。

语法

HRESULT CopyAccessList(
  [out] IDispatch **ppAccessControlList
);

parameters

[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

另请参阅

IADsAccessControlEntry

IADsAccessControlList

IADsSecurityDescriptor