var
lObj: IDirectoryObject;
lAttrs:
array of PWideChar;
lAttrEntries: PAdsAttrInfoArray;
lAttrCount: Cardinal;
lSD: PSECURITY_DESCRIPTOR;
// lSDSize: Cardinal;
lSID: PSID;
lAbsSD: PSECURITY_DESCRIPTOR;
lAbsSDSize: Cardinal;
lDacl: PACL;
lDaclSize: Cardinal;
lSacl: PACL;
lSaclSize: Cardinal;
lOwner: PSID;
lOwnerSize: Cardinal;
lGroup: PSID;
lGroupSize: Cardinal;
lJwSD: TJwSecurityDescriptor;
lJwSelfSid: TJwSecurityId;
lJwTypes: TJwObjectTypeArray;
lJwMapping: TJwSecurityGenericMappingClass;
lJwPrivSet: TJwPrivilegeSet;
lJwGrantedAccess: TJwAccessMaskArray;
lJwStatus: TJwCardinalArray;
lDesiredAccess: Cardinal;
lItm: TListItem;
lTypeGUID: TGUID;
begin
if Failed(ADsGetObject(PWideChar('
LDAP://' + ObjDN_CB.Text),
IDirectoryObject,
Pointer(lObj)))
then Exit;
SetLength(lAttrs, 2);
lAttrs[0] := '
nTSecurityDescriptor';
lAttrs[1] := '
objectSID';
if Failed(lObj.GetObjectAttributes(@lAttrs[0],
Length(lAttrs),
PADS_ATTR_INFO(lAttrEntries),
lAttrCount))
then Exit;
lSD := PSECURITY_DESCRIPTOR(lAttrEntries[0].pADsValues.SecurityDescriptor.lpValue);
// lSDSize := lAttrEntries[0].pADsValues.SecurityDescriptor.dwLength;
lSID := PSID(lAttrEntries[1].pADsValues.OctetString.lpValue);
lAbsSD :=
nil; lDacl :=
nil; lSacl :=
nil; lOwner :=
nil; lGroup :=
nil;
if not MakeAbsoluteSD(lSD, lAbsSD, lAbsSDSize, lDacl, lDaclSize, lSacl, lSaclSize, lOwner, lOwnerSize, lGroup, lGroupSize)
then
begin
lAbsSD := PSECURITY_DESCRIPTOR(LocalAlloc(0, lAbsSDSize));
lDacl := PACL(LocalAlloc(0, lDaclSize));
lSacl := PACL(LocalAlloc(0, lSaclSize));
lOwner := PSID(LocalAlloc(0, lOwnerSize));
lGroup := PSID(LocalAlloc(0, lGroupSize));
if not MakeAbsoluteSD(lSD, lAbsSD, lAbsSDSize, lDacl, lDaclSize, lSacl, lSaclSize, lOwner, lOwnerSize, lGroup, lGroupSize)
then
begin
FreeAdsMem(Pointer(lAttrEntries));
Abort;
end;
end;
lDesiredAccess := ADS_RIGHT_DS_CONTROL_ACCESS;
// = $00000100
lJwSD := TJwSecurityDescriptor.Create(lAbsSD);
// <<<--- Exception hier
try
lJwSelfSid := TJwSecurityId.Create(lSID);
try
SetLength(lJwTypes, 1);
lTypeGUID := StringToGuid(ObjTypeGuid_CB.Text);
lJwTypes[0].Level := ACCESS_OBJECT_GUID;
lJwTypes[0].Sbz := 0;
lJwTypes[0].ObjectType := @lTypeGUID;
lJwMapping := TJwSecurityGenericMapping;
TJwSecureGeneralObject.AccessCheckByTypeResultList(lJwSD, lJwSelfSid,
nil, lDesiredAccess, lJwTypes, lJwMapping, lJwPrivSet, lJwGrantedAccess, lJwStatus);
finally
lJwSelfSid.Free;
end;
finally
lJwSD.Free;
end;
end;