IADsAccessControlList::AddAce, méthode (iads.h)
La méthode IADsAccessControlList::AddAce ajoute un objet IADsAccessControlEntry à l’objet IADsAccessControlList .
Syntaxe
HRESULT AddAce(
[in] IDispatch *pAccessControlEntry
);
Paramètres
[in] pAccessControlEntry
Pointeur vers l’interface IDispatch de l’objet IADsAccessControlEntry à ajouter. Ce paramètre ne peut pas avoir la valeur NULL.
Valeur retournée
Retourne une valeur HRESULT standard, y compris ce qui suit.
Notes
Les entrées de contrôle d’accès doivent apparaître dans l’ordre suivant dans la liste de contrôle d’accès d’un descripteur de sécurité :
- AE refusés à l’accès qui s’appliquent à l’objet lui-même
- AES refusés à l’accès qui s’appliquent à un enfant de l’objet, comme un jeu de propriétés ou une propriété
- AES autorisés à accéder qui s’appliquent à l’objet lui-même
- AES autorisés à accéder qui s’appliquent à un enfant de l’objet, comme un jeu de propriétés ou une propriété
- Tous les AE hérités
Exemples
L’exemple de code Visual Basic suivant montre comment utiliser la méthode IADsAccessControlList::AddAce pour ajouter deux AES à une liste de contrôle d’accès.
Const ACL_REVISION_DS = &H4
Dim x as IADs
Dim sd as IADsSecurityDescriptor
Dim Ace1 As new IADsAccessControlEntry
Dim Ace2 As new IADsAccessControlEntry
Dim Dacl As new IADsAccessControlList
On Error GoTo Cleanup
Set x = GetObject("LDAP://OU=Sales,DC=Fabrikam,DC=com")
Set sd = x.Get("ntSecurityDescriptor")
' Add the ACEs to the Discretionary ACL.
Dacl.AclRevision = ACL_REVISION_DS 'DS ACL Revision
' Set up the first ACE.
Ace1.AccessMask = -1 'Full Permission (Allowed)
Ace1.AceType = ADS_ACETYPE_ACCESS_ALLOWED
Ace1.AceFlags = ADS_ACEFLAG_INHERIT_ACE
Ace1.Trustee = "myMachine\Administrator"
' Set up the 2nd ACE.
Ace2.AccessMask = -1 'Full Permission (Denied)
Ace2.AceType = ADS_ACETYPE_ACCESS_DENIED
Ace2.AceFlags = ADS_ACEFLAG_INHERIT_ACE
Ace2.Trustee = "aDomain\aUser"
' Add the ACEs to the Discretionary ACL.
Dacl.AddAce Ace1
Dacl.AddAce Ace2
'Commit the changes.
sd.DiscretionaryAcl = Dacl
x.Put "ntSecurityDescriptor", Array(sd)
x.SetInfo
Cleanup:
If (Err.Number<>0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
Set Ace1 = Nothing
Set Ace2 = Nothing
Set Dacl = Nothing
Set x = Nothing
Set sd = Nothing
L’exemple de code C++ suivant ajoute un ACE à une liste de contrôle d’accès à l’aide de la méthode IADsAccessControlList::AddAce . L’ACE ajouté a autorisé les droits d’accès avec l’autorisation complète.
HRESULT addAceTo(IADsAccessControlList *pAcl)
{
if(!pAcl)
{
return E_FAIL;
}
HRESULT hr = pAcl->put_AclRevision(ACL_REVISION_DS);
if(FAILED(hr))
{
return hr;
}
IADsAccessControlEntry *pAce = NULL;
pAce = createAce(-1, // Full permissions.
ADS_ACETYPE_ACCESS_ALLOWED,
ADS_ACEFLAG_INHERIT_ACE,
CComBSTR("aDomain\\aUser"));
if(!pAce)
{
return E_FAIL;
}
IDispatch *pDisp;
hr = pAce->QueryInterface(IID_IDispatch,(void**)&pDisp);
if(FAILED(hr))
{
pAce->Release();
return hr;
}
hr = pAcl->AddAce(pDisp);
pDisp->Release();
if(pAce) pAce->Release();
if(FAILED(hr))
{
return hr;
}
printf("Ace has been added to ACL.\n");
return hr;
}
////////////////////////////////////
// function to create an allowed ACE
////////////////////////////////////
IADsAccessControlEntry *createAce(
long mask,
long type,
long flag,
BSTR trustee)
{
HRESULT hr;
IADsAccessControlEntry *pAce;
hr = CoCreateInstance(CLSID_AccessControlEntry,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsAccessControlEntry,
(void**)&pAce);
if(FAILED(hr))
{
if(pAce)
{
pAce->Release();
}
return NULL;
}
hr = pAce->put_AccessMask(mask);
hr = pAce->put_AceType(type);
hr = pAce->put_AceFlags(flag);
hr = pAce->put_Trustee(trustee);
return pAce;
}
Configuration requise
Client minimal pris en charge | Windows Vista |
Serveur minimal pris en charge | Windows Server 2008 |
Plateforme cible | Windows |
En-tête | iads.h |
DLL | Activeds.dll |
Voir aussi
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour