Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] LDAP/AD is not importing all users #9309

Merged
merged 1 commit into from
Jan 2, 2018
Merged
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
56 changes: 38 additions & 18 deletions packages/rocketchat-ldap/server/ldap.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ export default class LDAP {
searchAllPaged(BaseDN, options, page) {
this.bindIfNecessary();

const processPage = ({entries, title, end, next}) => {
logger.search.info(title);
// Force LDAP idle to wait the record processing
this.client._updateIdle(true);
page(null, entries, {end, next: () => {
// Reset idle timer
this.client._updateIdle();
next && next();
}});
};

this.client.search(BaseDN, options, (error, res) => {
if (error) {
logger.search.error(error);
Expand All @@ -392,33 +403,42 @@ export default class LDAP {
entries.push(this.extractLdapEntryData(entry));

if (entries.length >= internalPageSize) {
logger.search.info('Internal Page');
this.client._updateIdle(true);
page(null, entries, {end: false, next: () => {
// Reset idle timer
this.client._updateIdle();
}});
processPage({
entries,
title: 'Internal Page',
end: false
});
entries = [];
}
});

res.on('page', (result, next) => {
if (!next) {
logger.search.debug('Final Page');
this.client._updateIdle(true);
page(null, entries, {end: true, next: () => {
// Reset idle timer
this.client._updateIdle();
}});
processPage({
entries,
title: 'Final Page',
end: true
});
} else if (entries.length) {
logger.search.info('Page');
// Force LDAP idle to wait the record processing
this.client._updateIdle(true);
page(null, entries, {end: !next, next: () => {
// Reset idle timer
this.client._updateIdle();
next();
}});
processPage({
entries,
title: 'Page',
end: false,
next
});
entries = [];
}
});

res.on('end', () => {
if (entries.length) {
processPage({
entries,
title: 'Final Page',
end: true
});
entries = [];
}
});
Expand Down