Platform SDK: Active Directory, ADSI, and Directory Services

IADsSecurityDescriptor::CopySecurityDescriptor

The IADsSecurityDescriptor::CopySecurityDescriptor method copies an ADSI security descriptor object that holds security information about an object.

HRESULT CopySecurityDescriptor(
  IDispatch ** ppSecurityDescriptor
);

Parameters

[out] ppSecurityDescriptor
Pointer to a security descriptor object.

Return Values

This method returns the standard return values, including E_INVALIDARG, E_OUTOFMEMORY, E_UNEXPECTED, and E_FAIL, as well as S_OK. For other return values, see ADSI Error Codes.

Example Code [Visual Basic]

Dim sd As IADsSecurityDescriptor
Dim sdNew As IADsSecurityDescriptor
 
Set ou = GetObject("LDAP://OU=Sales,DC=Fabrikam,DC=com")
Set sd = ou.Get("ntSecurityDescriptor")
Set sdNew = sd.CopySecurityDescriptor
ou.Put "ouSD", sdNew
ou.SetInfo

Example Code [C++]

The following C++ code snippet creates a private security descriptor by copying from an existing one, using IADsSecurityDescriptor::CopySecurityDescriptor.

IADsSecurityDescriptor *getSD(IADs*); // See IADsSecurityDescriptor

HRESULT copySD(IADs *pADsFrom, IADs *pADsTo)
{
   IADsSecurityDescriptor *psdFrom = NULL;

   // get the security descriptor from the source object
   psdFrom = getSD(pADsFrom);
   if(!psdFrom) return E_FAIL;

   // copy the source SD to the destination object.
   IDispatch *pDisp=NULL;
   HRESULT hr;
   hr = psdFrom->CopySecurityDescriptor(&pDisp);
   if(FAILED(hr)) {
      psd->Release();
      return hr;
   }

   VARIANT var;
   VariantInit(&var);
   V_DISPATCH(&var)=pDisp;
   V_VT(&var)=VT_DISPATCH;

   pADsTo->Put(L"privateSD",var);
   VariantClear(&var);
   if(psdFrom) psdFrom->Release();

   // commit the change to the directory
   pADsTo->SetInfo();
   return S_OK;
}

Requirements

  Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
  Windows 95/98: Requires Windows 95 or later (with DSClient).
  Header: Declared in Iads.h.

See Also

IADsAccessControlEntry, IADsAccessControlList