ldapts / ldapts

LDAP client written in typescript
MIT License
190 stars 36 forks source link

Binary attribute value gets corrupted due to wrong encoding #72

Closed soletan closed 4 years ago

soletan commented 4 years ago

Tried accessing a Samba-based PDC via LDAP including its objectSid attribute which comes binary-encoded. Just like with ldapjs I was realizing that binary content exposed this way gets corrupted due to assuming UTF-8 encoding when converting attribute values from Buffer to string, even though the resulting string is full of Unicode escape sequences, afterwards. In my case a 25-bytes buffer value becomes a 24 characters string of unicode escapes.

In ldapjs there is an opportunity to get the raw set of buffers instead of transcoded strings per search result entry.

joostdecock commented 4 years ago

Same problem fetching the thumbnailPhoto attribute from Active Directory. It would be nice to be able to get the raw value.

lennarkivistik commented 4 years ago

Same problem fetching the thumbnailPhoto attribute from Active Directory. It would be nice to be able to get the raw value.

add ;binary to the key in question so for thumbnailPhoto try fetching for: thumbnailPhoto;binary should give you the binary response https://github.com/ldapts/ldapts/issues/11

jgeurts commented 4 years ago

As of v2.6.0, you can now explicitly specify which attributes should return as Buffer. I hope that helps with some issues getting binary values.

const searchResult = await client.search('ou=Users,o=5be4c382c583e54de6a3ff52,dc=jumpcloud,dc=com', {
  filter: '(mail=peter.parker@marvel.com)',
  explicitBufferAttributes: ['thumbnailPhoto'],
});