Remove unused variable, fix (80, 'Other error') exceptions from ldb python bindings
[kai/samba-autobuild/.git] / source4 / lib / ldb / ldb.i
1 /*
2    Unix SMB/CIFS implementation.
3
4    Swig interface to ldb.
5
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>
9
10      ** NOTE! The following LGPL license applies to the ldb
11      ** library. This does NOT imply that all of Samba is released
12      ** under the LGPL
13    
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.
18
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.
23
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/>.
26 */
27
28 %module ldb
29
30 %{
31
32 #include <stdint.h>
33 #include <stdbool.h>
34 #include "talloc.h"
35 #include "ldb.h"
36 #include "ldb_errors.h"
37 #include "ldb_private.h"
38
39 typedef struct ldb_message ldb_msg;
40 typedef struct ldb_context ldb;
41 typedef struct ldb_dn ldb_dn;
42 typedef struct ldb_ldif ldb_ldif;
43 typedef struct ldb_message_element ldb_msg_element;
44 typedef int ldb_error;
45
46 %}
47
48 %import "carrays.i"
49 %import "typemaps.i"
50 %include "exception.i"
51 %import "stdint.i"
52
53 /* Don't expose talloc contexts in Python code. Python does reference 
54    counting for us, so just create a new top-level talloc context.
55  */
56 %typemap(in, numinputs=0, noblock=1) TALLOC_CTX * {
57     $1 = NULL;
58 }
59
60
61
62 %constant int SCOPE_DEFAULT = LDB_SCOPE_DEFAULT;
63 %constant int SCOPE_BASE = LDB_SCOPE_BASE;
64 %constant int SCOPE_ONELEVEL = LDB_SCOPE_ONELEVEL;
65 %constant int SCOPE_SUBTREE = LDB_SCOPE_SUBTREE;
66
67 %constant int CHANGETYPE_NONE = LDB_CHANGETYPE_NONE;
68 %constant int CHANGETYPE_ADD = LDB_CHANGETYPE_ADD;
69 %constant int CHANGETYPE_DELETE = LDB_CHANGETYPE_DELETE;
70 %constant int CHANGETYPE_MODIFY = LDB_CHANGETYPE_MODIFY;
71
72 /* 
73  * Wrap struct ldb_context
74  */
75
76 /* The ldb functions will crash if a NULL ldb context is passed so
77    catch this before it happens. */
78
79 %typemap(check,noblock=1) struct ldb_context* {
80         if ($1 == NULL)
81                 SWIG_exception(SWIG_ValueError, 
82                         "ldb context must be non-NULL");
83 }
84
85 %typemap(check,noblock=1) ldb_msg * {
86         if ($1 == NULL)
87                 SWIG_exception(SWIG_ValueError, 
88                         "Message can not be None");
89 }
90
91 /*
92  * Wrap struct ldb_val
93  */
94
95 %typemap(in,noblock=1) struct ldb_val *INPUT (struct ldb_val temp) {
96         $1 = &temp;
97         if (!PyString_Check($input)) {
98                 PyErr_SetString(PyExc_TypeError, "string arg expected");
99                 return NULL;
100         }
101         $1->length = PyString_Size($input);
102         $1->data = PyString_AsString($input);
103 }
104
105 %inline %{
106 PyObject *ldb_val_to_py_object(struct ldb_context *ldb_ctx, 
107                                struct ldb_message_element *el, 
108                                struct ldb_val *val)
109 {
110         const struct ldb_schema_attribute *a;
111         struct ldb_val new_val;
112         TALLOC_CTX *mem_ctx = talloc_new(NULL);
113         PyObject *ret;
114         
115         new_val = *val;
116         
117         if (ldb_ctx != NULL) {        
118                 a = ldb_schema_attribute_by_name(ldb_ctx, el->name);
119         
120                 if (a != NULL) {
121                         if (a->syntax->ldif_write_fn(ldb_ctx, mem_ctx, val, &new_val) != 0) {
122                                 talloc_free(mem_ctx);
123                                 return NULL;
124                         }
125                 }
126         } 
127         
128         ret = PyString_FromStringAndSize((const char *)new_val.data, new_val.length);
129         
130         talloc_free(mem_ctx);
131         
132         return ret;
133 }
134
135 %}
136
137 %typemap(out,noblock=1) struct ldb_val * {
138         $result = PyString_FromStringAndSize((const char *)$1->data, $1->length)
139 }
140
141 %typemap(out,noblock=1) struct ldb_val {
142         $result = PyString_FromStringAndSize((const char *)$1.data, $1.length)
143 }
144
145 /*
146  * Wrap struct ldb_result
147  */
148
149 %typemap(in,noblock=1,numinputs=0) struct ldb_result **OUT (struct ldb_result *temp_ldb_result) {
150         $1 = &temp_ldb_result;
151 }
152
153 #ifdef SWIGPYTHON
154 %typemap(argout,noblock=1) struct ldb_result ** (int i) {
155         $result = PyList_New((*$1)->count);
156     for (i = 0; i < (*$1)->count; i++) {
157         PyList_SetItem($result, i, 
158             SWIG_NewPointerObj((*$1)->msgs[i], SWIGTYPE_p_ldb_message, 0)
159         );
160     }
161 }
162
163 %typemap(in,noblock=1,numinputs=1) const char * const *NULL_STR_LIST {
164     if ($input == Py_None) {
165         $1 = NULL;
166     } else if (PySequence_Check($input)) {
167         int i;
168         $1 = talloc_array(NULL, char *, PySequence_Size($input)+1);
169         for(i = 0; i < PySequence_Size($input); i++)
170             $1[i] = PyString_AsString(PySequence_GetItem($input, i));
171         $1[i] = NULL;
172     } else {
173         SWIG_exception(SWIG_TypeError, "expected sequence");
174     }
175 }
176
177 %typemap(freearg,noblock=1) const char * const *NULL_STR_LIST {
178     talloc_free($1);
179 }
180
181 %apply const char * const *NULL_STR_LIST { const char * const *attrs }
182 %apply const char * const *NULL_STR_LIST { const char * const *control_strings }
183
184 #endif
185
186 %types(struct ldb_result *);
187
188 /*
189  * Wrap struct ldb_dn
190  */
191
192 %rename(__str__) ldb_dn::get_linearized;
193 %rename(__cmp__) ldb_dn::compare;
194 %rename(__len__) ldb_dn::get_comp_num;
195 %rename(Dn) ldb_dn;
196 typedef struct ldb_dn {
197     %extend {
198         ldb_dn(ldb *ldb_ctx, const char *str)
199         {
200             ldb_dn *ret = ldb_dn_new(ldb_ctx, ldb_ctx, str);
201             /* ldb_dn_new() doesn't accept NULL as memory context, so 
202                we do it this way... */
203             talloc_steal(NULL, ret);
204
205             if (ret == NULL)
206                 SWIG_exception(SWIG_ValueError, 
207                                 "unable to parse dn string");
208 fail:
209             return ret;
210         }
211         ~ldb_dn() { talloc_free($self); }
212         bool validate();
213         const char *get_casefold();
214         const char *get_linearized();
215         ldb_dn *parent() { return ldb_dn_get_parent(NULL, $self); }
216         int compare(ldb_dn *other);
217         bool is_valid();
218         bool is_special();
219         bool is_null();
220         bool check_special(const char *name);
221         int get_comp_num();
222         bool add_child(ldb_dn *child);
223         bool add_base(ldb_dn *base);
224         const char *canonical_str() {
225             return ldb_dn_canonical_string($self, $self);
226         }
227         const char *canonical_ex_str() {
228             return ldb_dn_canonical_ex_string($self, $self);
229         }
230 #ifdef SWIGPYTHON
231         ldb_dn *__add__(ldb_dn *other)
232         {
233             ldb_dn *ret = ldb_dn_copy(NULL, $self);
234             ldb_dn_add_child(ret, other);
235             return ret;
236         }
237
238         /* FIXME: implement __getslice__ */
239 #endif
240     %pythoncode {
241         def __eq__(self, other):
242             if isinstance(other, self.__class__):
243                 return self.__cmp__(other) == 0
244             if isinstance(other, str):
245                 return str(self) == other
246             return False
247     }
248     }
249 } ldb_dn;
250
251 #ifdef SWIGPYTHON
252 %{
253 int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, 
254                          struct ldb_context *ldb_ctx, ldb_dn **dn)
255 {
256     int ret;
257     struct ldb_dn *odn;
258     if (ldb_ctx != NULL && PyString_Check(object)) {
259         *dn = ldb_dn_new(mem_ctx, ldb_ctx, PyString_AsString(object));
260         return 0;
261     }
262     ret = SWIG_ConvertPtr(object, (void **)&odn, SWIGTYPE_p_ldb_dn, 
263                            SWIG_POINTER_EXCEPTION);
264     *dn = ldb_dn_copy(mem_ctx, odn);
265     return ret;
266 }
267
268 ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx,
269                                                PyObject *set_obj, int flags,
270                                                const char *attr_name)
271 {
272     struct ldb_message_element *me = talloc(mem_ctx, struct ldb_message_element);
273     me->name = attr_name;
274     me->flags = flags;
275     if (PyString_Check(set_obj)) {
276         me->num_values = 1;
277         me->values = talloc_array(me, struct ldb_val, me->num_values);
278         me->values[0].length = PyString_Size(set_obj);
279         me->values[0].data = (uint8_t *)talloc_strdup(me->values, 
280                                            PyString_AsString(set_obj));
281     } else if (PySequence_Check(set_obj)) {
282         int i;
283         me->num_values = PySequence_Size(set_obj);
284         me->values = talloc_array(me, struct ldb_val, me->num_values);
285         for (i = 0; i < me->num_values; i++) {
286             PyObject *obj = PySequence_GetItem(set_obj, i);
287             me->values[i].length = PyString_Size(obj);
288             me->values[i].data = (uint8_t *)PyString_AsString(obj);
289         }
290     } else {
291         talloc_free(me);
292         me = NULL;
293     }
294
295     return me;
296 }
297
298 PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, 
299                                  ldb_msg_element *me)
300 {
301     int i;
302     PyObject *result;
303
304     /* Python << 2.5 doesn't have PySet_New and PySet_Add. */
305     result = PyList_New(me->num_values);
306
307     for (i = 0; i < me->num_values; i++) {
308         PyList_SetItem(result, i,
309             ldb_val_to_py_object(ldb_ctx, me, &me->values[i]));
310     }
311
312     return result;
313 }
314
315 %}
316 #endif
317
318 /* ldb_message_element */
319 %rename(__cmp__) ldb_message_element::compare;
320 %rename(MessageElement) ldb_msg_element;
321 typedef struct ldb_message_element {
322     %extend {
323 #ifdef SWIGPYTHON
324         PyObject *__iter__(void)
325         {
326             return PyObject_GetIter(ldb_msg_element_to_set(NULL, $self));
327         }
328
329         PyObject *__set__(void)
330         {
331             return ldb_msg_element_to_set(NULL, $self);
332         }
333
334         ldb_msg_element(PyObject *set_obj, int flags=0, const char *name = NULL)
335         {
336             return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name);
337         }
338
339         int __len__()
340         {
341             return $self->num_values;
342         }
343 #endif
344
345         PyObject *get(int i)
346         {
347             if (i < 0 || i >= $self->num_values)
348                 return Py_None;
349
350             return ldb_val_to_py_object(NULL, $self, &$self->values[i]);
351         }
352
353         ~ldb_msg_element() { talloc_free($self); }
354         int compare(ldb_msg_element *);
355     }
356     %pythoncode {
357         def __getitem__(self, i):
358             ret = self.get(i)
359             if ret is None:
360                 raise KeyError("no such value")
361             return ret
362
363         def __eq__(self, other):
364             if (len(self) == 1 and self.get(0) == other):
365                 return True
366             if isinstance(other, self.__class__):
367                 return self.__cmp__(other) == 0
368             o = iter(other)
369             for i in range(len(self)):
370                 if self.get(i) != o.next():
371                     return False
372             return True
373     }
374 } ldb_msg_element;
375
376 /* ldb_message */
377
378 %rename(Message) ldb_message;
379 #ifdef SWIGPYTHON
380 %rename(__delitem__) ldb_message::remove_attr;
381 %typemap(out) ldb_msg_element * {
382         if ($1 == NULL)
383                 PyErr_SetString(PyExc_KeyError, "no such element");
384     else
385         $result = SWIG_NewPointerObj($1, SWIGTYPE_p_ldb_message_element, 0);
386 }
387 %rename(__getitem__) ldb_message::find_element;
388 //%typemap(out) ldb_msg_element *;
389
390
391 %inline {
392     PyObject *ldb_msg_list_elements(ldb_msg *msg)
393     {
394         int i;
395         PyObject *obj = PyList_New(msg->num_elements);
396         for (i = 0; i < msg->num_elements; i++)
397             PyList_SetItem(obj, i, PyString_FromString(msg->elements[i].name));
398         return obj;
399     }
400 }
401
402 #endif
403
404 typedef struct ldb_message {
405         ldb_dn *dn;
406
407     %extend {
408         ldb_msg(ldb_dn *dn = NULL) { 
409             ldb_msg *ret = ldb_msg_new(NULL); 
410             ret->dn = talloc_reference(ret, dn);
411             return ret;
412         }
413         ~ldb_msg() { talloc_free($self); }
414         ldb_msg_element *find_element(const char *name);
415         
416 #ifdef SWIGPYTHON
417         void __setitem__(const char *attr_name, ldb_msg_element *val)
418         {
419             struct ldb_message_element *el;
420             
421             ldb_msg_remove_attr($self, attr_name);
422
423             el = talloc($self, struct ldb_message_element);
424             el->name = talloc_strdup(el, attr_name);
425             el->num_values = val->num_values;
426             el->values = talloc_reference(el, val->values);
427
428             ldb_msg_add($self, el, val->flags);
429         }
430
431         void __setitem__(const char *attr_name, PyObject *val)
432         {
433             struct ldb_message_element *el = ldb_msg_element_from_pyobject(NULL,
434                                                 val, 0, attr_name);
435             talloc_steal($self, el);
436             ldb_msg_remove_attr($self, attr_name);
437             ldb_msg_add($self, el, el->flags);
438         }
439
440         unsigned int __len__() { return $self->num_elements; }
441
442         PyObject *keys(void)
443         {
444             return ldb_msg_list_elements($self);
445         }
446
447         PyObject *__iter__(void)
448         {
449             return PyObject_GetIter(ldb_msg_list_elements($self));
450         }
451 #endif
452         void remove_attr(const char *name);
453     }
454 } ldb_msg;
455
456 /* FIXME: Convert ldb_result to 3-tuple:
457    (msgs, refs, controls)
458  */
459
460 typedef struct ldb_ldif ldb_ldif;
461
462 #ifdef SWIGPYTHON
463 %{
464 static void py_ldb_debug(void *context, enum ldb_debug_level level, const char *fmt, va_list ap)
465 {
466     char *text;
467     PyObject *fn = context;
468
469     vasprintf(&text, fmt, ap);
470     PyObject_CallFunction(fn, (char *)"(i,s)", level, text);
471     free(text);
472 }
473 %}
474
475 %typemap(in,numinputs=1,noblock=1) (void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), void *context) {
476     $1 = py_ldb_debug;
477     /* FIXME: Should be decreased somewhere as well. Perhaps register a 
478        destructor and tie it to the ldb context ? */
479     Py_INCREF($input);
480     $2 = $input;
481 }
482 #endif
483
484 %inline {
485     static PyObject *ldb_ldif_to_pyobject(ldb_ldif *ldif)
486     {
487         if (ldif == NULL) {
488             return Py_None;
489         } else {
490             return Py_BuildValue((char *)"(iO)", ldif->changetype, 
491                    SWIG_NewPointerObj(ldif->msg, SWIGTYPE_p_ldb_message, 0));
492         }
493     }
494 }
495
496 /*
497  * Wrap ldb errors
498  */
499
500 %{
501 PyObject *PyExc_LdbError;
502 %}
503
504 %pythoncode %{
505     LdbError = _ldb.LdbError
506 %}
507
508 %init %{
509     PyExc_LdbError = PyErr_NewException((char *)"_ldb.LdbError", NULL, NULL);
510     PyDict_SetItemString(d, "LdbError", PyExc_LdbError);
511 %}
512
513 %ignore _LDB_ERRORS_H_;
514 %ignore LDB_SUCCESS;
515 %include "include/ldb_errors.h"
516
517 /*
518  * Wrap ldb functions 
519  */
520
521
522 %typemap(out,noblock=1) ldb_error {
523     if ($1 != LDB_SUCCESS) {
524         PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(i,s)", $1, ldb_strerror($1)));
525         SWIG_fail;
526     }
527     $result = Py_None;
528 };
529
530 %typemap(out,noblock=1) struct ldb_control ** {
531     if ($1 == NULL) {
532         PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(s)", ldb_errstring(arg1)));
533         SWIG_fail;
534     }
535     $result = SWIG_NewPointerObj($1, $1_descriptor, 0);
536 }
537
538 %rename(Ldb) ldb_context;
539
540 %typemap(in,noblock=1) struct ldb_dn * {
541     if (ldb_dn_from_pyobject(NULL, $input, arg1, &$1) != 0) {
542         SWIG_fail;
543     }
544 };
545
546 %typemap(freearg,noblock=1) struct ldb_dn * {
547     talloc_free($1);
548 };
549
550 %typemap(in,numinputs=1) ldb_msg *add_msg {
551     int dict_pos, msg_pos;
552     PyObject *key, *value;
553     ldb_msg_element *msgel;
554
555     if (PyDict_Check($input)) {
556         $1 = ldb_msg_new(NULL);
557         $1->elements = talloc_zero_array($1, struct ldb_message_element, PyDict_Size($input));
558         msg_pos = dict_pos = 0;
559         while (PyDict_Next($input, &dict_pos, &key, &value)) {
560             if (!strcmp(PyString_AsString(key), "dn")) {
561                 /* using argp0 (magic SWIG value) here is a hack */
562                 if (ldb_dn_from_pyobject($1, value, argp1, &$1->dn) != 0) {
563                     SWIG_exception(SWIG_TypeError, "unable to import dn object");
564                 }
565             } else {
566                 msgel = ldb_msg_element_from_pyobject($1->elements, value, 0, PyString_AsString(key));
567                 if (msgel == NULL) {
568                     SWIG_exception(SWIG_TypeError, "unable to import element");
569                 }
570                 memcpy(&$1->elements[msg_pos], msgel, sizeof(*msgel));
571                 msg_pos++;
572             }
573         }
574
575         if ($1->dn == NULL) {
576             SWIG_exception(SWIG_TypeError, "no dn set");
577         }
578
579         $1->num_elements = msg_pos;
580     } else {
581         if (SWIG_ConvertPtr($input, (void **)&$1, SWIGTYPE_p_ldb_message, 0) != 0) {
582             SWIG_exception(SWIG_TypeError, "unable to convert ldb message");
583         }
584     }
585 }
586
587 /* Top-level ldb operations */
588 typedef struct ldb_context {
589     %extend {
590         ldb(void) { return ldb_init(NULL); }
591
592         ldb_error connect(const char *url, unsigned int flags = 0, 
593             const char *options[] = NULL);
594
595         ~ldb() { talloc_free($self); }
596         ldb_error search_ex(TALLOC_CTX *mem_ctx,
597                    ldb_dn *base = NULL, 
598                    enum ldb_scope scope = LDB_SCOPE_DEFAULT, 
599                    const char *expression = NULL, 
600                    const char *const *attrs = NULL, 
601                    struct ldb_control **controls = NULL,
602                    struct ldb_result **OUT) {
603             int ret;
604             struct ldb_result *res;
605             struct ldb_request *req;
606             res = talloc_zero(mem_ctx, struct ldb_result);
607             if (!res) {
608                 return LDB_ERR_OPERATIONS_ERROR;
609             }
610
611             ret = ldb_build_search_req(&req, $self, mem_ctx,
612                            base?base:ldb_get_default_basedn($self),
613                            scope,
614                            expression,
615                            attrs,
616                            controls,
617                            res,
618                            ldb_search_default_callback);
619
620             if (ret != LDB_SUCCESS) {
621                 talloc_free(res);
622                 return ret;
623             }
624
625             ldb_set_timeout($self, req, 0); /* use default timeout */
626                 
627             ret = ldb_request($self, req);
628                 
629             if (ret == LDB_SUCCESS) {
630                 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
631             }
632
633             talloc_free(req);
634
635             *OUT = res;
636             return ret;
637         }
638
639         ldb_error delete(ldb_dn *dn);
640         ldb_error rename(ldb_dn *olddn, ldb_dn *newdn);
641         struct ldb_control **parse_control_strings(TALLOC_CTX *mem_ctx, 
642                                                    const char * const*control_strings);
643         ldb_error add(ldb_msg *add_msg);
644         ldb_error modify(ldb_msg *message);
645         ldb_dn *get_config_basedn();
646         ldb_dn *get_root_basedn();
647         ldb_dn *get_schema_basedn();
648         ldb_dn *get_default_basedn();
649         PyObject *schema_format_value(const char *element_name, PyObject *val)
650         {
651                 const struct ldb_schema_attribute *a;
652                 struct ldb_val old_val;
653                 struct ldb_val new_val;
654                 TALLOC_CTX *mem_ctx = talloc_new(NULL);
655                 PyObject *ret;
656                 
657                 old_val.data = PyString_AsString(val);
658                 old_val.length = PyString_Size(val);
659                 
660                 a = ldb_schema_attribute_by_name($self, element_name);
661         
662                 if (a == NULL) {
663                         return Py_None;
664                 }
665                 
666                 if (a->syntax->ldif_write_fn($self, mem_ctx, &old_val, &new_val) != 0) {
667                         talloc_free(mem_ctx);
668                         return Py_None;
669                  }
670         
671                 ret = PyString_FromStringAndSize((const char *)new_val.data, new_val.length);
672                 
673                 talloc_free(mem_ctx);
674                 
675                 return ret;
676         }
677
678         const char *errstring();
679         void set_create_perms(unsigned int perms);
680         void set_modules_dir(const char *path);
681         ldb_error set_debug(void (*debug)(void *context, enum ldb_debug_level level, 
682                                           const char *fmt, va_list ap),
683                             void *context);
684         ldb_error set_opaque(const char *name, void *value);
685         void *get_opaque(const char *name);
686         ldb_error transaction_start();
687         ldb_error transaction_commit();
688         ldb_error transaction_cancel();
689         void schema_attribute_remove(const char *name);
690         ldb_error schema_attribute_add(const char *attribute, unsigned flags, const char *syntax);
691         ldb_error setup_wellknown_attributes(void);
692         
693 #ifdef SWIGPYTHON
694         %typemap(in,numinputs=0,noblock=1) struct ldb_result **result_as_bool (struct ldb_result *tmp) { $1 = &tmp; }
695         %typemap(argout,noblock=1) struct ldb_result **result_as_bool { $result = ((*$1)->count > 0)?Py_True:Py_False; }
696         %typemap(freearg,noblock=1) struct ldb_result **result_as_bool { talloc_free(*$1); }
697         ldb_error __contains__(ldb_dn *dn, struct ldb_result **result_as_bool)
698         {
699             return ldb_search($self, dn, LDB_SCOPE_BASE, NULL, NULL, 
700                              result_as_bool);
701         }
702
703         PyObject *parse_ldif(const char *s)
704         {
705             PyObject *list = PyList_New(0);
706             struct ldb_ldif *ldif;
707             while ((ldif = ldb_ldif_read_string($self, &s)) != NULL) {
708                 PyList_Append(list, ldb_ldif_to_pyobject(ldif));
709             }
710             return PyObject_GetIter(list);
711         }
712
713 #endif
714     }
715     %pythoncode {
716         def __init__(self, url=None, flags=0, options=None):
717             _ldb.Ldb_swiginit(self,_ldb.new_Ldb())
718             if url is not None:
719                 self.connect(url, flags, options)
720
721         def search(self, base=None, scope=SCOPE_DEFAULT, expression=None, 
722                    attrs=None, controls=None):
723             parsed_controls = None
724             if controls is not None:
725                 parsed_controls = self.parse_control_strings(controls)
726             return self.search_ex(base, scope, expression, attrs, 
727                                   parsed_controls)
728     }
729
730 } ldb;
731
732 %typemap(in,noblock=1) struct ldb_dn *;
733 %typemap(freearg,noblock=1) struct ldb_dn *;
734
735 %nodefault ldb_message;
736 %nodefault ldb_context;
737 %nodefault Dn;
738
739 %rename(valid_attr_name) ldb_valid_attr_name;
740 int ldb_valid_attr_name(const char *s);
741
742 typedef unsigned long time_t;
743
744 %inline %{
745 static char *timestring(time_t t)
746 {
747     char *tresult = ldb_timestring(NULL, t);
748     char *result = strdup(tresult);
749     talloc_free(tresult);
750     return result; 
751 }
752 %}
753
754 %rename(string_to_time) ldb_string_to_time;
755 time_t ldb_string_to_time(const char *s);
756
757 %typemap(in,noblock=1) const struct ldb_module_ops * {
758     $1 = talloc_zero(talloc_autofree_context(), struct ldb_module_ops);
759
760     $1->name = (char *)PyObject_GetAttrString($input, (char *)"name");
761 }
762
763 %rename(register_module) ldb_register_module;
764 ldb_error ldb_register_module(const struct ldb_module_ops *);