diff options
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r-- | source4/lib/ldb/Makefile.in | 2 | ||||
-rw-r--r-- | source4/lib/ldb/config.mk | 2 | ||||
-rw-r--r-- | source4/lib/ldb/configure.ac | 2 | ||||
-rw-r--r-- | source4/lib/ldb/ldb.i | 88 | ||||
-rw-r--r-- | source4/lib/ldb/ldb.py | 5 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_wrap.c | 333 | ||||
-rwxr-xr-x | source4/lib/ldb/tests/python/ldap.py | 1472 |
7 files changed, 1109 insertions, 795 deletions
diff --git a/source4/lib/ldb/Makefile.in b/source4/lib/ldb/Makefile.in index 8be5d11958..7bd719cdd9 100644 --- a/source4/lib/ldb/Makefile.in +++ b/source4/lib/ldb/Makefile.in @@ -213,7 +213,7 @@ valgrindtest: all installcheck: install test -install:: all installdirs installheaders installlibs installbin installdoc \ +install:: all installdirs installheaders installlibs installbin installdocs \ @PYTHON_INSTALL_TARGET@ installdirs: diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk index a3b10a22d5..75ce89d6cf 100644 --- a/source4/lib/ldb/config.mk +++ b/source4/lib/ldb/config.mk @@ -130,7 +130,7 @@ VERSION = 0.0.1 SO_VERSION = 0 OUTPUT_TYPE = SHARED_LIBRARY CFLAGS = -Ilib/ldb/include -DESCRIPTION = LDAP-like embedded database library +PC_FILE = ldb.pc INIT_FUNCTION_TYPE = int (*) (void) OBJ_FILES = \ common/ldb.o \ diff --git a/source4/lib/ldb/configure.ac b/source4/lib/ldb/configure.ac index 62a840e561..176cef0f3e 100644 --- a/source4/lib/ldb/configure.ac +++ b/source4/lib/ldb/configure.ac @@ -11,7 +11,7 @@ AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""]) AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""]) AC_DEFUN([SMB_EXT_LIB], [echo -n ""]) AC_DEFUN([SMB_ENABLE], [echo -n ""]) -AC_INIT(ldb, 0.9.1) +AC_INIT(ldb, 0.9.2) AC_CONFIG_SRCDIR([common/ldb.c]) AC_LIBREPLACE_ALL_CHECKS 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 <tpot@samba.org> Copyright (C) 2006 Simo Sorce <idra@samba.org> - Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org> + Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org> ** 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; } diff --git a/source4/lib/ldb/ldb.py b/source4/lib/ldb/ldb.py index ab2a68a4b3..0bcfd36779 100644 --- a/source4/lib/ldb/ldb.py +++ b/source4/lib/ldb/ldb.py @@ -65,6 +65,7 @@ CHANGETYPE_NONE = _ldb.CHANGETYPE_NONE CHANGETYPE_ADD = _ldb.CHANGETYPE_ADD CHANGETYPE_DELETE = _ldb.CHANGETYPE_DELETE CHANGETYPE_MODIFY = _ldb.CHANGETYPE_MODIFY +ldb_val_to_py_object = _ldb.ldb_val_to_py_object class Dn(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr @@ -218,6 +219,7 @@ Ldb.get_config_basedn = new_instancemethod(_ldb.Ldb_get_config_basedn,None,Ldb) Ldb.get_root_basedn = new_instancemethod(_ldb.Ldb_get_root_basedn,None,Ldb) Ldb.get_schema_basedn = new_instancemethod(_ldb.Ldb_get_schema_basedn,None,Ldb) Ldb.get_default_basedn = new_instancemethod(_ldb.Ldb_get_default_basedn,None,Ldb) +Ldb.schema_format_value = new_instancemethod(_ldb.Ldb_schema_format_value,None,Ldb) Ldb.errstring = new_instancemethod(_ldb.Ldb_errstring,None,Ldb) Ldb.set_create_perms = new_instancemethod(_ldb.Ldb_set_create_perms,None,Ldb) Ldb.set_modules_dir = new_instancemethod(_ldb.Ldb_set_modules_dir,None,Ldb) @@ -227,6 +229,9 @@ Ldb.get_opaque = new_instancemethod(_ldb.Ldb_get_opaque,None,Ldb) Ldb.transaction_start = new_instancemethod(_ldb.Ldb_transaction_start,None,Ldb) Ldb.transaction_commit = new_instancemethod(_ldb.Ldb_transaction_commit,None,Ldb) Ldb.transaction_cancel = new_instancemethod(_ldb.Ldb_transaction_cancel,None,Ldb) +Ldb.schema_attribute_remove = new_instancemethod(_ldb.Ldb_schema_attribute_remove,None,Ldb) +Ldb.schema_attribute_add = new_instancemethod(_ldb.Ldb_schema_attribute_add,None,Ldb) +Ldb.setup_wellknown_attributes = new_instancemethod(_ldb.Ldb_setup_wellknown_attributes,None,Ldb) Ldb.__contains__ = new_instancemethod(_ldb.Ldb___contains__,None,Ldb) Ldb.parse_ldif = new_instancemethod(_ldb.Ldb_parse_ldif,None,Ldb) Ldb_swigregister = _ldb.Ldb_swigregister diff --git a/source4/lib/ldb/ldb_wrap.c b/source4/lib/ldb/ldb_wrap.c index c833246ead..51022e5930 100644 --- a/source4/lib/ldb/ldb_wrap.c +++ b/source4/lib/ldb/ldb_wrap.c @@ -2470,20 +2470,21 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) #define SWIGTYPE_p_ldb_message_element swig_types[8] #define SWIGTYPE_p_ldb_module_ops swig_types[9] #define SWIGTYPE_p_ldb_result swig_types[10] -#define SWIGTYPE_p_long_long swig_types[11] -#define SWIGTYPE_p_p_char swig_types[12] -#define SWIGTYPE_p_p_ldb_control swig_types[13] -#define SWIGTYPE_p_p_ldb_result swig_types[14] -#define SWIGTYPE_p_short swig_types[15] -#define SWIGTYPE_p_signed_char swig_types[16] -#define SWIGTYPE_p_unsigned_char swig_types[17] -#define SWIGTYPE_p_unsigned_int swig_types[18] -#define SWIGTYPE_p_unsigned_long swig_types[19] -#define SWIGTYPE_p_unsigned_long_long swig_types[20] -#define SWIGTYPE_p_unsigned_short swig_types[21] -#define SWIGTYPE_p_void swig_types[22] -static swig_type_info *swig_types[24]; -static swig_module_info swig_module = {swig_types, 23, 0, 0, 0, 0}; +#define SWIGTYPE_p_ldb_val swig_types[11] +#define SWIGTYPE_p_long_long swig_types[12] +#define SWIGTYPE_p_p_char swig_types[13] +#define SWIGTYPE_p_p_ldb_control swig_types[14] +#define SWIGTYPE_p_p_ldb_result swig_types[15] +#define SWIGTYPE_p_short swig_types[16] +#define SWIGTYPE_p_signed_char swig_types[17] +#define SWIGTYPE_p_unsigned_char swig_types[18] +#define SWIGTYPE_p_unsigned_int swig_types[19] +#define SWIGTYPE_p_unsigned_long swig_types[20] +#define SWIGTYPE_p_unsigned_long_long swig_types[21] +#define SWIGTYPE_p_unsigned_short swig_types[22] +#define SWIGTYPE_p_void swig_types[23] +static swig_type_info *swig_types[25]; +static swig_module_info swig_module = {swig_types, 24, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) @@ -2550,6 +2551,37 @@ SWIG_From_int (int value) } +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; +} + + + SWIGINTERN swig_type_info* SWIG_pchar_descriptor(void) { @@ -2719,7 +2751,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; @@ -2729,8 +2762,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; @@ -2738,10 +2770,10 @@ PyObject *ldb_msg_element_to_set(ldb_msg_element *me) SWIGINTERN PyObject *ldb_msg_element___iter__(ldb_msg_element *self){ - return PyObject_GetIter(ldb_msg_element_to_set(self)); + return PyObject_GetIter(ldb_msg_element_to_set(NULL, self)); } SWIGINTERN PyObject *ldb_msg_element___set__(ldb_msg_element *self){ - return ldb_msg_element_to_set(self); + return ldb_msg_element_to_set(NULL, self); } #include <limits.h> @@ -2898,9 +2930,7 @@ SWIGINTERN PyObject *ldb_msg_element_get(ldb_msg_element *self,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); + return ldb_val_to_py_object(NULL, self, &self->values[i]); } SWIGINTERN void delete_ldb_msg_element(ldb_msg_element *self){ talloc_free(self); } @@ -3129,6 +3159,33 @@ SWIGINTERN ldb_error ldb_add__SWIG_1(ldb *self,PyObject *py_msg){ fail: return 80; } +SWIGINTERN PyObject *ldb_schema_format_value(ldb *self,char const *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; + } SWIGINTERN ldb_error ldb___contains__(ldb *self,ldb_dn *dn,struct ldb_result **result_as_bool){ return ldb_search(self, dn, LDB_SCOPE_BASE, NULL, NULL, result_as_bool); @@ -3153,6 +3210,52 @@ static char *timestring(time_t t) #ifdef __cplusplus extern "C" { #endif +SWIGINTERN PyObject *_wrap_ldb_val_to_py_object(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + struct ldb_context *arg1 = (struct ldb_context *) 0 ; + struct ldb_message_element *arg2 = (struct ldb_message_element *) 0 ; + struct ldb_val *arg3 = (struct ldb_val *) 0 ; + PyObject *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *argp3 = 0 ; + int res3 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + char * kwnames[] = { + (char *) "ldb_ctx",(char *) "el",(char *) "val", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:ldb_val_to_py_object",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_val_to_py_object" "', argument " "1"" of type '" "struct ldb_context *""'"); + } + arg1 = (struct ldb_context *)(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_ldb_message_element, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_val_to_py_object" "', argument " "2"" of type '" "struct ldb_message_element *""'"); + } + arg2 = (struct ldb_message_element *)(argp2); + res3 = SWIG_ConvertPtr(obj2, &argp3,SWIGTYPE_p_ldb_val, 0 | 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ldb_val_to_py_object" "', argument " "3"" of type '" "struct ldb_val *""'"); + } + arg3 = (struct ldb_val *)(argp3); + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + result = (PyObject *)ldb_val_to_py_object(arg1,arg2,arg3); + resultobj = result; + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_new_Dn(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; @@ -4875,6 +4978,49 @@ fail: } +SWIGINTERN PyObject *_wrap_Ldb_schema_format_value(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + ldb *arg1 = (ldb *) 0 ; + char *arg2 = (char *) 0 ; + PyObject *arg3 = (PyObject *) 0 ; + PyObject *result = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "element_name",(char *) "val", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:Ldb_schema_format_value",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_schema_format_value" "', argument " "1"" of type '" "ldb *""'"); + } + arg1 = (ldb *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_schema_format_value" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + arg3 = obj2; + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + result = (PyObject *)ldb_schema_format_value(arg1,(char const *)arg2,arg3); + resultobj = result; + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + SWIGINTERN PyObject *_wrap_Ldb_errstring(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; @@ -5197,6 +5343,140 @@ fail: } +SWIGINTERN PyObject *_wrap_Ldb_schema_attribute_remove(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + ldb *arg1 = (ldb *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "name", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Ldb_schema_attribute_remove",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_schema_attribute_remove" "', argument " "1"" of type '" "ldb *""'"); + } + arg1 = (ldb *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_schema_attribute_remove" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + ldb_schema_attribute_remove(arg1,(char const *)arg2); + resultobj = SWIG_Py_Void(); + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Ldb_schema_attribute_add(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { + PyObject *resultobj = 0; + ldb *arg1 = (ldb *) 0 ; + char *arg2 = (char *) 0 ; + unsigned int arg3 ; + char *arg4 = (char *) 0 ; + ldb_error result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + unsigned int val3 ; + int ecode3 = 0 ; + int res4 ; + char *buf4 = 0 ; + int alloc4 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; + char * kwnames[] = { + (char *) "self",(char *) "attribute",(char *) "flags",(char *) "syntax", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOOO:Ldb_schema_attribute_add",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_schema_attribute_add" "', argument " "1"" of type '" "ldb *""'"); + } + arg1 = (ldb *)(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Ldb_schema_attribute_add" "', argument " "2"" of type '" "char const *""'"); + } + arg2 = (char *)(buf2); + ecode3 = SWIG_AsVal_unsigned_SS_int(obj2, &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Ldb_schema_attribute_add" "', argument " "3"" of type '" "unsigned int""'"); + } + arg3 = (unsigned int)(val3); + res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "Ldb_schema_attribute_add" "', argument " "4"" of type '" "char const *""'"); + } + arg4 = (char *)(buf4); + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + result = ldb_schema_attribute_add(arg1,(char const *)arg2,arg3,(char const *)arg4); + if (result != 0) { + PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(i,s)", result, ldb_strerror(result))); + SWIG_fail; + } + resultobj = Py_None; + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + if (alloc4 == SWIG_NEWOBJ) free((char*)buf4); + return NULL; +} + + +SWIGINTERN PyObject *_wrap_Ldb_setup_wellknown_attributes(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + ldb *arg1 = (ldb *) 0 ; + ldb_error result; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_context, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Ldb_setup_wellknown_attributes" "', argument " "1"" of type '" "ldb *""'"); + } + arg1 = (ldb *)(argp1); + if (arg1 == NULL) + SWIG_exception(SWIG_ValueError, + "ldb context must be non-NULL"); + result = ldb_setup_wellknown_attributes(arg1); + if (result != 0) { + PyErr_SetObject(PyExc_LdbError, Py_BuildValue((char *)"(i,s)", result, ldb_strerror(result))); + SWIG_fail; + } + resultobj = Py_None; + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_Ldb___contains__(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb *arg1 = (ldb *) 0 ; @@ -5400,6 +5680,7 @@ fail: static PyMethodDef SwigMethods[] = { + { (char *)"ldb_val_to_py_object", (PyCFunction) _wrap_ldb_val_to_py_object, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"new_Dn", (PyCFunction) _wrap_new_Dn, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"delete_Dn", (PyCFunction)_wrap_delete_Dn, METH_O, NULL}, { (char *)"Dn_validate", (PyCFunction)_wrap_Dn_validate, METH_O, NULL}, @@ -5454,6 +5735,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Ldb_get_root_basedn", (PyCFunction)_wrap_Ldb_get_root_basedn, METH_O, NULL}, { (char *)"Ldb_get_schema_basedn", (PyCFunction)_wrap_Ldb_get_schema_basedn, METH_O, NULL}, { (char *)"Ldb_get_default_basedn", (PyCFunction)_wrap_Ldb_get_default_basedn, METH_O, NULL}, + { (char *)"Ldb_schema_format_value", (PyCFunction) _wrap_Ldb_schema_format_value, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_errstring", (PyCFunction)_wrap_Ldb_errstring, METH_O, NULL}, { (char *)"Ldb_set_create_perms", (PyCFunction) _wrap_Ldb_set_create_perms, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_set_modules_dir", (PyCFunction) _wrap_Ldb_set_modules_dir, METH_VARARGS | METH_KEYWORDS, NULL}, @@ -5463,6 +5745,9 @@ static PyMethodDef SwigMethods[] = { { (char *)"Ldb_transaction_start", (PyCFunction)_wrap_Ldb_transaction_start, METH_O, NULL}, { (char *)"Ldb_transaction_commit", (PyCFunction)_wrap_Ldb_transaction_commit, METH_O, NULL}, { (char *)"Ldb_transaction_cancel", (PyCFunction)_wrap_Ldb_transaction_cancel, METH_O, NULL}, + { (char *)"Ldb_schema_attribute_remove", (PyCFunction) _wrap_Ldb_schema_attribute_remove, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_schema_attribute_add", (PyCFunction) _wrap_Ldb_schema_attribute_add, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_setup_wellknown_attributes", (PyCFunction)_wrap_Ldb_setup_wellknown_attributes, METH_O, NULL}, { (char *)"Ldb___contains__", (PyCFunction) _wrap_Ldb___contains__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_parse_ldif", (PyCFunction) _wrap_Ldb_parse_ldif, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_swigregister", Ldb_swigregister, METH_VARARGS, NULL}, @@ -5488,6 +5773,7 @@ static swig_type_info _swigt__p_ldb_message = {"_p_ldb_message", "ldb_msg *|stru static swig_type_info _swigt__p_ldb_message_element = {"_p_ldb_message_element", "struct ldb_message_element *|ldb_msg_element *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_ldb_module_ops = {"_p_ldb_module_ops", "struct ldb_module_ops *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_ldb_result = {"_p_ldb_result", "struct ldb_result *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_ldb_val = {"_p_ldb_val", "struct ldb_val *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_char = {"_p_p_char", "char **", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_p_ldb_control = {"_p_p_ldb_control", "struct ldb_control **", 0, 0, (void*)0, 0}; @@ -5513,6 +5799,7 @@ static swig_type_info *swig_type_initial[] = { &_swigt__p_ldb_message_element, &_swigt__p_ldb_module_ops, &_swigt__p_ldb_result, + &_swigt__p_ldb_val, &_swigt__p_long_long, &_swigt__p_p_char, &_swigt__p_p_ldb_control, @@ -5538,6 +5825,7 @@ static swig_cast_info _swigc__p_ldb_message[] = { {&_swigt__p_ldb_message, 0, 0 static swig_cast_info _swigc__p_ldb_message_element[] = { {&_swigt__p_ldb_message_element, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_ldb_module_ops[] = { {&_swigt__p_ldb_module_ops, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_ldb_result[] = { {&_swigt__p_ldb_result, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_ldb_val[] = { {&_swigt__p_ldb_val, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_long_long[] = { {&_swigt__p_long_long, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_char[] = { {&_swigt__p_p_char, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_p_ldb_control[] = { {&_swigt__p_p_ldb_control, 0, 0, 0},{0, 0, 0, 0}}; @@ -5563,6 +5851,7 @@ static swig_cast_info *swig_cast_initial[] = { _swigc__p_ldb_message_element, _swigc__p_ldb_module_ops, _swigc__p_ldb_result, + _swigc__p_ldb_val, _swigc__p_long_long, _swigc__p_p_char, _swigc__p_p_ldb_control, diff --git a/source4/lib/ldb/tests/python/ldap.py b/source4/lib/ldb/tests/python/ldap.py index 01b66a3890..f75bb8124d 100755 --- a/source4/lib/ldb/tests/python/ldap.py +++ b/source4/lib/ldb/tests/python/ldap.py @@ -6,20 +6,21 @@ import getopt import optparse import sys -# Add path to the library for in-tree use -sys.path.append("scripting/python") import samba.getopt as options from auth import system_session from ldb import (SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, LDB_ERR_NO_SUCH_OBJECT, LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS, LDB_ERR_ENTRY_ALREADY_EXISTS, LDB_ERR_UNWILLING_TO_PERFORM, - LDB_ERR_NOT_ALLOWED_ON_NON_LEAF) + LDB_ERR_NOT_ALLOWED_ON_NON_LEAF, LDB_ERR_OTHER) from samba import Ldb +from subunit import SubunitTestRunner import param +import unittest parser = optparse.OptionParser("ldap [options] <host>") -parser.add_option_group(options.SambaOptions(parser)) +sambaopts = options.SambaOptions(parser) +parser.add_option_group(sambaopts) parser.add_option_group(options.VersionOptions(parser)) # use command line creds if available credopts = options.CredentialsOptions(parser) @@ -33,126 +34,124 @@ if len(args) < 1: host = args[0] -lp = param.LoadParm() -if opts.configfile: - lp.load(opts.configfile) +lp = sambaopts.get_loadparm() -def delete_force(ldb, dn): - try: - ldb.delete(dn) - except LdbError, (num, _): - if num != LDB_ERR_NO_SUCH_OBJECT: - assert False - -def assertEquals(a1, a2): - assert a1 == a2, "Expected %r == %r" % (a1, a2) +class BasicTests(unittest.TestCase): + def delete_force(self, ldb, dn): + try: + ldb.delete(dn) + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) + + def find_basedn(self, ldb): + res = ldb.search(base="", expression="", scope=SCOPE_BASE, + attrs=["defaultNamingContext"]) + self.assertEquals(len(res), 1) + return res[0]["defaultNamingContext"][0] + + def find_configurationdn(self, ldb): + res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["configurationNamingContext"]) + self.assertEquals(len(res), 1) + return res[0]["configurationNamingContext"][0] + + def find_schemadn(self, ldb): + res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["schemaNamingContext"]) + self.assertEquals(len(res), 1) + return res[0]["schemaNamingContext"][0] + + def setUp(self): + self.ldb = ldb + self.gc_ldb = gc_ldb + self.base_dn = self.find_basedn(ldb) + self.configuration_dn = self.find_configurationdn(ldb) + self.schema_dn = self.find_schemadn(ldb) + + print "baseDN: %s\n" % self.base_dn + + self.delete_force(self.ldb, "cn=ldaptestuser,cn=users," + self.base_dn) + self.delete_force(self.ldb, "cn=ldaptestgroup,cn=users," + self.base_dn) + + def test_group_add_invalid_member(self): + """Testing group add with invalid member""" + try: + self.ldb.add({ + "dn": "cn=ldaptestgroup,cn=uSers," + self.base_dn, + "objectclass": "group", + "member": "cn=ldaptestuser,cn=useRs," + self.base_dn}) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) -def basic_tests(ldb, gc_ldb, base_dn, configuration_dn, schema_dn): - print "Running basic tests" + def test_all(self): + """Basic tests""" - delete_force(ldb, "cn=ldaptestuser,cn=users," + base_dn) - delete_force(ldb, "cn=ldaptestgroup,cn=users," + base_dn) + self.delete_force(self.ldb, "cn=ldaptestuser,cn=users," + self.base_dn) - print "Testing group add with invalid member" - try: - ldb.add({ - "dn": "cn=ldaptestgroup,cn=uSers," + base_dn, - "objectclass": "group", - "member": "cn=ldaptestuser,cn=useRs," + base_dn}) - except LdbError, (num, _): - if num != LDB_ERR_NO_SUCH_OBJECT: - assert False - else: - assert False - - print "Testing user add" - try: + print "Testing user add" ldb.add({ - "dn": "cn=ldaptestuser,cn=uSers," + base_dn, + "dn": "cn=ldaptestuser,cn=uSers," + self.base_dn, "objectclass": ["user", "person"], "cN": "LDAPtestUSER", "givenname": "ldap", "sn": "testy"}) - except LdbError: - ldb.delete("cn=ldaptestuser,cn=users," + base_dn) - ldb.add({ - "dn": "cn=ldaptestuser,cn=uSers," + base_dn, - "objectclass": ["user", "person"], - "cN": "LDAPtestUSER", - "givenname": "ldap", - "sn": "testy"}) - - ldb.add({ - "dn": "cn=ldaptestgroup,cn=uSers," + base_dn, - "objectclass": "group", - "member": "cn=ldaptestuser,cn=useRs," + base_dn}) - - try: - ldb.add({ - "dn": "cn=ldaptestcomputer,cn=computers," + base_dn, - "objectclass": "computer", - "cN": "LDAPtestCOMPUTER"}) - except LdbError: - ldb.delete("cn=ldaptestcomputer,cn=computers," + base_dn) + ldb.add({ - "dn": "cn=ldaptestcomputer,cn=computers," + base_dn, - "objectClass": "computer", - "cn": "LDAPtestCOMPUTER"}) - - try: - ldb.add({"dn": "cn=ldaptest2computer,cn=computers," + base_dn, - "objectClass": "computer", - "cn": "LDAPtest2COMPUTER", - "userAccountControl": "4096", - "displayname": "ldap testy"}) - except LdbError: - ldb.delete("cn=ldaptest2computer,cn=computers," + base_dn) + "dn": "cn=ldaptestgroup,cn=uSers," + self.base_dn, + "objectclass": "group", + "member": "cn=ldaptestuser,cn=useRs," + self.base_dn}) + + self.delete_force(ldb, "cn=ldaptestcomputer,cn=computers," + self.base_dn) ldb.add({ - "dn": "cn=ldaptest2computer,cn=computers," + base_dn, + "dn": "cn=ldaptestcomputer,cn=computers," + self.base_dn, + "objectclass": "computer", + "cN": "LDAPtestCOMPUTER"}) + + self.delete_force(self.ldb, "cn=ldaptest2computer,cn=computers," + self.base_dn) + ldb.add({"dn": "cn=ldaptest2computer,cn=computers," + self.base_dn, "objectClass": "computer", "cn": "LDAPtest2COMPUTER", "userAccountControl": "4096", "displayname": "ldap testy"}) - print "Testing attribute or value exists behaviour" - try: - ldb.modify_ldif(""" -dn: cn=ldaptest2computer,cn=computers,""" + base_dn + """ + print "Testing attribute or value exists behaviour" + try: + ldb.modify_ldif(""" +dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """ changetype: modify replace: servicePrincipalName servicePrincipalName: host/ldaptest2computer servicePrincipalName: host/ldaptest2computer servicePrincipalName: cifs/ldaptest2computer """) - except LdbError, (num, msg): - assert num == LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS + except LdbError, (num, msg): + self.assertEquals(num, LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS) - ldb.modify_ldif(""" -dn: cn=ldaptest2computer,cn=computers,""" + base_dn + """ + ldb.modify_ldif(""" +dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """ changetype: modify replace: servicePrincipalName servicePrincipalName: host/ldaptest2computer servicePrincipalName: cifs/ldaptest2computer """) - try: - ldb.modify_ldif(""" -dn: cn=ldaptest2computer,cn=computers,""" + base_dn + """ + try: + ldb.modify_ldif(""" +dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """ changetype: modify add: servicePrincipalName servicePrincipalName: host/ldaptest2computer """) - except LdbError, (num, msg): - assert num == LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS - - print "Testing ranged results" - ldb.modify_ldif(""" -dn: cn=ldaptest2computer,cn=computers,""" + base_dn + """ + except LdbError, (num, msg): + self.assertEquals(num, LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS) + + print "Testing ranged results" + ldb.modify_ldif(""" +dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """ changetype: modify replace: servicePrincipalName """) - - ldb.modify_ldif(""" -dn: cn=ldaptest2computer,cn=computers,""" + base_dn + """ + + ldb.modify_ldif(""" +dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """ changetype: modify add: servicePrincipalName servicePrincipalName: host/ldaptest2computer0 @@ -187,730 +186,685 @@ servicePrincipalName: host/ldaptest2computer28 servicePrincipalName: host/ldaptest2computer29 """) - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, - attrs=["servicePrincipalName;range=0-*"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - #print len(res[0]["servicePrincipalName;range=0-*"]) - assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-19"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" -# print res[0]["servicePrincipalName;range=0-19"].length - assertEquals(len(res[0]["servicePrincipalName;range=0-19"]), 20) - - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-30"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-40"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=30-40"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=30-*"]), 0) - - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=10-40"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=10-*"]), 20) -# pos_11 = res[0]["servicePrincipalName;range=10-*"][18] - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=11-40"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=11-*"]), 19) -# print res[0]["servicePrincipalName;range=11-*"][18] -# print pos_11 -# assertEquals((res[0]["servicePrincipalName;range=11-*"][18]), pos_11) - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=11-15"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=11-15"]), 5) -# assertEquals(res[0]["servicePrincipalName;range=11-15"][4], pos_11) - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" -# print res[0]["servicePrincipalName"][18] -# print pos_11 - assertEquals(len(res[0]["servicePrincipalName"]), 30) -# assertEquals(res[0]["servicePrincipalName"][18], pos_11) - - try: + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, + attrs=["servicePrincipalName;range=0-*"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + #print len(res[0]["servicePrincipalName;range=0-*"]) + self.assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-19"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + # print res[0]["servicePrincipalName;range=0-19"].length + self.assertEquals(len(res[0]["servicePrincipalName;range=0-19"]), 20) + + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-30"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-40"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=30-40"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=30-*"]), 0) + + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=10-40"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=10-*"]), 20) + # pos_11 = res[0]["servicePrincipalName;range=10-*"][18] + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=11-40"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=11-*"]), 19) + # print res[0]["servicePrincipalName;range=11-*"][18] + # print pos_11 + # self.assertEquals((res[0]["servicePrincipalName;range=11-*"][18]), pos_11) + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=11-15"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=11-15"]), 5) + # self.assertEquals(res[0]["servicePrincipalName;range=11-15"][4], pos_11) + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + # print res[0]["servicePrincipalName"][18] + # print pos_11 + self.assertEquals(len(res[0]["servicePrincipalName"]), 30) + # self.assertEquals(res[0]["servicePrincipalName"][18], pos_11) + + self.delete_force(self.ldb, "cn=ldaptestuser2,cn=users," + self.base_dn) ldb.add({ - "dn": "cn=ldaptestuser2,cn=useRs," + base_dn, - "objectClass": ["person", "user"], - "cn": "LDAPtestUSER2", - "givenname": "testy", - "sn": "ldap user2"}) - except LdbError: - ldb.delete("cn=ldaptestuser2,cn=users," + base_dn) - ldb.add({ - "dn": "cn=ldaptestuser2,cn=useRs," + base_dn, - "objectClass": ["person", "user"], - "cn": "LDAPtestUSER2", - "givenname": "testy", - "sn": "ldap user2"}) - - print "Testing Ambigious Name Resolution" -# Testing ldb.search for (&(anr=ldap testy)(objectClass=user)) - res = ldb.search(expression="(&(anr=ldap testy)(objectClass=user))") - assert len(res) == 3, "Could not find (&(anr=ldap testy)(objectClass=user))" - -# Testing ldb.search for (&(anr=testy ldap)(objectClass=user)) - res = ldb.search(expression="(&(anr=testy ldap)(objectClass=user))") - assert len(res) == 2, "Found only %d for (&(anr=testy ldap)(objectClass=user))" % len(res) - -# Testing ldb.search for (&(anr=ldap)(objectClass=user)) - res = ldb.search(expression="(&(anr=ldap)(objectClass=user))") - assert len(res) == 4, "Found only %d for (&(anr=ldap)(objectClass=user))" % len(res) - -# Testing ldb.search for (&(anr==ldap)(objectClass=user)) - res = ldb.search(expression="(&(anr==ldap)(objectClass=user))") - assert len(res) == 1, "Could not find (&(anr==ldap)(objectClass=user)). Found only %d for (&(anr=ldap)(objectClass=user))" % len(res) - - assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + base_dn)) - assertEquals(res[0]["cn"][0], "ldaptestuser") - assertEquals(res[0]["name"], "ldaptestuser") - -# Testing ldb.search for (&(anr=testy)(objectClass=user)) - res = ldb.search(expression="(&(anr=testy)(objectClass=user))") - assert len(res) == 2, "Found only %d for (&(anr=testy)(objectClass=user))" % len(res) - -# Testing ldb.search for (&(anr=ldap testy)(objectClass=user)) - res = ldb.search(expression="(&(anr=testy ldap)(objectClass=user))") - assert len(res) == 2, "Found only %d for (&(anr=ldap testy)(objectClass=user))" % len(res) - -# Testing ldb.search for (&(anr==ldap testy)(objectClass=user)) - res = ldb.search(expression="(&(anr==testy ldap)(objectClass=user))") - assert len(res) == 1, "Found only %d for (&(anr==ldap testy)(objectClass=user))" % len(res) - - assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + base_dn)) - assertEquals(res[0]["cn"][0], "ldaptestuser") - assertEquals(res[0]["name"][0], "ldaptestuser") - -# Testing ldb.search for (&(anr==testy ldap)(objectClass=user)) - res = ldb.search(expression="(&(anr==testy ldap)(objectClass=user))") - assert len(res) == 1, "Could not find (&(anr==testy ldap)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + base_dn)) - assertEquals(res[0]["cn"][0], "ldaptestuser") - assertEquals(res[0]["name"][0], "ldaptestuser") - - # Testing ldb.search for (&(anr=testy ldap user)(objectClass=user)) - res = ldb.search(expression="(&(anr=testy ldap user)(objectClass=user))") - assert len(res) == 1, "Could not find (&(anr=testy ldap user)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestuser2") - assertEquals(res[0]["name"], "ldaptestuser2") - - # Testing ldb.search for (&(anr==testy ldap user2)(objectClass=user)) - res = ldb.search(expression="(&(anr==testy ldap user2)(objectClass=user))") - assert len(res) == 1, "Could not find (&(anr==testy ldap user2)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestuser2") - assertEquals(res[0]["name"], "ldaptestuser2") - - # Testing ldb.search for (&(anr==ldap user2)(objectClass=user)) - res = ldb.search(expression="(&(anr==ldap user2)(objectClass=user))") - assert len(res) == 1, "Could not find (&(anr==ldap user2)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestuser2") - assertEquals(res[0]["name"], "ldaptestuser2") - - # Testing ldb.search for (&(anr==not ldap user2)(objectClass=user)) - res = ldb.search(expression="(&(anr==not ldap user2)(objectClass=user))") - assert len(res) == 0, "Must not find (&(anr==not ldap user2)(objectClass=user))" - - # Testing ldb.search for (&(anr=not ldap user2)(objectClass=user)) - res = ldb.search(expression="(&(anr=not ldap user2)(objectClass=user))") - assert len(res) == 0, "Must not find (&(anr=not ldap user2)(objectClass=user))" - - print "Testing Group Modifies" - ldb.modify_ldif(""" -dn: cn=ldaptestgroup,cn=users,""" + base_dn + """ + "dn": "cn=ldaptestuser2,cn=useRs," + self.base_dn, + "objectClass": ["person", "user"], + "cn": "LDAPtestUSER2", + "givenname": "testy", + "sn": "ldap user2"}) + + print "Testing Ambigious Name Resolution" + # Testing ldb.search for (&(anr=ldap testy)(objectClass=user)) + res = ldb.search(expression="(&(anr=ldap testy)(objectClass=user))") + self.assertEquals(len(res), 3, "Could not find (&(anr=ldap testy)(objectClass=user))") + + # Testing ldb.search for (&(anr=testy ldap)(objectClass=user)) + res = ldb.search(expression="(&(anr=testy ldap)(objectClass=user))") + self.assertEquals(len(res), 2, "Found only %d for (&(anr=testy ldap)(objectClass=user))" % len(res)) + + # Testing ldb.search for (&(anr=ldap)(objectClass=user)) + res = ldb.search(expression="(&(anr=ldap)(objectClass=user))") + self.assertEquals(len(res), 4, "Found only %d for (&(anr=ldap)(objectClass=user))" % len(res)) + + # Testing ldb.search for (&(anr==ldap)(objectClass=user)) + res = ldb.search(expression="(&(anr==ldap)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(anr==ldap)(objectClass=user)). Found only %d for (&(anr=ldap)(objectClass=user))" % len(res)) + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"][0], "ldaptestuser") + self.assertEquals(res[0]["name"], "ldaptestuser") + + # Testing ldb.search for (&(anr=testy)(objectClass=user)) + res = ldb.search(expression="(&(anr=testy)(objectClass=user))") + self.assertEquals(len(res), 2, "Found only %d for (&(anr=testy)(objectClass=user))" % len(res)) + + # Testing ldb.search for (&(anr=ldap testy)(objectClass=user)) + res = ldb.search(expression="(&(anr=testy ldap)(objectClass=user))") + self.assertEquals(len(res), 2, "Found only %d for (&(anr=ldap testy)(objectClass=user))" % len(res)) + + # Testing ldb.search for (&(anr==ldap testy)(objectClass=user)) + res = ldb.search(expression="(&(anr==testy ldap)(objectClass=user))") + self.assertEquals(len(res), 1, "Found only %d for (&(anr==ldap testy)(objectClass=user))" % len(res)) + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"][0], "ldaptestuser") + self.assertEquals(res[0]["name"][0], "ldaptestuser") + + # Testing ldb.search for (&(anr==testy ldap)(objectClass=user)) + res = ldb.search(expression="(&(anr==testy ldap)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(anr==testy ldap)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"][0], "ldaptestuser") + self.assertEquals(res[0]["name"][0], "ldaptestuser") + + # Testing ldb.search for (&(anr=testy ldap user)(objectClass=user)) + res = ldb.search(expression="(&(anr=testy ldap user)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(anr=testy ldap user)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestuser2") + self.assertEquals(res[0]["name"], "ldaptestuser2") + + # Testing ldb.search for (&(anr==testy ldap user2)(objectClass=user)) + res = ldb.search(expression="(&(anr==testy ldap user2)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(anr==testy ldap user2)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestuser2") + self.assertEquals(res[0]["name"], "ldaptestuser2") + + # Testing ldb.search for (&(anr==ldap user2)(objectClass=user)) + res = ldb.search(expression="(&(anr==ldap user2)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(anr==ldap user2)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestuser2") + self.assertEquals(res[0]["name"], "ldaptestuser2") + + # Testing ldb.search for (&(anr==not ldap user2)(objectClass=user)) + res = ldb.search(expression="(&(anr==not ldap user2)(objectClass=user))") + self.assertEquals(len(res), 0, "Must not find (&(anr==not ldap user2)(objectClass=user))") + + # Testing ldb.search for (&(anr=not ldap user2)(objectClass=user)) + res = ldb.search(expression="(&(anr=not ldap user2)(objectClass=user))") + self.assertEquals(len(res), 0, "Must not find (&(anr=not ldap user2)(objectClass=user))") + + print "Testing Group Modifies" + ldb.modify_ldif(""" +dn: cn=ldaptestgroup,cn=users,""" + self.base_dn + """ changetype: modify add: member -member: cn=ldaptestuser2,cn=users,""" + base_dn + """ -member: cn=ldaptestcomputer,cn=computers,""" + base_dn + """ +member: cn=ldaptestuser2,cn=users,""" + self.base_dn + """ +member: cn=ldaptestcomputer,cn=computers,""" + self.base_dn + """ """) - delete_force(ldb, "cn=ldaptestuser3,cn=users," + base_dn) + self.delete_force(ldb, "cn=ldaptestuser3,cn=users," + self.base_dn) - print "Testing adding non-existent user to a group" - try: - ldb.modify_ldif(""" -dn: cn=ldaptestgroup,cn=users,""" + base_dn + """ + print "Testing adding non-existent user to a group" + try: + ldb.modify_ldif(""" +dn: cn=ldaptestgroup,cn=users,""" + self.base_dn + """ changetype: modify add: member -member: cn=ldaptestuser3,cn=users,""" + base_dn + """ +member: cn=ldaptestuser3,cn=users,""" + self.base_dn + """ """) - except LdbError, (num, _): - assert num == LDB_ERR_NO_SUCH_OBJECT - else: - assert False - - print "Testing Renames" - - ldb.rename("cn=ldaptestuser2,cn=users," + base_dn, "cn=ldaptestuser3,cn=users," + base_dn) - - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestuser3,cn=users," + base_dn) - - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestUSER3,cn=users," + base_dn) - - print "Testing ldb.search for (&(cn=ldaptestuser3)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestuser3)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestuser3)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestUSER3") - assertEquals(res[0]["name"], "ldaptestUSER3") - -# This is a Samba special, and does not exist in real AD -# print "Testing ldb.search for (dn=CN=ldaptestUSER3,CN=Users," + base_dn + ")" -# res = ldb.search("(dn=CN=ldaptestUSER3,CN=Users," + base_dn + ")") -# if (res.error != 0 || len(res) != 1) { -# print "Could not find (dn=CN=ldaptestUSER3,CN=Users," + base_dn + ")" -# assertEquals(len(res), 1) -# } -# assertEquals(res[0].dn, ("CN=ldaptestUSER3,CN=Users," + base_dn)) -# assertEquals(res[0].cn, "ldaptestUSER3") -# assertEquals(res[0].name, "ldaptestUSER3") - - print "Testing ldb.search for (distinguishedName=CN=ldaptestUSER3,CN=Users," + base_dn + ")" - res = ldb.search(expression="(distinguishedName=CN=ldaptestUSER3,CN=Users," + base_dn + ")") - assert len(res) == 1, "Could not find (dn=CN=ldaptestUSER3,CN=Users," + base_dn + ")" - assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestUSER3") - assertEquals(res[0]["name"], "ldaptestUSER3") - - # ensure we cannot add it again - try: - ldb.add({"dn": "cn=ldaptestuser3,cn=userS," + base_dn, - "objectClass": ["person", "user"], - "cn": "LDAPtestUSER3"}) - except LdbError, (num, _): - assert num == LDB_ERR_ENTRY_ALREADY_EXISTS - else: - assert False - - # rename back - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestuser2,cn=users," + base_dn) - - # ensure we cannnot rename it twice - try: - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestuser2,cn=users," + base_dn) - except LdbError, (num, _): - assert num == LDB_ERR_NO_SUCH_OBJECT - else: - assert False - - # ensure can now use that name - ldb.add({"dn": "cn=ldaptestuser3,cn=users," + base_dn, - "objectClass": ["person", "user"], - "cn": "LDAPtestUSER3"}) - - # ensure we now cannnot rename - try: - ldb.rename("cn=ldaptestuser2,cn=users," + base_dn, "cn=ldaptestuser3,cn=users," + base_dn) - except LdbError, (num, _): - assert num == LDB_ERR_ENTRY_ALREADY_EXISTS - else: - assert False - try: - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestuser3,cn=configuration," + base_dn) - except LdbError, (num, _): - assert num in (71, 64) - else: - assert False - - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestuser5,cn=users," + base_dn) - - ldb.delete("cn=ldaptestuser5,cn=users," + base_dn) - - delete_force(ldb, "cn=ldaptestgroup2,cn=users," + base_dn) - - ldb.rename("cn=ldaptestgroup,cn=users," + base_dn, "cn=ldaptestgroup2,cn=users," + base_dn) - - print "Testing subtree Renames" - - ldb.add({"dn": "cn=ldaptestcontainer," + base_dn, - "objectClass": "container"}) - - try: - ldb.add({"dn": "CN=ldaptestuser4,CN=ldaptestcontainer," + base_dn, - "objectClass": ["person", "user"], - "cn": "LDAPtestUSER4"}) - except LdbError: - ldb.delete("cn=ldaptestuser4,cn=ldaptestcontainer," + base_dn) - ldb.add({"dn": "CN=ldaptestuser4,CN=ldaptestcontainer," + base_dn, + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) + + print "Testing Renames" + + ldb.rename("cn=ldaptestuser2,cn=users," + self.base_dn, "cn=ldaptestuser3,cn=users," + self.base_dn) + + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestuser3,cn=users," + self.base_dn) + + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestUSER3,cn=users," + self.base_dn) + + print "Testing ldb.search for (&(cn=ldaptestuser3)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestuser3)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser3)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestUSER3") + self.assertEquals(res[0]["name"], "ldaptestUSER3") + + # This is a Samba special, and does not exist in real AD + # print "Testing ldb.search for (dn=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")" + # res = ldb.search("(dn=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")") + # if (res.error != 0 || len(res) != 1) { + # print "Could not find (dn=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")" + # self.assertEquals(len(res), 1) + # } + # self.assertEquals(res[0].dn, ("CN=ldaptestUSER3,CN=Users," + self.base_dn)) + # self.assertEquals(res[0].cn, "ldaptestUSER3") + # self.assertEquals(res[0].name, "ldaptestUSER3") + + print "Testing ldb.search for (distinguishedName=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")" + res = ldb.search(expression="(distinguishedName=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")") + self.assertEquals(len(res), 1, "Could not find (dn=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")") + self.assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestUSER3") + self.assertEquals(res[0]["name"], "ldaptestUSER3") + + # ensure we cannot add it again + try: + ldb.add({"dn": "cn=ldaptestuser3,cn=userS," + self.base_dn, "objectClass": ["person", "user"], - "cn": "LDAPtestUSER4"}) + "cn": "LDAPtestUSER3"}) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_ENTRY_ALREADY_EXISTS) + + # rename back + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestuser2,cn=users," + self.base_dn) + + # ensure we cannnot rename it twice + try: + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, + "cn=ldaptestuser2,cn=users," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) + + # ensure can now use that name + ldb.add({"dn": "cn=ldaptestuser3,cn=users," + self.base_dn, + "objectClass": ["person", "user"], + "cn": "LDAPtestUSER3"}) + + # ensure we now cannnot rename + try: + ldb.rename("cn=ldaptestuser2,cn=users," + self.base_dn, "cn=ldaptestuser3,cn=users," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_ENTRY_ALREADY_EXISTS) + try: + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestuser3,cn=configuration," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertTrue(num in (71, 64)) + + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestuser5,cn=users," + self.base_dn) - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + ldb.delete("cn=ldaptestuser5,cn=users," + self.base_dn) + + self.delete_force(ldb, "cn=ldaptestgroup2,cn=users," + self.base_dn) + + ldb.rename("cn=ldaptestgroup,cn=users," + self.base_dn, "cn=ldaptestgroup2,cn=users," + self.base_dn) + + print "Testing subtree Renames" + + ldb.add({"dn": "cn=ldaptestcontainer," + self.base_dn, + "objectClass": "container"}) + + self.delete_force(self.ldb, "cn=ldaptestuser4,cn=ldaptestcontainer," + self.base_dn) + ldb.add({"dn": "CN=ldaptestuser4,CN=ldaptestcontainer," + self.base_dn, + "objectClass": ["person", "user"], + "cn": "LDAPtestUSER4"}) + + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify add: member -member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + base_dn + """ +member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """ """) - - print "Testing ldb.rename of cn=ldaptestcontainer," + base_dn + " to cn=ldaptestcontainer2," + base_dn - ldb.rename("CN=ldaptestcontainer," + base_dn, "CN=ldaptestcontainer2," + base_dn) - - print "Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestuser4)(objectClass=user))" - - print "Testing subtree ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + base_dn - try: - ldb.search("cn=ldaptestcontainer," + base_dn, - expression="(&(cn=ldaptestuser4)(objectClass=user))", - scope=SCOPE_SUBTREE) - except LdbError, (num, _): - assert num == LDB_ERR_NO_SUCH_OBJECT - else: - assert False - - print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + base_dn - try: - res = ldb.search("cn=ldaptestcontainer," + base_dn, expression="(&(cn=ldaptestuser4)(objectClass=user))", scope=SCOPE_ONELEVEL) - except LdbError, (num, _): - assert num == LDB_ERR_NO_SUCH_OBJECT - else: - assert False - - print "Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in renamed container" - res = ldb.search("cn=ldaptestcontainer2," + base_dn, expression="(&(cn=ldaptestuser4)(objectClass=user))", scope=SCOPE_SUBTREE) - assert len(res) == 1, "Could not find (&(cn=ldaptestuser4)(objectClass=user)) under cn=ldaptestcontainer2," + base_dn - - assertEquals(str(res[0].dn), ("CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn)) - assertEquals(res[0]["memberOf"][0].upper(), ("CN=ldaptestgroup2,CN=Users," + base_dn).upper()) - - print "Testing ldb.search for (&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn + ")(objectclass=group)) to check subtree renames and linked attributes" - res = ldb.search(base_dn, expression="(&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn + ")(objectclass=group))", scope=SCOPE_SUBTREE) - assert len(res) == 1, "Could not find (&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn + ")(objectclass=group)), perhaps linked attributes are not conistant with subtree renames?" - - print "Testing ldb.rename (into itself) of cn=ldaptestcontainer2," + base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer2," + base_dn - try: - ldb.rename("cn=ldaptestcontainer2," + base_dn, "cn=ldaptestcontainer,cn=ldaptestcontainer2," + base_dn) - except LdbError, (num, _): - assert num == LDB_ERR_UNWILLING_TO_PERFORM - else: - assert False - - print "Testing ldb.rename (into non-existent container) of cn=ldaptestcontainer2," + base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer3," + base_dn - try: - ldb.rename("cn=ldaptestcontainer2," + base_dn, "cn=ldaptestcontainer,cn=ldaptestcontainer3," + base_dn) - except LdbError, (num, _): - assert num in (53, 80) - else: - assert False - - print "Testing delete (should fail, not a leaf node) of renamed cn=ldaptestcontainer2," + base_dn - try: - ldb.delete("cn=ldaptestcontainer2," + base_dn) - except LdbError, (num, _): - assert num == LDB_ERR_NOT_ALLOWED_ON_NON_LEAF - else: - assert False - - print "Testing base ldb.search for CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn - res = ldb.search(expression="(objectclass=*)", base=("CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn), scope=SCOPE_BASE) - assert len(res) == 1 - res = ldb.search(expression="(cn=ldaptestuser40)", base=("CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn), scope=SCOPE_BASE) - assert len(res) == 0 - - print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in cn=ldaptestcontainer2," + base_dn - res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))", base="cn=ldaptestcontainer2," + base_dn, scope=SCOPE_ONELEVEL) - # FIXME: assert len(res) == 0 - - print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in cn=ldaptestcontainer2," + base_dn - res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))", base="cn=ldaptestcontainer2," + base_dn, scope=SCOPE_SUBTREE) - #FIXME: assert len(res) == 0 - - print "Testing delete of subtree renamed "+("CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn) - ldb.delete(("CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn)) - print "Testing delete of renamed cn=ldaptestcontainer2," + base_dn - ldb.delete("cn=ldaptestcontainer2," + base_dn) - - try: - ldb.add({"dn": "cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn, "objectClass": "user"}) - except LdbError, (num, _): - ldb.delete("cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn) - ldb.add({"dn": "cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn, "objectClass": "user"}) - - try: - ldb.add({"dn": "cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn, "objectClass": "user"}) - except LdbError, (num, _): - ldb.delete("cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn) - ldb.add({"dn": "cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn, - "objectClass": "user"}) - - print "Testing ldb.search for (&(cn=ldaptestuser)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestuser)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestuser") - assertEquals(res[0]["name"], "ldaptestuser") - assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) - assert("objectGUID" in res[0]) - assert("whenCreated" in res[0]) - assertEquals(res[0]["objectCategory"], ("CN=Person,CN=Schema,CN=Configuration," + base_dn)) - assertEquals(int(res[0]["sAMAccountType"][0]), 805306368) -# assertEquals(res[0].userAccountControl, 546) - assertEquals(res[0]["memberOf"][0], ("CN=ldaptestgroup2,CN=Users," + base_dn)) - assertEquals(len(res[0]["memberOf"]), 1) - - print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))" - res2 = ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))") - assert len(res2) == 1, "Could not find (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))" - - assertEquals(res[0].dn, res2[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon))" - res3 = ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=PerSon))") - assert len(res3) == 1, "Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)): matched " + len(res3) - - assertEquals(res[0].dn, res3[0].dn) - - if gc_ldb is not None: - print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog" - res3gc = gc_ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=PerSon))") - assert len(res3gc) == 1 - - assertEquals(res[0].dn, res3gc[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in with 'phantom root' control" - - res3control = gc_ldb.search(base_dn, expression="(&(cn=ldaptestuser)(objectCategory=PerSon))", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:2"]) - assert len(res3control) == 1, "Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog" - - assertEquals(res[0].dn, res3control[0].dn) - - ldb.delete(res[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestcomputer)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestcomputer,CN=Computers," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestcomputer") - assertEquals(res[0]["name"], "ldaptestcomputer") - assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user", "computer"]) - assert("objectGUID" in res[0]) - assert("whenCreated" in res[0]) - assertEquals(res[0]["objectCategory"], ("CN=Computer,CN=Schema,CN=Configuration," + base_dn)) - assertEquals(int(res[0]["primaryGroupID"][0]), 513) -# assertEquals(res[0].sAMAccountType, 805306368) -# assertEquals(res[0].userAccountControl, 546) - assertEquals(res[0]["memberOf"][0], "CN=ldaptestgroup2,CN=Users," + base_dn) - assertEquals(len(res[0]["memberOf"]), 1) - - print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))" - res2 = ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))") - assert len(res2) == 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))" - - assertEquals(res[0].dn, res2[0].dn) - - if gc_ldb is not None: - print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + ")) in Global Catlog" - res2gc = gc_ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))") - assert len(res2gc) == 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + ")) in Global Catlog" - - assertEquals(res[0].dn, res2gc[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER))" - res3 = ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=compuTER))") - assert len(res3) == 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER))" - - assertEquals(res[0].dn, res3[0].dn) - - if gc_ldb is not None: - print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog" - res3gc = gc_ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=compuTER))") - assert len(res3gc) == 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog" - - assertEquals(res[0].dn, res3gc[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestcomp*r)(objectCategory=compuTER))" - res4 = ldb.search(expression="(&(cn=ldaptestcomp*r)(objectCategory=compuTER))") - assert len(res4) == 1, "Could not find (&(cn=ldaptestcomp*r)(objectCategory=compuTER))" - - assertEquals(res[0].dn, res4[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestcomput*)(objectCategory=compuTER))" - res5 = ldb.search(expression="(&(cn=ldaptestcomput*)(objectCategory=compuTER))") - assert len(res5) == 1, "Could not find (&(cn=ldaptestcomput*)(objectCategory=compuTER))" - - assertEquals(res[0].dn, res5[0].dn) - - print "Testing ldb.search for (&(cn=*daptestcomputer)(objectCategory=compuTER))" - res6 = ldb.search(expression="(&(cn=*daptestcomputer)(objectCategory=compuTER))") - assert len(res6) == 1, "Could not find (&(cn=*daptestcomputer)(objectCategory=compuTER))" - - assertEquals(res[0].dn, res6[0].dn) - - ldb.delete(res[0].dn) - - print "Testing ldb.search for (&(cn=ldaptest2computer)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptest2computer)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptest2computer)(objectClass=user))" - - assertEquals(res[0].dn, ("CN=ldaptest2computer,CN=Computers," + base_dn)) - assertEquals(res[0]["cn"], "ldaptest2computer") - assertEquals(res[0]["name"], "ldaptest2computer") - assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user", "computer"]) - assert("objectGUID" in res[0]) - assert("whenCreated" in res[0]) - assertEquals(res[0]["objectCategory"][0], "CN=Computer,CN=Schema,CN=Configuration," + base_dn) - assertEquals(int(res[0]["sAMAccountType"][0]), 805306369) -# assertEquals(res[0].userAccountControl, 4098) - - ldb.delete(res[0].dn) - - attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "memberOf"] - print "Testing ldb.search for (&(cn=ldaptestUSer2)(objectClass=user))" - res = ldb.search(base_dn, expression="(&(cn=ldaptestUSer2)(objectClass=user))", scope=SCOPE_SUBTREE, attrs=attrs) - assert len(res) == 1, "Could not find (&(cn=ldaptestUSer2)(objectClass=user))" - - assertEquals(res[0].dn, ("CN=ldaptestuser2,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestuser2") - assertEquals(res[0]["name"], "ldaptestuser2") - assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) - assert("objectGUID" in res[0]) - assert("whenCreated" in res[0]) - assert("nTSecurityDescriptor" in res[0]) - assertEquals(res[0]["memberOf"][0], ("CN=ldaptestgroup2,CN=Users," + base_dn)) - - attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "member"] - print "Testing ldb.search for (&(cn=ldaptestgroup2)(objectClass=group))" - res = ldb.search(base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) - assert len(res) == 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))" - - assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestgroup2") - assertEquals(res[0]["name"], "ldaptestgroup2") - assertEquals(res[0]["objectClass"], ["top", "group"]) - assert("objectGuid" not in res[0]) - assert("whenCreated" in res[0]) - assert("nTSecurityDescriptor" in res[0]) - assertEquals(res[0]["member"], ["CN=ldaptestuser2,CN=Users," + base_dn]) - - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + + print "Testing ldb.rename of cn=ldaptestcontainer," + self.base_dn + " to cn=ldaptestcontainer2," + self.base_dn + ldb.rename("CN=ldaptestcontainer," + self.base_dn, "CN=ldaptestcontainer2," + self.base_dn) + + print "Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser4)(objectClass=user))") + + print "Testing subtree ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + self.base_dn + try: + ldb.search("cn=ldaptestcontainer," + self.base_dn, + expression="(&(cn=ldaptestuser4)(objectClass=user))", + scope=SCOPE_SUBTREE) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) + + print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + self.base_dn + try: + res = ldb.search("cn=ldaptestcontainer," + self.base_dn, + expression="(&(cn=ldaptestuser4)(objectClass=user))", scope=SCOPE_ONELEVEL) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) + + print "Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in renamed container" + res = ldb.search("cn=ldaptestcontainer2," + self.base_dn, expression="(&(cn=ldaptestuser4)(objectClass=user))", scope=SCOPE_SUBTREE) + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser4)(objectClass=user)) under cn=ldaptestcontainer2," + self.base_dn) + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn)) + self.assertEquals(res[0]["memberOf"][0].upper(), ("CN=ldaptestgroup2,CN=Users," + self.base_dn).upper()) + + print "Testing ldb.search for (&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn + ")(objectclass=group)) to check subtree renames and linked attributes" + res = ldb.search(self.base_dn, expression="(&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn + ")(objectclass=group))", scope=SCOPE_SUBTREE) + self.assertEquals(len(res), 1, "Could not find (&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn + ")(objectclass=group)), perhaps linked attributes are not conistant with subtree renames?") + + print "Testing ldb.rename (into itself) of cn=ldaptestcontainer2," + self.base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer2," + self.base_dn + try: + ldb.rename("cn=ldaptestcontainer2," + self.base_dn, "cn=ldaptestcontainer,cn=ldaptestcontainer2," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_UNWILLING_TO_PERFORM) + + print "Testing ldb.rename (into non-existent container) of cn=ldaptestcontainer2," + self.base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer3," + self.base_dn + try: + ldb.rename("cn=ldaptestcontainer2," + self.base_dn, "cn=ldaptestcontainer,cn=ldaptestcontainer3," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertTrue(num in (LDB_ERR_UNWILLING_TO_PERFORM, LDB_ERR_OTHER)) + + print "Testing delete (should fail, not a leaf node) of renamed cn=ldaptestcontainer2," + self.base_dn + try: + ldb.delete("cn=ldaptestcontainer2," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NOT_ALLOWED_ON_NON_LEAF) + + print "Testing base ldb.search for CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn + res = ldb.search(expression="(objectclass=*)", base=("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn), scope=SCOPE_BASE) + self.assertEquals(len(res), 1) + res = ldb.search(expression="(cn=ldaptestuser40)", base=("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn), scope=SCOPE_BASE) + self.assertEquals(len(res), 0) + + print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in cn=ldaptestcontainer2," + self.base_dn + res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))", base=("cn=ldaptestcontainer2," + self.base_dn), scope=SCOPE_ONELEVEL) + # FIXME: self.assertEquals(len(res), 0) + + print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in cn=ldaptestcontainer2," + self.base_dn + res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))", base=("cn=ldaptestcontainer2," + self.base_dn), scope=SCOPE_SUBTREE) + # FIXME: self.assertEquals(len(res), 0) + + print "Testing delete of subtree renamed "+("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn) + ldb.delete(("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn)) + print "Testing delete of renamed cn=ldaptestcontainer2," + self.base_dn + ldb.delete("cn=ldaptestcontainer2," + self.base_dn) + + self.delete_force(self.ldb, "cn=ldaptestutf8user èùéìòà ,cn=users," + self.base_dn) + ldb.add({"dn": "cn=ldaptestutf8user èùéìòà ,cn=users," + self.base_dn, "objectClass": "user"}) + + self.delete_force(self.ldb, "cn=ldaptestutf8user2 èùéìòà ,cn=users," + self.base_dn) + ldb.add({"dn": "cn=ldaptestutf8user2 èùéìòà ,cn=users," + self.base_dn, "objectClass": "user"}) + + print "Testing ldb.search for (&(cn=ldaptestuser)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestuser)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestuser") + self.assertEquals(res[0]["name"], "ldaptestuser") + self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) + self.assertTrue("objectGUID" in res[0]) + self.assertTrue("whenCreated" in res[0]) + self.assertEquals(res[0]["objectCategory"], ("CN=Person,CN=Schema,CN=Configuration," + self.base_dn)) + self.assertEquals(int(res[0]["sAMAccountType"][0]), 805306368) + # self.assertEquals(res[0].userAccountControl, 546) + self.assertEquals(res[0]["memberOf"][0], ("CN=ldaptestgroup2,CN=Users," + self.base_dn)) + self.assertEquals(len(res[0]["memberOf"]), 1) + + print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + self.base_dn + "))" + res2 = ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + self.base_dn + "))") + self.assertEquals(len(res2), 1, "Could not find (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + self.base_dn + "))") + + self.assertEquals(res[0].dn, res2[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon))" + res3 = ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=PerSon))") + self.assertEquals(len(res3), 1, "Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)): matched %d" % len(res3)) + + self.assertEquals(res[0].dn, res3[0].dn) + + if gc_ldb is not None: + print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog" + res3gc = gc_ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=PerSon))") + self.assertEquals(len(res3gc), 1) + + self.assertEquals(res[0].dn, res3gc[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in with 'phantom root' control" + + res3control = gc_ldb.search(self.base_dn, expression="(&(cn=ldaptestuser)(objectCategory=PerSon))", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:2"]) + self.assertEquals(len(res3control), 1, "Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog") + + self.assertEquals(res[0].dn, res3control[0].dn) + + ldb.delete(res[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestcomputer)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestcomputer,CN=Computers," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestcomputer") + self.assertEquals(res[0]["name"], "ldaptestcomputer") + self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user", "computer"]) + self.assertTrue("objectGUID" in res[0]) + self.assertTrue("whenCreated" in res[0]) + self.assertEquals(res[0]["objectCategory"], ("CN=Computer,CN=Schema,CN=Configuration," + self.base_dn)) + self.assertEquals(int(res[0]["primaryGroupID"][0]), 513) + # self.assertEquals(res[0].sAMAccountType, 805306368) + # self.assertEquals(res[0].userAccountControl, 546) + self.assertEquals(res[0]["memberOf"][0], "CN=ldaptestgroup2,CN=Users," + self.base_dn) + self.assertEquals(len(res[0]["memberOf"]), 1) + + print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + "))" + res2 = ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + "))") + self.assertEquals(len(res2), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + "))") + + self.assertEquals(res[0].dn, res2[0].dn) + + if gc_ldb is not None: + print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + ")) in Global Catlog" + res2gc = gc_ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + "))") + self.assertEquals(len(res2gc), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + ")) in Global Catlog") + + self.assertEquals(res[0].dn, res2gc[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER))" + res3 = ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=compuTER))") + self.assertEquals(len(res3), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER))") + + self.assertEquals(res[0].dn, res3[0].dn) + + if gc_ldb is not None: + print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog" + res3gc = gc_ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=compuTER))") + self.assertEquals(len(res3gc), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog") + + self.assertEquals(res[0].dn, res3gc[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestcomp*r)(objectCategory=compuTER))" + res4 = ldb.search(expression="(&(cn=ldaptestcomp*r)(objectCategory=compuTER))") + self.assertEquals(len(res4), 1, "Could not find (&(cn=ldaptestcomp*r)(objectCategory=compuTER))") + + self.assertEquals(res[0].dn, res4[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestcomput*)(objectCategory=compuTER))" + res5 = ldb.search(expression="(&(cn=ldaptestcomput*)(objectCategory=compuTER))") + self.assertEquals(len(res5), 1, "Could not find (&(cn=ldaptestcomput*)(objectCategory=compuTER))") + + self.assertEquals(res[0].dn, res5[0].dn) + + print "Testing ldb.search for (&(cn=*daptestcomputer)(objectCategory=compuTER))" + res6 = ldb.search(expression="(&(cn=*daptestcomputer)(objectCategory=compuTER))") + self.assertEquals(len(res6), 1, "Could not find (&(cn=*daptestcomputer)(objectCategory=compuTER))") + + self.assertEquals(res[0].dn, res6[0].dn) + + ldb.delete(res[0].dn) + + print "Testing ldb.search for (&(cn=ldaptest2computer)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptest2computer)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptest2computer)(objectClass=user))") + + self.assertEquals(res[0].dn, ("CN=ldaptest2computer,CN=Computers," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptest2computer") + self.assertEquals(res[0]["name"], "ldaptest2computer") + self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user", "computer"]) + self.assertTrue("objectGUID" in res[0]) + self.assertTrue("whenCreated" in res[0]) + self.assertEquals(res[0]["objectCategory"][0], "CN=Computer,CN=Schema,CN=Configuration," + self.base_dn) + self.assertEquals(int(res[0]["sAMAccountType"][0]), 805306369) + # self.assertEquals(res[0].userAccountControl, 4098) + + ldb.delete(res[0].dn) + + attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "memberOf"] + print "Testing ldb.search for (&(cn=ldaptestUSer2)(objectClass=user))" + res = ldb.search(self.base_dn, expression="(&(cn=ldaptestUSer2)(objectClass=user))", scope=SCOPE_SUBTREE, attrs=attrs) + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestUSer2)(objectClass=user))") + + self.assertEquals(res[0].dn, ("CN=ldaptestuser2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestuser2") + self.assertEquals(res[0]["name"], "ldaptestuser2") + self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) + self.assertTrue("objectGUID" in res[0]) + self.assertTrue("whenCreated" in res[0]) + self.assertTrue("nTSecurityDescriptor" in res[0]) + self.assertEquals(res[0]["memberOf"][0], ("CN=ldaptestgroup2,CN=Users," + self.base_dn)) + + attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "member"] + print "Testing ldb.search for (&(cn=ldaptestgroup2)(objectClass=group))" + res = ldb.search(self.base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))") + + self.assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestgroup2") + self.assertEquals(res[0]["name"], "ldaptestgroup2") + self.assertEquals(res[0]["objectClass"], ["top", "group"]) + self.assertTrue("objectGuid" not in res[0]) + self.assertTrue("whenCreated" in res[0]) + self.assertTrue("nTSecurityDescriptor" in res[0]) + self.assertEquals(res[0]["member"], ["CN=ldaptestuser2,CN=Users," + self.base_dn]) + + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify replace: member -member: CN=ldaptestuser2,CN=Users,""" + base_dn + """ -member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + base_dn + """ +member: CN=ldaptestuser2,CN=Users,""" + self.base_dn + """ +member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self.base_dn + """ """) - - print "Testing Linked attribute behaviours" - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + + print "Testing Linked attribute behaviours" + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify delete: member """) - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify add: member -member: CN=ldaptestuser2,CN=Users,""" + base_dn + """ -member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + base_dn + """ +member: CN=ldaptestuser2,CN=Users,""" + self.base_dn + """ +member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self.base_dn + """ """) - - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify replace: member """) - - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify add: member -member: CN=ldaptestuser2,CN=Users,""" + base_dn + """ -member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + base_dn + """ +member: CN=ldaptestuser2,CN=Users,""" + self.base_dn + """ +member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self.base_dn + """ """) - - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify delete: member -member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + base_dn + """ +member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self.base_dn + """ """) - - res = ldb.search(base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) - assert len(res) == 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))" + + res = ldb.search(self.base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))") + + self.assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["member"][0], ("CN=ldaptestuser2,CN=Users," + self.base_dn)) + self.assertEquals(len(res[0]["member"]), 1) - assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + base_dn)) - assertEquals(res[0]["member"][0], ("CN=ldaptestuser2,CN=Users," + base_dn)) - assertEquals(len(res[0]["member"]), 1) + ldb.delete(("CN=ldaptestuser2,CN=Users," + self.base_dn)) - ldb.delete(("CN=ldaptestuser2,CN=Users," + base_dn)) + attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "member"] + print "Testing ldb.search for (&(cn=ldaptestgroup2)(objectClass=group)) to check linked delete" + res = ldb.search(self.base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group)) to check linked delete") - attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "member"] - print "Testing ldb.search for (&(cn=ldaptestgroup2)(objectClass=group)) to check linked delete" - res = ldb.search(base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) - assert len(res) == 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group)) to check linked delete" + self.assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + self.base_dn)) + self.assertTrue("member" not in res[0]) - assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + base_dn)) - assert("member" not in res[0]) + print "Testing ldb.search for (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))") - print "Testing ldb.search for (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))" + self.assertEquals(res[0].dn, ("CN=ldaptestutf8user èùéìòà,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestutf8user èùéìòà") + self.assertEquals(res[0]["name"], "ldaptestutf8user èùéìòà") + self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) + self.assertTrue("objectGUID" in res[0]) + self.assertTrue("whenCreated" in res[0]) - assertEquals(res[0].dn, ("CN=ldaptestutf8user èùéìòà,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestutf8user èùéìòà") - assertEquals(res[0]["name"], "ldaptestutf8user èùéìòà") - assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) - assert("objectGUID" in res[0]) - assert("whenCreated" in res[0]) + ldb.delete(res[0].dn) - ldb.delete(res[0].dn) + print "Testing ldb.search for (&(cn=ldaptestutf8user2*)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestutf8user2*)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestutf8user2*)(objectClass=user))") - print "Testing ldb.search for (&(cn=ldaptestutf8user2*)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestutf8user2*)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestutf8user2*)(objectClass=user))" + ldb.delete(res[0].dn) - ldb.delete(res[0].dn) + ldb.delete(("CN=ldaptestgroup2,CN=Users," + self.base_dn)) - ldb.delete(("CN=ldaptestgroup2,CN=Users," + base_dn)) + print "Testing ldb.search for (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))") - print "Testing ldb.search for (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))") + #FIXME: self.assert len(res) == 1, "Could not find (expect space collapse, win2k3 fails) (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))" - #FIXME: assert len(res) == 1, "Could not find (expect space collapse, win2k3 fails) (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))" + print "Testing that we can't get at the configuration DN from the main search base" + res = ldb.search(self.base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertEquals(len(res), 0) - print "Testing that we can't get at the configuration DN from the main search base" - res = ldb.search(base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert len(res) == 0, "Got configuration DN " + res[0].dn + " which should not be able to be seen from main search base" - assertEquals(len(res), 0) + print "Testing that we can get at the configuration DN from the main search base on the LDAP port with the 'phantom root' search_options control" + res = ldb.search(self.base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:2"]) + self.assertTrue(len(res) > 0) - print "Testing that we can get at the configuration DN from the main search base on the LDAP port with the 'phantom root' search_options control" - res = ldb.search(base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:2"]) - assert(len(res) > 0) + if gc_ldb is not None: + print "Testing that we can get at the configuration DN from the main search base on the GC port with the search_options control == 0" + + res = gc_ldb.search(self.base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:0"]) + self.assertTrue(len(res) > 0) - if gc_ldb is not None: - print "Testing that we can get at the configuration DN from the main search base on the GC port with the search_options control == 0" + print "Testing that we do find configuration elements in the global catlog" + res = gc_ldb.search(self.base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing that we do find configuration elements and user elements at the same time" + res = gc_ldb.search(self.base_dn, expression="(|(objectClass=crossRef)(objectClass=person))", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing that we do find configuration elements in the global catlog, with the configuration basedn" + res = gc_ldb.search(self.configuration_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing that we can get at the configuration DN on the main LDAP port" + res = ldb.search(self.configuration_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing objectCategory canonacolisation" + res = ldb.search(self.configuration_dn, expression="objectCategory=ntDsDSA", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0, "Didn't find any records with objectCategory=ntDsDSA") + self.assertTrue(len(res) != 0) - res = gc_ldb.search(base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:0"]) - assert(len(res) > 0) - - print "Testing that we do find configuration elements in the global catlog" - res = gc_ldb.search(base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert (len(res) > 0) - - print "Testing that we do find configuration elements and user elements at the same time" - res = gc_ldb.search(base_dn, expression="(|(objectClass=crossRef)(objectClass=person))", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert (len(res) > 0) - - print "Testing that we do find configuration elements in the global catlog, with the configuration basedn" - res = gc_ldb.search(configuration_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert (len(res) > 0) - - print "Testing that we can get at the configuration DN on the main LDAP port" - res = ldb.search(configuration_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert (len(res) > 0) - - print "Testing objectCategory canonacolisation" - res = ldb.search(configuration_dn, expression="objectCategory=ntDsDSA", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert len(res) > 0, "Didn't find any records with objectCategory=ntDsDSA" - assert(len(res) != 0) - - res = ldb.search(configuration_dn, expression="objectCategory=CN=ntDs-DSA," + schema_dn, scope=SCOPE_SUBTREE, attrs=["cn"]) - assert len(res) > 0, "Didn't find any records with objectCategory=CN=ntDs-DSA," + schema_dn - assert(len(res) != 0) - - print "Testing objectClass attribute order on "+ base_dn - res = ldb.search(expression="objectClass=domain", base=base_dn, - scope=SCOPE_BASE, attrs=["objectClass"]) - assertEquals(len(res), 1) - - assertEquals(res[0]["objectClass"], ["top", "domain", "domainDNS"]) - -# check enumeration - - print "Testing ldb.search for objectCategory=person" - res = ldb.search(base_dn, expression="objectCategory=person", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert(len(res) > 0) - - print "Testing ldb.search for objectCategory=person with domain scope control" - res = ldb.search(base_dn, expression="objectCategory=person", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) - assert(len(res) > 0) - - print "Testing ldb.search for objectCategory=user" - res = ldb.search(base_dn, expression="objectCategory=user", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert(len(res) > 0) - - - print "Testing ldb.search for objectCategory=user with domain scope control" - res = ldb.search(base_dn, expression="objectCategory=user", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) - assert(len(res) > 0) - - print "Testing ldb.search for objectCategory=group" - res = ldb.search(base_dn, expression="objectCategory=group", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert(len(res) > 0) - - print "Testing ldb.search for objectCategory=group with domain scope control" - res = ldb.search(base_dn, expression="objectCategory=group", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) - assert(len(res) > 0) - -def basedn_tests(ldb, gc_ldb): - print "Testing for all rootDSE attributes" - res = ldb.search(scope=SCOPE_BASE, attrs=[]) - assertEquals(len(res), 1) - - print "Testing for highestCommittedUSN" - res = ldb.search("", scope=SCOPE_BASE, attrs=["highestCommittedUSN"]) - assertEquals(len(res), 1) - assert(int(res[0]["highestCommittedUSN"][0]) != 0) - - print "Testing for netlogon via LDAP" - res = ldb.search("", scope=SCOPE_BASE, attrs=["netlogon"]) - assertEquals(len(res), 0) - - print "Testing for netlogon and highestCommittedUSN via LDAP" - res = ldb.search("", scope=SCOPE_BASE, - attrs=["netlogon", "highestCommittedUSN"]) - assertEquals(len(res), 0) - - -def find_basedn(ldb): - res = ldb.search(base="", expression="", scope=SCOPE_BASE, - attrs=["defaultNamingContext"]) - assertEquals(len(res), 1) - return res[0]["defaultNamingContext"][0] - - -def find_configurationdn(ldb): - res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["configurationNamingContext"]) - assertEquals(len(res), 1) - return res[0]["configurationNamingContext"][0] - - -def find_schemadn(ldb): - res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["schemaNamingContext"]) - assertEquals(len(res), 1) - return res[0]["schemaNamingContext"][0] + res = ldb.search(self.configuration_dn, expression="objectCategory=CN=ntDs-DSA," + self.schema_dn, scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0, "Didn't find any records with objectCategory=CN=ntDs-DSA," + self.schema_dn) + self.assertTrue(len(res) != 0) + + print "Testing objectClass attribute order on "+ self.base_dn + res = ldb.search(expression="objectClass=domain", base=self.base_dn, + scope=SCOPE_BASE, attrs=["objectClass"]) + self.assertEquals(len(res), 1) + + self.assertEquals(res[0]["objectClass"], ["top", "domain", "domainDNS"]) + + # check enumeration + + print "Testing ldb.search for objectCategory=person" + res = ldb.search(self.base_dn, expression="objectCategory=person", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing ldb.search for objectCategory=person with domain scope control" + res = ldb.search(self.base_dn, expression="objectCategory=person", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) + self.assertTrue(len(res) > 0) + + print "Testing ldb.search for objectCategory=user" + res = ldb.search(self.base_dn, expression="objectCategory=user", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing ldb.search for objectCategory=user with domain scope control" + res = ldb.search(self.base_dn, expression="objectCategory=user", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) + self.assertTrue(len(res) > 0) + + print "Testing ldb.search for objectCategory=group" + res = ldb.search(self.base_dn, expression="objectCategory=group", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing ldb.search for objectCategory=group with domain scope control" + res = ldb.search(self.base_dn, expression="objectCategory=group", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) + self.assertTrue(len(res) > 0) + + +class BaseDnTests(unittest.TestCase): + def setUp(self): + self.ldb = ldb + + def test_rootdse_attrs(self): + """Testing for all rootDSE attributes""" + res = self.ldb.search(scope=SCOPE_BASE, attrs=[]) + self.assertEquals(len(res), 1) + + def test_highestcommittedusn(self): + """Testing for highestCommittedUSN""" + res = self.ldb.search("", scope=SCOPE_BASE, attrs=["highestCommittedUSN"]) + self.assertEquals(len(res), 1) + self.assertTrue(int(res[0]["highestCommittedUSN"][0]) != 0) + + def test_netlogon(self): + """Testing for netlogon via LDAP""" + res = self.ldb.search("", scope=SCOPE_BASE, attrs=["netlogon"]) + self.assertEquals(len(res), 0) + + def test_netlogon_highestcommitted_usn(self): + """Testing for netlogon and highestCommittedUSN via LDAP""" + res = self.ldb.search("", scope=SCOPE_BASE, + attrs=["netlogon", "highestCommittedUSN"]) + self.assertEquals(len(res), 0) + if not "://" in host: host = "ldap://%s" % host ldb = Ldb(host, credentials=creds, session_info=system_session(), lp=lp) -base_dn = find_basedn(ldb) -configuration_dn = find_configurationdn(ldb) -schema_dn = find_schemadn(ldb) - -print "baseDN: %s\n" % base_dn - gc_ldb = Ldb("%s:3268" % host, credentials=creds, session_info=system_session(), lp=lp) -basic_tests(ldb, gc_ldb, base_dn, configuration_dn, schema_dn) -basedn_tests(ldb, gc_ldb) +runner = SubunitTestRunner() +runner.run(unittest.makeSuite(BaseDnTests)) +runner.run(unittest.makeSuite(BasicTests)) |