Skip to content
Open
Changes from 1 commit
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
86 changes: 85 additions & 1 deletion lib/activedirectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
});
Expand Down Expand Up @@ -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;