RECHERCHE DANS L'ACTIVEDIRECTORY

f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 - 10 janv. 2007 à 18:52
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 - 10 janv. 2007 à 20:27
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/41047-recherche-dans-l-activedirectory

f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
10 janv. 2007 à 20:27
code desactivé temporairement en attente de verification du dit "plagia".

si il s'agit d'un réel plagia de source delphi existante ce serat simple : bannissement expeditif.

si c'est juste une adaptation delphi d'un code C++, il faudrat juste penser a mentionner les sources originale.
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
10 janv. 2007 à 19:32
on peu egalement faire une fonction plus specialisée sur le meme principe :


function ByteArrayToHexStr(const lByteArray : array of byte; const iBAStart,iBAEnd : integer; const lSep : char; const lIncludeSep : boolean = false): string;
const
Digits: array[$0..$F] of char ='0123456789abcdef';
var
ISV : boolean;
P : PChar;
I,L : integer;
begin
L := iBAEnd-iBAStart;

ISV := IncludeSep and (Sep <> #0);

if ISV then
SetLength(Result, (L shl 1) + (L-1))
else
SetLength(Result, L shl 1);
P := PChar(Result);
for I := iBAStart to iBAEnd do begin
P[0] := Digits[lByteArray[I] shr 4];
P[1] := Digits[lByteArray[I] and $F];
if (I < iBAEnd) and ISV then begin
P[2] := lSep;
inc(P,3);
end else
Inc(P,2);
end;
end;


comme ça on peu remplacer :

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]])

par

result := ByteArrayToHexStr(Psia.Value,0,5,'');

si Psia.value n'est pas de type Array of Byte on peu tricher avec une astuce trés simple :



function AllToHexStr(const lpBuffer; const lBufferSize,iBStart,iBEnd : integer; const lSeparator : char; const lIncludeSeparator : boolean = false) : string;
const
Digits: array[$0..$F] of char ='0123456789abcdef';
var
ISV : boolean;
pR : PChar;
pB : ^byte;
I,L : integer;
begin
L := lBEnd-lBStart;
if L > lBufferSize then L := lBufferSize;

ISV := lIncludeSeparator and (lSeparator <> #0);

if ISV then
SetLength(Result, (L shl 1) + (L-1))
else
SetLength(Result, L shl 1);

pR := PChar(Result);
pB := @lpBuffer;
inc(pB,lBufferSize-lBEnd-1);

for I := lBEnd downto lBStart do begin
pR[0] := Digits[pB^ shr 4];
pR[1] := Digits[pB^ and $F];
if (I > lBStart) and ISV then begin
pR[2] := lSeparator;
inc(pR,3);
end else
Inc(pR,2);
dec(pB);
end;
end;

de memoire ça devrait marcher ... surrement un petit debuggage a faire avant.

sinon, si on a pas besoin de recuperer des portions du buffer mais a chaque fois le buffer complet, on peu tout simplifier comme cela :

function AllToHexStr(const lpBuffer; const lBufferSize : integer; const lSeparator : char; const lIncludeSeparator : boolean = false) : string;
const
Digits: array[$0..$F] of char ='0123456789abcdef';
var
ISV : boolean;
pR : PChar;
pB : ^byte;
I,LM : integer;
begin
ISV := lIncludeSeparator and (lSeparator <> #0);
LM := lBufferSize-1;

if ISV then
SetLength(Result, (lBufferSize shl 1) + (lBufferSize-1))
else
SetLength(Result, lBufferSize shl 1);

pR := PChar(Result);
pB := @lpBuffer;
inc(pB,lBufferSize-1);

for I := 0 to LM do begin
pR[0] := Digits[pB^ shr 4];
pR[1] := Digits[pB^ and $F];

if (I < LM) and ISV then begin
pR[2] := lSeparator;
inc(pR,3);
end else
Inc(pR,2);

dec(pB);
end;
end;

fonction simple a utiliser ...

exemple :

AllToHexStr(ByteArray,Length(ByteArray),'-',true) = '04-99-FF-E4-B1-00'
(pratique pour les adresses MAC)

AllToHexStr(MD5Digest,Length(MD5Digest),'') = 543c2d45e6f45g632df4e5534558f569

AllToHexStr(Psia.Value,Length(Psia.Value),'') = ........

AllToHexStr(VariableInteger, SizeOf(Integer), '') = FF54749C

AllToHexStr(VariableFloat, SizeOf(Double),'') = [bit signe][bits exposant][bits mantisse]

(edit1.text = '0123456789')
var S : string;
S := Edit1.Text;
AllToHexStr(PChar(S), Length(Edit1.Text),' ', true) = 30 31 32 33 34 35 36 37 38 39

attention pour les chaines on doit PCharisé la chaine, si la chaine est une propriétée d'un objet on doit utiliser une variable locale de type string a transmettre a la fonction.
cela evite les problemes de "doit etre une variable", "ne peu pas transmettre un objet constante"
jace1975 Messages postés 81 Date d'inscription mardi 31 mai 2005 Statut Membre Dernière intervention 12 octobre 2007 1
10 janv. 2007 à 19:13
garçon, y'a un big probleme avec ce que tu fais :

Cette source appartient a qqu'un d'autre (une institution financière francaise, pas très dur a trouver) et c'est totalement illégal et crétin de faire ce que tu fais. Si ca se sait que tu divulgue du code (qqu'il soit) de l'ADSI dans sous les yeux de regard extérieurs, ils sont en droit de t'attaquer en justice (si, si , je suis en train de vérifier dans leur foutu pls, reglement RSI,...)


Perso je m'en fous,mais je voudrais pas que mon site préféré de delphi ferme, à cause d'un utilisateur trop faineant pour masquer l'origine de la source.
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
10 janv. 2007 à 18:52
Ce serait bien de refaire le Zip mais cette fois en ne partant que du repertoire "Code Exemple ADSI"


tu peu aussi modifier cela pour plus de performance et possibilitée :

function ByteToStr(const T : array of byte; const CSep : char; const IncludeSep : boolean = false): string;
const
Digits: array[$0..$F] of char ='0123456789abcdef';
var
ISV : boolean;
P : PChar;
I,L,MI : integer;
begin
Try
L := Length(T);
MI := High(T);
ISV := IncludeSep and (Sep <> #0);
if ISV then
SetLength(Result, (L shl 1) + (L-1))
else
SetLength(Result, L shl 1);
P := PChar(Result);
for I := Low(T) to MI do begin
P[0] := Digits[T[I] shr 4];
P[1] := Digits[T[I] and $F];
if (I < MI) and ISV then begin
P[2] := Sep;
inc(P,3);
end else
Inc(P,2);
end;
Except
LogEvenement('/ Echec lors de la conversion des Bytes en Strings');
End;
end;
Rejoignez-nous