novitiate has asked for the wisdom of the Perl Monks concerning the following question:

I have been fooling arround with Net::LDAP to query an exchange system. I want to get the NT account name
from the query, but I get a value that looks like this:

010500000000000515000000C60B7E00B719917EF21E5310FA0E0000

after reading some stuff over at M$oft, it seems that Exchange stores the NT SID in hex format
as opposed to binary (as the OS does). I found this code snippet for VB to convert it to binary:
'The SID is stored in a hexadecimal representation of the binary SID 'so we convert it and store it in a byte array tmp = Len(strSID) / 2 - 1 ReDim bByte(tmp) As Byte For i = 0 To tmp - 1 bByte(i) = CInt("&h" & Mid(strSID, (i * 2) + 1, 2)) Next 'Allocate space for the strings so the API won't GPF strName = Space(64) strDomain = Space(64) 'Get the NT Domain and UserName 'Note: This can't be done from VBScript directly 'because VBScript doesn't support making the 'LookupAccountSid API call ret = LookupAccountSid(vbNullString, bByte(0), strName, Len(strName) +, strDomain, Len(strDomain), iType

can anyone help me with the first part here where the hex value is stored in a byteArray ?
i assume we need pack here but, sadly, i am one of the many who do not understand pack.

humbly,
novitiate

"...goodnight you princes of main(e)"  --The Cider House Rules

Replies are listed 'Best First'.
Re: pack hex to bin
by I0 (Priest) on Aug 22, 2001 at 22:58 UTC
    $bByte=pack"H*",'010500000000000515000000C60B7E00B719917EF21E5310FA0E00';
      I bow humbly b4 you, o bhikshus and bhikshinas.thank you
      i know i am not alone in my ignorance; but i make a solemn vow to plumb the depths of pack......

      humbly,
      novitiate

      "...goodnight you princes of main(e)"  --The Cider House Rules
Re: pack hex to bin
by blakem (Monsignor) on Aug 22, 2001 at 23:07 UTC
    Since the immediate question has already been answered, you should know that you aren't alone in your ignorance of pack. Seek enligntenment at Confession of a Perl Hacker.

    -Blake