Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 524
  • Last Modified:

Translate C++ to Delphi

Hello,
simply translate the following C code to Delphi ;-)
Perhaps you can not translate the first lines directly. (I think you have to use one of the Delphi functions:
AllocateAndInitializeSid
BuildExplicitAccessWithName
http://msdn.microsoft.com/library/en-us/security/security/taking_object_ownership.asp
http://msdn.microsoft.com/library/en-us/security/security/creating_a_security_descriptor_for_a_new_object.asp
)

Thank you for your help!


---- Start of C code -------------

BOOL AdjustDacl(HANDLE h, DWORD DesiredAccess)
{
// the WORLD Sid is trivial to form programmatically (S-1-1-0)
   SID world = { SID_REVISION, 1, SECURITY_WORLD_SID_AUTHORITY, 0 };

   EXPLICIT_ACCESS ea =
   {
      DesiredAccess,
      SET_ACCESS,
      NO_INHERITANCE,
      {
         0, NO_MULTIPLE_TRUSTEE,
         TRUSTEE_IS_SID,
         TRUSTEE_IS_USER,
         reinterpret_cast<LPTSTR>(&world)
      }
   };
   ACL* pdacl = 0;
   DWORD err = SetEntriesInAcl(1, &ea, 0, &pdacl);
   if (err == ERROR_SUCCESS)
   {
      err = SetSecurityInfo(h, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, 0, 0, pdacl, 0);
      LocalFree(pdacl);
      return(err == ERROR_SUCCESS);
   }
   else
      return(FALSE);
}
0
bengore
Asked:
bengore
  • 2
1 Solution
 
robert_marquardtCommented:
Get the big Win32 conversion from Marcel van Brakel.
http://delphi-jedi.org/APILIBRARY
I contains JwaAclApi.pas which in turn contains SetEntriesInAcl.

For the rest i try it directly here. I hope the types and consts are all somewhere in Marcels conversion.

function AdjustDacl(h: THandle; DesiredAccess: DWORD): LongBool;
// the WORLD Sid is trivial to form programmatically (S-1-1-0)
const
  cWorld: SID = ( SID_REVISION, 1, SECURITY_WORLD_SID_AUTHORITY, 0 };
var
  world: SID;
  ea: EXPLICIT_ACCESS;
  pdacl: PACL;
  err: DWORD;
begin
  world := cWorld;
  ea.grfAccessPermissions := DesiredAccess;
  ea.grfAccessMode := SET_ACCESS;
  ea.grfInheritance := NO_INHERITANCE;
  ea.Trustee.pMultipleTrustee := nil;
  ea.Trustee.MultipleTrusteeOperation := NO_MULTIPLE_TRUSTEE;
  ea.Trustee.TrusteeForm := TRUSTEE_IS_SID;
  ea.Trustee.TrusteeType := TRUSTEE_IS_USER;
  ea.Trustee.ptstrName := PChar(@world);
  pdacl := nil;
  err := SetEntriesInAcl(1, @ea, nil, pdacl);
  Result := err = ERROR_SUCCESS;
  if Result then
  begin
    err := SetSecurityInfo(h, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, nil, nil, pdacl, nil);
     LocalFree(pdacl);
     Result := err = ERROR_SUCCESS;
  end;
end;
0
 
robert_marquardtCommented:
Forgot to replace "}"

  SID world = { SID_REVISION, 1, SECURITY_WORLD_SID_AUTHORITY, 0);

This should be very near the real thing.
0
 
bengoreAuthor Commented:
Ok! You get the 500 points!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now