Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Paging events not firing as expected #385

Closed
sinfloodmusic opened this issue Jul 12, 2016 · 10 comments
Closed

Paging events not firing as expected #385

sinfloodmusic opened this issue Jul 12, 2016 · 10 comments
Labels

Comments

@sinfloodmusic
Copy link

sinfloodmusic commented Jul 12, 2016

Hello,

Not having any luck with the ldap paging against Active Directory. I think I've fought through the paging/paged documentation mismatch (Issue 321 appears to have been closed too soon) but can't seem to get ldapjs to fire off all of the paging events, or handle ranged/paged results correctly.

Here's my code. It works _perfectly_ when I have a group with 20 members. But if I request a group with 5200 or so members (and it should start paging) I get a single searchEntry event called with a range of data, then one "page" event (with empty results), and then an "end" event. Pages 1500-2999, 3000-4499, 4500-5200 do not appear to be coming in.

values = [];

var client = ldap.createClient({
    url: myServer 
});

client.on('connect', function (){

    client.bind(myAccount, myPass, function(err) {

        var opts = {
          filter: ('(cn=' + myGroupName + ')'),
          scope: 'sub',
          attributes: ['dn', 'sn', 'cn','member'],
          paged: { pageSize: 250 }
        };

        client.search(myContainer, opts, function(err, ldapresponse) {

            ldapresponse.on('searchEntry', function(entry) {
                console.log("searchEntry event");

                if (Array.isArray(entry.object["member"])){
                    values = entry.object["member"]
                }
                else {
                    values.push(entry.object["member"]);
                }

                console.log("found: " + values.length + " members in group");

            });

            ldapresponse.on('page', function(entry) {
                console.log("page event");
                console.log('entry: ' + JSON.stringify(entry));
            });

            ldapresponse.on('end', function(result) {
                console.log('end event');
                res.setHeader('Content-Type', 'application/json')   
                res.send(JSON.stringify(values));       
            });

            ldapresponse.on('error', function(resErr) {
                console.log("error " + resErr);
            });
        });
    });

});

When I query a 5200 member group, I get a single searchEntry event with an object like this:

entry: {"dn":"CN=MyGroupName,DC=domain,DC=com","controls":[],"cn":"MyGroupName"
,"member":[],"member;range=0-1499":["USERDN1","USERDN2","USERDN3","USERDN4", ...... ]}

It's a ranged object so assuming there's some paging to be done... But the next event to fire is the page event, which seems to have empty data, then the "end" event and it's all done.

Can someone point out what I'm doing wrong here? I see that the activedirectory library, which leverages ldapjs, is able to handle paged results, but looks like it's doing this at a lower-layer and using a PagedResultControl rather than depending on these "page" events.

I can't find any examples in this repo or the interwebs that has working paging code, I'm assuming I'm doing something wrong, but I've tried "paging" and "paged" and it's just not working.

Thanks for having a look!

@sinfloodmusic sinfloodmusic changed the title Paged Paging not working correctly for me (at least against Active Directory) Paging events not firing as expected Jul 14, 2016
@sinfloodmusic
Copy link
Author

I'm losing hope as the sample ldapjs-search app doesn't appear to be able to handles paging either:

node .\ldapjs-search -b "dc=mydomain,dc=com" -s "sub" -D "CN=myaccount,DC=mydomain,DC=com" -w "mypass" -i -u "ldap://server.mydomain.com" -g 200 "(samaccountname=mygroup)" member

This too returns just the range 0-1499 and that's it. This happens with or without the -g (paging) option.

So if the sample code can't seem to page, pretty sure I'm hosed.

@sinfloodmusic
Copy link
Author

sinfloodmusic commented Aug 2, 2016

Is this project still alive? No commits since December 2015, and my report of a search result paging not functioning (even using the provided demo application) hasn't even gained a comment in 22 days.

@Xotl
Copy link
Contributor

Xotl commented Aug 8, 2016

@sinfloodmusic, Seems that the owners doesn't care about this project anymore.

About your Issue, take a look at the Issue #362. It seem you ran into the very same problem as me few months ago.

@sinfloodmusic
Copy link
Author

@Xotl, Thanks. It appears that this project has been abandoned - which is a total bummer.

I did run into your issue, with the documentation not matching. That burned at least an hour or two - scratching my head wondering what was going on.

I did eventually resolve that, and the issue I have now (paging) is even encountered by the example code they provide, so there appears to be an underlying paging bug when it comes to "range" returns. Not insurmountable, I did find that the activedirectory library just uses some lower layer controls to get around it, but it's very hard to read. I have a workaround in the meantime, when I get time I guess I'll just do what they are doing.

@DeChrish
Copy link

Any alternate for node-ldapjs ?

@sinfloodmusic
Copy link
Author

I haven't found one - but if you do find one please post here. My workaround just shells out to powershell, runs the AD cmdlets which write to stdout, then my nodejs picks it up from there. It's quite a bit slower, but at the moment I don't need the speed that "native" will get me. That may change as my requirements change. The bummer is that sticks me to running this on a Windows box and I'd rather run this on linux.

@terryxsq
Copy link

terryxsq commented Sep 29, 2016

So first you need to use paged instead of paging in the options.
Secondly you need to pass a callback in the on page event. Something like the following.

ldapresponse.on('page', function(entry, cb) {
  if(cb) cb();
});

the cb basically tells it to carry on. however you need to check if cb because for the last batch there will be no cb available because it is the end and no more pages will come after that.

@schulzetenberg
Copy link

@terryxsq I did not have any luck with your suggestion as cb is undefined the first time the function is called.

@jsumners
Copy link
Member

I think this has been sufficiently answered. If not, feel free to re-open.

@jsumners
Copy link
Member

⚠️ This issue has been locked due to age. If you have encountered a recent
problem that seems to be covered by this issue, please open a new issue.

Please include a minimal reproducible example
when opening a new issue.

@ldapjs ldapjs locked as resolved and limited conversation to collaborators Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants