Bonjour

en voulant modifier un de mes programmes sous tokyo qui a été compilé la dernière fois sous Berlin
j'ai des souci avec GetNamedSecurityInfo

En mode debug ça génère une erreur "Violation d'accès à l'adresse 75E5F471 dans le module ADVAPI32.dll ..."
pour essayer de comprendre d’où venais le problème j'ai repris un bous de code pour afficher le sécurité d'un fichier cf plus bas
en mode debug même erreur sur la ligne GetNamedSecurityInfo
en mode Release idem
si j’exécute le programme compilé en mode debug là çà marche
si j’exécute le programme compilé en mode release çà plante avec même message d'erreur
si dans la clause use je mais juste aclAPI, accCtrl au lieu de winapi.aclAPI, winapi.accCtrl çà plante dans tous les cas

Si quelqu'un à une idée sur le pb ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
unit Unit2;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,winapi.aclAPI, winapi.accCtrl,
  Vcl.StdCtrls;
 
type
  TForm2 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;
 
var
  Form2: TForm2;
 
implementation
 
{$R *.dfm}
const
  SID_REVISION  = 1;
  FILENAME_ADVAPI32     = 'ADVAPI32.DLL';
  PROC_CONVERTSIDTOSTRINGSIDA   = 'ConvertSidToStringSidA';
 
type
  TConvertSidToStringSidA = function (Sid: PSID;
    var StringSid: LPSTR): BOOL; stdcall;
 
function WinGetSidStr(Sid : PSid) : string;
var
  SidToStr      : TConvertSidToStringSidA;
  h             : LongWord;
  Buf           : array [0..MAX_PATH - 1] of char;
  p             : PAnsiChar;
begin
  h := LoadLibrary (FILENAME_ADVAPI32);
  if h <> 0 then
  try
    @SidToStr := GetProcAddress (h, PROC_CONVERTSIDTOSTRINGSIDA);
    if @SidToStr <> nil then
    begin
      FillChar (Buf, SizeOf(Buf), 0);
      if SidToStr (Sid, p) then
        Result := '[' + string(p) + ']';
      LocalFree (LongWord(p));
    end;
  finally
    FreeLibrary (h);
  end;
end;
 
function SIdToStr(Sid : PSid): string;
var
  Psia          : PSIDIdentifierAuthority;
  SubAuthCount  : LongWord;
  i             : LongWord;
begin
  if IsValidSid (Sid) then
  begin
    if (Win32Platform = VER_PLATFORM_WIN32_NT) and
      (Win32MajorVersion >= 5) then
      Result := WinGetSidStr(Sid)
    else
    begin
      Psia := GetSidIdentifierAuthority (Sid);
      SubAuthCount := GetSidSubAuthorityCount (Sid)^;
      Result := Format('[S-%u-', [SID_REVISION]);
      if ((Psia.Value[0] <> 0) or (Psia.Value[1] <> 0)) then
        Result := Result + Format ('%.2x%.2x%.2x%.2x%.2x%.2x', [Psia.Value[0],
          Psia.Value[1], Psia.Value[2], Psia.Value[3], Psia.Value[4],
          Psia.Value[5]])
      else
        Result := Result + Format ('%u', [LongWord(Psia.Value[5]) +
          LongWord(Psia.Value[4] shl 8) + LongWord(Psia.Value[3] shl 16) +
          LongWord(Psia.Value[2] shl 24)]);
      for i := 0 to SubAuthCount - 1 do
        Result := Result + Format ('-%u', [GetSidSubAuthority(Sid, i)^]);
      Result := Result + ']';
    end;
end;
end;
 
function GetName(OwnerSID: PSID):String;
var
  OwnerName, DomainName: Array[0..100] of Char;
  cbSize: DWORD;
  OwnerType: SID_NAME_USE;
begin
  cbSize := SizeOf(OwnerName);
  if not LookupAccountSID(nil, OwnerSID, OwnerName,
          cbSize, DomainName, cbSize, OwnerType)
  then result:= SIDToStr(OwnerSID)
  else result:= Format('%s\%s',[DomainName,OwnerName]);
end;
 
function GetLocalUserSidStr (const UserName : string) : string;
var
  RefDomain     : array [0..MAX_PATH - 1] of char;      // enough
  RefDomainSize : LongWord;
  Snu           : SID_NAME_USE;
  Sid           : PSid;
  SidSize       : LongWord;
begin
  SidSize := 0;
  RefDomainSize := SizeOf(RefDomain);
  Sid := nil;
  FillChar (RefDomain, SizeOf(RefDomain), 0);
  LookupAccountName (nil, PChar(UserName), Sid, SidSize, RefDomain,
  RefDomainSize, Snu);
  Sid := AllocMem (SidSize);
  try
    RefDomainSize := SizeOf(RefDomain);
    if LookupAccountName (nil, PChar(UserName), Sid, SidSize, RefDomain,
      RefDomainSize, Snu) then
      Result := SidToStr(Sid);
  finally
    FreeMem (Sid, SidSize);
  end;
end;
 
procedure GetEAList(filename: string; Alist: TStrings);
type
  TEAArray = Array [0..0] of EXPLICIT_ACCESS;
  PEAArray = ^TEAArray;
var
  pSD: PSECURITY_DESCRIPTOR;
  countofexplicitentries: Cardinal;
  ListOfExplicitEntries: PEXPLICIT_ACCESS_A;
  EAList: PEAArray;
  pExplicitAccess: EXPLICIT_ACCESS;
  pDACL: PACL;
  i: integer;
begin
  AList.Clear;
  if not (GetNamedSecurityInfo(PChar(filename),SE_FILE_OBJECT,
           DACL_SECURITY_INFORMATION, Nil, Nil, @pDACL, Nil,
          pSD)=0)
    then Exit;
  GetMem(ListOfExplicitEntries,SizeOf(ListOfExplicitEntries));
  if GetExplicitEntriesFromAcl(pDACL^,countofexplicitentries,@EAList) <>
    ERROR_SUCCESS
    then begin
           FreeMem(ListOfExplicitEntries);
           Exit;
         end;
  AList.Add('countofexplicitentries = ' + inttostr(countofexplicitentries));
  if (countofexplicitentries > 0) then
  for i:= 0 to countofexplicitentries - 1 do
  begin
 
    AList.Add(intToStr(pExplicitAccess.grfAccessPermissions));
 
    pExplicitAccess:= EAList[i];
    AList.Add(GetName(pExplicitAccess.Trustee.ptstrName));
    case pExplicitAccess.Trustee.trusteetype of
      TRUSTEE_IS_USER: Alist.Add('TRUSTEE_IS_USER');
      TRUSTEE_IS_GROUP: Alist.Add('TRUSTEE_IS_GROUP');
      TRUSTEE_IS_DOMAIN: Alist.Add('TRUSTEE_IS_DOMAIN');
      TRUSTEE_IS_ALIAS: Alist.Add('TRUSTEE_IS_ALIAS');
      TRUSTEE_IS_DELETED: Alist.Add('TRUSTEE_IS_DELETED');
      TRUSTEE_IS_INVALID: Alist.Add('TRUSTEE_IS_INVALID');
      TRUSTEE_IS_WELL_KNOWN_GROUP: Alist.Add('TRUSTEE_IS_WELL_KNOWN_GROUP');
      TRUSTEE_IS_UNKNOWN: Alist.Add('TRUSTEE_IS_UNKNOWN');
    end;
    case pExplicitAccess.grfAccessMode of
      NOT_USED_ACCESS: Alist.Add('NOT_USED_ACCESS');
      GRANT_ACCESS: Alist.Add('GRANT_ACCESS');
      SET_ACCESS: Alist.Add('SET_ACCESS');
      DENY_ACCESS: Alist.Add('DENY_ACCESS');
      REVOKE_ACCESS: Alist.Add('REVOKE_ACCESS');
      SET_AUDIT_FAILURE: Alist.Add('SET_AUDIT_FAILURE');
    end;
  end
  else AList.Add('---');
  FreeMem(ListOfExplicitEntries);
  localfree(pSD);
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
   GetEAList('c:\tototiti',listBox1.Items);
end;
 
end.