Hello

I'm talking to active directory through Net::LDAP, and I want to extract user GUIDs in a readable form.

If I query a user, I don't get a GUID field, but instead a nasty contraption called objectGUID. This, I believe is supposed to be a 128bit binary field. In a debugger, it looks like this:

  'objectGUID' => 'Q?Ot?qM?r/?'

I have a GuidToString routine, filthily stolen from the internets, which I have posted below. In a nutshell, I'm looking for a hex string in the form: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"

The below code gives me that, but something is just not right, especially as most of the strings I get back have > 8 0's on the end in most cases.

Has anybody played with this before? Afaik, guid is the only thing that can never change on a users ad account, and I need to record these for a intranet based web app.

Any help much appreciated...

Here's that routine...

sub GuidToString { return sprintf "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%0 +2X", unpack("I", $_[0]), unpack("S", substr($_[0], 4, 2)), unpack("S", substr($_[0], 6, 2)), unpack("C", substr($_[0], 8, 1)), unpack("C", substr($_[0], 9, 1)), unpack("C", substr($_[0], 10, 1)), unpack("C", substr($_[0], 11, 1)), unpack("C", substr($_[0], 12, 1)), unpack("C", substr($_[0], 13, 1)), unpack("C", substr($_[0], 14, 1)), unpack("C", substr($_[0], 15, 1)); }

In reply to Net::LDAP GUID... by muffinman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.