IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API, COM et SDKs Delphi Discussion :

Problème avec GetNamedSecurityInfo sous Tokyo 10.2


Sujet :

API, COM et SDKs Delphi

  1. #1
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2003
    Messages
    167
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : Distribution

    Informations forums :
    Inscription : Décembre 2003
    Messages : 167
    Points : 208
    Points
    208
    Par défaut Problème avec GetNamedSecurityInfo sous Tokyo 10.2
    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.

  2. #2
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2003
    Messages
    167
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : Distribution

    Informations forums :
    Inscription : Décembre 2003
    Messages : 167
    Points : 208
    Points
    208
    Par défaut
    Bon je viens de tester avec Berlin et là plus de problèmes
    il semble que la déclaration de GetNamedSecurityInfo ait changé entre les deux version
    pour berlin

    Nom : berlin.jpg
Affichages : 317
Taille : 52,6 Ko

    pour tokyo

    Nom : tokyo.jpg
Affichages : 371
Taille : 64,2 Ko

  3. #3
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 445
    Points
    28 445
    Par défaut
    sous Berlin :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    function GetNamedSecurityInfo(pObjectName: LPWSTR; ObjectType: SE_OBJECT_TYPE;
             SecurityInfo: SECURITY_INFORMATION; ppsidOwner, ppsidGroup: PPSID; ppDacl, ppSacl: PACL;
             var ppSecurityDescriptor: PSECURITY_DESCRIPTOR): DWORD; stdcall;
    sous Tokyo:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    function GetNamedSecurityInfo(pObjectName: LPWSTR; ObjectType: SE_OBJECT_TYPE;
             SecurityInfo: SECURITY_INFORMATION; ppsidOwner, ppsidGroup: PPSID; ppDacl, ppSacl: PPACL;
             ppSecurityDescriptor: PPSECURITY_DESCRIPTOR): DWORD; stdcall;
    ils ont remplacé le "var pointer" par un "ppointer" fonctionnellement c'est la même chose mais du coup tu dois ajouter un {$IFDEF VER320}@{$ENDIF}pSD

    parfois je préfère redéclarer la fonction plutôt que de garnir mon code avec des $IFDEF...
    Developpez.com: Mes articles, forum FlashPascal
    Entreprise: Execute SARL
    Le Store Excute Store

  4. #4
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2003
    Messages
    167
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : Distribution

    Informations forums :
    Inscription : Décembre 2003
    Messages : 167
    Points : 208
    Points
    208
    Par défaut
    Bonjour Paul TOTH

    En effet en ajoutant le @ cela fonctionne
    je venais juste de résoudre mon pb
    galère ces changement de déclaration surtout que c'est pas forcement par là que je commence à chercher
    cela donne donc
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
      if not (GetNamedSecurityInfo(PChar(filename),SE_FILE_OBJECT,
               DACL_SECURITY_INFORMATION, Nil, Nil, @pDACL, Nil,
              @pSD)=0)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème avec un sous-sous formulaire
    Par arthur24 dans le forum Access
    Réponses: 2
    Dernier message: 13/01/2006, 16h50
  2. Problème avec EInOutError sous delphi 2005
    Par Teb dans le forum Langage
    Réponses: 3
    Dernier message: 19/08/2005, 11h48
  3. fichier .bat : problèmes avec des sous-répertoires
    Par aymron dans le forum Windows
    Réponses: 4
    Dernier message: 23/06/2005, 09h33
  4. Problème avec glutFullScreen() sous linux...
    Par MaxPayne dans le forum OpenGL
    Réponses: 1
    Dernier message: 29/11/2004, 11h30
  5. Problème avec CopyDir sous D5
    Par Houben Jacques dans le forum Langage
    Réponses: 3
    Dernier message: 26/05/2003, 22h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo