ruby-net-ldap
ruby-net-ldap copied to clipboard
documentation. Helper method to get sid from MS LDAP
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 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.
@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!
@net1957 Awesome! Thanks for this issue. Very helfpull for me. Sorry for my bad Englsh ;)
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?