summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb.i
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2008-03-26 15:18:17 +1100
committerAndrew Bartlett <abartlet@samba.org>2008-03-26 15:18:17 +1100
commitff8256ad6ce4e62462e4b58cfcff1005f6363226 (patch)
tree9a5bbcd1481f505b7d1edeae09427d13e8b2cf3d /source4/lib/ldb/ldb.i
parent5738491674574cd913dac2ad4f3851f4a0189ef4 (diff)
downloadsamba-ff8256ad6ce4e62462e4b58cfcff1005f6363226.tar.gz
samba-ff8256ad6ce4e62462e4b58cfcff1005f6363226.tar.bz2
samba-ff8256ad6ce4e62462e4b58cfcff1005f6363226.zip
Clean up the ldb python bindings to be 64 bit safe.
Thanks in particular to arkanes and KirkMcDonald on #python for their assistance, suggesting breaking the DN check. I eventually found it while trying to cut down on the number of gcc warnings, which is why we also add printf annotations. Andrew Bartlett (This used to be commit ba30e82d4efcba23c49622de43d3d6fc9c800e35)
Diffstat (limited to 'source4/lib/ldb/ldb.i')
-rw-r--r--source4/lib/ldb/ldb.i25
1 files changed, 17 insertions, 8 deletions
diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i
index b0723a8ecd..e01a1107d2 100644
--- a/source4/lib/ldb/ldb.i
+++ b/source4/lib/ldb/ldb.i
@@ -469,6 +469,8 @@ typedef struct ldb_ldif ldb_ldif;
#ifdef SWIGPYTHON
%{
+static void py_ldb_debug(void *context, enum ldb_debug_level level, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3, 0);
+
static void py_ldb_debug(void *context, enum ldb_debug_level level, const char *fmt, va_list ap)
{
char *text;
@@ -564,22 +566,29 @@ PyObject *PyExc_LdbError;
};
%typemap(in,numinputs=1) ldb_msg *add_msg {
- int dict_pos, msg_pos;
- PyObject *key, *value;
+ Py_ssize_t dict_pos, msg_pos;
ldb_msg_element *msgel;
+ PyObject *key, *value;
if (PyDict_Check($input)) {
+ PyObject *dn_value = PyDict_GetItemString($input, "dn");
$1 = ldb_msg_new(NULL);
$1->elements = talloc_zero_array($1, struct ldb_message_element, PyDict_Size($input));
msg_pos = dict_pos = 0;
- while (PyDict_Next($input, &dict_pos, &key, &value)) {
- if (strcmp(PyString_AsString(key), "dn") == 0) {
- /* using argp0 (magic SWIG value) here is a hack */
- if (ldb_dn_from_pyobject($1, value, argp1, &$1->dn) != 0) {
+ if (dn_value) {
+ /* using argp1 (magic SWIG value) here is a hack */
+ if (ldb_dn_from_pyobject($1, dn_value, argp1, &$1->dn) != 0) {
SWIG_exception(SWIG_TypeError, "unable to import dn object");
}
- } else {
- msgel = ldb_msg_element_from_pyobject($1->elements, value, 0, PyString_AsString(key));
+ if ($1->dn == NULL) {
+ SWIG_exception(SWIG_TypeError, "dn set but not found");
+ }
+ }
+
+ while (PyDict_Next($input, &dict_pos, &key, &value)) {
+ char *key_str = PyString_AsString(key);
+ if (strcmp(key_str, "dn") != 0) {
+ msgel = ldb_msg_element_from_pyobject($1->elements, value, 0, key_str);
if (msgel == NULL) {
SWIG_exception(SWIG_TypeError, "unable to import element");
}