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

ldap_result() doesn't honour passed timeout value. #20

Closed
phillipod opened this issue May 6, 2015 · 1 comment
Closed

ldap_result() doesn't honour passed timeout value. #20

phillipod opened this issue May 6, 2015 · 1 comment
Assignees
Labels
Milestone

Comments

@phillipod
Copy link
Collaborator

This code blocks indefinitely:

print "===== LISTEN_FOR_CHANGES / NEXT_CHANGED_ENTRIES\n";

my $listen_msg = $ld->listen_for_changes(
  -basedn => "dc=example,dc=com",
  -scope => LDAP_SCOPE_SUBTREE,
  -filter => "(objectClass=*)",
  -cookie => "/tmp/tmp.cookie", # has to exist first, even for first-run. There will be a pull request...
);

# First result should be Sync Info (LDAP_RES_INTERMEDIATE)
@entries = $ld->next_changed_entries($listen_msg, 0, 1);

# Second result should be empty if run after cookie has been updated,
# and therefore the timeout of "1" should be honoured
@entries = $ld->next_changed_entries($listen_msg, 0, 1);

LDAPapi.xs has this:

int
ldap_result(ld, msgid, all, timeout, result)
   ... 
   CODE:
    {
        struct timeval *tv_timeout = NULL, timeoutbuf;
        if (atof(timeout) > 0 && timeout && *timeout) { ... }
        RETVAL = ldap_result(ld, msgid, all, NULL, &result);
    }
   ...

The NULL parameter being passed is the timeout.

The result of this is that on OpenLDAP ldap_result() will use whatever has been set by ldap_set_options(), with the default being to wait forever (equivalent to timeout being set to -1), while Mozilla LDAP's ldap_result() will just wait forever.

In effect, synchronous operations work perfectly - but the asynchronous API does not - once ldap_result() is called, it's synchronous for the scope of of the all parameter unless a timeout has been set by ldap_set_options().

Note that fixing this has a knock-on impact to actually using next_changed_entries() in a timeout environment as next_changed_entries() does not support the case where a timeout has occurred.

I'll create a pull request to resolve both these things. Happily the test suite in #5 will already test the majority of the frequently consumed synchronous and asynchronous API .

@phillipod phillipod self-assigned this May 6, 2015
@phillipod phillipod added the bug label May 6, 2015
@phillipod phillipod added this to the 3.0.4 milestone May 6, 2015
@phillipod
Copy link
Collaborator Author

Hum. Note that I've tested the knock-on impact to using next_changed_entries() in a tree with ldap_result() fixed.

However, if the OpenLDAP C documentation for ldap_result() is correct and a NULL parameter being passed uses the value set with LDAP_OPT_TIMEOUT, then it should be possible to prove next_changed_entries() is broken on a non-modified build by setting a timeout like this.

However, this does not appear to work.

Investigating ldap_set_option(), it appears to do a fairly naive "just send this data to the function" - which works fine for pretty much most of the options supported by Mozilla LDAP. But OpenLDAP's support for 'struct timeval' options for LDAP_OPT_TIMEOUT and LDAP_OPT_NETWORK_TIMEOUT wouldn't work like this, and this is supported by ldap_set_option() returning -1.

quanah added a commit that referenced this issue May 12, 2015
…meout

 - Fixes #20: ldap_result() doesn't honour passed t…
rra pushed a commit to whm/libnet-ldapapi-perl that referenced this issue Dec 25, 2020
  * New upstream release.
  * Fix undef comparison
  * Misc variable initializations to quiet warnings
  * Fixed sasl mechanisms initializtion
  * Examples cleanup
  * LDAPv3 extended operation support
  * New developer mode test suite
  * Fixed quanah/net-ldapapi#3: ldap_set_rebind_proc XS being called with
    invalid arguments from set_rebind_proc
  * Fixed quanah/net-ldapapi#6: ldap_sasl_bind has wrong prototype in
    LDAPapi.xs
  * Fixed quanah/net-ldapapi#8: search_s() clobbers ATTRS parameter
  * Fixed quanah/net-ldapapi#11: result() blocking when called with output
    from rename()
  * Fixed quanah/net-ldapapi#20: ldap_result() doesn't honour passed
    timeout value
  * Fixed quanah/net-ldapapi#21: ldap_set_option(LDAP_OPT_TIMEOUT, 1) on
    OpenLDAP returns -1
  * Fixed quanah/net-ldapapi#28: Server control responses get eaten after
    a NULL character in the berval
  * Fixed quanah/net-ldapapi#30: ldap_search_ext() and ldap_search_ext_s()
    segfault when used with timeout
  * Fixed quanah/net-ldapapi#31: ldap_result() and ldap_url_search_st()
    timeout parameters have a granularity of 1 second
  * Fixed quanah/net-ldapapi#40: Server control requests get eaten after a
    NULL character in the berval
  * Correct merge problem with POD error.
  * Update standards version to 3.9.8 (no changes required).

[dgit import package libnet-ldapapi-perl 3.0.4-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant