?
Solved

Translate C++ to Delphi

Posted on 2003-03-13
3
Medium Priority
?
522 Views
Last Modified: 2010-04-03
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
Comment
Question by:bengore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 2000 total points
ID: 8127620
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
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 8127631
Forgot to replace "}"

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

This should be very near the real thing.
0
 

Author Comment

by:bengore
ID: 8128195
Ok! You get the 500 points!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question