views:

117

answers:

1

Hi,

I'm using JEDI WSCL to change permissions on a folder during installation. When compiling without Optimization, and with Range Checking, I get a rangecheck when setting the new Access Control List.

procedure SetFilePermissions(const folder: string);
var
  FileObject: TJwSecureFileObject;
  DACL: TJwDAccessControlList;
begin
  FileObject := TJwSecureFileObject.Create(folder);
  try
     DACL := FileObject.DACL;
     JwInitWellknownSIDs;
     DACL.Add(TJwDiscretionaryAccessControlEntryAllow.Create(nil, [afObjectInheritAce],   GENERIC_ALL, JwWorldSID, false));
     FileObject.SetDACL(DACL);
  finally
    FileObject.Free;
  end;
end;

It lookes like it comes from function TJwSecurityId.CreateCopyOfSID( ) in JwsclSid.pas, but I can not find out why.

Do anybody have any clue?

I'm using Delphi 2007, btw, and the wscl code is the latest from sourceforge.

regards,
-Vegar

+7  A: 

The reason is the declaration of the PSID structure. It has a memeber called SubAuthority that is defined as follow:

SubAuthority: array [0..ANYSIZE_ARRAY - 1] of DWORD;

ANYSIZE_ARRAY is a constant that is set to 1 and thus the range of the array is 0 to 0. This is a c construct converted to Delphi but Delphi doesn't know it. The structure is created safely by allocating enough space to allow more than just one DWORD in the array.

This exception happens quite often if you are using variable c structures in Delphi with activated range check error.

However, as a solution you can turn off the switch for JWSCL by opening the jwscl.inc file and add {$R-}. AFAIK the switch lasts only to the end of each unit and then the default value is used. The inc file is included in every single jwscl file.

ChristianWimmer
Wow! Wasn't sure anyone would have an answer, but then it popups up, fast and accurate. Thanks!
Vegar
Probably because wimmer is the maintainer of JWSCL ;)
Runner
Well isn't great that the maintainers are around here (I'm the other one) ;-) If you don't know the "Jedi Windows Security Library" please check it out!
Remko
I agree it is great. And thanks to both of you for doing a great job.
Runner
Wow. I'm obviously short on memory. Got the same problem again. Didn't have a clue of what was wrong. Google pointed me right to my own question on SO, though, so thanks for the answer, again... :-/
Vegar