iads.h (iads.h) IADsSecurityDescriptor 介面

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