ruby-net-ldap icon indicating copy to clipboard operation
ruby-net-ldap copied to clipboard

documentation. Helper method to get sid from MS LDAP

Open net1957 opened this issue 10 years ago • 4 comments

after may time I finally got to decode the SID binary string you got from AD in objectsid or some other fields

perhaps you could put this in some doc to help other people.

   # http://blogs.msdn.com/b/oldnewthing/archive/2004/03/15/89753.aspx
   # need ruby 1.9.3 or newer
    def get_sid_string(data)
      sid = data.unpack('b x nN V*')
      sid[1, 2] = Array[nil, b48_to_fixnum(sid[1], sid[2])]
      'S-' + sid.compact.join('-')
    end

    B32 = 2**32

    def b48_to_fixnum(i16, i32)
      i32 + (i16 * B32)
    end

net1957 avatar Sep 27 '15 16:09 net1957

@net1957 thanks for writing in. I'm not sure where a good place to put this would be. Perhaps it would make sense in a wiki? Even having this issue will make it easier for google to index. Leaving this open for more feedback.

jch avatar Sep 29 '15 00:09 jch

@net1957 @jch , This is great. I'd been struggling for a while trying to decode the objectsid when I stumbled across this. Thanks for the effort and leaving this open!

treiff avatar Aug 03 '16 15:08 treiff

@net1957 Awesome! Thanks for this issue. Very helfpull for me. Sorry for my bad Englsh ;)

korotindev avatar Feb 19 '17 05:02 korotindev

This has been fantastically useful since I found this page! Has anybody done the reverse? That is, convert a string SID to the hex/binary representation so one could search for it in AD?

agouaux avatar Jul 09 '21 15:07 agouaux