IADsSecurityDescriptor 接口 (iads.h)

IADsSecurityDescriptor 接口提供对 ADSI 安全描述符对象上的属性的访问。

继承

IADsSecurityDescriptor 接口继承自 IDispatch 接口。 IADsSecurityDescriptor 还具有以下类型的成员:

方法

IADsSecurityDescriptor 接口包含以下方法。

 
IADsSecurityDescriptor::CopySecurityDescriptor

IADsSecurityDescriptor::CopySecurityDescriptor 方法复制保存有关对象的安全数据的 ADSI 安全描述符对象。

注解

使用此接口检查访问控制并将其更改为 Active Directory 目录服务对象。 还可以使用它来创建安全描述符的副本。 若要获取此接口,请使用 IADs.Get 方法获取对象的 ntSecurityDescriptor 属性。 有关如何创建新的安全描述符并在对象上设置它的详细信息,请参阅 为新目录对象创建安全描述符Null DACL 和空 DACL

通常,无法修改安全描述符的所有部分。 例如,如果当前用户完全控制对象,但不是管理员且不拥有该对象,则用户可以修改 DACL,但不能修改所有者。 更新 ntSecurityDescriptor 时,这将导致错误。 为了避免此问题, 可以使用 IADsObjectOptions 接口来指定应修改的安全描述符的特定部分。

示例

下面的代码示例演示如何使用 IADsObjectOptions 接口来仅修改安全描述符的特定部分。

Const ADS_OPTION_SECURITY_MASK = 3
Const ADS_SECURITY_INFO_OWNER = 1
Const ADS_SECURITY_INFO_GROUP = 2
Const ADS_SECURITY_INFO_DACL = 4

Dim obj as IADs
Dim sd as IADsSecurityDescriptor
Dim oOptions as IADsObjectOptions

' Bind to the object.
Set obj = GetObject("LDAP://.....")

' Get the IADsSecurityDescriptor.
Set sd = obj.Get("ntSecurityDescriptor")

' Modify the DACL as required.

' Get the IADsObjectOptions for the object - not the IADsSecurityDescriptor.
Set oOptions = obj

' Set options so that only the DACL will be updated.
oOptions.SetOption ADS_OPTION_SECURITY_MASK, ADS_INFO_DACL

' Update the security descriptor.
obj.Put "ntSecurityDescriptor", sd
obj.SetInfo

下面的代码示例演示如何显示安全描述符中的数据。

' Get the security descriptor.
Dim x As IADs
Dim sd As IADsSecurityDescriptor

On Error GoTo Cleanup
 
Set x = GetObject("LDAP://DC=Fabrikam,DC=com")
Set sd = x.Get("ntSecurityDescriptor")
Debug.Print sd.Control
Debug.Print sd.Group
Debug.Print sd.Owner
Debug.Print sd.Revision
 
Cleanup:
    If (Err.Number<>0) Then
        MsgBox("An error has occurred. " & Err.Number)
    End If
    Set x = Nothing
    Set sd = Nothing

下面的代码示例演示如何显示目录对象的安全描述符中的数据。

HRESULT DisplaySD(IADs *pObj)
{
    IADsSecurityDescriptor *pSD = NULL;
    BSTR bstr = NULL;
    long lVal = 0;    
    HRESULT hr = S_OK;
    VARIANT var;
    
    VariantInit(&var);

    if(pObj==NULL)
    {
        return E_FAIL;
    }
    
    hr = pObj->Get(CComBSTR("ntSecurityDescriptor"), &var);
    if(FAILED(hr)){goto Cleanup;}
    
    
    hr = V_DISPATCH(&var)->QueryInterface(IID_IADsSecurityDescriptor,(void**)&pSD);
    if(FAILED(hr)){goto Cleanup;}
    
   hr = pSD->get_Control(&lVal);
   printf("SD Control = %d\n",lVal);

   hr = pSD->get_Owner(&bstr);
   printf("SD Owner   = %S\n",bstr);
   SysFreeString(bstr);

   hr = pSD->get_Group(&bstr);
   printf("SD Group   = %S\n",bstr);
   SysFreeString(bstr);

   hr = pSD->get_Revision(&lVal);
   printf("SD Revision= %d\n",lVal);
        
Cleanup:
    VariantClear(&var);
    if(pSD) pSD->Release();
    return hr;
}

要求

要求
最低受支持的客户端 Windows Vista
最低受支持的服务器 Windows Server 2008
目标平台 Windows
标头 iads.h

另请参阅

为新目录对象创建安全描述符

IADsAccessControlEntry

IADsAccessControlList

IDispatch

Null DACL 和空 DACL