[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha8-1154-gbe9441a

Andrew Bartlett abartlet at samba.org
Mon Aug 24 04:24:36 MDT 2009


The branch, master has been updated
       via  be9441ac3fa167f97f54700e52dec9995b170fa3 (commit)
       via  7234a24f821743c60075d1e2868fba7b0f2a8f8b (commit)
       via  b4e8d927cd91b2fc1221d9834715153c7487b715 (commit)
       via  bf54b419ae4f2f87afba1ba1e83c97b05b18c9b0 (commit)
       via  cc330f93625290dc5f67c9c0f2f17e566ddbf1f1 (commit)
      from  0f98d539e2edc8f1d57271fb20051189699222a7 (commit)

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


- Log -----------------------------------------------------------------
commit be9441ac3fa167f97f54700e52dec9995b170fa3
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Aug 24 20:22:18 2009 +1000

    s4:dsdb Use talloc_strndup() to ensure OIDs are null terminated
    
    The OIDs are not NULL terminated by the python caller, in line with
    the LDB API, but we need them to be here, as we were casting them to a
    string.
    
    Andrew Bartlett

commit 7234a24f821743c60075d1e2868fba7b0f2a8f8b
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Aug 24 20:11:43 2009 +1000

    s4:ldb Add python binding and test for ldb_msg_diff()

commit b4e8d927cd91b2fc1221d9834715153c7487b715
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Aug 24 13:15:31 2009 +1000

    s4:dsdb Add const

commit bf54b419ae4f2f87afba1ba1e83c97b05b18c9b0
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Aug 24 13:15:17 2009 +1000

    s4:dsdb remove unused variable

commit cc330f93625290dc5f67c9c0f2f17e566ddbf1f1
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon Aug 24 13:09:10 2009 +1000

    s4:dsdb use talloc_strndup() in GET_STRING_LDB() rather than walk off the end
    
    The problem is that samdb_result_string() and
    ldb_msg_find_attr_as_string() both simply cast the string, rather than
    ensuring the return value is NULL terminated.  This may be best
    regarded as a flaw in LDB, but fixing it there is going to be more
    difficult.
    
    Andrew Bartlett

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

Summary of changes:
 source4/dsdb/samdb/ldb_modules/schema_fsmo.c |   20 +++++++++-------
 source4/dsdb/schema/schema_init.c            |   24 +++++++++++++-----
 source4/dsdb/schema/schema_query.c           |    4 +-
 source4/lib/ldb/pyldb.c                      |   32 ++++++++++++++++++++++++++
 source4/lib/ldb/tests/python/api.py          |   11 +++++++++
 5 files changed, 73 insertions(+), 18 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/samdb/ldb_modules/schema_fsmo.c b/source4/dsdb/samdb/ldb_modules/schema_fsmo.c
index 290232b..c482ab5 100644
--- a/source4/dsdb/samdb/ldb_modules/schema_fsmo.c
+++ b/source4/dsdb/samdb/ldb_modules/schema_fsmo.c
@@ -172,8 +172,8 @@ static int schema_fsmo_add(struct ldb_module *module, struct ldb_request *req)
 {
 	struct ldb_context *ldb;
 	struct dsdb_schema *schema;
-	const char *attributeID = NULL;
-	const char *governsID = NULL;
+	const struct ldb_val *attributeID = NULL;
+	const struct ldb_val *governsID = NULL;
 	const char *oid_attr = NULL;
 	const char *oid = NULL;
 	uint32_t id32;
@@ -202,21 +202,24 @@ static int schema_fsmo_add(struct ldb_module *module, struct ldb_request *req)
 		return LDB_ERR_UNWILLING_TO_PERFORM;
 	}
 
-	attributeID = samdb_result_string(req->op.add.message, "attributeID", NULL);
-	governsID = samdb_result_string(req->op.add.message, "governsID", NULL);
+	attributeID = ldb_msg_find_ldb_val(req->op.add.message, "attributeID");
+	governsID = ldb_msg_find_ldb_val(req->op.add.message, "governsID");
 
 	if (attributeID) {
 		oid_attr = "attributeID";
-		oid = attributeID;
+		oid = talloc_strndup(req, (const char *)attributeID->data, attributeID->length);
 	} else if (governsID) {
 		oid_attr = "governsID";
-		oid = governsID;
+		oid = talloc_strndup(req, (const char *)governsID->data, governsID->length);
+	} else {
+		return ldb_next_request(module, req);
 	}
 
 	if (!oid) {
-		return ldb_next_request(module, req);
+		ldb_oom(ldb);
+		return LDB_ERR_OPERATIONS_ERROR;
 	}
-
+		
 	status = dsdb_map_oid2int(schema, oid, &id32);
 	if (W_ERROR_IS_OK(status)) {
 		return ldb_next_request(module, req);
@@ -408,7 +411,6 @@ static int generate_possibleInferiors(struct ldb_context *ldb, struct ldb_messag
 	int ret, i;
 	const char *first_component_name = ldb_dn_get_component_name(dn, 0);
 	const struct ldb_val *first_component_val;
-	const char *class_name;
 	const struct dsdb_class *schema_class;
 	const char **possibleInferiors;
 
diff --git a/source4/dsdb/schema/schema_init.c b/source4/dsdb/schema/schema_init.c
index 170d5a1..c2d4597 100644
--- a/source4/dsdb/schema/schema_init.c
+++ b/source4/dsdb/schema/schema_init.c
@@ -653,14 +653,24 @@ static int dsdb_schema_setup_ldb_schema_attribute(struct ldb_context *ldb,
 }
 
 
-
 #define GET_STRING_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
-	(p)->elem = samdb_result_string(msg, attr, NULL);\
-	if (strict && (p)->elem == NULL) { \
-		d_printf("%s: %s == NULL\n", __location__, attr); \
-		return WERR_INVALID_PARAM; \
-	} \
-	talloc_steal(mem_ctx, (p)->elem); \
+	struct ldb_val *get_string_val = ldb_msg_find_ldb_val(msg, attr); \
+	if (get_string_val == NULL) { \
+		if (strict) {					  \
+			d_printf("%s: %s == NULL\n", __location__, attr); \
+			return WERR_INVALID_PARAM;			\
+		} else {						\
+			(p)->elem = NULL;				\
+		}							\
+	} else {							\
+		(p)->elem = talloc_strndup(mem_ctx,			\
+					   (const char *)get_string_val->data, \
+					   get_string_val->length); \
+		if (!(p)->elem) {					\
+			d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
+			return WERR_NOMEM;				\
+		}							\
+	}								\
 } while (0)
 
 #define GET_STRING_LIST_LDB(msg, attr, mem_ctx, p, elem, strict) do {	\
diff --git a/source4/dsdb/schema/schema_query.c b/source4/dsdb/schema/schema_query.c
index 0e5efa9..7d696e8 100644
--- a/source4/dsdb/schema/schema_query.c
+++ b/source4/dsdb/schema/schema_query.c
@@ -157,7 +157,7 @@ const struct dsdb_class *dsdb_class_by_lDAPDisplayName(const struct dsdb_schema
 }
 
 const struct dsdb_class *dsdb_class_by_lDAPDisplayName_ldb_val(const struct dsdb_schema *schema,
-							       struct ldb_val *name)
+							       const struct ldb_val *name)
 {
 	struct dsdb_class *c;
 	if (!name) return NULL;
@@ -177,7 +177,7 @@ const struct dsdb_class *dsdb_class_by_cn(const struct dsdb_schema *schema,
 }
 
 const struct dsdb_class *dsdb_class_by_cn_ldb_val(const struct dsdb_schema *schema,
-						  struct ldb_val *cn)
+						  const struct ldb_val *cn)
 {
 	struct dsdb_class *c;
 	if (!cn) return NULL;
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index d55e0aa..67e1d5c 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -845,6 +845,35 @@ static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args)
 	return PyObject_GetIter(list);
 }
 
+static PyObject *py_ldb_msg_diff(PyLdbObject *self, PyObject *args)
+{
+	PyObject *py_msg_old;
+	PyObject *py_msg_new;
+	struct ldb_message *diff;
+	PyObject *py_ret;
+
+	if (!PyArg_ParseTuple(args, "OO", &py_msg_old, &py_msg_new))
+		return NULL;
+
+	if (!PyLdbMessage_Check(py_msg_old)) {
+		PyErr_SetString(PyExc_TypeError, "Expected Ldb Message for old message");
+		return NULL;
+	}
+
+	if (!PyLdbMessage_Check(py_msg_new)) {
+		PyErr_SetString(PyExc_TypeError, "Expected Ldb Message for new message");
+		return NULL;
+	}
+
+	diff = ldb_msg_diff(PyLdb_AsLdbContext(self), PyLdbMessage_AsMessage(py_msg_old), PyLdbMessage_AsMessage(py_msg_new));
+	if (diff == NULL) 
+		return NULL;
+
+	py_ret = PyLdbMessage_FromMessage(diff);
+
+	return py_ret;
+}
+
 static PyObject *py_ldb_schema_format_value(PyLdbObject *self, PyObject *args)
 {
 	const struct ldb_schema_attribute *a;
@@ -1087,6 +1116,9 @@ static PyMethodDef py_ldb_methods[] = {
 	{ "parse_ldif", (PyCFunction)py_ldb_parse_ldif, METH_VARARGS,
 		"S.parse_ldif(ldif) -> iter(messages)\n"
 		"Parse a string formatted using LDIF." },
+	{ "msg_diff", (PyCFunction)py_ldb_msg_diff, METH_VARARGS,
+		"S.msg_diff(Message) -> Message\n"
+		"Return an LDB Message of the difference between two Message objects." },
 	{ "get_opaque", (PyCFunction)py_ldb_get_opaque, METH_VARARGS,
 		"S.get_opaque(name) -> value\n"
 		"Get an opaque value set on this LDB connection. \n"
diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py
index 110b1ca..d946bf0 100755
--- a/source4/lib/ldb/tests/python/api.py
+++ b/source4/lib/ldb/tests/python/api.py
@@ -451,6 +451,17 @@ class LdbMsgTests(unittest.TestCase):
     def test_get_unknown(self):
         self.assertEquals(None, self.msg.get("lalalala"))
 
+    def test_msg_diff(self):
+        l = ldb.Ldb()
+        msgs = l.parse_ldif("dn: foo=bar\nfoo: bar\nbaz: do\n\ndn: foo=bar\nfoo: bar\nbaz: dont\n")
+        msg1 = msgs.next()[1]
+        msg2 = msgs.next()[1]
+        msgdiff = l.msg_diff(msg1, msg2)
+        self.assertEquals("foo=bar", msgdiff.get("dn").__str__())
+        self.assertRaises(KeyError, lambda: msgdiff["foo"])
+        self.assertEquals(1, len(msgdiff))
+
+
 
 class MessageElementTests(unittest.TestCase):
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list