Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#3

Re: Dateizugriffsrechte auslesen

  Alt 23. Jun 2006, 12:22
Das ist bisher alles:
Delphi-Quellcode:
(******************************************************************************
*                                                                            *
*  FileOwner                                                                *
*  FileOwner.dpr -- Demo "Was ist die SID?"                                  *
*                                                                            *
*  Copyright (c) 2006 Michael Puff  [url]http://www.michael-puff.de[/url]              *
*                                                                            *
******************************************************************************)


program FileACL;

{$APPTYPE CONSOLE}

uses
  Windows, SysUtils;
  
type
  SE_OBJECT_TYPE = (
    SE_UNKNOWN_OBJECT_TYPE,
    SE_FILE_OBJECT,
    SE_SERVICE,
    SE_PRINTER,
    SE_REGISTRY_KEY,
    SE_LMSHARE,
    SE_KERNEL_OBJECT,
    SE_WINDOW_OBJECT,
    SE_DS_OBJECT,
    SE_DS_OBJECT_ALL,
    SE_PROVIDER_DEFINED_OBJECT,
    SE_WMIGUID_OBJECT
    );

function ConvertSidToStringSidW(SID: PSID; var StringSid: LPWSTR): Boolean; stdcall;
    external 'advapi32.dllname 'ConvertSidToStringSidW';


function GetNamedSecurityInfoW(pObjectName: PWideChar; ObjectType: SE_OBJECT_TYPE; SecurityInfo: SECURITY_INFORMATION;
  var ppsidOwner: PSID; var ppsidGroup: PSID; var ppDacl: PACL; var ppSacl: PACL; var ppSecurityDescriptor:
  PSecurity_Descriptor): DWORD; stdcall; external 'Advapi32.dll';

function SysErrorMessage(ErrorCode: Integer): string;
var
  Len : Integer;
  Buffer : array[0..255] of Char;
begin
  Len := FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_ARGUMENT_ARRAY, nil, ErrorCode, 0, Buffer,
    SizeOf(Buffer), nil);
  while (Len > 0) and (Buffer[Len - 1] in [#0..#32, '.']) do
    Dec(Len);
  SetString(Result, Buffer, Len);
end;


function GetFileACL(const Filename: WideString): PACL;
var
  sidOwner, sidGroup: PSID;
  dacl, sacl : PACL;
  psd : PSECURITY_DESCRIPTOR;
begin
  result := nil;
  if GetNamedSecurityInfoW(PWideChar(Filename), SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION, sidOwner, sidGroup, dacl,
    sacl, psd) = 0 then
  begin
    result := dacl;
  end;
end;

var
  s: WideString;
  err: DWORD;
  sid: PSID;

begin
  Writeln('Datei' + #9 + ': ' + ExtractFilename(ParamStr(0)));
  sid := GetFileACL(ParamStr(0));
  if Assigned(sid) then
  begin

  end
  else
    Writeln(SyserrorMessage(err));
  Readln;
end.
Wie gesagt, ich weiß jetzt nicht genau, wie es weitergehen soll und mit welchen API-Funktionen.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat