Closed annmarie-switzer closed 4 years ago
I ran the above search on a local OU, both with the given program and ldapsearch
from OpenLDAP, and it appears that some entries don't have an objectSid
at all. Where it exists, it will be in bin_attrs
. Can you reproduce a situation where ldap3
returns no values for objectSid
, and some other LDAP search utility has some values for the same result entry?
I realize I was making an assumption that was wrong - I though all objects in AD had a SID but apparently that's not the case, so that explains why attrs
and bin_attrs
were empty for some objects.
Now, for those that do have an objectSid
, I am having some trouble parsing them.
If the objectSid is in attrs, it looks like this:
"\u{1}\u{2}\u{0}\u{0}\u{0}\u{0}\u{0}\u{5} \u{0}\u{0}\u{0} \u{2}\u{0}\u{0}"
If the objectSid is in bin_attrs, it looks like this:
[ 1, 5, 0, 0, 0, 0, 0, 5, 21, 0, 0, 0, 132, 79, 208, 182, 78, 22, 60, 206, 137, 224, 237, 253, 232, 3, 0, 0, ]
I can't figure out how to parse either of these into a SID. It should look something this:
S-1-5-21-1943420175-2293888159-2611305999-65646
I found an article describing the format. If the value happens to be representable as a String
, its underlying raw byte slice should be the input to the conversion.
Thanks, I will try this for the bin_attrs version.
Is there a way to have streaming_search return objectSid
ALWAYS as a bin_attr
? Or do you have any idea how the version returned in attrs
can be converted? I'm not sure how that string is supposed to be parsed.
Is there a way to have streaming_search return
objectSid
ALWAYS as abin_attr
?
Afraid not; conversion to String
is always tried first. I toyed with deserializing entries into structs, but never needed it that badly.
Or do you have any idea how the version returned in
attrs
can be converted?
With String::as_bytes()
, as hinted above.
Thank you for your help! Using that article as a guide, I made a helper function that will convert these binary streams into a human-readable SID that can be checked against the Active Directory UI:
use byteorder::*;
pub fn convert_sid_to_str(mut b_sid: Vec<u8>) -> String {
let revision = b_sid.remove(0);
let _dashes = b_sid.remove(0);
let remaining = b_sid.split_off(6);
let six = BigEndian::read_uint(&b_sid, 6);
let mut ints = vec![];
let chunks = remaining.chunks(4);
for chunk in chunks {
let int = format!("{}", LittleEndian::read_uint(chunk, 4));
ints.push(int);
};
format!("S-{}-{}-{}", revision, six, ints.join("-"))
}
When I use the
streaming_search_with
method, I am getting results bask that have no attributes. Since every object in AD should have at least one attribute, in this case I am testing onobjectSid
, I don't know why this is happening.Maybe I have misconfigured something?