Add msgid to info dict created by LDAPerror.
While rewriting a nasty perl LDAP sync program in python I encountered one
quirk with python-ldap that made my life a bit difficult. When doing
asynchronous searches an ldap exception in result3() doesn't include 'msgid'
in the info dict. Since I'm tracking pending work by the msgid of the
search, having the msgid in the exception is very useful for removing work
items.
Here is a patch to the 'C' code of python-ldap to provide msgid.
Thanks,
Chris Dukes
Only in python-ldap-2.3.9: build
Only in python-ldap-2.3.9: dist
Only in python-ldap-2.3.9/Lib/python_ldap.egg-info: native_libs.txt
diff -urwp python-ldap-2.3.9.orig/Lib/python_ldap.egg-info/SOURCES.txt python-ldap-2.3.9/Lib/python_ldap.egg-info/SOURCES.txt
--- python-ldap-2.3.9.orig/Lib/python_ldap.egg-info/SOURCES.txt 2009-07-26 10:51:44.0 -0400
+++ python-ldap-2.3.9/Lib/python_ldap.egg-info/SOURCES.txt 2009-10-22 09:56:54.0 -0400
@@ -84,6 +84,7 @@ Lib/ldap/schema/tokenizer.py
Lib/python_ldap.egg-info/PKG-INFO
Lib/python_ldap.egg-info/SOURCES.txt
Lib/python_ldap.egg-info/dependency_links.txt
+Lib/python_ldap.egg-info/native_libs.txt
Lib/python_ldap.egg-info/not-zip-safe
Lib/python_ldap.egg-info/requires.txt
Lib/python_ldap.egg-info/top_level.txt
diff -urwp python-ldap-2.3.9.orig/Modules/errors.c python-ldap-2.3.9/Modules/errors.c
--- python-ldap-2.3.9.orig/Modules/errors.c 2009-04-17 08:19:09.0 -0400
+++ python-ldap-2.3.9/Modules/errors.c 2009-10-22 09:56:50.0 -0400
@@ -45,7 +45,7 @@ LDAPerr(int errnum)
/* Convert an LDAP error into an informative python exception */
PyObject*
-LDAPerror( LDAP*l, char*msg )
+LDAPerror( LDAP*l, char*msg, int msgid )
{
if (l == NULL) {
PyErr_SetFromErrno( LDAPexception_class );
@@ -91,6 +91,11 @@ LDAPerror( LDAP*l, char*msg )
ldap_memfree(matched);
}
+if (msgid >= 0) {
+str = PyInt_FromLong((long)msgid);
+PyDict_SetItemString( info, "msgid", str );
+}
+
if (errnum == LDAP_REFERRAL) {
str = PyString_FromString(msg);
if (str)
diff -urwp python-ldap-2.3.9.orig/Modules/errors.h python-ldap-2.3.9/Modules/errors.h
--- python-ldap-2.3.9.orig/Modules/errors.h 2009-04-17 08:19:09.0 -0400
+++ python-ldap-2.3.9/Modules/errors.h 2009-10-22 09:40:18.0 -0400
@@ -9,7 +9,7 @@
#include "ldap.h"
extern PyObject* LDAPexception_class;
-extern PyObject* LDAPerror( LDAP*, char*msg );
+extern PyObject* LDAPerror( LDAP*, char*msg, int msgid );
extern void LDAPinit_errors( PyObject* );
PyObject* LDAPerr(int errnum);
diff -urwp python-ldap-2.3.9.orig/Modules/functions.c python-ldap-2.3.9/Modules/functions.c
--- python-ldap-2.3.9.orig/Modules/functions.c 2009-04-17 08:19:09.0 -0400
+++ python-ldap-2.3.9/Modules/functions.c 2009-10-22 09:46:58.0 -0400
@@ -23,7 +23,7 @@ l_ldap_initialize(PyObject* unused, PyOb
ret = ldap_initialize(&ld, uri);
Py_END_ALLOW_THREADS
if (ret != LDAP_SUCCESS)
- return LDAPerror(ld, "ldap_initialize");
+ return LDAPerror(ld, "ldap_initialize", -1);
return (PyObject*)newLDAPObject(ld);
}
diff -urwp python-ldap-2.3.9.orig/Modules/LDAPObject.c python-ldap-2.3.9/Modules/LDAPObject.c
--- python-ldap-2.3.9.orig/Modules/LDAPObject.c 2009-04-17 08:19:09.0 -0400
+++ python-ldap-2.3.9/Modules/LDAPObject.c 2009-10-22 09:39:56.0 -0400
@@ -356,7 +356,7 @@ l_ldap_unbind_ext( LDAPObject* self, PyO
LDAPControl_List_DEL( client_ldcs );
if ( ldaperror!=LDAP_SUCCESS )
- return LDAPerror( self->ldap, "ldap_unbind_ext" );
+ return LDAPerror( self->ldap, "ldap_unbind_ext", -1 );
self->valid = 0;
Py_INCREF(Py_None);
@@ -399,7 +399,7 @@ l_ldap_abandon_ext( LDAPObject* self, Py
LDAPControl_List_DEL( client_ldcs );
if ( ldaperror!=LDAP_SUCCESS )
- return LDAPerror( self->ldap, "ldap_abandon_ext" );
+ return LDAPerror( self->ldap, "ldap_abandon_ext", -1 );
Py_INCREF(Py_None);
return Py_None;
@@ -448,7 +448,7 @@ l_ldap_add_ext( LDAPObject* self, PyObje
LDAPControl_List_DEL( client_ldcs );
if ( ldaperror!=LDAP_SUCCESS )
- return LDAPerror( self->ldap, "ldap_add_ext" );
+ return LDAPerror( self->ldap, "ldap_add_ext", -1 );
return PyInt_FromLong(msgid);
}
@@ -493,7 +493,7 @@ l_ldap_simple_bind( LDAPObject* self, Py
LDAPControl_List_DEL( client_ldcs );
if ( ldaperror!=LDAP_SUCCESS )
- return LDAPerror( self->ldap, "ldap_simple_bind" );
+ return LDAPerror( self->ldap, "ldap_simple_bind", -1 );
return PyInt_FromLong( msgid );
}
@@ -693,7 +693,7 @@ l_ldap_sasl_interactive_bind_s( LDAPObje
LDAPControl_List_DEL( client_ldcs );
if (msgid != LDAP_SUCCESS)
- return LDAPerror( self->ldap, "ldap_sasl_interactive_bind_s" );
+ return LDAPerror( self->ldap, "ldap_sasl_interactive_bind_s", -1 );
return PyInt_FromLong( msgid );
}
#endif
@@ -738,7 +738,7 @@ l_ldap_cancel( LDAPObject*
Re: Preparing release 2.3.10, please test!
Michael, I went to check my patch to provide msgid in a result exception against 2.3.10. I have found a problem on constants.c gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DHAVE_LIBLDAP_R -DHAVE_SASL -DHAVE_TLS -DLDAPMODULE_VERSION=2.3.10 -IModules -I/usr/local/openldap-2.3/include -I/usr/include/sasl -I/usr/include/python2.5 -c Modules/constants.c -o build/temp.linux-i686-2.5/Modules/constants.o Modules/constants.c: In function ‘LDAPinit_constants’: Modules/constants.c:185: error: ‘LDAP_OPT_X_TLS_PROTOCOL_MIN’ undeclared (first use in this function) Modules/constants.c:185: error: (Each undeclared identifier is reported only once Modules/constants.c:185: error: for each function it appears in.) error: command 'gcc' failed with exit status 1 This error is repeatable with a pristine checkout before I applied my patch. This #define is not present in libldap2-dev 2.4.9-0ubuntu0 (Which ships with Ubuntu Hardy), but is present in libldap2-dev 2.4.17-2 (Debian Sid). I am currently disinclined to update libldap2 until a new ubuntu LTS is released, but I do make use of python-virtualenv when I need a python environment that is newer than the one that ships with ubuntu Hardy. Thanks, Chris Dukes -- Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference___ Python-LDAP-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/python-ldap-dev
Re: Preparing release 2.3.10, please test!
The following patch allows the LDAP_OPT_X_TLS_PROTOCOL_MIN to work with libldap2-dev 2.4.9-0ubuntu0 Thanks, Chris Dukes Only in python-ldap/build: bdist.linux-i686 Only in python-ldap/build/lib.linux-i686-2.5: _ldap.so Only in python-ldap: dist Only in python-ldap/Lib/python_ldap.egg-info: native_libs.txt diff -urwp python-ldap.orig/Modules/constants.c python-ldap/Modules/constants.c --- python-ldap.orig/Modules/constants.c 2009-09-15 09:29:53.0 -0400 +++ python-ldap/Modules/constants.c 2009-10-22 13:09:50.0 -0400 @@ -182,8 +182,10 @@ LDAPinit_constants( PyObject* d ) add_int(d,OPT_X_TLS_CRL_PEER); add_int(d,OPT_X_TLS_CRL_ALL); add_int(d,OPT_X_TLS_NEWCTX); +#ifdef OPT_X_TLS_PROTOCOL_MIN add_int(d,OPT_X_TLS_PROTOCOL_MIN); #endif +#endif add_int(d,OPT_X_SASL_MECH); add_int(d,OPT_X_SASL_REALM); add_int(d,OPT_X_SASL_AUTHCID); diff -urwp python-ldap.orig/Modules/options.c python-ldap/Modules/options.c --- python-ldap.orig/Modules/options.c 2009-09-14 19:07:43.0 -0400 +++ python-ldap/Modules/options.c 2009-10-22 13:10:10.0 -0400 @@ -80,8 +80,10 @@ LDAP_set_option(LDAPObject *self, int op case LDAP_OPT_X_TLS: case LDAP_OPT_X_TLS_REQUIRE_CERT: case LDAP_OPT_X_TLS_NEWCTX: +#ifdef OPT_X_TLS_PROTOCOL_MIN case LDAP_OPT_X_TLS_PROTOCOL_MIN: #endif +#endif #ifdef HAVE_SASL case LDAP_OPT_X_SASL_SSF_MIN: case LDAP_OPT_X_SASL_SSF_MAX: @@ -216,8 +218,10 @@ LDAP_get_option(LDAPObject *self, int op #ifdef HAVE_TLS case LDAP_OPT_X_TLS: case LDAP_OPT_X_TLS_REQUIRE_CERT: +#ifdef OPT_X_TLS_PROTOCOL_MIN case LDAP_OPT_X_TLS_PROTOCOL_MIN: #endif +#endif #ifdef HAVE_SASL case LDAP_OPT_X_SASL_SSF_MIN: case LDAP_OPT_X_SASL_SSF_MAX: -- Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference___ Python-LDAP-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/python-ldap-dev
Add msgid to info dict created by LDAPerror.
And here is the patch cleaned up against python-ldap 2.3.10
Thanks,
Chris Dukes
Binary files python-ldap.TLS_PROTOCOL_MIN/build/lib.linux-i686-2.5/_ldap.so and python-ldap/build/lib.linux-i686-2.5/_ldap.so differ
Binary files python-ldap.TLS_PROTOCOL_MIN/dist/python_ldap-2.3.10-py2.5-linux-i686.egg and python-ldap/dist/python_ldap-2.3.10-py2.5-linux-i686.egg differ
diff -urwp python-ldap.TLS_PROTOCOL_MIN/Lib/python_ldap.egg-info/SOURCES.txt python-ldap/Lib/python_ldap.egg-info/SOURCES.txt
--- python-ldap.TLS_PROTOCOL_MIN/Lib/python_ldap.egg-info/SOURCES.txt 2009-10-22 13:10:12.0 -0400
+++ python-ldap/Lib/python_ldap.egg-info/SOURCES.txt 2009-10-22 13:17:27.0 -0400
@@ -52,7 +52,9 @@ Lib/ldap/schema/subentry.py
Lib/ldap/schema/tokenizer.py
Lib/python_ldap.egg-info/PKG-INFO
Lib/python_ldap.egg-info/SOURCES.txt
+Lib/python_ldap.egg-info/SOURCES.txt.orig
Lib/python_ldap.egg-info/dependency_links.txt
+Lib/python_ldap.egg-info/native_libs.txt
Lib/python_ldap.egg-info/not-zip-safe
Lib/python_ldap.egg-info/requires.txt
Lib/python_ldap.egg-info/top_level.txt
Only in python-ldap/Lib/python_ldap.egg-info: SOURCES.txt.orig
diff -urwp python-ldap.TLS_PROTOCOL_MIN/Modules/errors.c python-ldap/Modules/errors.c
--- python-ldap.TLS_PROTOCOL_MIN/Modules/errors.c 2009-04-17 08:19:09.0 -0400
+++ python-ldap/Modules/errors.c 2009-10-22 13:15:40.0 -0400
@@ -45,7 +45,7 @@ LDAPerr(int errnum)
/* Convert an LDAP error into an informative python exception */
PyObject*
-LDAPerror( LDAP*l, char*msg )
+LDAPerror( LDAP*l, char*msg, int msgid )
{
if (l == NULL) {
PyErr_SetFromErrno( LDAPexception_class );
@@ -91,6 +91,11 @@ LDAPerror( LDAP*l, char*msg )
ldap_memfree(matched);
}
+if (msgid >= 0) {
+str = PyInt_FromLong((long)msgid);
+PyDict_SetItemString( info, "msgid", str );
+}
+
if (errnum == LDAP_REFERRAL) {
str = PyString_FromString(msg);
if (str)
diff -urwp python-ldap.TLS_PROTOCOL_MIN/Modules/errors.h python-ldap/Modules/errors.h
--- python-ldap.TLS_PROTOCOL_MIN/Modules/errors.h 2009-04-17 08:19:09.0 -0400
+++ python-ldap/Modules/errors.h 2009-10-22 13:15:40.0 -0400
@@ -9,7 +9,7 @@
#include "ldap.h"
extern PyObject* LDAPexception_class;
-extern PyObject* LDAPerror( LDAP*, char*msg );
+extern PyObject* LDAPerror( LDAP*, char*msg, int msgid );
extern void LDAPinit_errors( PyObject* );
PyObject* LDAPerr(int errnum);
diff -urwp python-ldap.TLS_PROTOCOL_MIN/Modules/functions.c python-ldap/Modules/functions.c
--- python-ldap.TLS_PROTOCOL_MIN/Modules/functions.c 2009-08-17 01:00:57.0 -0400
+++ python-ldap/Modules/functions.c 2009-10-22 13:15:40.0 -0400
@@ -24,7 +24,7 @@ l_ldap_initialize(PyObject* unused, PyOb
ret = ldap_initialize(&ld, uri);
Py_END_ALLOW_THREADS
if (ret != LDAP_SUCCESS)
- return LDAPerror(ld, "ldap_initialize");
+ return LDAPerror(ld, "ldap_initialize", -1);
return (PyObject*)newLDAPObject(ld);
}
Only in python-ldap/Modules: functions.c.orig
diff -urwp python-ldap.TLS_PROTOCOL_MIN/Modules/LDAPObject.c python-ldap/Modules/LDAPObject.c
--- python-ldap.TLS_PROTOCOL_MIN/Modules/LDAPObject.c 2009-10-08 14:22:44.0 -0400
+++ python-ldap/Modules/LDAPObject.c 2009-10-22 13:17:01.0 -0400
@@ -355,7 +355,7 @@ l_ldap_unbind_ext( LDAPObject* self, PyO
LDAPControl_List_DEL( client_ldcs );
if ( ldaperror!=LDAP_SUCCESS )
- return LDAPerror( self->ldap, "ldap_unbind_ext" );
+ return LDAPerror( self->ldap, "ldap_unbind_ext", -1 );
self->valid = 0;
Py_INCREF(Py_None);
@@ -396,7 +396,7 @@ l_ldap_abandon_ext( LDAPObject* self, Py
LDAPControl_List_DEL( client_ldcs );
if ( ldaperror!=LDAP_SUCCESS )
- return LDAPerror( self->ldap, "ldap_abandon_ext" );
+ return LDAPerror( self->ldap, "ldap_abandon_ext", -1 );
Py_INCREF(Py_None);
return Py_None;
@@ -443,7 +443,7 @@ l_ldap_add_ext( LDAPObject* self, PyObje
LDAPControl_List_DEL( client_ldcs );
if ( ldaperror!=LDAP_SUCCESS )
- return LDAPerror( self->ldap, "ldap_add_ext" );
+ return LDAPerror( self->ldap, "ldap_add_ext", -1 );
return PyInt_FromLong(msgid);
}
@@ -486,7 +486,7 @@ l_ldap_simple_bind( LDAPObject* self, Py
LDAPControl_List_DEL( client_ldcs );
if ( ldaperror!=LDAP_SUCCESS )
- return LDAPerror( self->ldap, "ldap_simple_bind" );
+ return LDAPerror( self->ldap, "ldap_simple_bind", -1 );
return PyInt_FromLong( msgid );
}
@@ -684,7 +684,7 @@ l_ldap_sasl_interactive_bind_s( LDAPObje
LDAPControl_List_DEL( client_ldcs );
if (msgid != LDAP_SUCCESS)
- return LDAPerror( self->ldap, "ldap_sasl_interactive_bind_s" );
+ return LDAPerror( self->ldap, "ldap_sasl_interactive_bind_s", -1 );
return PyInt_FromLong( msgid );
}
#endif
@@ -727,7 +727,7 @@ l_ldap_cancel( LDAPObject* self, PyObjec
LDAPControl_List_DEL( clie
Re: Preparing release 2.3.10, please test!
Chris Dukes wrote: > > I went to check my patch to provide msgid in a result exception against > 2.3.10. > I have found a problem on constants.c > [..] > Modules/constants.c:185: error: ‘LDAP_OPT_X_TLS_PROTOCOL_MIN’ undeclared > (first use in this function) Should be #ifdef LDAP_OPT_X_TLS_PROTOCOL_MIN add_int(d,OPT_X_TLS_PROTOCOL_MIN); #endif Will committ the patch later. Thanks for testing! Ciao, Michael. -- Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference ___ Python-LDAP-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/python-ldap-dev
