diff --git a/CHANGES b/CHANGES index 884c1d0..df35179 100644 --- a/CHANGES +++ b/CHANGES @@ -36,6 +36,7 @@ Modules/ * Fix memory leak in whoami * Fix internal error handling of LDAPControl_to_List() * Fix two memory leaks and release GIL in encode_assertion_control +* Allow set_option() to set timeouts to infinity and, thanks to Michael Ströder: * removed unused code schema.c * moved code from version.c to ldapmodule.c diff --git a/Doc/reference/ldap.rst b/Doc/reference/ldap.rst index c28cdec..1f7ae5b 100644 --- a/Doc/reference/ldap.rst +++ b/Doc/reference/ldap.rst @@ -156,6 +156,9 @@ following option identifiers are defined as constants: .. py:data:: OPT_NETWORK_TIMEOUT + .. versionchanged:: 3.0 + A timeout of ``-1`` resets timeout to infinity. + .. py:data:: OPT_PROTOCOL_VERSION Sets the LDAP protocol version used for a connection. This is mapped to @@ -180,6 +183,9 @@ following option identifiers are defined as constants: .. py:data:: OPT_TIMEOUT + .. versionchanged:: 3.0 + A timeout of ``-1`` resets timeout to infinity. + .. py:data:: OPT_URI .. _ldap-sasl-options: diff --git a/Modules/options.c b/Modules/options.c index f5bae42..647f859 100644 --- a/Modules/options.c +++ b/Modules/options.c @@ -140,10 +140,20 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value) if (!PyArg_Parse(value, "d:set_option", &doubleval)) return 0; if (doubleval >= 0) { - set_timeval_from_double( &tv, doubleval ); + set_timeval_from_double( &tv, doubleval ); + ptr = &tv; + } else if (doubleval == -1) { + /* -1 is infinity timeout */ + tv.tv_sec = -1; + tv.tv_usec = 0; ptr = &tv; } else { - ptr = NULL; + PyErr_Format( + PyExc_ValueError, + "timeout must be >= 0 or -1 for infinity, got %d", + option + ); + return 0; } break; case LDAP_OPT_SERVER_CONTROLS: