AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi WinAPI Problem mit Rechten setzen in der Registry
Thema durchsuchen
Ansicht
Themen-Optionen

WinAPI Problem mit Rechten setzen in der Registry

Ein Thema von RWarnecke · begonnen am 21. Dez 2006 · letzter Beitrag vom 27. Feb 2009
 
Dezipaitor

Registriert seit: 14. Apr 2003
Ort: Stuttgart
1.701 Beiträge
 
Delphi 7 Professional
 
#14

Re: WinAPI Problem mit Rechten setzen in der Registry

  Alt 26. Feb 2009, 13:45
Zitat:
Problem: Ich erhalte bei Registry oder Dateizugriff ERROR_ACCESS_DENIED obwohl ich Owner oder Admin bin
Besitzer zu sein bedeutet, dass man immer das Recht WRITE_DAC hat, auch wenn dies die DACL verweigert. Dann kann man sie anpassen und sich selbst alle Rechte geben.


Beispiel für File Security

Beispiel für Registry Key Security.
Delphi-Quellcode:
program RegKeySecurity;

{.$APPTYPE CONSOLE}

uses
  SysUtils,
  Registry,
  JwaWindows,
  JwsclToken,
  JwsclSecureObjects,
  JwsclPrivileges,
  JwsclAcl,
  JwsclDescriptor,
  JwsclTypes,
  JwsclConstants,
  JwsclKnownSid,
  JwsclUtils,
  JwsclStrings;

procedure SetRegKeySecurity(KeyRoot : HKEY; KeyName : String);
var
  Privs : IJwPrivilegeScope;
  Key : HKEY;
  KeySec : TJwSecureRegistryKey;
  DACL : TJwDAccessControlList;
begin
  JwInitWellKnownSIDs; //inits JwSecurityProcessUserSID

  if RegOpenKeyEx(KeyRoot, PChar(KeyName), 0, KEY_ALL_ACCESS, Key) = ERROR_ACCESS_DENIED then
  begin
    //not necessary since KeySec.TakeOwnerShip(); does it on its own
    //But just show the power of interfaces
    //The privilege will be restored to inactive state when the procedure exists
    Privs := JwGetPrivilegeScope([SE_TAKE_OWNERSHIP_NAME], pst_Enable);

    //First open key for write owner
    if RegOpenKeyEx(KeyRoot, PChar(KeyName), 0, WRITE_OWNER, Key) <> 0 then
      RaiseLastOSError;

    try
      //take ownership - can fail with exception
      TJwSecureRegistryKey.TakeOwnerShip(Key);

      //we need to reopen the handle for further access
      if RegOpenKeyEx(KeyRoot, PChar(KeyName), 0, WRITE_DAC, Key) <> 0 then
        RaiseLastOSError;

      //because access is granted on handle creation we need to
      //recreate the object

      KeySec := TJwSecureRegistryKey.Create(Key);
      try
        DACL := KeySec.DACL; //returns a cached DACL so we must not free it!

        //add process user with full access
        //and also set inheritance
        DACL.Add(TJwDiscretionaryAccessControlEntryAllow.Create(nil, [afContainerInheritAce], KEY_ALL_ACCESS, JwSecurityProcessUserSID));
        //set DACL - may fail with exception
        KeySec.SetDACL(DACL);
      finally
        KeySec.Free;
      end;
    finally
      RegCloseKey(Key)
    end;
  end;
end;

begin
  SetRegKeySecurity(HKEY_CURRENT_USER, 'test');
end.
Christian
Windows, Tokens, Access Control List, Dateisicherheit, Desktop, Vista Elevation?
Goto: JEDI API LIB & Windows Security Code Library (JWSCL)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:41 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz