diff --git a/lib/activedirectory.js b/lib/activedirectory.js index 316dd10..fa8e66a 100755 --- a/lib/activedirectory.js +++ b/lib/activedirectory.js @@ -1665,7 +1665,8 @@ ActiveDirectory.prototype.findUser = function findUser(opts, username, includeMe log.trace('findUser(%j,%s,%s)', opts, username, includeMembership); var localOpts = _.defaults(_.omit(opts || {}, 'attributes'), { - filter: getUserQueryFilter.call(self, username), + //filter: getUserQueryFilter.call(self, username), + filter: '(mail=' + username + ')', scope: 'sub', attributes: joinAttributes((opts || {}).attributes || defaultAttributes.user || [], getRequiredLdapAttributesForUser(opts)) }); @@ -1895,5 +1896,88 @@ ActiveDirectory.prototype.getRootDSE = function getRootDSE(url, attributes, call }); }); }; +ActiveDirectory.prototype.changePassword = function changePassword(username, newPassword, callback) { + /** + * Inline function to encode string to base 64 + * + * @private + */ + function encodePassword(password) { + return new Buffer('"' + password + '"', 'utf16le').toString(); + } + + var client = createClient.call(this); + + client.search(this.baseDN, { + filter: '(mail=' + username + ')', + attributes: 'dn', + scope: 'sub' + }, function(err, res) { + if (err) { + callback(err); + return; + } + res.on('searchEntry', function(entry) { + var userDN = entry.object.dn; + client.modify(userDN, [ + new ldap.Change({ + operation: 'replace', + modification: { + unicodePwd: encodePassword(newPassword) + } + }) + ], function(err) { + if (err) { + callback(err); + } else { + callback(); + client.unbind(); + } + }); + }); + }); +}; +ActiveDirectory.prototype.changeAtributos = function changeAtributos(username, atributos, callback) { + /** + * Inline function to encode string to base 64 + * + * @private + */ + var client = createClient.call(this); + client.search(this.baseDN, { + filter: '(mail=' + username + ')', + attributes: 'dn', + scope: 'sub' + }, function(err, res) { + if (err) { + callback(err); + return; + } + res.on('searchEntry', function(entry) { + var userDN = entry.object.dn; + atributos.forEach(function (rl_atributos) { + client.modify(userDN, [ + new ldap.Change({ + operation: 'replace', + modification: rl_atributos + }) + ], function(err) { + if (err) { + console.log(entry.object.dn); + console.log(rl_atributos); + console.log(err); + //client.unbind(); + /* callback(err); */ + return; + } else { + /* callback(); */ + /* client.unbind(); */ + } + }); + }); + callback(); + }); + }); +}; module.exports = ActiveDirectory;