2017-10-18 61 views
0

我試圖從AD使用node.js獲取信息。我試過activedirectoryldapauth-fork,一般情況下代碼有效,但如果我需要一些octetstring數據,如objectGUID,我會在對象中看到一個垃圾字符串。我found二進制數據被轉換爲utf-8字符串。但問題是數據在轉換期間被損壞(很多cahrs代碼爲65533),我無法將該字符串恢復爲原始二進制文件。從活動目錄中讀取objectGUID

如何訪問octetstring格式的數據以獲取正確的二進制表示?

​​

相關:

回答

0

entryParser是有這個目的:

const ActiveDirectory = require('activedirectory'); 

const config = { 
    url: 'LDAP://ldap.example.com', 
    baseDN: 'OU=Users,DC=example,DC=com', 
    username: '[email protected]', 
    password: 'password', 
    entryParser(entry, raw, callback) { 
    if (raw.hasOwnProperty("objectGUID")) { entry.objectGUID = raw.objectGUID; } 
    callback(entry); 
    } 
}; 

const ad = new ActiveDirectory(config); 

const query = { 
    filter: '(objectClass=user)', 
    attributes: ["dn", "cn", "objectGUID", "objectSid"] 
}; 

ad.findUsers(query, function (err, result) { 
    if (err) { 
    return console.error(err); 
    } 

    console.log(result.length); 
    console.log(result[0]); // objectGUID contains Buffer with strange byte order 
    console.log(result[0].objectGUID 
    .toString('hex') 
    .replace(
     /^(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)(..)$/, 
     "{$4$3$2$1-$6$5-$8$7-$10$9-$16$15$14$13$12$11}" 
    ).toUpperCase() // Normal guid, conversion could be moved into the parser 
); 
}); 
+0

這可能會幫助:http://ldapwiki.com/WIK我/的objectGUID – jwilleke