From ea851658411e3ff03a906f7ae6afc7e9319d6f90 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Nov 2007 11:47:55 +0100 Subject: r26068: Import improved Python bindings for LDB, including tests. (This used to be commit fc3a8caef749ddac56a4f035dde8b6ceeaa95c48) --- source4/lib/ldb/ldb.i | 241 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 source4/lib/ldb/ldb.i (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i new file mode 100644 index 0000000000..cdf1d66de1 --- /dev/null +++ b/source4/lib/ldb/ldb.i @@ -0,0 +1,241 @@ +/* + Unix SMB/CIFS implementation. + + Swig interface to ldb. + + Copyright (C) 2005,2006 Tim Potter + Copyright (C) 2006 Simo Sorce + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see . +*/ + +%module ldb + +%{ + +/* Some typedefs to help swig along */ + +typedef unsigned char uint8_t; +typedef unsigned long long uint64_t; +typedef long long int64_t; + +/* Include headers */ + +#include +#include "talloc.h" +#include "ldb.h" + +%} + +%include "carrays.i" +%include "exception.i" + +/* + * Constants + */ + +#define LDB_SUCCESS 0 +#define LDB_ERR_OPERATIONS_ERROR 1 +#define LDB_ERR_PROTOCOL_ERROR 2 +#define LDB_ERR_TIME_LIMIT_EXCEEDED 3 +#define LDB_ERR_SIZE_LIMIT_EXCEEDED 4 +#define LDB_ERR_COMPARE_FALSE 5 +#define LDB_ERR_COMPARE_TRUE 6 +#define LDB_ERR_AUTH_METHOD_NOT_SUPPORTED 7 +#define LDB_ERR_STRONG_AUTH_REQUIRED 8 +/* 9 RESERVED */ +#define LDB_ERR_REFERRAL 10 +#define LDB_ERR_ADMIN_LIMIT_EXCEEDED 11 +#define LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION 12 +#define LDB_ERR_CONFIDENTIALITY_REQUIRED 13 +#define LDB_ERR_SASL_BIND_IN_PROGRESS 14 +#define LDB_ERR_NO_SUCH_ATTRIBUTE 16 +#define LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE 17 +#define LDB_ERR_INAPPROPRIATE_MATCHING 18 +#define LDB_ERR_CONSTRAINT_VIOLATION 19 +#define LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS 20 +#define LDB_ERR_INVALID_ATTRIBUTE_SYNTAX 21 +/* 22-31 unused */ +#define LDB_ERR_NO_SUCH_OBJECT 32 +#define LDB_ERR_ALIAS_PROBLEM 33 +#define LDB_ERR_INVALID_DN_SYNTAX 34 +/* 35 RESERVED */ +#define LDB_ERR_ALIAS_DEREFERENCING_PROBLEM 36 +/* 37-47 unused */ +#define LDB_ERR_INAPPROPRIATE_AUTHENTICATION 48 +#define LDB_ERR_INVALID_CREDENTIALS 49 +#define LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS 50 +#define LDB_ERR_BUSY 51 +#define LDB_ERR_UNAVAILABLE 52 +#define LDB_ERR_UNWILLING_TO_PERFORM 53 +#define LDB_ERR_LOOP_DETECT 54 +/* 55-63 unused */ +#define LDB_ERR_NAMING_VIOLATION 64 +#define LDB_ERR_OBJECT_CLASS_VIOLATION 65 +#define LDB_ERR_NOT_ALLOWED_ON_NON_LEAF 66 +#define LDB_ERR_NOT_ALLOWED_ON_RDN 67 +#define LDB_ERR_ENTRY_ALREADY_EXISTS 68 +#define LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED 69 +/* 70 RESERVED FOR CLDAP */ +#define LDB_ERR_AFFECTS_MULTIPLE_DSAS 71 +/* 72-79 unused */ +#define LDB_ERR_OTHER 80 + +enum ldb_scope {LDB_SCOPE_DEFAULT=-1, + LDB_SCOPE_BASE=0, + LDB_SCOPE_ONELEVEL=1, + LDB_SCOPE_SUBTREE=2}; + +/* + * Wrap struct ldb_context + */ + +/* The ldb functions will crash if a NULL ldb context is passed so + catch this before it happens. */ + +%typemap(check) struct ldb_context* { + if ($1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); +} + +/* + * Wrap a small bit of talloc + */ + +/* Use talloc_init() to create a parameter to pass to ldb_init(). Don't + forget to free it using talloc_free() afterwards. */ + +TALLOC_CTX *talloc_init(char *name); +int talloc_free(TALLOC_CTX *ptr); + +/* + * Wrap struct ldb_val + */ + +%typemap(in) struct ldb_val *INPUT (struct ldb_val temp) { + $1 = &temp; + if (!PyString_Check($input)) { + PyErr_SetString(PyExc_TypeError, "string arg expected"); + return NULL; + } + $1->length = PyString_Size($input); + $1->data = PyString_AsString($input); +} + +%typemap(out) struct ldb_val { + $result = PyString_FromStringAndSize($1.data, $1.length); +} + +/* + * Wrap struct ldb_result + */ + +%typemap(in, numinputs=0) struct ldb_result **OUT (struct ldb_result *temp_ldb_result) { + $1 = &temp_ldb_result; +} + +%typemap(argout) struct ldb_result ** { + resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_ldb_result, 0); +} + +%types(struct ldb_result *); + +/* + * Wrap struct ldb_message_element + */ + +%array_functions(struct ldb_val, ldb_val_array); + +struct ldb_message_element { + unsigned int flags; + const char *name; + unsigned int num_values; + struct ldb_val *values; +}; + +/* + * Wrap struct ldb_message + */ + +%array_functions(struct ldb_message_element, ldb_message_element_array); + +struct ldb_message { + struct ldb_dn *dn; + unsigned int num_elements; + struct ldb_message_element *elements; +}; + +/* + * Wrap struct ldb_result + */ + +%array_functions(struct ldb_message *, ldb_message_ptr_array); + +struct ldb_result { + unsigned int count; + struct ldb_message **msgs; + char **refs; + struct ldb_control **controls; +}; + +/* + * Wrap ldb functions + */ + +/* Initialisation */ + +int ldb_global_init(void); +struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx); + +/* Error handling */ + +const char *ldb_errstring(struct ldb_context *ldb); +const char *ldb_strerror(int ldb_err); + +/* Top-level ldb operations */ + +int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]); + +int ldb_search(struct ldb_context *ldb, struct ldb_dn *base, enum ldb_scope scope, const char *expression, const char * const *attrs, struct ldb_result **OUT); + +int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn); + +int ldb_rename(struct ldb_context *ldb, struct ldb_dn *olddn, struct ldb_dn *newdn); + +int ldb_add(struct ldb_context *ldb, const struct ldb_message *message); + +/* Ldb message operations */ + +struct ldb_message *ldb_msg_new(void *mem_ctx); + +struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg, const char *attr_name); + +int ldb_msg_add_value(struct ldb_message *msg, const char *attr_name, const struct ldb_val *val, struct ldb_message_element **return_el); + +void ldb_msg_remove_attr(struct ldb_message *msg, const char *attr); + +int ldb_msg_sanity_check(struct ldb_context *ldb, const struct ldb_message *msg); + +/* DN operations */ + +/* struct ldb_dn *ldb_dn_explode(void *mem_ctx, const char *dn); */ + +/* char *ldb_dn_linearize(void *mem_ctx, const struct ldb_dn *dn); */ + +%rename(ldb_context) Ldb; -- cgit From efc0cc6be26b1866aca871b2deb37452c9ea47f6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Nov 2007 12:31:47 +0100 Subject: r26080: Import updated LDB bindings. (This used to be commit 19342e66a7279805daf9f810b9dc808247110a8a) --- source4/lib/ldb/ldb.i | 593 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 460 insertions(+), 133 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index cdf1d66de1..9a55327a07 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -1,10 +1,11 @@ -/* +/* Unix SMB/CIFS implementation. Swig interface to ldb. Copyright (C) 2005,2006 Tim Potter Copyright (C) 2006 Simo Sorce + Copyright (C) 2007 Jelmer Vernooij ** NOTE! The following LGPL license applies to the ldb ** library. This does NOT imply that all of Samba is released @@ -24,82 +25,41 @@ License along with this library; if not, see . */ -%module ldb +%module(package="ldb") ldb %{ -/* Some typedefs to help swig along */ - -typedef unsigned char uint8_t; -typedef unsigned long long uint64_t; -typedef long long int64_t; - /* Include headers */ +#include #include #include "talloc.h" #include "ldb.h" +#include "ldb_errors.h" + +typedef struct ldb_message ldb_msg; +typedef struct ldb_context ldb; +typedef struct ldb_dn ldb_dn; +typedef struct ldb_ldif ldb_ldif; +typedef struct ldb_message_element ldb_msg_element; +typedef int ldb_error; %} -%include "carrays.i" +%import "carrays.i" +%import "typemaps.i" %include "exception.i" +%import "stdint.i" -/* - * Constants - */ +%constant int SCOPE_DEFAULT = LDB_SCOPE_DEFAULT; +%constant int SCOPE_BASE = LDB_SCOPE_BASE; +%constant int SCOPE_ONELEVEL = LDB_SCOPE_ONELEVEL; +%constant int SCOPE_SUBTREE = LDB_SCOPE_SUBTREE; -#define LDB_SUCCESS 0 -#define LDB_ERR_OPERATIONS_ERROR 1 -#define LDB_ERR_PROTOCOL_ERROR 2 -#define LDB_ERR_TIME_LIMIT_EXCEEDED 3 -#define LDB_ERR_SIZE_LIMIT_EXCEEDED 4 -#define LDB_ERR_COMPARE_FALSE 5 -#define LDB_ERR_COMPARE_TRUE 6 -#define LDB_ERR_AUTH_METHOD_NOT_SUPPORTED 7 -#define LDB_ERR_STRONG_AUTH_REQUIRED 8 -/* 9 RESERVED */ -#define LDB_ERR_REFERRAL 10 -#define LDB_ERR_ADMIN_LIMIT_EXCEEDED 11 -#define LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION 12 -#define LDB_ERR_CONFIDENTIALITY_REQUIRED 13 -#define LDB_ERR_SASL_BIND_IN_PROGRESS 14 -#define LDB_ERR_NO_SUCH_ATTRIBUTE 16 -#define LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE 17 -#define LDB_ERR_INAPPROPRIATE_MATCHING 18 -#define LDB_ERR_CONSTRAINT_VIOLATION 19 -#define LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS 20 -#define LDB_ERR_INVALID_ATTRIBUTE_SYNTAX 21 -/* 22-31 unused */ -#define LDB_ERR_NO_SUCH_OBJECT 32 -#define LDB_ERR_ALIAS_PROBLEM 33 -#define LDB_ERR_INVALID_DN_SYNTAX 34 -/* 35 RESERVED */ -#define LDB_ERR_ALIAS_DEREFERENCING_PROBLEM 36 -/* 37-47 unused */ -#define LDB_ERR_INAPPROPRIATE_AUTHENTICATION 48 -#define LDB_ERR_INVALID_CREDENTIALS 49 -#define LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS 50 -#define LDB_ERR_BUSY 51 -#define LDB_ERR_UNAVAILABLE 52 -#define LDB_ERR_UNWILLING_TO_PERFORM 53 -#define LDB_ERR_LOOP_DETECT 54 -/* 55-63 unused */ -#define LDB_ERR_NAMING_VIOLATION 64 -#define LDB_ERR_OBJECT_CLASS_VIOLATION 65 -#define LDB_ERR_NOT_ALLOWED_ON_NON_LEAF 66 -#define LDB_ERR_NOT_ALLOWED_ON_RDN 67 -#define LDB_ERR_ENTRY_ALREADY_EXISTS 68 -#define LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED 69 -/* 70 RESERVED FOR CLDAP */ -#define LDB_ERR_AFFECTS_MULTIPLE_DSAS 71 -/* 72-79 unused */ -#define LDB_ERR_OTHER 80 - -enum ldb_scope {LDB_SCOPE_DEFAULT=-1, - LDB_SCOPE_BASE=0, - LDB_SCOPE_ONELEVEL=1, - LDB_SCOPE_SUBTREE=2}; +%constant int CHANGETYPE_NONE = LDB_CHANGETYPE_NONE; +%constant int CHANGETYPE_ADD = LDB_CHANGETYPE_ADD; +%constant int CHANGETYPE_DELETE = LDB_CHANGETYPE_DELETE; +%constant int CHANGETYPE_MODIFY = LDB_CHANGETYPE_MODIFY; /* * Wrap struct ldb_context @@ -114,16 +74,16 @@ enum ldb_scope {LDB_SCOPE_DEFAULT=-1, "ldb context must be non-NULL"); } +%typemap(check) ldb_msg * { + if ($1 == NULL) + SWIG_exception(SWIG_ValueError, + "Message can not be None"); +} + /* * Wrap a small bit of talloc */ -/* Use talloc_init() to create a parameter to pass to ldb_init(). Don't - forget to free it using talloc_free() afterwards. */ - -TALLOC_CTX *talloc_init(char *name); -int talloc_free(TALLOC_CTX *ptr); - /* * Wrap struct ldb_val */ @@ -139,103 +99,470 @@ int talloc_free(TALLOC_CTX *ptr); } %typemap(out) struct ldb_val { - $result = PyString_FromStringAndSize($1.data, $1.length); + $result = PyString_FromStringAndSize((const char *)$1.data, $1.length); } -/* - * Wrap struct ldb_result - */ - -%typemap(in, numinputs=0) struct ldb_result **OUT (struct ldb_result *temp_ldb_result) { - $1 = &temp_ldb_result; +%typemap(in) ldb_msg *add_msg (int dict_pos, int msg_pos, PyObject *key, + PyObject *value, ldb_msg_element *msgel) { + if (PyDict_Check($input)) { + $1 = ldb_msg_new(NULL); + $1->num_elements = PyDict_Size($input) - 1; /* dn isn't in there */ + $1->elements = talloc_zero_array($1, struct ldb_message_element, $1->num_elements+1); + msg_pos = dict_pos = 0; + while (PyDict_Next($input, &dict_pos, &key, &value)) { + if (!strcmp(PyString_AsString(key), "dn")) { + if (ldb_dn_from_pyobject(value, &$1->dn) != 0) + SWIG_exception(SWIG_TypeError, "unable to convert dn"); + } else { + msgel = ldb_msg_element_from_pyobject(value, 0, PyString_AsString(key)); + memcpy(&$1->elements[msg_pos], msgel, sizeof(*msgel)); + msg_pos++; + } + dict_pos++; + } + + if ($1->dn == NULL) + SWIG_exception(SWIG_TypeError, "no dn set"); + } else { + if (SWIG_ConvertPtr($input, &$1, SWIGTYPE_p_ldb_message, 0) != 0) + return NULL; + } } -%typemap(argout) struct ldb_result ** { - resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_ldb_result, 0); -} - -%types(struct ldb_result *); - -/* - * Wrap struct ldb_message_element - */ - -%array_functions(struct ldb_val, ldb_val_array); +%typemap(freearg) ldb_msg *add_msg { +//talloc_free($1); +} -struct ldb_message_element { - unsigned int flags; - const char *name; - unsigned int num_values; - struct ldb_val *values; -}; /* - * Wrap struct ldb_message + * Wrap struct ldb_result */ -%array_functions(struct ldb_message_element, ldb_message_element_array); +%typemap(in, numinputs=0) struct ldb_result **OUT (struct ldb_result *temp_ldb_result) { + $1 = &temp_ldb_result; +} -struct ldb_message { - struct ldb_dn *dn; - unsigned int num_elements; - struct ldb_message_element *elements; -}; +#ifdef SWIGPYTHON +%typemap(argout) struct ldb_result ** (int i) { + $result = PyList_New((*$1)->count); + for (i = 0; i < (*$1)->count; i++) { + PyList_SetItem($result, i, + SWIG_NewPointerObj((*$1)->msgs[i], SWIGTYPE_p_ldb_message, 0) + ); + } +} -/* - * Wrap struct ldb_result - */ +%typemap(in, numinputs=1) const char * const *attrs { + if ($input == Py_None) { + $1 = NULL; + } else if (PySequence_Check($input)) { + int i; + $1 = talloc_array(NULL, char *, PySequence_Size($input)+1); + for(i = 0; i < PySequence_Size($input); i++) + $1[i] = PyString_AsString(PySequence_GetItem($input, i)); + $1[i] = NULL; + } else { + SWIG_exception(SWIG_TypeError, "expected sequence"); + } +} -%array_functions(struct ldb_message *, ldb_message_ptr_array); +%typemap(freearg) const char * const *attrs { + talloc_free($1); +} +#endif -struct ldb_result { - unsigned int count; - struct ldb_message **msgs; - char **refs; - struct ldb_control **controls; -}; +%types(struct ldb_result *); /* - * Wrap ldb functions + * Wrap struct ldb_dn */ -/* Initialisation */ +%rename(__str__) ldb_dn::get_linearized; +%rename(__cmp__) ldb_dn::compare; +%rename(__len__) ldb_dn::get_comp_num; +%rename(Dn) ldb_dn; +typedef struct ldb_dn { + %extend { + ldb_dn(ldb *ldb, const char *str) + { + ldb_dn *ret = ldb_dn_new(ldb, ldb, str); + /* ldb_dn_new() doesn't accept NULL as memory context, so + we do it this way... */ + talloc_steal(NULL, ret); + + if (ret == NULL) + SWIG_exception(SWIG_ValueError, + "unable to parse dn string"); +fail: + return ret; + } + ~ldb_dn() { talloc_free($self); } + bool validate(); + const char *get_casefold(); + const char *get_linearized(); + ldb_dn *parent() { return ldb_dn_get_parent(NULL, $self); } + int compare(ldb_dn *other); + bool is_valid(); + bool is_special(); + bool is_null(); + bool check_special(const char *name); + int get_comp_num(); + bool add_child(ldb_dn *child); + bool add_base(ldb_dn *base); + const char *canonical_str() { + return ldb_dn_canonical_string($self, $self); + } + const char *canonical_ex_str() { + return ldb_dn_canonical_ex_string($self, $self); + } +#ifdef SWIGPYTHON + ldb_dn *__add__(ldb_dn *other) + { + ldb_dn *ret = ldb_dn_copy(NULL, $self); + ldb_dn_add_child(ret, other); + return ret; + } + + /* FIXME: implement __getslice__ */ +#endif + } +} ldb_dn; + +#ifdef SWIGPYTHON +%inline { +int ldb_dn_from_pyobject(PyObject *object, ldb_dn **dn) +{ + return SWIG_ConvertPtr(object, dn, SWIGTYPE_p_ldb_dn, 0); +} -int ldb_global_init(void); -struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx); +ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags, + const char *attr_name) +{ + struct ldb_message_element *me = talloc(NULL, struct ldb_message_element); + me->name = attr_name; + me->flags = flags; + if (PyString_Check(set_obj)) { + me->num_values = 1; + me->values = talloc_array(me, struct ldb_val, me->num_values); + me->values[0].length = PyString_Size(set_obj); + me->values[0].data = (uint8_t *)talloc_strdup(me->values, + PyString_AsString(set_obj)); + } else if (PySequence_Check(set_obj)) { + int i; + me->num_values = PySequence_Size(set_obj); + me->values = talloc_array(me, struct ldb_val, me->num_values); + for (i = 0; i < me->num_values; i++) { + PyObject *obj = PySequence_GetItem(set_obj, i); + me->values[i].length = PyString_Size(obj); + me->values[i].data = (uint8_t *)PyString_AsString(obj); + } + } else { + talloc_free(me); + me = NULL; + } + + return me; +} -/* Error handling */ +PyObject *ldb_msg_element_to_set(ldb_msg_element *me) +{ + int i; + PyObject *result; -const char *ldb_errstring(struct ldb_context *ldb); -const char *ldb_strerror(int ldb_err); + /* Python << 2.5 doesn't have PySet_New and PySet_Add. */ + result = PyList_New(me->num_values); -/* Top-level ldb operations */ + for (i = 0; i < me->num_values; i++) { + PyList_SetItem(result, i, + PyString_FromStringAndSize((const char *)me->values[i].data, + me->values[i].length)); + } -int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]); + return result; +} -int ldb_search(struct ldb_context *ldb, struct ldb_dn *base, enum ldb_scope scope, const char *expression, const char * const *attrs, struct ldb_result **OUT); +} +#endif + +/* ldb_message_element */ +%rename(__cmp__) ldb_message_element::compare; +%rename(MessageElement) ldb_msg_element; +typedef struct ldb_message_element { + %extend { +#ifdef SWIGPYTHON + PyObject *__iter__(void) + { + return PyObject_GetIter(ldb_msg_element_to_set($self)); + } + + PyObject *__set__(void) + { + return ldb_msg_element_to_set($self); + } + + ldb_msg_element(PyObject *set_obj, int flags=0, const char *name = NULL) + { + return ldb_msg_element_from_pyobject(set_obj, flags, name); + } +#endif + ~ldb_msg_element() { talloc_free($self); } + int compare(ldb_msg_element *); + } +} ldb_msg_element; + +/* ldb_message */ + +%rename(Message) ldb_message; +#ifdef SWIGPYTHON +%rename(__delitem__) ldb_message::remove_attr; +%typemap(out) ldb_msg_element * { + if ($1 == NULL) + PyErr_SetString(PyExc_KeyError, "no such element"); + else + $result = SWIG_NewPointerObj($1, SWIGTYPE_p_ldb_message_element, 0); +} +%rename(__getitem__) ldb_message::find_element; +//%typemap(out) ldb_msg_element *; + + +%inline { + PyObject *ldb_msg_list_elements(ldb_msg *msg) + { + int i; + PyObject *obj = PyList_New(msg->num_elements); + for (i = 0; i < msg->num_elements; i++) + PyList_SetItem(obj, i, PyString_FromString(msg->elements[i].name)); + return obj; + } +} -int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn); +#endif + +typedef struct ldb_message { + ldb_dn *dn; + + %extend { + ldb_msg(ldb_dn *dn = NULL) { + ldb_msg *ret = ldb_msg_new(NULL); + ret->dn = talloc_reference(ret, dn); + return ret; + } + ~ldb_msg() { talloc_free($self); } + + ldb_msg_element *find_element(const char *name); + +#ifdef SWIGPYTHON + void __setitem__(const char *attr_name, ldb_msg_element *val) + { + struct ldb_message_element *el; + + ldb_msg_remove_attr($self, attr_name); + + el = talloc($self, struct ldb_message_element); + el->name = talloc_strdup(el, attr_name); + el->num_values = val->num_values; + el->values = talloc_reference(el, val->values); + + ldb_msg_add($self, el, val->flags); + } + + void __setitem__(const char *attr_name, PyObject *val) + { + struct ldb_message_element *el = ldb_msg_element_from_pyobject( + val, 0, attr_name); + talloc_steal($self, el); + ldb_msg_remove_attr($self, attr_name); + ldb_msg_add($self, el, el->flags); + } + + unsigned int __len__() { return $self->num_elements; } + + PyObject *keys(void) + { + return ldb_msg_list_elements($self); + } + + PyObject *__iter__(void) + { + return PyObject_GetIter(ldb_msg_list_elements($self)); + } +#endif + void remove_attr(const char *name); + } +} ldb_msg; + +/* FIXME: Convert ldb_result to 3-tuple: + (msgs, refs, controls) + */ -int ldb_rename(struct ldb_context *ldb, struct ldb_dn *olddn, struct ldb_dn *newdn); +typedef struct ldb_ldif ldb_ldif; -int ldb_add(struct ldb_context *ldb, const struct ldb_message *message); +#ifdef SWIGPYTHON +%{ +static void py_ldb_debug(void *context, enum ldb_debug_level level, const char *fmt, va_list ap) +{ + char *text; + PyObject *fn = context; + + vasprintf(&text, fmt, ap); + PyObject_CallFunction(fn, "(i,s)", level, text); + free(text); +} +%} -/* Ldb message operations */ +%typemap(in,numinputs=1) (void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), + void *context) { + $1 = py_ldb_debug; + /* FIXME: Should be decreased somewhere as well. Perhaps register a destructor and + tie it to the ldb context ? */ + Py_INCREF($input); + $2 = $input; +} +#endif + +%inline { + static PyObject *ldb_ldif_to_pyobject(ldb_ldif *ldif) + { + if (ldif == NULL) { + return Py_None; + } else { + return Py_BuildValue("(iO)", ldif->changetype, + SWIG_NewPointerObj(ldif->msg, SWIGTYPE_p_ldb_message, 0)); + } + } +} -struct ldb_message *ldb_msg_new(void *mem_ctx); +/* + * Wrap ldb errors + */ -struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg, const char *attr_name); +%{ +PyObject *PyExc_LdbError; +%} -int ldb_msg_add_value(struct ldb_message *msg, const char *attr_name, const struct ldb_val *val, struct ldb_message_element **return_el); +%pythoncode %{ + LdbError = _ldb.LdbError +%} -void ldb_msg_remove_attr(struct ldb_message *msg, const char *attr); +%init %{ + PyExc_LdbError = PyErr_NewException("_ldb.LdbError", NULL, NULL); + PyDict_SetItemString(d, "LdbError", PyExc_LdbError); +%} -int ldb_msg_sanity_check(struct ldb_context *ldb, const struct ldb_message *msg); +%ignore _LDB_ERRORS_H_; +%ignore LDB_SUCCESS; +%include "include/ldb_errors.h" -/* DN operations */ +/* + * Wrap ldb functions + */ -/* struct ldb_dn *ldb_dn_explode(void *mem_ctx, const char *dn); */ +%rename(Ldb) ldb; +/* Top-level ldb operations */ +typedef struct ldb_context { + %typemap(out) ldb_error { + if ($1 != LDB_SUCCESS) { + PyErr_SetObject(PyExc_LdbError, Py_BuildValue("(i,s)", $1, ldb_strerror($1))); + SWIG_fail; + } + $result = Py_None; + }; + %extend { + ldb(const char *url=NULL, unsigned int flags = 0, + const char *options[] = NULL) + { + ldb *ldb = ldb_init(NULL); + + if (url != NULL) { + int ret; + + ret = ldb_connect(ldb, url, flags, options); + if (ret != LDB_SUCCESS) + SWIG_exception(SWIG_ValueError, ldb_errstring(ldb)); + } + + return ldb; + +fail: + talloc_free(ldb); + return NULL; + } + + ldb_error connect(const char *url, unsigned int flags = 0, + const char *options[] = NULL); + + ~ldb() { talloc_free($self); } + ldb_error search(ldb_dn *base = NULL, + enum ldb_scope scope = LDB_SCOPE_DEFAULT, + const char *expression = NULL, + const char * const *attrs = NULL, + struct ldb_result **OUT); + ldb_error delete(ldb_dn *dn); + ldb_error rename(ldb_dn *olddn, ldb_dn *newdn); + ldb_error add(ldb_msg *add_msg); + ldb_error modify(ldb_msg *message); + ldb_dn *get_config_basedn(); + ldb_dn *get_root_basedn(); + ldb_dn *get_schema_basedn(); + ldb_dn *get_default_basedn(); + const char *errstring(); + void set_create_perms(unsigned int perms); + void set_modules_dir(const char *path); + ldb_error set_debug(void (*debug)(void *context, enum ldb_debug_level level, + const char *fmt, va_list ap), + void *context); + ldb_error set_opaque(const char *name, void *value); + void *get_opaque(const char *name); + ldb_error transaction_start(); + ldb_error transaction_commit(); + ldb_error transaction_cancel(); + +#ifdef SWIGPYTHON + bool __contains__(ldb_dn *dn) + { + struct ldb_result *result; + + int ret = ldb_search($self, dn, LDB_SCOPE_BASE, NULL, NULL, + &result); + + /* FIXME: Check ret and set exception if necessary */ + + return result->count > 0; + } + + PyObject *parse_ldif(const char *s) + { + PyObject *list = PyList_New(0); + struct ldb_ldif *ldif; + while ((ldif = ldb_ldif_read_string($self, &s)) != NULL) { + PyList_Append(list, ldb_ldif_to_pyobject(ldif)); + } + return PyObject_GetIter(list); + } + +#endif + } +} ldb; + +%nodefault ldb_message; +%nodefault Ldb; +%nodefault Dn; + +%rename(valid_attr_name) ldb_valid_attr_name; +int ldb_valid_attr_name(const char *s); + +typedef unsigned long time_t; -/* char *ldb_dn_linearize(void *mem_ctx, const struct ldb_dn *dn); */ +%{ +char *timestring(time_t t) +{ + char *tresult = ldb_timestring(NULL, t); + char *result = strdup(tresult); + talloc_free(tresult); + return result; +} +%} +char *timestring(time_t t); -%rename(ldb_context) Ldb; +%rename(string_to_time) ldb_string_to_time; +time_t ldb_string_to_time(const char *s); -- cgit From 39adc2418a0586261c6c4aea36f72596c6cf8897 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Nov 2007 13:07:16 +0100 Subject: r26088: Import some native-python python modules and move original python swig torture code to common python directory as well. (This used to be commit cbf656ff054ab2b0b5ca81e1d4f16ac54c8098f1) --- source4/lib/ldb/ldb.i | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 9a55327a07..b37082af38 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -553,8 +553,8 @@ int ldb_valid_attr_name(const char *s); typedef unsigned long time_t; -%{ -char *timestring(time_t t) +%inline %{ +static char *timestring(time_t t) { char *tresult = ldb_timestring(NULL, t); char *result = strdup(tresult); @@ -562,7 +562,6 @@ char *timestring(time_t t) return result; } %} -char *timestring(time_t t); %rename(string_to_time) ldb_string_to_time; time_t ldb_string_to_time(const char *s); -- cgit From 3023afce68684b5c256c1951adb62f255e00c7bc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 Nov 2007 14:26:16 +0100 Subject: r26112: Do proper error checking in __contains__. (This used to be commit b67cc409fa5aa931b0847b7d3bdd2edf72daf88d) --- source4/lib/ldb/ldb.i | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index b37082af38..3b7a949fb7 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -29,8 +29,6 @@ %{ -/* Include headers */ - #include #include #include "talloc.h" @@ -80,10 +78,6 @@ typedef int ldb_error; "Message can not be None"); } -/* - * Wrap a small bit of talloc - */ - /* * Wrap struct ldb_val */ @@ -133,7 +127,6 @@ typedef int ldb_error; //talloc_free($1); } - /* * Wrap struct ldb_result */ @@ -413,8 +406,8 @@ static void py_ldb_debug(void *context, enum ldb_debug_level level, const char * %typemap(in,numinputs=1) (void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), void *context) { $1 = py_ldb_debug; - /* FIXME: Should be decreased somewhere as well. Perhaps register a destructor and - tie it to the ldb context ? */ + /* FIXME: Should be decreased somewhere as well. Perhaps register a + destructor and tie it to the ldb context ? */ Py_INCREF($input); $2 = $input; } @@ -518,16 +511,13 @@ fail: ldb_error transaction_cancel(); #ifdef SWIGPYTHON - bool __contains__(ldb_dn *dn) + %typemap(in,numinputs=0) struct ldb_result **result_as_bool (struct ldb_result *tmp) { $1 = &tmp; } + %typemap(argout) struct ldb_result **result_as_bool { $result = ((*$1)->count > 0)?Py_True:Py_False; } + %typemap(freearg) struct ldb_result **result_as_bool { talloc_free(*$1); } + ldb_error __contains__(ldb_dn *dn, struct ldb_result **result_as_bool) { - struct ldb_result *result; - - int ret = ldb_search($self, dn, LDB_SCOPE_BASE, NULL, NULL, - &result); - - /* FIXME: Check ret and set exception if necessary */ - - return result->count > 0; + return ldb_search($self, dn, LDB_SCOPE_BASE, NULL, NULL, + result_as_bool); } PyObject *parse_ldif(const char *s) -- cgit From e541cc54f41ff8ed88047b3533a5615beec0dbe7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 Nov 2007 20:12:08 +0100 Subject: r26119: Fix warnings. (This used to be commit 38a6522e44938ae05356916182d6c3bb1b6e881b) --- source4/lib/ldb/ldb.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 3b7a949fb7..9dd8f7c8af 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -118,7 +118,7 @@ typedef int ldb_error; if ($1->dn == NULL) SWIG_exception(SWIG_TypeError, "no dn set"); } else { - if (SWIG_ConvertPtr($input, &$1, SWIGTYPE_p_ldb_message, 0) != 0) + if (SWIG_ConvertPtr($input, (void **)&$1, SWIGTYPE_p_ldb_message, 0) != 0) return NULL; } } @@ -225,7 +225,7 @@ fail: %inline { int ldb_dn_from_pyobject(PyObject *object, ldb_dn **dn) { - return SWIG_ConvertPtr(object, dn, SWIGTYPE_p_ldb_dn, 0); + return SWIG_ConvertPtr(object, (void **)dn, SWIGTYPE_p_ldb_dn, 0); } ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags, -- cgit From f023784d066f25135c2e54e91475418e80070873 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 28 Nov 2007 22:41:34 +0100 Subject: r26187: Fix module name, indentation. (This used to be commit ef790ebf3a712dbbb85d6af65c804199c2c084fc) --- source4/lib/ldb/ldb.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 9dd8f7c8af..aec4e2294f 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -513,7 +513,7 @@ fail: #ifdef SWIGPYTHON %typemap(in,numinputs=0) struct ldb_result **result_as_bool (struct ldb_result *tmp) { $1 = &tmp; } %typemap(argout) struct ldb_result **result_as_bool { $result = ((*$1)->count > 0)?Py_True:Py_False; } - %typemap(freearg) struct ldb_result **result_as_bool { talloc_free(*$1); } + %typemap(freearg) struct ldb_result **result_as_bool { talloc_free(*$1); } ldb_error __contains__(ldb_dn *dn, struct ldb_result **result_as_bool) { return ldb_search($self, dn, LDB_SCOPE_BASE, NULL, NULL, -- cgit From 0a01f50f9802ecfae430d2218af3b96a3682218d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 16 Dec 2007 15:50:02 +0100 Subject: r26475: Add ldb.set_credentials function. (This used to be commit dbebb4ef477d2c8de7b8d1e5cde9b9dada47044f) --- source4/lib/ldb/ldb.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index aec4e2294f..364b07ce34 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -25,7 +25,7 @@ License along with this library; if not, see . */ -%module(package="ldb") ldb +%module ldb %{ -- cgit From b0360e3a8617c59661d0b0fd805666e6cefcd811 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 17 Dec 2007 08:20:20 +0100 Subject: r26496: Move some provision functions to a new SamDB class, support setting session_info on a ldb context from python. (This used to be commit 75cfb0d609687538048a7d72a499a5205af46a34) --- source4/lib/ldb/ldb.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 364b07ce34..97cc16806d 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -450,7 +450,7 @@ PyObject *PyExc_LdbError; * Wrap ldb functions */ -%rename(Ldb) ldb; +%rename(Ldb) ldb_context; /* Top-level ldb operations */ typedef struct ldb_context { %typemap(out) ldb_error { @@ -535,7 +535,7 @@ fail: } ldb; %nodefault ldb_message; -%nodefault Ldb; +%nodefault ldb_context; %nodefault Dn; %rename(valid_attr_name) ldb_valid_attr_name; -- cgit From 6e2459211dbd59c8884049faa0d63c1712dbadfe Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 19 Dec 2007 23:27:34 +0100 Subject: r26537: Support ldb.add({'dn': 'dc=foo,bar=bla', ...}). (This used to be commit e91fe76d296973430f71502c9b614d0dfac4d83c) --- source4/lib/ldb/ldb.i | 87 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 35 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 97cc16806d..15a49ec9c5 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -96,37 +96,6 @@ typedef int ldb_error; $result = PyString_FromStringAndSize((const char *)$1.data, $1.length); } -%typemap(in) ldb_msg *add_msg (int dict_pos, int msg_pos, PyObject *key, - PyObject *value, ldb_msg_element *msgel) { - if (PyDict_Check($input)) { - $1 = ldb_msg_new(NULL); - $1->num_elements = PyDict_Size($input) - 1; /* dn isn't in there */ - $1->elements = talloc_zero_array($1, struct ldb_message_element, $1->num_elements+1); - msg_pos = dict_pos = 0; - while (PyDict_Next($input, &dict_pos, &key, &value)) { - if (!strcmp(PyString_AsString(key), "dn")) { - if (ldb_dn_from_pyobject(value, &$1->dn) != 0) - SWIG_exception(SWIG_TypeError, "unable to convert dn"); - } else { - msgel = ldb_msg_element_from_pyobject(value, 0, PyString_AsString(key)); - memcpy(&$1->elements[msg_pos], msgel, sizeof(*msgel)); - msg_pos++; - } - dict_pos++; - } - - if ($1->dn == NULL) - SWIG_exception(SWIG_TypeError, "no dn set"); - } else { - if (SWIG_ConvertPtr($input, (void **)&$1, SWIGTYPE_p_ldb_message, 0) != 0) - return NULL; - } -} - -%typemap(freearg) ldb_msg *add_msg { -//talloc_free($1); -} - /* * Wrap struct ldb_result */ @@ -222,10 +191,16 @@ fail: } ldb_dn; #ifdef SWIGPYTHON -%inline { -int ldb_dn_from_pyobject(PyObject *object, ldb_dn **dn) +%{ +int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, + struct ldb_context *ldb, ldb_dn **dn) { - return SWIG_ConvertPtr(object, (void **)dn, SWIGTYPE_p_ldb_dn, 0); + if (ldb != NULL && PyString_Check(object)) { + *dn = ldb_dn_new(mem_ctx, ldb, PyString_AsString(object)); + return 0; + } + return SWIG_ConvertPtr(object, (void **)dn, SWIGTYPE_p_ldb_dn, + SWIG_POINTER_EXCEPTION); } ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags, @@ -274,7 +249,7 @@ PyObject *ldb_msg_element_to_set(ldb_msg_element *me) return result; } -} +%} #endif /* ldb_message_element */ @@ -493,6 +468,48 @@ fail: ldb_error delete(ldb_dn *dn); ldb_error rename(ldb_dn *olddn, ldb_dn *newdn); ldb_error add(ldb_msg *add_msg); + ldb_error add(PyObject *py_msg) + { + ldb_error ret; + int dict_pos, msg_pos; + PyObject *key, *value; + ldb_msg_element *msgel; + ldb_msg *msg = NULL; + if (PyDict_Check(py_msg)) { + msg = ldb_msg_new(NULL); + msg->num_elements = PyDict_Size(py_msg) - 1; /* dn isn't in there */ + msg->elements = talloc_zero_array(msg, struct ldb_message_element, msg->num_elements+1); + msg_pos = dict_pos = 0; + while (PyDict_Next(py_msg, &dict_pos, &key, &value)) { + if (!strcmp(PyString_AsString(key), "dn")) { + if (ldb_dn_from_pyobject(msg, value, $self, &msg->dn) != 0) { + return LDB_ERR_OTHER; + } + } else { + msgel = ldb_msg_element_from_pyobject(value, 0, PyString_AsString(key)); + memcpy(&msg->elements[msg_pos], msgel, sizeof(*msgel)); + msg_pos++; + } + dict_pos++; + } + + if (msg->dn == NULL) { + SWIG_exception(SWIG_TypeError, "no dn set"); + return LDB_ERR_OTHER; + } + } else { + if (SWIG_ConvertPtr(py_msg, (void **)&msg, SWIGTYPE_p_ldb_message, 0) != 0) + return LDB_ERR_OTHER; + } + + ret = ldb_add($self,msg); + + talloc_free(msg); + return ret; + + fail: + return LDB_ERR_OTHER; + } ldb_error modify(ldb_msg *message); ldb_dn *get_config_basedn(); ldb_dn *get_root_basedn(); -- cgit From fb021305e4bc1175ae0d1960fbafc7eba29ef2f0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 22 Dec 2007 14:28:45 -0600 Subject: r26567: Allow registering new ldb modules from python. (This used to be commit 485db76d8476fce399a9b6cb977cf55ea35ec189) --- source4/lib/ldb/ldb.i | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 15a49ec9c5..1ed1b45eaf 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -34,6 +34,7 @@ #include "talloc.h" #include "ldb.h" #include "ldb_errors.h" +#include "ldb_private.h" typedef struct ldb_message ldb_msg; typedef struct ldb_context ldb; @@ -425,16 +426,18 @@ PyObject *PyExc_LdbError; * Wrap ldb functions */ + +%typemap(out) ldb_error { + if ($1 != LDB_SUCCESS) { + PyErr_SetObject(PyExc_LdbError, Py_BuildValue("(i,s)", $1, ldb_strerror($1))); + SWIG_fail; + } + $result = Py_None; +}; + %rename(Ldb) ldb_context; /* Top-level ldb operations */ typedef struct ldb_context { - %typemap(out) ldb_error { - if ($1 != LDB_SUCCESS) { - PyErr_SetObject(PyExc_LdbError, Py_BuildValue("(i,s)", $1, ldb_strerror($1))); - SWIG_fail; - } - $result = Py_None; - }; %extend { ldb(const char *url=NULL, unsigned int flags = 0, const char *options[] = NULL) @@ -572,3 +575,12 @@ static char *timestring(time_t t) %rename(string_to_time) ldb_string_to_time; time_t ldb_string_to_time(const char *s); + +%typemap(in) const struct ldb_module_ops * { + $1 = talloc_zero(talloc_autofree_context(), struct ldb_module_ops); + + $1->name = PyObject_GetAttrString($input, "name"); +} + +%rename(register_module) ldb_register_module; +ldb_error ldb_register_module(const struct ldb_module_ops *); -- cgit From aa0a06f13c44e0eca0b3f2f0c34f0f7995b87159 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 23 Dec 2007 19:19:41 -0600 Subject: r26570: - Trim size of the swig-generated Python bindings by removing a bunch of {}'s. - Start working on Python equivalents for various EJS tests. - Fix regression in argument order for reg_diff_apply() in EJS bindings. (This used to be commit c550c03372cb260b78f6a6c132e70571bc4cb852) --- source4/lib/ldb/ldb.i | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 1ed1b45eaf..7c8241ba54 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -67,13 +67,13 @@ typedef int ldb_error; /* The ldb functions will crash if a NULL ldb context is passed so catch this before it happens. */ -%typemap(check) struct ldb_context* { +%typemap(check,noblock=1) struct ldb_context* { if ($1 == NULL) SWIG_exception(SWIG_ValueError, "ldb context must be non-NULL"); } -%typemap(check) ldb_msg * { +%typemap(check,noblock=1) ldb_msg * { if ($1 == NULL) SWIG_exception(SWIG_ValueError, "Message can not be None"); @@ -83,7 +83,7 @@ typedef int ldb_error; * Wrap struct ldb_val */ -%typemap(in) struct ldb_val *INPUT (struct ldb_val temp) { +%typemap(in,noblock=1) struct ldb_val *INPUT (struct ldb_val temp) { $1 = &temp; if (!PyString_Check($input)) { PyErr_SetString(PyExc_TypeError, "string arg expected"); @@ -93,7 +93,7 @@ typedef int ldb_error; $1->data = PyString_AsString($input); } -%typemap(out) struct ldb_val { +%typemap(out,noblock=1) struct ldb_val { $result = PyString_FromStringAndSize((const char *)$1.data, $1.length); } @@ -101,7 +101,7 @@ typedef int ldb_error; * Wrap struct ldb_result */ -%typemap(in, numinputs=0) struct ldb_result **OUT (struct ldb_result *temp_ldb_result) { +%typemap(in,noblock=1,numinputs=0) struct ldb_result **OUT (struct ldb_result *temp_ldb_result) { $1 = &temp_ldb_result; } @@ -115,7 +115,7 @@ typedef int ldb_error; } } -%typemap(in, numinputs=1) const char * const *attrs { +%typemap(in,noblock=1,numinputs=1) const char * const *attrs { if ($input == Py_None) { $1 = NULL; } else if (PySequence_Check($input)) { @@ -196,12 +196,16 @@ fail: int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, struct ldb_context *ldb, ldb_dn **dn) { + int ret; + struct ldb_dn *odn; if (ldb != NULL && PyString_Check(object)) { *dn = ldb_dn_new(mem_ctx, ldb, PyString_AsString(object)); return 0; } - return SWIG_ConvertPtr(object, (void **)dn, SWIGTYPE_p_ldb_dn, + ret = SWIG_ConvertPtr(object, (void **)&odn, SWIGTYPE_p_ldb_dn, SWIG_POINTER_EXCEPTION); + *dn = ldb_dn_copy(mem_ctx, odn); + return ret; } ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags, @@ -277,6 +281,15 @@ typedef struct ldb_message_element { ~ldb_msg_element() { talloc_free($self); } int compare(ldb_msg_element *); } + %pythoncode { + def __eq__(self, other): + if (isinstance(other, str) and + len(set(self)) == 1 and + set(self).pop() == other): + return True + return self.__cmp__(other) == 0 + + } } ldb_msg_element; /* ldb_message */ @@ -427,7 +440,7 @@ PyObject *PyExc_LdbError; */ -%typemap(out) ldb_error { +%typemap(out,noblock=1) ldb_error { if ($1 != LDB_SUCCESS) { PyErr_SetObject(PyExc_LdbError, Py_BuildValue("(i,s)", $1, ldb_strerror($1))); SWIG_fail; @@ -436,6 +449,17 @@ PyObject *PyExc_LdbError; }; %rename(Ldb) ldb_context; + +%typemap(in,noblock=1) struct ldb_dn * { + if (ldb_dn_from_pyobject(NULL, $input, arg1, &$1) != 0) { + SWIG_fail; + } +}; + +%typemap(freearg,noblock=1) struct ldb_dn * { + talloc_free($1); +}; + /* Top-level ldb operations */ typedef struct ldb_context { %extend { @@ -554,6 +578,9 @@ fail: } } ldb; +%typemap(in,noblock=1) struct ldb_dn *; +%typemap(freearg,noblock=1) struct ldb_dn *; + %nodefault ldb_message; %nodefault ldb_context; %nodefault Dn; -- cgit From d0ba9f001474bfee9b1e8fb516effab736cd4050 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 23 Dec 2007 20:56:41 -0600 Subject: r26572: Fix warnings in the Python code. (This used to be commit 15038d9586d0b58f301ca8c39c21ef10c4283f28) --- source4/lib/ldb/ldb.i | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 7c8241ba54..ffb69986e5 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -146,9 +146,9 @@ typedef int ldb_error; %rename(Dn) ldb_dn; typedef struct ldb_dn { %extend { - ldb_dn(ldb *ldb, const char *str) + ldb_dn(ldb *ldb_ctx, const char *str) { - ldb_dn *ret = ldb_dn_new(ldb, ldb, str); + ldb_dn *ret = ldb_dn_new(ldb_ctx, ldb_ctx, str); /* ldb_dn_new() doesn't accept NULL as memory context, so we do it this way... */ talloc_steal(NULL, ret); @@ -194,12 +194,12 @@ fail: #ifdef SWIGPYTHON %{ int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, - struct ldb_context *ldb, ldb_dn **dn) + struct ldb_context *ldb_ctx, ldb_dn **dn) { int ret; struct ldb_dn *odn; - if (ldb != NULL && PyString_Check(object)) { - *dn = ldb_dn_new(mem_ctx, ldb, PyString_AsString(object)); + if (ldb_ctx != NULL && PyString_Check(object)) { + *dn = ldb_dn_new(mem_ctx, ldb_ctx, PyString_AsString(object)); return 0; } ret = SWIG_ConvertPtr(object, (void **)&odn, SWIGTYPE_p_ldb_dn, @@ -387,7 +387,7 @@ static void py_ldb_debug(void *context, enum ldb_debug_level level, const char * PyObject *fn = context; vasprintf(&text, fmt, ap); - PyObject_CallFunction(fn, "(i,s)", level, text); + PyObject_CallFunction(fn, (char *)"(i,s)", level, text); free(text); } %} @@ -408,7 +408,7 @@ static void py_ldb_debug(void *context, enum ldb_debug_level level, const char * if (ldif == NULL) { return Py_None; } else { - return Py_BuildValue("(iO)", ldif->changetype, + return Py_BuildValue((char *)"(iO)", ldif->changetype, SWIG_NewPointerObj(ldif->msg, SWIGTYPE_p_ldb_message, 0)); } } @@ -427,7 +427,7 @@ PyObject *PyExc_LdbError; %} %init %{ - PyExc_LdbError = PyErr_NewException("_ldb.LdbError", NULL, NULL); + PyExc_LdbError = PyErr_NewException((char *)"_ldb.LdbError", NULL, NULL); PyDict_SetItemString(d, "LdbError", PyExc_LdbError); %} @@ -442,7 +442,7 @@ PyObject *PyExc_LdbError; %typemap(out,noblock=1) ldb_error { if ($1 != LDB_SUCCESS) { - PyErr_SetObject(PyExc_LdbError, Py_BuildValue("(i,s)", $1, ldb_strerror($1))); + PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(i,s)", $1, ldb_strerror($1))); SWIG_fail; } $result = Py_None; @@ -466,20 +466,20 @@ typedef struct ldb_context { ldb(const char *url=NULL, unsigned int flags = 0, const char *options[] = NULL) { - ldb *ldb = ldb_init(NULL); + ldb *ldb_ctx = ldb_init(NULL); if (url != NULL) { int ret; - ret = ldb_connect(ldb, url, flags, options); + ret = ldb_connect(ldb_ctx, url, flags, options); if (ret != LDB_SUCCESS) - SWIG_exception(SWIG_ValueError, ldb_errstring(ldb)); + SWIG_exception(SWIG_ValueError, ldb_errstring(ldb_ctx)); } - return ldb; + return ldb_ctx; fail: - talloc_free(ldb); + talloc_free(ldb_ctx); return NULL; } @@ -606,7 +606,7 @@ time_t ldb_string_to_time(const char *s); %typemap(in) const struct ldb_module_ops * { $1 = talloc_zero(talloc_autofree_context(), struct ldb_module_ops); - $1->name = PyObject_GetAttrString($input, "name"); + $1->name = (char *)PyObject_GetAttrString($input, (char *)"name"); } %rename(register_module) ldb_register_module; -- cgit From a822a14d1ec7e2635c3d004cc7488e4fd27b8d16 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Dec 2007 11:02:45 -0600 Subject: r26584: Fix exception handling in ldb constructor. (This used to be commit 5383cf8e69233b3cb7c1876f52644537e459dea6) --- source4/lib/ldb/ldb.i | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index ffb69986e5..7960d38bb5 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -463,25 +463,7 @@ PyObject *PyExc_LdbError; /* Top-level ldb operations */ typedef struct ldb_context { %extend { - ldb(const char *url=NULL, unsigned int flags = 0, - const char *options[] = NULL) - { - ldb *ldb_ctx = ldb_init(NULL); - - if (url != NULL) { - int ret; - - ret = ldb_connect(ldb_ctx, url, flags, options); - if (ret != LDB_SUCCESS) - SWIG_exception(SWIG_ValueError, ldb_errstring(ldb_ctx)); - } - - return ldb_ctx; - -fail: - talloc_free(ldb_ctx); - return NULL; - } + ldb(void) { return ldb_init(NULL); } ldb_error connect(const char *url, unsigned int flags = 0, const char *options[] = NULL); @@ -576,6 +558,13 @@ fail: #endif } + %pythoncode { + def __init__(self, url=None, flags=0, options=None): + _ldb.Ldb_swiginit(self,_ldb.new_Ldb()) + if url is not None: + self.connect(url, flags, options) + } + } ldb; %typemap(in,noblock=1) struct ldb_dn *; -- cgit From f4b30bebca41a2cf41d94acd0bd333358aebf8d0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 30 Dec 2007 16:46:14 -0600 Subject: r26631: ldb/python: Fix missing elements bug and memory leak. * Don't increase the PyDict_Next() counter - Python already does that for us. * Fix a talloc(NULL, ...) memory leak in the code that constructed ldb message elements. (This used to be commit dc2a612927289da78017abf4ad51a4d51292e3a1) --- source4/lib/ldb/ldb.i | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 7960d38bb5..5569d08ebb 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -208,10 +208,11 @@ int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, return ret; } -ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags, +ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, + PyObject *set_obj, int flags, const char *attr_name) { - struct ldb_message_element *me = talloc(NULL, struct ldb_message_element); + struct ldb_message_element *me = talloc(mem_ctx, struct ldb_message_element); me->name = attr_name; me->flags = flags; if (PyString_Check(set_obj)) { @@ -275,7 +276,7 @@ typedef struct ldb_message_element { ldb_msg_element(PyObject *set_obj, int flags=0, const char *name = NULL) { - return ldb_msg_element_from_pyobject(set_obj, flags, name); + return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name); } #endif ~ldb_msg_element() { talloc_free($self); } @@ -350,7 +351,7 @@ typedef struct ldb_message { void __setitem__(const char *attr_name, PyObject *val) { - struct ldb_message_element *el = ldb_msg_element_from_pyobject( + struct ldb_message_element *el = ldb_msg_element_from_pyobject(NULL, val, 0, attr_name); talloc_steal($self, el); ldb_msg_remove_attr($self, attr_name); @@ -486,8 +487,7 @@ typedef struct ldb_context { ldb_msg *msg = NULL; if (PyDict_Check(py_msg)) { msg = ldb_msg_new(NULL); - msg->num_elements = PyDict_Size(py_msg) - 1; /* dn isn't in there */ - msg->elements = talloc_zero_array(msg, struct ldb_message_element, msg->num_elements+1); + msg->elements = talloc_zero_array(msg, struct ldb_message_element, PyDict_Size(py_msg)); msg_pos = dict_pos = 0; while (PyDict_Next(py_msg, &dict_pos, &key, &value)) { if (!strcmp(PyString_AsString(key), "dn")) { @@ -495,17 +495,22 @@ typedef struct ldb_context { return LDB_ERR_OTHER; } } else { - msgel = ldb_msg_element_from_pyobject(value, 0, PyString_AsString(key)); + msgel = ldb_msg_element_from_pyobject(msg->elements, value, 0, PyString_AsString(key)); + if (msgel == NULL) { + SWIG_exception(SWIG_TypeError, "unable to import element"); + return LDB_ERR_OTHER; + } memcpy(&msg->elements[msg_pos], msgel, sizeof(*msgel)); msg_pos++; } - dict_pos++; } if (msg->dn == NULL) { SWIG_exception(SWIG_TypeError, "no dn set"); return LDB_ERR_OTHER; } + + msg->num_elements = msg_pos; } else { if (SWIG_ConvertPtr(py_msg, (void **)&msg, SWIGTYPE_p_ldb_message, 0) != 0) return LDB_ERR_OTHER; -- cgit From 99870953785b3515a6d0a916d72d1c75695cc05d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Jan 2008 01:52:26 -0600 Subject: r26641: ldb(Python): Remove some unnecessary {}'s. (This used to be commit f250bc18e9e32d62d262901cec65586a15cd8db1) --- source4/lib/ldb/ldb.i | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 5569d08ebb..57cb6b5f47 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -106,7 +106,7 @@ typedef int ldb_error; } #ifdef SWIGPYTHON -%typemap(argout) struct ldb_result ** (int i) { +%typemap(argout,noblock=1) struct ldb_result ** (int i) { $result = PyList_New((*$1)->count); for (i = 0; i < (*$1)->count; i++) { PyList_SetItem($result, i, @@ -129,7 +129,7 @@ typedef int ldb_error; } } -%typemap(freearg) const char * const *attrs { +%typemap(freearg,noblock=1) const char * const *attrs { talloc_free($1); } #endif @@ -331,7 +331,6 @@ typedef struct ldb_message { return ret; } ~ldb_msg() { talloc_free($self); } - ldb_msg_element *find_element(const char *name); #ifdef SWIGPYTHON @@ -393,8 +392,7 @@ static void py_ldb_debug(void *context, enum ldb_debug_level level, const char * } %} -%typemap(in,numinputs=1) (void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), - void *context) { +%typemap(in,numinputs=1,noblock=1) (void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), void *context) { $1 = py_ldb_debug; /* FIXME: Should be decreased somewhere as well. Perhaps register a destructor and tie it to the ldb context ? */ @@ -485,6 +483,7 @@ typedef struct ldb_context { PyObject *key, *value; ldb_msg_element *msgel; ldb_msg *msg = NULL; + if (PyDict_Check(py_msg)) { msg = ldb_msg_new(NULL); msg->elements = talloc_zero_array(msg, struct ldb_message_element, PyDict_Size(py_msg)); @@ -516,7 +515,7 @@ typedef struct ldb_context { return LDB_ERR_OTHER; } - ret = ldb_add($self,msg); + ret = ldb_add($self, msg); talloc_free(msg); return ret; @@ -542,9 +541,9 @@ typedef struct ldb_context { ldb_error transaction_cancel(); #ifdef SWIGPYTHON - %typemap(in,numinputs=0) struct ldb_result **result_as_bool (struct ldb_result *tmp) { $1 = &tmp; } - %typemap(argout) struct ldb_result **result_as_bool { $result = ((*$1)->count > 0)?Py_True:Py_False; } - %typemap(freearg) struct ldb_result **result_as_bool { talloc_free(*$1); } + %typemap(in,numinputs=0,noblock=1) struct ldb_result **result_as_bool (struct ldb_result *tmp) { $1 = &tmp; } + %typemap(argout,noblock=1) struct ldb_result **result_as_bool { $result = ((*$1)->count > 0)?Py_True:Py_False; } + %typemap(freearg,noblock=1) struct ldb_result **result_as_bool { talloc_free(*$1); } ldb_error __contains__(ldb_dn *dn, struct ldb_result **result_as_bool) { return ldb_search($self, dn, LDB_SCOPE_BASE, NULL, NULL, @@ -597,7 +596,7 @@ static char *timestring(time_t t) %rename(string_to_time) ldb_string_to_time; time_t ldb_string_to_time(const char *s); -%typemap(in) const struct ldb_module_ops * { +%typemap(in,noblock=1) const struct ldb_module_ops * { $1 = talloc_zero(talloc_autofree_context(), struct ldb_module_ops); $1->name = (char *)PyObject_GetAttrString($input, (char *)"name"); -- cgit From 9269db983d847be7a0cdc9eb2bcc4ebe3066be1c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 00:23:33 +0100 Subject: python/ldb: Add __getitem__ implementation for LdbMessageElement. (This used to be commit e6498a0780dd31dfc623a69432004b606aeaccbe) --- source4/lib/ldb/ldb.i | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 57cb6b5f47..0ad628fdf5 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -279,10 +279,27 @@ typedef struct ldb_message_element { return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name); } #endif + + PyObject *get(int i) + { + if (i < 0 || i >= $self->num_values) + return Py_None; + + return PyString_FromStringAndSize( + (const char *)$self->values[i].data, + $self->values[i].length); + } + ~ldb_msg_element() { talloc_free($self); } int compare(ldb_msg_element *); } %pythoncode { + def __getitem__(self, i): + ret = self.get(i) + if ret is None: + raise KeyError("no such value") + return ret + def __eq__(self, other): if (isinstance(other, str) and len(set(self)) == 1 and -- cgit From c3695026e1cfac3e835e937ed9343d82500cf197 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 01:02:58 +0100 Subject: ldb/python: Implement __len__ for MessageElement. (This used to be commit a8f90ed34ce9341080b63c801ef54b82de42b8e6) --- source4/lib/ldb/ldb.i | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 0ad628fdf5..57fa36584e 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -278,6 +278,11 @@ typedef struct ldb_message_element { { return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name); } + + int __len__() + { + return $self->num_values; + } #endif PyObject *get(int i) -- cgit From 2466d2cc5e210a124bb23cb9d2c8d3cc608a7c7f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 01:55:56 +0100 Subject: ldb/python: Allow comparing a MessageElement to a list or a singleton. (This used to be commit 1ccbab81d79f83bb419104f2bbaf2ae7b368e90f) --- source4/lib/ldb/ldb.i | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 57fa36584e..b6718351f8 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -306,12 +306,15 @@ typedef struct ldb_message_element { return ret def __eq__(self, other): - if (isinstance(other, str) and - len(set(self)) == 1 and - set(self).pop() == other): + if (len(self) == 1 and self.get(0) == other): return True - return self.__cmp__(other) == 0 - + if isinstance(other, self.__class__): + return self.__cmp__(other) == 0 + o = iter(other) + for i in range(len(self)): + if self.get(i) != o.next(): + return False + return True } } ldb_msg_element; -- cgit From 1f4838b8a3e5f0c7c400097f56329e5a133ec4e8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 02:36:59 +0100 Subject: python/ldap: Wrap parse_control_strings(). (This used to be commit b27e5a68530c4fd6430cbb174b63f8ff2b6f4e53) --- source4/lib/ldb/ldb.i | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index b6718351f8..cf4a335954 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -50,6 +50,15 @@ typedef int ldb_error; %include "exception.i" %import "stdint.i" +/* Don't expose talloc contexts in Python code. Python does reference + counting for us, so just create a new top-level talloc context. + */ +%typemap(in, numinputs=0, noblock=1) TALLOC_CTX * { + $1 = NULL; +} + + + %constant int SCOPE_DEFAULT = LDB_SCOPE_DEFAULT; %constant int SCOPE_BASE = LDB_SCOPE_BASE; %constant int SCOPE_ONELEVEL = LDB_SCOPE_ONELEVEL; @@ -115,7 +124,7 @@ typedef int ldb_error; } } -%typemap(in,noblock=1,numinputs=1) const char * const *attrs { +%typemap(in,noblock=1,numinputs=1) const char * const *NULL_STR_LIST { if ($input == Py_None) { $1 = NULL; } else if (PySequence_Check($input)) { @@ -129,9 +138,13 @@ typedef int ldb_error; } } -%typemap(freearg,noblock=1) const char * const *attrs { +%typemap(freearg,noblock=1) const char * const *NULL_STR_LIST { talloc_free($1); } + +%apply const char * const *NULL_STR_LIST { const char * const *attrs } +%apply const char * const *NULL_STR_LIST { const char * const *control_strings } + #endif %types(struct ldb_result *); @@ -472,6 +485,14 @@ PyObject *PyExc_LdbError; $result = Py_None; }; +%typemap(out,noblock=1) struct ldb_control ** { + if ($1 == NULL) { + PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(s)", ldb_errstring(arg1))); + SWIG_fail; + } + $result = SWIG_NewPointerObj($1, $1_descriptor, 0); +} + %rename(Ldb) ldb_context; %typemap(in,noblock=1) struct ldb_dn * { @@ -500,6 +521,8 @@ typedef struct ldb_context { struct ldb_result **OUT); ldb_error delete(ldb_dn *dn); ldb_error rename(ldb_dn *olddn, ldb_dn *newdn); + struct ldb_control **parse_control_strings(TALLOC_CTX *mem_ctx, + const char * const*control_strings); ldb_error add(ldb_msg *add_msg); ldb_error add(PyObject *py_msg) { -- cgit From 1d8cdddcd0901c5886099b7596f6d9629bdfad69 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 03:25:22 +0100 Subject: python/ldap: Support controls argument to ldb.search(). (This used to be commit 9eddc27f13fa2feb56d6b015e66d8c54081487da) --- source4/lib/ldb/ldb.i | 52 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index cf4a335954..2604393e8f 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -514,11 +514,49 @@ typedef struct ldb_context { const char *options[] = NULL); ~ldb() { talloc_free($self); } - ldb_error search(ldb_dn *base = NULL, + ldb_error search_ex(TALLOC_CTX *mem_ctx, + ldb_dn *base = NULL, enum ldb_scope scope = LDB_SCOPE_DEFAULT, const char *expression = NULL, - const char * const *attrs = NULL, - struct ldb_result **OUT); + const char *const *attrs = NULL, + struct ldb_control **controls = NULL, + struct ldb_result **OUT) { + int ret; + struct ldb_result *res; + struct ldb_request *req; + res = talloc_zero(mem_ctx, struct ldb_result); + if (!res) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ret = ldb_build_search_req(&req, $self, mem_ctx, + base?base:ldb_get_default_basedn($self), + scope, + expression, + attrs, + controls, + res, + ldb_search_default_callback); + + if (ret != LDB_SUCCESS) { + talloc_free(res); + return ret; + } + + ldb_set_timeout($self, req, 0); /* use default timeout */ + + ret = ldb_request($self, req); + + if (ret == LDB_SUCCESS) { + ret = ldb_wait(req->handle, LDB_WAIT_ALL); + } + + talloc_free(req); + + *OUT = res; + return ret; + } + ldb_error delete(ldb_dn *dn); ldb_error rename(ldb_dn *olddn, ldb_dn *newdn); struct ldb_control **parse_control_strings(TALLOC_CTX *mem_ctx, @@ -615,6 +653,14 @@ typedef struct ldb_context { _ldb.Ldb_swiginit(self,_ldb.new_Ldb()) if url is not None: self.connect(url, flags, options) + + def search(self, base=None, scope=SCOPE_DEFAULT, expression=None, + attrs=None, controls=None): + parsed_controls = None + if controls is not None: + parsed_controls = self.parse_control_strings(controls) + return self.search_ex(base, scope, expression, attrs, + parsed_controls) } } ldb; -- cgit From 79d466c37397a9d3d236f1c81d7d7fda479bd052 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Jan 2008 04:05:41 +0100 Subject: ldb/python: Support comparing Dn's to strings. (This used to be commit 355878907970b396e4031426fda260d981c417eb) --- source4/lib/ldb/ldb.i | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 2604393e8f..560142eb6d 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -201,6 +201,14 @@ fail: /* FIXME: implement __getslice__ */ #endif + %pythoncode { + def __eq__(self, other): + if isinstance(other, self.__class__): + return self.__cmp__(other) == 0 + if isinstance(other, str): + return str(self) == other + return False + } } } ldb_dn; -- cgit From c28c683208aad1a136c8c6decc3297bf1995aa90 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 25 Jan 2008 03:46:47 +0100 Subject: ldb/python: Add bindings for schema functions. (This used to be commit 9f6ea4692ca79c607538871c597698b98abf13d0) --- source4/lib/ldb/ldb.i | 88 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 11 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 560142eb6d..336100c4f0 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -5,7 +5,7 @@ Copyright (C) 2005,2006 Tim Potter Copyright (C) 2006 Simo Sorce - Copyright (C) 2007 Jelmer Vernooij + Copyright (C) 2007-2008 Jelmer Vernooij ** NOTE! The following LGPL license applies to the ldb ** library. This does NOT imply that all of Samba is released @@ -102,8 +102,44 @@ typedef int ldb_error; $1->data = PyString_AsString($input); } +%inline %{ +PyObject *ldb_val_to_py_object(struct ldb_context *ldb_ctx, + struct ldb_message_element *el, + struct ldb_val *val) +{ + const struct ldb_schema_attribute *a; + struct ldb_val new_val; + TALLOC_CTX *mem_ctx = talloc_new(NULL); + PyObject *ret; + + new_val = *val; + + if (ldb_ctx != NULL) { + a = ldb_schema_attribute_by_name(ldb_ctx, el->name); + + if (a != NULL) { + if (a->syntax->ldif_write_fn(ldb_ctx, mem_ctx, val, &new_val) != 0) { + talloc_free(mem_ctx); + return NULL; + } + } + } + + ret = PyString_FromStringAndSize((const char *)new_val.data, new_val.length); + + talloc_free(mem_ctx); + + return ret; +} + +%} + +%typemap(out,noblock=1) struct ldb_val * { + $result = PyString_FromStringAndSize((const char *)$1->data, $1->length) +} + %typemap(out,noblock=1) struct ldb_val { - $result = PyString_FromStringAndSize((const char *)$1.data, $1.length); + $result = PyString_FromStringAndSize((const char *)$1.data, $1.length) } /* @@ -259,7 +295,8 @@ ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, return me; } -PyObject *ldb_msg_element_to_set(ldb_msg_element *me) +PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, + ldb_msg_element *me) { int i; PyObject *result; @@ -269,8 +306,7 @@ PyObject *ldb_msg_element_to_set(ldb_msg_element *me) for (i = 0; i < me->num_values; i++) { PyList_SetItem(result, i, - PyString_FromStringAndSize((const char *)me->values[i].data, - me->values[i].length)); + ldb_val_to_py_object(ldb_ctx, me, &me->values[i])); } return result; @@ -287,12 +323,12 @@ typedef struct ldb_message_element { #ifdef SWIGPYTHON PyObject *__iter__(void) { - return PyObject_GetIter(ldb_msg_element_to_set($self)); + return PyObject_GetIter(ldb_msg_element_to_set(NULL, $self)); } PyObject *__set__(void) { - return ldb_msg_element_to_set($self); + return ldb_msg_element_to_set(NULL, $self); } ldb_msg_element(PyObject *set_obj, int flags=0, const char *name = NULL) @@ -311,9 +347,7 @@ typedef struct ldb_message_element { if (i < 0 || i >= $self->num_values) return Py_None; - return PyString_FromStringAndSize( - (const char *)$self->values[i].data, - $self->values[i].length); + return ldb_val_to_py_object(NULL, $self, &$self->values[i]); } ~ldb_msg_element() { talloc_free($self); } @@ -622,6 +656,35 @@ typedef struct ldb_context { ldb_dn *get_root_basedn(); ldb_dn *get_schema_basedn(); ldb_dn *get_default_basedn(); + PyObject *schema_format_value(const char *element_name, PyObject *val) + { + const struct ldb_schema_attribute *a; + struct ldb_val old_val; + struct ldb_val new_val; + TALLOC_CTX *mem_ctx = talloc_new(NULL); + PyObject *ret; + + old_val.data = PyString_AsString(val); + old_val.length = PyString_Size(val); + + a = ldb_schema_attribute_by_name($self, element_name); + + if (a == NULL) { + return Py_None; + } + + if (a->syntax->ldif_write_fn($self, mem_ctx, &old_val, &new_val) != 0) { + talloc_free(mem_ctx); + return Py_None; + } + + ret = PyString_FromStringAndSize((const char *)new_val.data, new_val.length); + + talloc_free(mem_ctx); + + return ret; + } + const char *errstring(); void set_create_perms(unsigned int perms); void set_modules_dir(const char *path); @@ -633,7 +696,10 @@ typedef struct ldb_context { ldb_error transaction_start(); ldb_error transaction_commit(); ldb_error transaction_cancel(); - + void schema_attribute_remove(const char *name); + ldb_error schema_attribute_add(const char *attribute, unsigned flags, const char *syntax); + ldb_error setup_wellknown_attributes(void); + #ifdef SWIGPYTHON %typemap(in,numinputs=0,noblock=1) struct ldb_result **result_as_bool (struct ldb_result *tmp) { $1 = &tmp; } %typemap(argout,noblock=1) struct ldb_result **result_as_bool { $result = ((*$1)->count > 0)?Py_True:Py_False; } -- cgit From 748f1c09629b251176a36f24c871b045192206ed Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Mar 2008 13:01:02 +0100 Subject: Fix error handling in ldb.add(). (This used to be commit a7f89b5bb28601597a4a0f75ec2b97bac02370d9) --- source4/lib/ldb/ldb.i | 84 +++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 47 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 336100c4f0..2c04662f25 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -547,6 +547,43 @@ PyObject *PyExc_LdbError; talloc_free($1); }; +%typemap(in,numinputs=1) ldb_msg *add_msg { + ldb_error ret; + int dict_pos, msg_pos; + PyObject *key, *value; + ldb_msg_element *msgel; + + if (PyDict_Check($input)) { + $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")) { + if (ldb_dn_from_pyobject($1, value, $self, &$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 (msgel == NULL) { + SWIG_exception(SWIG_TypeError, "unable to import element"); + } + memcpy(&$1->elements[msg_pos], msgel, sizeof(*msgel)); + msg_pos++; + } + } + + if ($1->dn == NULL) { + SWIG_exception(SWIG_TypeError, "no dn set"); + } + + $1->num_elements = msg_pos; + } else { + if (SWIG_ConvertPtr($input, (void **)&$1, SWIGTYPE_p_ldb_message, 0) != 0) { + SWIG_exception(SWIG_TypeError, "unable to convert ldb message"); + } + } +} + /* Top-level ldb operations */ typedef struct ldb_context { %extend { @@ -604,53 +641,6 @@ typedef struct ldb_context { struct ldb_control **parse_control_strings(TALLOC_CTX *mem_ctx, const char * const*control_strings); ldb_error add(ldb_msg *add_msg); - ldb_error add(PyObject *py_msg) - { - ldb_error ret; - int dict_pos, msg_pos; - PyObject *key, *value; - ldb_msg_element *msgel; - ldb_msg *msg = NULL; - - if (PyDict_Check(py_msg)) { - msg = ldb_msg_new(NULL); - msg->elements = talloc_zero_array(msg, struct ldb_message_element, PyDict_Size(py_msg)); - msg_pos = dict_pos = 0; - while (PyDict_Next(py_msg, &dict_pos, &key, &value)) { - if (!strcmp(PyString_AsString(key), "dn")) { - if (ldb_dn_from_pyobject(msg, value, $self, &msg->dn) != 0) { - return LDB_ERR_OTHER; - } - } else { - msgel = ldb_msg_element_from_pyobject(msg->elements, value, 0, PyString_AsString(key)); - if (msgel == NULL) { - SWIG_exception(SWIG_TypeError, "unable to import element"); - return LDB_ERR_OTHER; - } - memcpy(&msg->elements[msg_pos], msgel, sizeof(*msgel)); - msg_pos++; - } - } - - if (msg->dn == NULL) { - SWIG_exception(SWIG_TypeError, "no dn set"); - return LDB_ERR_OTHER; - } - - msg->num_elements = msg_pos; - } else { - if (SWIG_ConvertPtr(py_msg, (void **)&msg, SWIGTYPE_p_ldb_message, 0) != 0) - return LDB_ERR_OTHER; - } - - ret = ldb_add($self, msg); - - talloc_free(msg); - return ret; - - fail: - return LDB_ERR_OTHER; - } ldb_error modify(ldb_msg *message); ldb_dn *get_config_basedn(); ldb_dn *get_root_basedn(); -- cgit From 830051b494ea52475e9349e6908ff8576a990051 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Mar 2008 21:18:12 +0100 Subject: Remove unused variable, fix (80, 'Other error') exceptions from ldb python bindings (This used to be commit 2303063cbd2e65580618124ef8ecf42867d2b952) --- source4/lib/ldb/ldb.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 2c04662f25..da4c52f778 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -548,7 +548,6 @@ PyObject *PyExc_LdbError; }; %typemap(in,numinputs=1) ldb_msg *add_msg { - ldb_error ret; int dict_pos, msg_pos; PyObject *key, *value; ldb_msg_element *msgel; @@ -559,7 +558,8 @@ PyObject *PyExc_LdbError; msg_pos = dict_pos = 0; while (PyDict_Next($input, &dict_pos, &key, &value)) { if (!strcmp(PyString_AsString(key), "dn")) { - if (ldb_dn_from_pyobject($1, value, $self, &$1->dn) != 0) { + /* using argp0 (magic SWIG value) here is a hack */ + if (ldb_dn_from_pyobject($1, value, argp1, &$1->dn) != 0) { SWIG_exception(SWIG_TypeError, "unable to import dn object"); } } else { -- cgit From f042c1509032ff7c2ce87ea543e2fcda59b70532 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 4 Mar 2008 13:45:31 +1100 Subject: Try to return sane ldb error strings We don't just want to return just strerror(ret) when things go wrong. Andrew Bartlett (This used to be commit 7f0341dd589150ab01563957460cdcf42515cadc) --- source4/lib/ldb/ldb.i | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index da4c52f778..0d9679d21e 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -42,6 +42,7 @@ typedef struct ldb_dn ldb_dn; typedef struct ldb_ldif ldb_ldif; typedef struct ldb_message_element ldb_msg_element; typedef int ldb_error; +typedef int ldb_int_error; %} @@ -520,6 +521,14 @@ PyObject *PyExc_LdbError; %typemap(out,noblock=1) ldb_error { + if ($1 != LDB_SUCCESS) { + PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(i,s)", $1, ldb_errstring(arg1))); + SWIG_fail; + } + $result = Py_None; +}; + +%typemap(out,noblock=1) ldb_int_error { if ($1 != LDB_SUCCESS) { PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(i,s)", $1, ldb_strerror($1))); SWIG_fail; @@ -761,4 +770,4 @@ time_t ldb_string_to_time(const char *s); } %rename(register_module) ldb_register_module; -ldb_error ldb_register_module(const struct ldb_module_ops *); +ldb_int_error ldb_register_module(const struct ldb_module_ops *); -- cgit From 7da5ec17e666a9992cd0bd774b2360aafed8f3f3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 11 Mar 2008 14:20:42 +1100 Subject: Make error handling in ldb more consistant. This change ensures we give an immidiate error if the DN won't parse. Also clean up strcmp use to be more standard. Andrew Bartlett (This used to be commit 1b15f374a89b99f3c43d9c2ce06dde9c67383e66) --- source4/lib/ldb/ldb.i | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 0d9679d21e..bd41e1e23e 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -258,6 +258,9 @@ int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, struct ldb_dn *odn; if (ldb_ctx != NULL && PyString_Check(object)) { *dn = ldb_dn_new(mem_ctx, ldb_ctx, PyString_AsString(object)); + if (!*dn) { + return SWIG_ERROR; + } return 0; } ret = SWIG_ConvertPtr(object, (void **)&odn, SWIGTYPE_p_ldb_dn, @@ -566,7 +569,7 @@ PyObject *PyExc_LdbError; $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")) { + 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) { SWIG_exception(SWIG_TypeError, "unable to import dn object"); -- cgit From 5af56a613c3a954f80eeef21887f9317119af8ba Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Mar 2008 11:11:55 +1100 Subject: More safety around ldb_dn C functions in python bindings. Ensure that the ldb python binding 'TypeError dn not set' errors are not in the SWIG wrapper's use of ldb functions, put some more error checks in. Andrew Bartlett (This used to be commit 8d4c831184cff8bca85daf6cc711b189b5cf3a47) --- source4/lib/ldb/ldb.i | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index bd41e1e23e..b0723a8ecd 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -257,15 +257,19 @@ int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, int ret; struct ldb_dn *odn; if (ldb_ctx != NULL && PyString_Check(object)) { - *dn = ldb_dn_new(mem_ctx, ldb_ctx, PyString_AsString(object)); - if (!*dn) { + odn = ldb_dn_new(mem_ctx, ldb_ctx, PyString_AsString(object)); + if (!odn) { return SWIG_ERROR; } + *dn = odn; return 0; } ret = SWIG_ConvertPtr(object, (void **)&odn, SWIGTYPE_p_ldb_dn, SWIG_POINTER_EXCEPTION); *dn = ldb_dn_copy(mem_ctx, odn); + if (odn && !*dn) { + return SWIG_ERROR; + } return ret; } -- cgit From ff8256ad6ce4e62462e4b58cfcff1005f6363226 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 26 Mar 2008 15:18:17 +1100 Subject: 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) --- source4/lib/ldb/ldb.i | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb.i') 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"); } -- cgit From 8ed6f6d5a825c8b0e8d66d30877a91a96fe6e7a4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 11 Apr 2008 00:43:23 +0200 Subject: Return SAM ldb context and loadparm context as part of C provision result. (This used to be commit a3e1b835656470f1a80f0fa69f53a9df849baee3) --- source4/lib/ldb/ldb.i | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index e01a1107d2..6b94f19cb5 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -251,6 +251,14 @@ fail: #ifdef SWIGPYTHON %{ +struct ldb_context *ldb_context_from_py_object(PyObject *py_obj) +{ + struct ldb_context *ldb_ctx; + if (SWIG_ConvertPtr(py_obj, (void *)&ldb_ctx, SWIGTYPE_p_ldb_context, 0 | 0 ) < 0) + return NULL; + return ldb_ctx; +} + int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, struct ldb_context *ldb_ctx, ldb_dn **dn) { -- cgit From ae4611909609b8a0466938171812f10974dc054a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 19 May 2008 23:07:04 +0200 Subject: Add __repr__ implementations for ldb.Message, ldb.MessageElement and ldb.Dn. (This used to be commit b9119c0f0f524d43ff09825dffb24a5e77a240f4) --- source4/lib/ldb/ldb.i | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 6b94f19cb5..75482011fb 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -229,6 +229,14 @@ fail: return ldb_dn_canonical_ex_string($self, $self); } #ifdef SWIGPYTHON + char *__repr__(void) + { + char *dn = ldb_dn_get_linearized($self), *ret; + asprintf(&ret, "Dn('%s')", dn); + talloc_free(dn); + return ret; + } + ldb_dn *__add__(ldb_dn *other) { ldb_dn *ret = ldb_dn_copy(NULL, $self); @@ -376,6 +384,9 @@ typedef struct ldb_message_element { raise KeyError("no such value") return ret + def __repr__(self): + return "MessageElement([%s])" % (",".join(repr(x) for x in self.__set__())) + def __eq__(self, other): if (len(self) == 1 and self.get(0) == other): return True @@ -400,17 +411,22 @@ typedef struct ldb_message_element { else $result = SWIG_NewPointerObj($1, SWIGTYPE_p_ldb_message_element, 0); } -%rename(__getitem__) ldb_message::find_element; //%typemap(out) ldb_msg_element *; %inline { PyObject *ldb_msg_list_elements(ldb_msg *msg) { - int i; - PyObject *obj = PyList_New(msg->num_elements); - for (i = 0; i < msg->num_elements; i++) - PyList_SetItem(obj, i, PyString_FromString(msg->elements[i].name)); + int i, j = 0; + PyObject *obj = PyList_New(msg->num_elements+(msg->dn != NULL?1:0)); + if (msg->dn != NULL) { + PyList_SetItem(obj, j, PyString_FromString("dn")); + j++; + } + for (i = 0; i < msg->num_elements; i++) { + PyList_SetItem(obj, j, PyString_FromString(msg->elements[i].name)); + j++; + } return obj; } } @@ -466,6 +482,28 @@ typedef struct ldb_message { } #endif void remove_attr(const char *name); +%pythoncode { + def get(self, key, default=None): + if key == "dn": + return self.dn + return self.find_element(key) + + def __getitem__(self, key): + ret = self.get(key, None) + if ret is None: + raise KeyError("No such element") + return ret + + def iteritems(self): + for k in self.keys(): + yield k, self[k] + + def items(self): + return list(self.iteritems()) + + def __repr__(self): + return "Message(%s)" % repr(dict(self.iteritems())) +} } } ldb_msg; @@ -753,6 +791,8 @@ typedef struct ldb_context { def search(self, base=None, scope=SCOPE_DEFAULT, expression=None, attrs=None, controls=None): + if not (attrs is None or isinstance(attrs, list)): + raise TypeError("attributes not a list") parsed_controls = None if controls is not None: parsed_controls = self.parse_control_strings(controls) -- cgit From 43a22c9b4a7868a740e2de417f50702209d2aced Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 19 May 2008 23:12:13 +0200 Subject: Add __repr__ implementation for Ldb. (This used to be commit 5607aea07f66f09fd5b33842d07d2fbbf44d13e7) --- source4/lib/ldb/ldb.i | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 75482011fb..18e981f7be 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -781,6 +781,12 @@ typedef struct ldb_context { return PyObject_GetIter(list); } + char *__repr__(void) + { + char *ret; + asprintf(&ret, "", ret); + return ret; + } #endif } %pythoncode { -- cgit From 505cea9d4c9ae3b7baf401fd543500041c20f93d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 16:50:33 +0200 Subject: Add some docstrings to ldb python module, fix MessageElement name. (This used to be commit 717283331f8a1ebd80e7ec52d9bfe709f869ec86) --- source4/lib/ldb/ldb.i | 93 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 17 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 18e981f7be..6a807a7dde 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -40,7 +40,7 @@ typedef struct ldb_message ldb_msg; typedef struct ldb_context ldb; typedef struct ldb_dn ldb_dn; typedef struct ldb_ldif ldb_ldif; -typedef struct ldb_message_element ldb_msg_element; +typedef struct ldb_message_element ldb_message_element; typedef int ldb_error; typedef int ldb_int_error; @@ -210,21 +210,35 @@ fail: return ret; } ~ldb_dn() { talloc_free($self); } + %feature("docstring") validate "S.validate() -> bool\n" \ + "Validate DN is correct."; bool validate(); const char *get_casefold(); const char *get_linearized(); ldb_dn *parent() { return ldb_dn_get_parent(NULL, $self); } int compare(ldb_dn *other); bool is_valid(); + %feature("docstring") is_special "S.is_special() -> bool\n" \ + "Check whether this is a special LDB DN."; bool is_special(); + %feature("docstring") is_null "S.is_null() -> bool\n" \ + "Check whether this is a null DN."; bool is_null(); bool check_special(const char *name); int get_comp_num(); + %feature("docstring") add_child "S.add_child(dn) -> None\n" \ + "Add a child DN to this DN."; bool add_child(ldb_dn *child); + %feature("docstring") add_base "S.add_base(dn) -> None\n" \ + "Add a base DN to this DN."; bool add_base(ldb_dn *base); + %feature("docstring") canonical_str "S.canonical_str() -> string\n" \ + "Canonical version of this DN (like a posix path)."; const char *canonical_str() { return ldb_dn_canonical_string($self, $self); } + %feature("docstring") canonical_ex_str "S.canonical_ex_str() -> string\n" \ + "Canonical version of this DN (like a posix path, with terminating newline)."; const char *canonical_ex_str() { return ldb_dn_canonical_ex_string($self, $self); } @@ -289,7 +303,7 @@ int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, return ret; } -ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, +ldb_message_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *set_obj, int flags, const char *attr_name) { @@ -320,7 +334,7 @@ ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, } PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, - ldb_msg_element *me) + ldb_message_element *me) { int i; PyObject *result; @@ -339,9 +353,10 @@ PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, %} #endif +int ldb_msg_element_compare(ldb_message_element *, ldb_message_element *); /* ldb_message_element */ -%rename(__cmp__) ldb_message_element::compare; -%rename(MessageElement) ldb_msg_element; +%rename(MessageElement) ldb_message_element; +%rename(ldb_message_element_compare) ldb_msg_element_compare; typedef struct ldb_message_element { %extend { #ifdef SWIGPYTHON @@ -355,7 +370,7 @@ typedef struct ldb_message_element { return ldb_msg_element_to_set(NULL, $self); } - ldb_msg_element(PyObject *set_obj, int flags=0, const char *name = NULL) + ldb_message_element(PyObject *set_obj, int flags=0, const char *name = NULL) { return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name); } @@ -374,8 +389,8 @@ typedef struct ldb_message_element { return ldb_val_to_py_object(NULL, $self, &$self->values[i]); } - ~ldb_msg_element() { talloc_free($self); } - int compare(ldb_msg_element *); + ~ldb_message_element() { talloc_free($self); } + %rename(__cmp__) ldb_msg_element_compare; } %pythoncode { def __getitem__(self, i): @@ -398,21 +413,19 @@ typedef struct ldb_message_element { return False return True } -} ldb_msg_element; +} ldb_message_element; /* ldb_message */ %rename(Message) ldb_message; #ifdef SWIGPYTHON %rename(__delitem__) ldb_message::remove_attr; -%typemap(out) ldb_msg_element * { +%typemap(out) ldb_message_element * { if ($1 == NULL) PyErr_SetString(PyExc_KeyError, "no such element"); else $result = SWIG_NewPointerObj($1, SWIGTYPE_p_ldb_message_element, 0); } -//%typemap(out) ldb_msg_element *; - %inline { PyObject *ldb_msg_list_elements(ldb_msg *msg) @@ -443,10 +456,10 @@ typedef struct ldb_message { return ret; } ~ldb_msg() { talloc_free($self); } - ldb_msg_element *find_element(const char *name); + ldb_message_element *find_element(const char *name); #ifdef SWIGPYTHON - void __setitem__(const char *attr_name, ldb_msg_element *val) + void __setitem__(const char *attr_name, ldb_message_element *val) { struct ldb_message_element *el; @@ -613,7 +626,7 @@ PyObject *PyExc_LdbError; %typemap(in,numinputs=1) ldb_msg *add_msg { Py_ssize_t dict_pos, msg_pos; - ldb_msg_element *msgel; + ldb_message_element *msgel; PyObject *key, *value; if (PyDict_Check($input)) { @@ -660,6 +673,8 @@ typedef struct ldb_context { %extend { ldb(void) { return ldb_init(NULL); } + %feature("docstring") connect "S.connect(url,flags=0,options=None) -> None\n" \ + "Connect to a LDB URL."; ldb_error connect(const char *url, unsigned int flags = 0, const char *options[] = NULL); @@ -707,11 +722,19 @@ typedef struct ldb_context { return ret; } + %feature("docstring") delete "S.delete(dn) -> None\n" \ + "Remove an entry."; ldb_error delete(ldb_dn *dn); + %feature("docstring") rename "S.rename(old_dn, new_dn) -> None\n" \ + "Rename an entry."; ldb_error rename(ldb_dn *olddn, ldb_dn *newdn); struct ldb_control **parse_control_strings(TALLOC_CTX *mem_ctx, const char * const*control_strings); + %feature("docstring") add "S.add(message) -> None\n" \ + "Add an entry."; ldb_error add(ldb_msg *add_msg); + %feature("docstring") modify "S.modify(message) -> None\n" \ + "Modify an entry."; ldb_error modify(ldb_msg *message); ldb_dn *get_config_basedn(); ldb_dn *get_root_basedn(); @@ -747,20 +770,36 @@ typedef struct ldb_context { } const char *errstring(); + %feature("docstring") set_create_perms "S.set_create_perms(mode) -> None\n" \ + "Set mode to use when creating new LDB files."; void set_create_perms(unsigned int perms); + %feature("docstring") set_modules_dir "S.set_modules_dir(path) -> None\n" \ + "Set path LDB should search for modules"; void set_modules_dir(const char *path); ldb_error set_debug(void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), void *context); + %feature("docstring") set_opaque "S.set_opaque(name, value) -> None\n" \ + "Set an opaque value on this LDB connection. \n" + ":note: Passing incorrect values may cause crashes."; ldb_error set_opaque(const char *name, void *value); + %feature("docstring") get_opaque "S.get_opaque(name) -> value\n" \ + "Get an opaque value set on this LDB connection. \n" + ":note: The returned value may not be useful in Python."; void *get_opaque(const char *name); + %feature("docstring") transaction_start "S.transaction_start() -> None\n" \ + "Start a new transaction."; ldb_error transaction_start(); + %feature("docstring") transaction_commit "S.transaction_commit() -> None\n" \ + "Commit currently active transaction."; ldb_error transaction_commit(); + %feature("docstring") transaction_commit "S.transaction_cancel() -> None\n" \ + "Cancel currently active transaction."; ldb_error transaction_cancel(); void schema_attribute_remove(const char *name); ldb_error schema_attribute_add(const char *attribute, unsigned flags, const char *syntax); - ldb_error setup_wellknown_attributes(void); - + ldb_error setup_wellknown_attributes(void); + #ifdef SWIGPYTHON %typemap(in,numinputs=0,noblock=1) struct ldb_result **result_as_bool (struct ldb_result *tmp) { $1 = &tmp; } %typemap(argout,noblock=1) struct ldb_result **result_as_bool { $result = ((*$1)->count > 0)?Py_True:Py_False; } @@ -771,6 +810,9 @@ typedef struct ldb_context { result_as_bool); } + %feature("docstring") parse_ldif "S.parse_ldif(ldif) -> iter(messages)\n" \ + "Parse a string formatted using LDIF."; + PyObject *parse_ldif(const char *s) { PyObject *list = PyList_New(0); @@ -791,12 +833,25 @@ typedef struct ldb_context { } %pythoncode { def __init__(self, url=None, flags=0, options=None): + """Create a new LDB object. + + Will also connect to the specified URL if one was given. + """ _ldb.Ldb_swiginit(self,_ldb.new_Ldb()) if url is not None: self.connect(url, flags, options) def search(self, base=None, scope=SCOPE_DEFAULT, expression=None, attrs=None, controls=None): + """Search in a database. + + :param base: Optional base DN to search + :param scope: Search scope (SCOPE_BASE, SCOPE_ONELEVEL or SCOPE_SUBTREE) + :param expression: Optional search expression + :param attrs: Attributes to return (defaults to all) + :param controls: Optional list of controls + :return: Iterator over Message objects + """ if not (attrs is None or isinstance(attrs, list)): raise TypeError("attributes not a list") parsed_controls = None @@ -816,6 +871,8 @@ typedef struct ldb_context { %nodefault Dn; %rename(valid_attr_name) ldb_valid_attr_name; +%feature("docstring") ldb_valid_attr_name "S.valid_attr_name(name) -> bool\n" + "Check whether the supplied name is a valid attribute name."; int ldb_valid_attr_name(const char *s); typedef unsigned long time_t; @@ -839,5 +896,7 @@ time_t ldb_string_to_time(const char *s); $1->name = (char *)PyObject_GetAttrString($input, (char *)"name"); } +%feature("docstring") ldb_register_module "S.register_module(module) -> None\n" + "Register a LDB module."; %rename(register_module) ldb_register_module; ldb_int_error ldb_register_module(const struct ldb_module_ops *); -- cgit From fb2d69a140c123ff78df113532d4ead21f3362c3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 17:02:31 +0200 Subject: Add more docstrings in the ldb python module. (This used to be commit a649a010670ee2c0d155aa62654841cf1f2bab8f) --- source4/lib/ldb/ldb.i | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 6a807a7dde..38a928ffb1 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -194,6 +194,7 @@ PyObject *ldb_val_to_py_object(struct ldb_context *ldb_ctx, %rename(__cmp__) ldb_dn::compare; %rename(__len__) ldb_dn::get_comp_num; %rename(Dn) ldb_dn; +%feature("docstring") ldb_dn "A LDB distinguished name."; typedef struct ldb_dn { %extend { ldb_dn(ldb *ldb_ctx, const char *str) @@ -356,6 +357,7 @@ PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, int ldb_msg_element_compare(ldb_message_element *, ldb_message_element *); /* ldb_message_element */ %rename(MessageElement) ldb_message_element; +%feature("docstring") ldb_message_element "Message element."; %rename(ldb_message_element_compare) ldb_msg_element_compare; typedef struct ldb_message_element { %extend { @@ -417,6 +419,7 @@ typedef struct ldb_message_element { /* ldb_message */ +%feature("docstring") ldb_message "Message."; %rename(Message) ldb_message; #ifdef SWIGPYTHON %rename(__delitem__) ldb_message::remove_attr; @@ -613,6 +616,7 @@ PyObject *PyExc_LdbError; } %rename(Ldb) ldb_context; +%feature("docstring") ldb_context "Connection to a LDB database."; %typemap(in,noblock=1) struct ldb_dn * { if (ldb_dn_from_pyobject(NULL, $input, arg1, &$1) != 0) { @@ -776,6 +780,9 @@ typedef struct ldb_context { %feature("docstring") set_modules_dir "S.set_modules_dir(path) -> None\n" \ "Set path LDB should search for modules"; void set_modules_dir(const char *path); + %feature("docstring") set_debug "S.set_debug(callback) -> None\n" \ + "Set callback for LDB debug messages.\n" \ + "The callback should accept a debug level and debug text."; ldb_error set_debug(void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), void *context); @@ -793,7 +800,7 @@ typedef struct ldb_context { %feature("docstring") transaction_commit "S.transaction_commit() -> None\n" \ "Commit currently active transaction."; ldb_error transaction_commit(); - %feature("docstring") transaction_commit "S.transaction_cancel() -> None\n" \ + %feature("docstring") transaction_cancel "S.transaction_cancel() -> None\n" \ "Cancel currently active transaction."; ldb_error transaction_cancel(); void schema_attribute_remove(const char *name); @@ -877,6 +884,9 @@ int ldb_valid_attr_name(const char *s); typedef unsigned long time_t; +%feature("docstring") timestring "S.timestring(int) -> string\n" + "Generate a LDAP time string from a UNIX timestamp"; + %inline %{ static char *timestring(time_t t) { @@ -888,6 +898,8 @@ static char *timestring(time_t t) %} %rename(string_to_time) ldb_string_to_time; +%feature("docstring") string_to_time "S.string_to_time(string) -> int\n" + "Parse a LDAP time string into a UNIX timestamp."; time_t ldb_string_to_time(const char *s); %typemap(in,noblock=1) const struct ldb_module_ops * { -- cgit From 9893651c0237c9dba43aadfb8f5f68be74bbfd6c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 17:15:00 +0200 Subject: Add module docstring, docstrings for constructors. (This used to be commit 67d738d6e65476263a2b7c236a57fe2b0a2dfe32) --- source4/lib/ldb/ldb.i | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 38a928ffb1..2c5b7535b5 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -25,7 +25,11 @@ License along with this library; if not, see . */ -%module ldb +%define DOCSTRING +"An interface to LDB, a LDAP-like API that can either to talk an embedded database (TDB-based) or a standards-compliant LDAP server." +%enddef + +%module(docstring=DOCSTRING) ldb %{ @@ -197,6 +201,8 @@ PyObject *ldb_val_to_py_object(struct ldb_context *ldb_ctx, %feature("docstring") ldb_dn "A LDB distinguished name."; typedef struct ldb_dn { %extend { + %feature("docstring") ldb_dn "S.__init__(ldb, string)\n" \ + "Create a new DN."; ldb_dn(ldb *ldb_ctx, const char *str) { ldb_dn *ret = ldb_dn_new(ldb_ctx, ldb_ctx, str); @@ -216,6 +222,8 @@ fail: bool validate(); const char *get_casefold(); const char *get_linearized(); + %feature("docstring") parent "S.parent() -> dn\n" \ + "Get the parent for this DN."; ldb_dn *parent() { return ldb_dn_get_parent(NULL, $self); } int compare(ldb_dn *other); bool is_valid(); @@ -898,7 +906,7 @@ static char *timestring(time_t t) %} %rename(string_to_time) ldb_string_to_time; -%feature("docstring") string_to_time "S.string_to_time(string) -> int\n" +%feature("docstring") ldb_string_to_time "S.string_to_time(string) -> int\n" "Parse a LDAP time string into a UNIX timestamp."; time_t ldb_string_to_time(const char *s); -- cgit From c401aa93573460f10256218a6a1902839b17b884 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 17:42:18 +0200 Subject: Use restructuredText formatting for docstrings. (This used to be commit 0cc58decd74d20f3d7dff93ddef1c8bce4d49ad0) --- source4/lib/ldb/ldb.i | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 2c5b7535b5..21bee63ea8 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -920,3 +920,7 @@ time_t ldb_string_to_time(const char *s); "Register a LDB module."; %rename(register_module) ldb_register_module; ldb_int_error ldb_register_module(const struct ldb_module_ops *); + +%pythoncode { +__docformat__ = "restructuredText" +} -- cgit From 564b6ed025bdfbd93876e084e9f3dd1a6774fa5c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 04:07:42 +0200 Subject: Add proper implementation of MessageElement.__cmp__. (This used to be commit 076e2cc356978ac313fcfdf8d8243f4ed1d629b0) --- source4/lib/ldb/ldb.i | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 21bee63ea8..061d13a2dd 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -362,14 +362,17 @@ PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, %} #endif -int ldb_msg_element_compare(ldb_message_element *, ldb_message_element *); /* ldb_message_element */ %rename(MessageElement) ldb_message_element; %feature("docstring") ldb_message_element "Message element."; -%rename(ldb_message_element_compare) ldb_msg_element_compare; typedef struct ldb_message_element { %extend { #ifdef SWIGPYTHON + int __cmp__(ldb_message_element *other) + { + return ldb_msg_element_compare($self, other); + } + PyObject *__iter__(void) { return PyObject_GetIter(ldb_msg_element_to_set(NULL, $self)); @@ -400,7 +403,6 @@ typedef struct ldb_message_element { } ~ldb_message_element() { talloc_free($self); } - %rename(__cmp__) ldb_msg_element_compare; } %pythoncode { def __getitem__(self, i): -- cgit From adbfc2c65c45c8e7fdc6b0148e24ea3cef13ca86 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 15 Jun 2008 19:16:06 +0200 Subject: Fix ldb python bindings after events changes. (This used to be commit dd1f24d0c6dfb19ba08282b91998f6881782c4fb) --- source4/lib/ldb/ldb.i | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 061d13a2dd..23b5e0db7a 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -685,7 +685,9 @@ PyObject *PyExc_LdbError; /* Top-level ldb operations */ typedef struct ldb_context { %extend { - ldb(void) { return ldb_init(NULL); } + ldb(void) { + return ldb_init(NULL, event_context_init(NULL)); + } %feature("docstring") connect "S.connect(url,flags=0,options=None) -> None\n" \ "Connect to a LDB URL."; -- cgit From 4a33e5e41b5a03c86758c38ffc1b02dd657962d9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 16 Jun 2008 15:25:48 +0200 Subject: Add include in swig file as well. (This used to be commit c623313189728dd0553384e2e115cf10db4c7f25) --- source4/lib/ldb/ldb.i | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 23b5e0db7a..db2fcdeb5b 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -39,6 +39,7 @@ #include "ldb.h" #include "ldb_errors.h" #include "ldb_private.h" +#include "events.h" typedef struct ldb_message ldb_msg; typedef struct ldb_context ldb; -- cgit From 9cdfcd2b1adc01378d2e828360cf7829097eef29 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 16 Jun 2008 23:25:48 +0200 Subject: Change order of includes in swig file to avoid warnings. (This used to be commit 0e1fccbd73eb0f219ea9662c56ee6da8a92f641a) --- source4/lib/ldb/ldb.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb.i') diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index db2fcdeb5b..4b61ddba5b 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -36,10 +36,10 @@ #include #include #include "talloc.h" +#include "events.h" #include "ldb.h" #include "ldb_errors.h" #include "ldb_private.h" -#include "events.h" typedef struct ldb_message ldb_msg; typedef struct ldb_context ldb; -- cgit