Skip to content

Commit

Permalink
str(errno) as info attribute of LDAPError instance in case of LDAP_OP…
Browse files Browse the repository at this point in the history
…T_ERROR_STRING returning null-string
  • Loading branch information
stroeder committed Apr 24, 2017
1 parent 11932ab commit 44a4bfa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Lib/
* removed unused 2nd argument of ldap.schema.tokenizer.split_tokens()
* fixed method calls in ReconnectLDAPObject (thanks to Philipp Hahn)

Modules/
* an empty info message is replaced with str(errno) if errno is non-zero
which gives more information e.g. in case of ldap.SERVER_DOWN
(thanks to Markus Klein)

Tests/
* re-factored t_ldap_schema_tokenizer.py

Expand Down Expand Up @@ -1348,4 +1353,4 @@ Released 2.0.0pre02 2002-02-01
----------------------------------------------------------------
Released 1.10alpha3 2000-09-19

$Id: CHANGES,v 1.413 2017/04/24 08:25:16 stroeder Exp $
$Id: CHANGES,v 1.414 2017/04/24 18:32:50 stroeder Exp $
14 changes: 10 additions & 4 deletions Modules/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* errors that arise from ldap use
* Most errors become their own exception
* See http://www.python-ldap.org/ for details.
* $Id: errors.c,v 1.27 2017/04/24 13:48:15 stroeder Exp $ */
* $Id: errors.c,v 1.28 2017/04/24 18:32:51 stroeder Exp $ */

#include "common.h"
#include "errors.h"
#include <errno.h>
#include <string.h>

/* the base exception class */

Expand Down Expand Up @@ -96,13 +98,17 @@ LDAPerror( LDAP *l, char *msg )
if (str)
PyDict_SetItemString( info, "info", str );
Py_XDECREF(str);
} else if (ldap_get_option(l, LDAP_OPT_ERROR_STRING, &error) >= 0
&& error != NULL) {
if (*error != '\0') {
} else if (ldap_get_option(l, LDAP_OPT_ERROR_STRING, &error) >= 0) {
if (error != NULL && *error != '\0') {
str = PyString_FromString(error);
if (str)
PyDict_SetItemString( info, "info", str );
Py_XDECREF(str);
} else if (errno != 0) {
str = PyString_FromString(strerror(errno));
if(str)
PyDict_SetItemString( info, "info", str);
Py_XDECREF(str);
}
ldap_memfree(error);
}
Expand Down

0 comments on commit 44a4bfa

Please sign in to comment.