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