The branch, master has been updated
       via  960b75531530c05fcaaa7400e52f2b688a6e8d88 (commit)
       via  de1e3e2cf0c666a51b062ed5395906892beb53c0 (commit)
       via  8f4e4d2e3039997106f9da3dcd5b057d99802ecf (commit)
       via  4fff36f618420dea2e004f87ae5a2699eabd140a (commit)
       via  ee577ef0eef2d666504d1b78bb102b5c2e070b03 (commit)
      from  19de802c171f70ec4de102452afac52e2c0e548f (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 960b75531530c05fcaaa7400e52f2b688a6e8d88
Author: Jelmer Vernooij <jel...@samba.org>
Date:   Sat Mar 21 02:19:25 2009 +0100

    pyldb: Let conversion to LDIF up to the user of the API rather than doing
    it implicitly.

commit de1e3e2cf0c666a51b062ed5395906892beb53c0
Author: Jelmer Vernooij <jel...@samba.org>
Date:   Sat Mar 21 01:00:18 2009 +0100

    Remove unnecessary duplication of string in memory.

commit 8f4e4d2e3039997106f9da3dcd5b057d99802ecf
Author: Jelmer Vernooij <jel...@samba.org>
Date:   Fri Mar 20 22:58:15 2009 +0100

    Adapt Zahari's test to the generic LDB Python tests.

commit 4fff36f618420dea2e004f87ae5a2699eabd140a
Author: zahari <zah...@darkstar.zahari.local>
Date:   Fri Mar 20 12:03:29 2009 +0200

    Setting nTSecurityDescriptor via LDAP fails
    
    Fix for the problem was substitute talloc_strndup() with
    talloc_memdup(), allocate 1 more character and put null character
    ('\0') in the extra place so data copied is null terminated.
    
    Signed-off-by: Jelmer Vernooij <jel...@samba.org>

commit ee577ef0eef2d666504d1b78bb102b5c2e070b03
Author: Jelmer Vernooij <jel...@samba.org>
Date:   Fri Mar 20 22:52:57 2009 +0100

    Add more comments.

-----------------------------------------------------------------------

Summary of changes:
 source4/lib/ldb/pyldb.c             |   63 +++++++++++++++++++++++-----------
 source4/lib/ldb/tests/python/api.py |   13 +++++++
 2 files changed, 55 insertions(+), 21 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index 7ff4bf4..bceda05 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -5,7 +5,7 @@
 
    Copyright (C) 2005,2006 Tim Potter <t...@samba.org>
    Copyright (C) 2006 Simo Sorce <i...@samba.org>
-   Copyright (C) 2007-2008 Jelmer Vernooij <jel...@samba.org>
+   Copyright (C) 2007-2009 Jelmer Vernooij <jel...@samba.org>
 
         ** NOTE! The following LGPL license applies to the ldb
         ** library. This does NOT imply that all of Samba is released
@@ -65,18 +65,7 @@ static PyObject *PyObject_FromLdbValue(struct ldb_context 
*ldb_ctx,
        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);
@@ -84,6 +73,14 @@ static PyObject *PyObject_FromLdbValue(struct ldb_context 
*ldb_ctx,
        return ret;
 }
 
+/**
+ * Obtain a ldb DN from a Python object.
+ *
+ * @param mem_ctx Memory context
+ * @param object Python object
+ * @param ldb_ctx LDB context
+ * @return Whether or not the conversion succeeded
+ */
 bool PyObject_AsDn(TALLOC_CTX *mem_ctx, PyObject *object, 
                   struct ldb_context *ldb_ctx, struct ldb_dn **dn)
 {
@@ -104,6 +101,12 @@ bool PyObject_AsDn(TALLOC_CTX *mem_ctx, PyObject *object,
        return false;
 }
 
+/**
+ * Create a Python object from a ldb_result.
+ *
+ * @param result LDB result to convert
+ * @return Python object with converted result (a list object)
+ */
 static PyObject *PyLdbResult_FromResult(struct ldb_result *result)
 {
        PyObject *ret;
@@ -119,7 +122,16 @@ static PyObject *PyLdbResult_FromResult(struct ldb_result 
*result)
        return ret;
 }
 
-static struct ldb_result *PyLdbResult_AsResult(TALLOC_CTX *mem_ctx, PyObject 
*obj)
+/**
+ * Create a LDB Result from a Python object. 
+ * If conversion fails, NULL will be returned and a Python exception set.
+ *
+ * @param mem_ctx Memory context in which to allocate the LDB Result
+ * @param obj Python object to convert
+ * @return a ldb_result, or NULL if the conversion failed
+ */
+static struct ldb_result *PyLdbResult_AsResult(TALLOC_CTX *mem_ctx, 
+                                                                               
           PyObject *obj)
 {
        struct ldb_result *res;
        int i;
@@ -451,7 +463,6 @@ static PyObject *py_ldb_get_schema_basedn(PyLdbObject *self)
        return PyLdbDn_FromDn(dn);
 }
 
-
 static PyObject *py_ldb_get_config_basedn(PyLdbObject *self)
 {
        struct ldb_dn *dn = ldb_get_config_basedn(PyLdb_AsLdbContext(self));
@@ -460,7 +471,6 @@ static PyObject *py_ldb_get_config_basedn(PyLdbObject *self)
        return PyLdbDn_FromDn(dn);
 }
 
-
 static PyObject *py_ldb_get_default_basedn(PyLdbObject *self)
 {
        struct ldb_dn *dn = ldb_get_default_basedn(PyLdb_AsLdbContext(self));
@@ -652,8 +662,6 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject 
*args)
        Py_RETURN_NONE;
 }
 
-
-
 static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args)
 {
        PyObject *py_dn;
@@ -1257,6 +1265,21 @@ PyTypeObject PyLdbModule = {
        .tp_flags = Py_TPFLAGS_DEFAULT,
 };
 
+
+/**
+ * Create a ldb_message_element from a Python object.
+ *
+ * This will accept any sequence objects that contains strings, or 
+ * a string object.
+ *
+ * A reference to set_obj will be borrowed. 
+ *
+ * @param mem_ctx Memory context
+ * @param set_obj Python object to convert
+ * @param flags ldb_message_element flags to set
+ * @param attr_name Name of the attribute
+ * @return New ldb_message_element, allocated as child of mem_ctx
+ */
 struct ldb_message_element *PyObject_AsMessageElement(TALLOC_CTX *mem_ctx,
                                                                                
           PyObject *set_obj, int flags,
                                                                                
           const char *attr_name)
@@ -1274,9 +1297,7 @@ struct ldb_message_element 
*PyObject_AsMessageElement(TALLOC_CTX *mem_ctx,
                me->num_values = 1;
                me->values = talloc_array(me, struct ldb_val, me->num_values);
                me->values[0].length = PyString_Size(set_obj);
-               me->values[0].data = (uint8_t *)talloc_strndup(me->values,
-                                       PyString_AsString(set_obj),
-                                       me->values[0].length);
+               me->values[0].data = (uint8_t *)PyString_AsString(set_obj);
        } else if (PySequence_Check(set_obj)) {
                int i;
                me->num_values = PySequence_Size(set_obj);
diff --git a/source4/lib/ldb/tests/python/api.py 
b/source4/lib/ldb/tests/python/api.py
index c372b8f..07500e2 100755
--- a/source4/lib/ldb/tests/python/api.py
+++ b/source4/lib/ldb/tests/python/api.py
@@ -258,6 +258,19 @@ class SimpleLdb(unittest.TestCase):
         l = ldb.Ldb(filename())
         l.set_debug(my_report_fn)
 
+    def test_zero_byte_string(self):
+        """Testing we do not get trapped in the \0 byte in a property 
string."""
+        l = ldb.Ldb(filename())
+        l.add({
+            "dn" : "dc=somedn",
+            "objectclass" : "user",
+            "cN" : "LDAPtestUSER",
+            "givenname" : "ldap",
+            "displayname" : "foo\0bar",
+        })
+        res = l.search(expression="(dn=dc=somedn)")
+        self.assertEquals("foo\0bar", res[0]["displayname"][0])
+
 
 class DnTests(unittest.TestCase):
     def setUp(self):


-- 
Samba Shared Repository

Reply via email to