Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/activedirectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const defaultEntryParser = function (entry, raw, callback) {
entry.objectSid = utils.binarySidToStringSid(raw.objectSid)
}
if (Object.prototype.hasOwnProperty.call(raw, 'objectGUID')) {
entry.objectGUID = utils.binarySidToStringSid(raw.objectGUID)
entry.objectGUID = utils.binaryToGuidString(raw.objectGUID)
}
callback(entry)
}
Expand Down
26 changes: 26 additions & 0 deletions lib/components/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,33 @@ function binarySidToStringSid (sid) {
return parts.join('-')
}

/**
* Converts a binary GUID to a string representation.
*
* @param {Buffer} guid - Buffer containing 16 bytes of GUID.
* @returns {string} - GUID in the `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` string format.
* @throws {Error} - If the buffer length is not equal to 16 bytes.
*/
function binaryToGuidString(guid) {
if (guid.length !== 16) {
throw new Error("Invalid data length. Expected 16 bytes for GUID.");
}

// Use two-digit hex representation for each part
const parts = [];
parts.push(guid.readUInt32LE(0).toString(16).padStart(8, '0'));
parts.push(guid.readUInt16LE(4).toString(16).padStart(4, '0'));
parts.push(guid.readUInt16LE(6).toString(16).padStart(4, '0'));
parts.push(guid.readUInt16BE(8).toString(16).padStart(4, '0'));
parts.push(guid.slice(10).toString('hex'));

// Create GUID in the correct format
return parts.slice(0, 3).join('-') + '-' + parts.slice(3).join('-');
}


module.exports = {
binaryToGuidString,
binarySidToStringSid,
createClient,
getCompoundFilter,
Expand Down