2 Unix SMB/CIFS implementation.
6 Copyright (C) 2005,2006 Tim Potter <tpot@samba.org>
7 Copyright (C) 2006 Simo Sorce <idra@samba.org>
8 Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
10 ** NOTE! The following LGPL license applies to the ldb
11 ** library. This does NOT imply that all of Samba is released
14 This library is free software; you can redistribute it and/or
15 modify it under the terms of the GNU Lesser General Public
16 License as published by the Free Software Foundation; either
17 version 3 of the License, or (at your option) any later version.
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, see <http://www.gnu.org/licenses/>.
29 "An interface to LDB, a LDAP-like API that can either to talk an embedded database (TDB-based) or a standards-compliant LDAP server."
32 %module(docstring=DOCSTRING) ldb
40 #include "ldb_errors.h"
41 #include "ldb_private.h"
43 typedef struct ldb_message ldb_msg;
44 typedef struct ldb_context ldb;
45 typedef struct ldb_dn ldb_dn;
46 typedef struct ldb_ldif ldb_ldif;
47 typedef struct ldb_message_element ldb_message_element;
48 typedef int ldb_error;
49 typedef int ldb_int_error;
55 %include "exception.i"
58 /* Don't expose talloc contexts in Python code. Python does reference
59 counting for us, so just create a new top-level talloc context.
61 %typemap(in, numinputs=0, noblock=1) TALLOC_CTX * {
67 %constant int SCOPE_DEFAULT = LDB_SCOPE_DEFAULT;
68 %constant int SCOPE_BASE = LDB_SCOPE_BASE;
69 %constant int SCOPE_ONELEVEL = LDB_SCOPE_ONELEVEL;
70 %constant int SCOPE_SUBTREE = LDB_SCOPE_SUBTREE;
72 %constant int CHANGETYPE_NONE = LDB_CHANGETYPE_NONE;
73 %constant int CHANGETYPE_ADD = LDB_CHANGETYPE_ADD;
74 %constant int CHANGETYPE_DELETE = LDB_CHANGETYPE_DELETE;
75 %constant int CHANGETYPE_MODIFY = LDB_CHANGETYPE_MODIFY;
78 * Wrap struct ldb_context
81 /* The ldb functions will crash if a NULL ldb context is passed so
82 catch this before it happens. */
84 %typemap(check,noblock=1) struct ldb_context* {
86 SWIG_exception(SWIG_ValueError,
87 "ldb context must be non-NULL");
90 %typemap(check,noblock=1) ldb_msg * {
92 SWIG_exception(SWIG_ValueError,
93 "Message can not be None");
100 %typemap(in,noblock=1) struct ldb_val *INPUT (struct ldb_val temp) {
102 if (!PyString_Check($input)) {
103 PyErr_SetString(PyExc_TypeError, "string arg expected");
106 $1->length = PyString_Size($input);
107 $1->data = PyString_AsString($input);
111 PyObject *ldb_val_to_py_object(struct ldb_context *ldb_ctx,
112 struct ldb_message_element *el,
115 const struct ldb_schema_attribute *a;
116 struct ldb_val new_val;
117 TALLOC_CTX *mem_ctx = talloc_new(NULL);
122 if (ldb_ctx != NULL) {
123 a = ldb_schema_attribute_by_name(ldb_ctx, el->name);
126 if (a->syntax->ldif_write_fn(ldb_ctx, mem_ctx, val, &new_val) != 0) {
127 talloc_free(mem_ctx);
133 ret = PyString_FromStringAndSize((const char *)new_val.data, new_val.length);
135 talloc_free(mem_ctx);
142 %typemap(out,noblock=1) struct ldb_val * {
143 $result = PyString_FromStringAndSize((const char *)$1->data, $1->length)
146 %typemap(out,noblock=1) struct ldb_val {
147 $result = PyString_FromStringAndSize((const char *)$1.data, $1.length)
151 * Wrap struct ldb_result
154 %typemap(in,noblock=1,numinputs=0) struct ldb_result **OUT (struct ldb_result *temp_ldb_result) {
155 $1 = &temp_ldb_result;
159 %typemap(argout,noblock=1) struct ldb_result ** (int i) {
160 $result = PyList_New((*$1)->count);
161 for (i = 0; i < (*$1)->count; i++) {
162 PyList_SetItem($result, i,
163 SWIG_NewPointerObj((*$1)->msgs[i], SWIGTYPE_p_ldb_message, 0)
168 %typemap(in,noblock=1,numinputs=1) const char * const *NULL_STR_LIST {
169 if ($input == Py_None) {
171 } else if (PySequence_Check($input)) {
173 $1 = talloc_array(NULL, char *, PySequence_Size($input)+1);
174 for(i = 0; i < PySequence_Size($input); i++)
175 $1[i] = PyString_AsString(PySequence_GetItem($input, i));
178 SWIG_exception(SWIG_TypeError, "expected sequence");
182 %typemap(freearg,noblock=1) const char * const *NULL_STR_LIST {
186 %apply const char * const *NULL_STR_LIST { const char * const *attrs }
187 %apply const char * const *NULL_STR_LIST { const char * const *control_strings }
191 %types(struct ldb_result *);
197 %rename(__str__) ldb_dn::get_linearized;
198 %rename(__cmp__) ldb_dn::compare;
199 %rename(__len__) ldb_dn::get_comp_num;
201 %feature("docstring") ldb_dn "A LDB distinguished name.";
202 typedef struct ldb_dn {
204 %feature("docstring") ldb_dn "S.__init__(ldb, string)\n" \
206 ldb_dn(ldb *ldb_ctx, const char *str)
208 ldb_dn *ret = ldb_dn_new(ldb_ctx, ldb_ctx, str);
209 /* ldb_dn_new() doesn't accept NULL as memory context, so
210 we do it this way... */
211 talloc_steal(NULL, ret);
214 SWIG_exception(SWIG_ValueError,
215 "unable to parse dn string");
219 ~ldb_dn() { talloc_free($self); }
220 %feature("docstring") validate "S.validate() -> bool\n" \
221 "Validate DN is correct.";
223 const char *get_casefold();
224 const char *get_linearized();
225 %feature("docstring") parent "S.parent() -> dn\n" \
226 "Get the parent for this DN.";
227 ldb_dn *parent() { return ldb_dn_get_parent(NULL, $self); }
228 int compare(ldb_dn *other);
230 %feature("docstring") is_special "S.is_special() -> bool\n" \
231 "Check whether this is a special LDB DN.";
233 %feature("docstring") is_null "S.is_null() -> bool\n" \
234 "Check whether this is a null DN.";
236 bool check_special(const char *name);
238 %feature("docstring") add_child "S.add_child(dn) -> None\n" \
239 "Add a child DN to this DN.";
240 bool add_child(ldb_dn *child);
241 %feature("docstring") add_base "S.add_base(dn) -> None\n" \
242 "Add a base DN to this DN.";
243 bool add_base(ldb_dn *base);
244 %feature("docstring") canonical_str "S.canonical_str() -> string\n" \
245 "Canonical version of this DN (like a posix path).";
246 const char *canonical_str() {
247 return ldb_dn_canonical_string($self, $self);
249 %feature("docstring") canonical_ex_str "S.canonical_ex_str() -> string\n" \
250 "Canonical version of this DN (like a posix path, with terminating newline).";
251 const char *canonical_ex_str() {
252 return ldb_dn_canonical_ex_string($self, $self);
257 char *dn = ldb_dn_get_linearized($self), *ret;
258 asprintf(&ret, "Dn('%s')", dn);
263 ldb_dn *__add__(ldb_dn *other)
265 ldb_dn *ret = ldb_dn_copy(NULL, $self);
266 ldb_dn_add_child(ret, other);
270 /* FIXME: implement __getslice__ */
273 def __eq__(self, other):
274 if isinstance(other, self.__class__):
275 return self.__cmp__(other) == 0
276 if isinstance(other, str):
277 return str(self) == other
285 struct ldb_context *ldb_context_from_py_object(PyObject *py_obj)
287 struct ldb_context *ldb_ctx;
288 if (SWIG_ConvertPtr(py_obj, (void *)&ldb_ctx, SWIGTYPE_p_ldb_context, 0 | 0 ) < 0)
293 int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object,
294 struct ldb_context *ldb_ctx, ldb_dn **dn)
298 if (ldb_ctx != NULL && PyString_Check(object)) {
299 odn = ldb_dn_new(mem_ctx, ldb_ctx, PyString_AsString(object));
306 ret = SWIG_ConvertPtr(object, (void **)&odn, SWIGTYPE_p_ldb_dn,
307 SWIG_POINTER_EXCEPTION);
308 *dn = ldb_dn_copy(mem_ctx, odn);
315 ldb_message_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx,
316 PyObject *set_obj, int flags,
317 const char *attr_name)
319 struct ldb_message_element *me = talloc(mem_ctx, struct ldb_message_element);
320 me->name = attr_name;
322 if (PyString_Check(set_obj)) {
324 me->values = talloc_array(me, struct ldb_val, me->num_values);
325 me->values[0].length = PyString_Size(set_obj);
326 me->values[0].data = (uint8_t *)talloc_strdup(me->values,
327 PyString_AsString(set_obj));
328 } else if (PySequence_Check(set_obj)) {
330 me->num_values = PySequence_Size(set_obj);
331 me->values = talloc_array(me, struct ldb_val, me->num_values);
332 for (i = 0; i < me->num_values; i++) {
333 PyObject *obj = PySequence_GetItem(set_obj, i);
334 me->values[i].length = PyString_Size(obj);
335 me->values[i].data = (uint8_t *)PyString_AsString(obj);
345 PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx,
346 ldb_message_element *me)
351 /* Python << 2.5 doesn't have PySet_New and PySet_Add. */
352 result = PyList_New(me->num_values);
354 for (i = 0; i < me->num_values; i++) {
355 PyList_SetItem(result, i,
356 ldb_val_to_py_object(ldb_ctx, me, &me->values[i]));
365 /* ldb_message_element */
366 %rename(MessageElement) ldb_message_element;
367 %feature("docstring") ldb_message_element "Message element.";
368 typedef struct ldb_message_element {
371 int __cmp__(ldb_message_element *other)
373 return ldb_msg_element_compare($self, other);
376 PyObject *__iter__(void)
378 return PyObject_GetIter(ldb_msg_element_to_set(NULL, $self));
381 PyObject *__set__(void)
383 return ldb_msg_element_to_set(NULL, $self);
386 ldb_message_element(PyObject *set_obj, int flags=0, const char *name = NULL)
388 return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name);
393 return $self->num_values;
399 if (i < 0 || i >= $self->num_values)
402 return ldb_val_to_py_object(NULL, $self, &$self->values[i]);
405 ~ldb_message_element() { talloc_free($self); }
408 def __getitem__(self, i):
411 raise KeyError("no such value")
415 return "MessageElement([%s])" % (",".join(repr(x) for x in self.__set__()))
417 def __eq__(self, other):
418 if (len(self) == 1 and self.get(0) == other):
420 if isinstance(other, self.__class__):
421 return self.__cmp__(other) == 0
423 for i in range(len(self)):
424 if self.get(i) != o.next():
428 } ldb_message_element;
432 %feature("docstring") ldb_message "Message.";
433 %rename(Message) ldb_message;
435 %rename(__delitem__) ldb_message::remove_attr;
436 %typemap(out) ldb_message_element * {
438 PyErr_SetString(PyExc_KeyError, "no such element");
440 $result = SWIG_NewPointerObj($1, SWIGTYPE_p_ldb_message_element, 0);
444 PyObject *ldb_msg_list_elements(ldb_msg *msg)
447 PyObject *obj = PyList_New(msg->num_elements+(msg->dn != NULL?1:0));
448 if (msg->dn != NULL) {
449 PyList_SetItem(obj, j, PyString_FromString("dn"));
452 for (i = 0; i < msg->num_elements; i++) {
453 PyList_SetItem(obj, j, PyString_FromString(msg->elements[i].name));
462 typedef struct ldb_message {
466 ldb_msg(ldb_dn *dn = NULL) {
467 ldb_msg *ret = ldb_msg_new(NULL);
468 ret->dn = talloc_reference(ret, dn);
471 ~ldb_msg() { talloc_free($self); }
472 ldb_message_element *find_element(const char *name);
475 void __setitem__(const char *attr_name, ldb_message_element *val)
477 struct ldb_message_element *el;
479 ldb_msg_remove_attr($self, attr_name);
481 el = talloc($self, struct ldb_message_element);
482 el->name = talloc_strdup(el, attr_name);
483 el->num_values = val->num_values;
484 el->values = talloc_reference(el, val->values);
486 ldb_msg_add($self, el, val->flags);
489 void __setitem__(const char *attr_name, PyObject *val)
491 struct ldb_message_element *el = ldb_msg_element_from_pyobject(NULL,
493 talloc_steal($self, el);
494 ldb_msg_remove_attr($self, attr_name);
495 ldb_msg_add($self, el, el->flags);
498 unsigned int __len__() { return $self->num_elements; }
502 return ldb_msg_list_elements($self);
505 PyObject *__iter__(void)
507 return PyObject_GetIter(ldb_msg_list_elements($self));
510 void remove_attr(const char *name);
512 def get(self, key, default=None):
515 return self.find_element(key)
517 def __getitem__(self, key):
518 ret = self.get(key, None)
520 raise KeyError("No such element")
524 for k in self.keys():
528 return list(self.iteritems())
531 return "Message(%s)" % repr(dict(self.iteritems()))
536 /* FIXME: Convert ldb_result to 3-tuple:
537 (msgs, refs, controls)
540 typedef struct ldb_ldif ldb_ldif;
544 static void py_ldb_debug(void *context, enum ldb_debug_level level, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3, 0);
546 static void py_ldb_debug(void *context, enum ldb_debug_level level, const char *fmt, va_list ap)
549 PyObject *fn = context;
551 vasprintf(&text, fmt, ap);
552 PyObject_CallFunction(fn, (char *)"(i,s)", level, text);
557 %typemap(in,numinputs=1,noblock=1) (void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), void *context) {
559 /* FIXME: Should be decreased somewhere as well. Perhaps register a
560 destructor and tie it to the ldb context ? */
567 static PyObject *ldb_ldif_to_pyobject(ldb_ldif *ldif)
572 return Py_BuildValue((char *)"(iO)", ldif->changetype,
573 SWIG_NewPointerObj(ldif->msg, SWIGTYPE_p_ldb_message, 0));
583 PyObject *PyExc_LdbError;
587 LdbError = _ldb.LdbError
591 PyExc_LdbError = PyErr_NewException((char *)"_ldb.LdbError", NULL, NULL);
592 PyDict_SetItemString(d, "LdbError", PyExc_LdbError);
595 %ignore _LDB_ERRORS_H_;
597 %include "include/ldb_errors.h"
604 %typemap(out,noblock=1) ldb_error {
605 if ($1 != LDB_SUCCESS) {
606 PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(i,s)", $1, ldb_errstring(arg1)));
612 %typemap(out,noblock=1) ldb_int_error {
613 if ($1 != LDB_SUCCESS) {
614 PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(i,s)", $1, ldb_strerror($1)));
620 %typemap(out,noblock=1) struct ldb_control ** {
622 PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(s)", ldb_errstring(arg1)));
625 $result = SWIG_NewPointerObj($1, $1_descriptor, 0);
628 %rename(Ldb) ldb_context;
629 %feature("docstring") ldb_context "Connection to a LDB database.";
631 %typemap(in,noblock=1) struct ldb_dn * {
632 if (ldb_dn_from_pyobject(NULL, $input, arg1, &$1) != 0) {
637 %typemap(freearg,noblock=1) struct ldb_dn * {
641 %typemap(in,numinputs=1) ldb_msg *add_msg {
642 Py_ssize_t dict_pos, msg_pos;
643 ldb_message_element *msgel;
644 PyObject *key, *value;
646 if (PyDict_Check($input)) {
647 PyObject *dn_value = PyDict_GetItemString($input, "dn");
648 $1 = ldb_msg_new(NULL);
649 $1->elements = talloc_zero_array($1, struct ldb_message_element, PyDict_Size($input));
650 msg_pos = dict_pos = 0;
652 /* using argp1 (magic SWIG value) here is a hack */
653 if (ldb_dn_from_pyobject($1, dn_value, argp1, &$1->dn) != 0) {
654 SWIG_exception(SWIG_TypeError, "unable to import dn object");
656 if ($1->dn == NULL) {
657 SWIG_exception(SWIG_TypeError, "dn set but not found");
661 while (PyDict_Next($input, &dict_pos, &key, &value)) {
662 char *key_str = PyString_AsString(key);
663 if (strcmp(key_str, "dn") != 0) {
664 msgel = ldb_msg_element_from_pyobject($1->elements, value, 0, key_str);
666 SWIG_exception(SWIG_TypeError, "unable to import element");
668 memcpy(&$1->elements[msg_pos], msgel, sizeof(*msgel));
673 if ($1->dn == NULL) {
674 SWIG_exception(SWIG_TypeError, "no dn set");
677 $1->num_elements = msg_pos;
679 if (SWIG_ConvertPtr($input, (void **)&$1, SWIGTYPE_p_ldb_message, 0) != 0) {
680 SWIG_exception(SWIG_TypeError, "unable to convert ldb message");
685 /* Top-level ldb operations */
686 typedef struct ldb_context {
688 ldb(void) { return ldb_init(NULL); }
690 %feature("docstring") connect "S.connect(url,flags=0,options=None) -> None\n" \
691 "Connect to a LDB URL.";
692 ldb_error connect(const char *url, unsigned int flags = 0,
693 const char *options[] = NULL);
695 ~ldb() { talloc_free($self); }
696 ldb_error search_ex(TALLOC_CTX *mem_ctx,
698 enum ldb_scope scope = LDB_SCOPE_DEFAULT,
699 const char *expression = NULL,
700 const char *const *attrs = NULL,
701 struct ldb_control **controls = NULL,
702 struct ldb_result **OUT) {
704 struct ldb_result *res;
705 struct ldb_request *req;
706 res = talloc_zero(mem_ctx, struct ldb_result);
708 return LDB_ERR_OPERATIONS_ERROR;
711 ret = ldb_build_search_req(&req, $self, mem_ctx,
712 base?base:ldb_get_default_basedn($self),
718 ldb_search_default_callback);
720 if (ret != LDB_SUCCESS) {
725 ldb_set_timeout($self, req, 0); /* use default timeout */
727 ret = ldb_request($self, req);
729 if (ret == LDB_SUCCESS) {
730 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
739 %feature("docstring") delete "S.delete(dn) -> None\n" \
741 ldb_error delete(ldb_dn *dn);
742 %feature("docstring") rename "S.rename(old_dn, new_dn) -> None\n" \
744 ldb_error rename(ldb_dn *olddn, ldb_dn *newdn);
745 struct ldb_control **parse_control_strings(TALLOC_CTX *mem_ctx,
746 const char * const*control_strings);
747 %feature("docstring") add "S.add(message) -> None\n" \
749 ldb_error add(ldb_msg *add_msg);
750 %feature("docstring") modify "S.modify(message) -> None\n" \
752 ldb_error modify(ldb_msg *message);
753 ldb_dn *get_config_basedn();
754 ldb_dn *get_root_basedn();
755 ldb_dn *get_schema_basedn();
756 ldb_dn *get_default_basedn();
757 PyObject *schema_format_value(const char *element_name, PyObject *val)
759 const struct ldb_schema_attribute *a;
760 struct ldb_val old_val;
761 struct ldb_val new_val;
762 TALLOC_CTX *mem_ctx = talloc_new(NULL);
765 old_val.data = PyString_AsString(val);
766 old_val.length = PyString_Size(val);
768 a = ldb_schema_attribute_by_name($self, element_name);
774 if (a->syntax->ldif_write_fn($self, mem_ctx, &old_val, &new_val) != 0) {
775 talloc_free(mem_ctx);
779 ret = PyString_FromStringAndSize((const char *)new_val.data, new_val.length);
781 talloc_free(mem_ctx);
786 const char *errstring();
787 %feature("docstring") set_create_perms "S.set_create_perms(mode) -> None\n" \
788 "Set mode to use when creating new LDB files.";
789 void set_create_perms(unsigned int perms);
790 %feature("docstring") set_modules_dir "S.set_modules_dir(path) -> None\n" \
791 "Set path LDB should search for modules";
792 void set_modules_dir(const char *path);
793 %feature("docstring") set_debug "S.set_debug(callback) -> None\n" \
794 "Set callback for LDB debug messages.\n" \
795 "The callback should accept a debug level and debug text.";
796 ldb_error set_debug(void (*debug)(void *context, enum ldb_debug_level level,
797 const char *fmt, va_list ap),
799 %feature("docstring") set_opaque "S.set_opaque(name, value) -> None\n" \
800 "Set an opaque value on this LDB connection. \n"
801 ":note: Passing incorrect values may cause crashes.";
802 ldb_error set_opaque(const char *name, void *value);
803 %feature("docstring") get_opaque "S.get_opaque(name) -> value\n" \
804 "Get an opaque value set on this LDB connection. \n"
805 ":note: The returned value may not be useful in Python.";
806 void *get_opaque(const char *name);
807 %feature("docstring") transaction_start "S.transaction_start() -> None\n" \
808 "Start a new transaction.";
809 ldb_error transaction_start();
810 %feature("docstring") transaction_commit "S.transaction_commit() -> None\n" \
811 "Commit currently active transaction.";
812 ldb_error transaction_commit();
813 %feature("docstring") transaction_cancel "S.transaction_cancel() -> None\n" \
814 "Cancel currently active transaction.";
815 ldb_error transaction_cancel();
816 void schema_attribute_remove(const char *name);
817 ldb_error schema_attribute_add(const char *attribute, unsigned flags, const char *syntax);
818 ldb_error setup_wellknown_attributes(void);
821 %typemap(in,numinputs=0,noblock=1) struct ldb_result **result_as_bool (struct ldb_result *tmp) { $1 = &tmp; }
822 %typemap(argout,noblock=1) struct ldb_result **result_as_bool { $result = ((*$1)->count > 0)?Py_True:Py_False; }
823 %typemap(freearg,noblock=1) struct ldb_result **result_as_bool { talloc_free(*$1); }
824 ldb_error __contains__(ldb_dn *dn, struct ldb_result **result_as_bool)
826 return ldb_search($self, dn, LDB_SCOPE_BASE, NULL, NULL,
830 %feature("docstring") parse_ldif "S.parse_ldif(ldif) -> iter(messages)\n" \
831 "Parse a string formatted using LDIF.";
833 PyObject *parse_ldif(const char *s)
835 PyObject *list = PyList_New(0);
836 struct ldb_ldif *ldif;
837 while ((ldif = ldb_ldif_read_string($self, &s)) != NULL) {
838 PyList_Append(list, ldb_ldif_to_pyobject(ldif));
840 return PyObject_GetIter(list);
846 asprintf(&ret, "<ldb connection at 0x%x>", ret);
852 def __init__(self, url=None, flags=0, options=None):
853 """Create a new LDB object.
855 Will also connect to the specified URL if one was given.
857 _ldb.Ldb_swiginit(self,_ldb.new_Ldb())
859 self.connect(url, flags, options)
861 def search(self, base=None, scope=SCOPE_DEFAULT, expression=None,
862 attrs=None, controls=None):
863 """Search in a database.
865 :param base: Optional base DN to search
866 :param scope: Search scope (SCOPE_BASE, SCOPE_ONELEVEL or SCOPE_SUBTREE)
867 :param expression: Optional search expression
868 :param attrs: Attributes to return (defaults to all)
869 :param controls: Optional list of controls
870 :return: Iterator over Message objects
872 if not (attrs is None or isinstance(attrs, list)):
873 raise TypeError("attributes not a list")
874 parsed_controls = None
875 if controls is not None:
876 parsed_controls = self.parse_control_strings(controls)
877 return self.search_ex(base, scope, expression, attrs,
883 %typemap(in,noblock=1) struct ldb_dn *;
884 %typemap(freearg,noblock=1) struct ldb_dn *;
886 %nodefault ldb_message;
887 %nodefault ldb_context;
890 %rename(valid_attr_name) ldb_valid_attr_name;
891 %feature("docstring") ldb_valid_attr_name "S.valid_attr_name(name) -> bool\n"
892 "Check whether the supplied name is a valid attribute name.";
893 int ldb_valid_attr_name(const char *s);
895 typedef unsigned long time_t;
897 %feature("docstring") timestring "S.timestring(int) -> string\n"
898 "Generate a LDAP time string from a UNIX timestamp";
901 static char *timestring(time_t t)
903 char *tresult = ldb_timestring(NULL, t);
904 char *result = strdup(tresult);
905 talloc_free(tresult);
910 %rename(string_to_time) ldb_string_to_time;
911 %feature("docstring") ldb_string_to_time "S.string_to_time(string) -> int\n"
912 "Parse a LDAP time string into a UNIX timestamp.";
913 time_t ldb_string_to_time(const char *s);
915 %typemap(in,noblock=1) const struct ldb_module_ops * {
916 $1 = talloc_zero(talloc_autofree_context(), struct ldb_module_ops);
918 $1->name = (char *)PyObject_GetAttrString($input, (char *)"name");
921 %feature("docstring") ldb_register_module "S.register_module(module) -> None\n"
922 "Register a LDB module.";
923 %rename(register_module) ldb_register_module;
924 ldb_int_error ldb_register_module(const struct ldb_module_ops *);
927 __docformat__ = "restructuredText"