[SCM] Samba Shared Repository - branch master updated

Matthias Dieter Wallnöfer mdw at samba.org
Sun Oct 24 12:40:02 MDT 2010


The branch, master has been updated
       via  3218968 s4:dsdb - use LDB results in "add_time_element" and "add_uint64_element"
       via  49dee0e s4:dsdb - use the more safe "samdb_msg_add_(u)int*" calls always where possible
      from  482c022 pidl:Samba4/NDR/Parser: fix NDR64 union alignment

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


- Log -----------------------------------------------------------------
commit 32189689df2bc40473dfeaccff6219f8e0d56b76
Author: Matthias Dieter Wallnöfer <mdw at samba.org>
Date:   Sun Oct 24 19:39:26 2010 +0200

    s4:dsdb - use LDB results in "add_time_element" and "add_uint64_element"
    
    In both the "objectguid" and the "repl_meta_data" DSDB module.
    
    Autobuild-User: Matthias Dieter Wallnöfer <mdw at samba.org>
    Autobuild-Date: Sun Oct 24 18:39:43 UTC 2010 on sn-devel-104

commit 49dee0e453049a2b26aaacf81e61a0f11afccd91
Author: Matthias Dieter Wallnöfer <mdw at samba.org>
Date:   Sun Oct 24 19:30:12 2010 +0200

    s4:dsdb - use the more safe "samdb_msg_add_(u)int*" calls always where possible
    
    This should prevent all possible integer storage problems in future.

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

Summary of changes:
 source4/dsdb/samdb/ldb_modules/objectguid.c     |   42 +++++++++++++---------
 source4/dsdb/samdb/ldb_modules/repl_meta_data.c |   30 +++++++++++-----
 source4/dsdb/samdb/ldb_modules/rootdse.c        |   13 ++++---
 source4/dsdb/samdb/ldb_modules/util.c           |    5 ++-
 source4/libnet/libnet_join.c                    |    5 +--
 5 files changed, 57 insertions(+), 38 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/samdb/ldb_modules/objectguid.c b/source4/dsdb/samdb/ldb_modules/objectguid.c
index bf730d9..d7dc885 100644
--- a/source4/dsdb/samdb/ldb_modules/objectguid.c
+++ b/source4/dsdb/samdb/ldb_modules/objectguid.c
@@ -55,18 +55,20 @@ static int add_time_element(struct ldb_message *msg, const char *attr, time_t t)
 {
 	struct ldb_message_element *el;
 	char *s;
+	int ret;
 
 	if (ldb_msg_find_element(msg, attr) != NULL) {
-		return 0;
+		return LDB_SUCCESS;
 	}
 
 	s = ldb_timestring(msg, t);
 	if (s == NULL) {
-		return -1;
+		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
-	if (ldb_msg_add_string(msg, attr, s) != 0) {
-		return -1;
+	ret = ldb_msg_add_string(msg, attr, s);
+	if (ret != LDB_SUCCESS) {
+		return ret;
 	}
 
 	el = ldb_msg_find_element(msg, attr);
@@ -74,22 +76,25 @@ static int add_time_element(struct ldb_message *msg, const char *attr, time_t t)
 	   is ignored */
 	el->flags = LDB_FLAG_MOD_REPLACE;
 
-	return 0;
+	return LDB_SUCCESS;
 }
 
 /*
   add a uint64_t element to a record
 */
-static int add_uint64_element(struct ldb_message *msg, const char *attr, uint64_t v)
+static int add_uint64_element(struct ldb_context *ldb, struct ldb_message *msg,
+			      const char *attr, uint64_t v)
 {
 	struct ldb_message_element *el;
+	int ret;
 
 	if (ldb_msg_find_element(msg, attr) != NULL) {
-		return 0;
+		return LDB_SUCCESS;
 	}
 
-	if (ldb_msg_add_fmt(msg, attr, "%llu", (unsigned long long)v) != 0) {
-		return -1;
+	ret = samdb_msg_add_uint64(ldb, msg, msg, attr, v);
+	if (ret != LDB_SUCCESS) {
+		return ret;
 	}
 
 	el = ldb_msg_find_element(msg, attr);
@@ -97,7 +102,7 @@ static int add_uint64_element(struct ldb_message *msg, const char *attr, uint64_
 	   is ignored */
 	el->flags = LDB_FLAG_MOD_REPLACE;
 
-	return 0;
+	return LDB_SUCCESS;
 }
 
 struct og_context {
@@ -174,12 +179,12 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
 	guid = GUID_random();
 
 	ret = dsdb_msg_add_guid(msg, &guid, "objectGUID");
-	if (ret) {
+	if (ret != LDB_SUCCESS) {
 		return ret;
 	}
 	
-	if (add_time_element(msg, "whenCreated", t) != 0 ||
-	    add_time_element(msg, "whenChanged", t) != 0) {
+	if (add_time_element(msg, "whenCreated", t) != LDB_SUCCESS ||
+	    add_time_element(msg, "whenChanged", t) != LDB_SUCCESS) {
 		return ldb_operr(ldb);
 	}
 
@@ -188,8 +193,10 @@ static int objectguid_add(struct ldb_module *module, struct ldb_request *req)
 	 * make sure this function is split and a callback is used */
 	ret = ldb_sequence_number(ldb, LDB_SEQ_NEXT, &seq_num);
 	if (ret == LDB_SUCCESS) {
-		if (add_uint64_element(msg, "uSNCreated", seq_num) != 0 ||
-		    add_uint64_element(msg, "uSNChanged", seq_num) != 0) {
+		if (add_uint64_element(ldb, msg, "uSNCreated",
+				       seq_num) != LDB_SUCCESS ||
+		    add_uint64_element(ldb, msg, "uSNChanged",
+				       seq_num) != LDB_SUCCESS) {
 			return ldb_operr(ldb);
 		}
 	}
@@ -241,14 +248,15 @@ static int objectguid_modify(struct ldb_module *module, struct ldb_request *req)
 		return ldb_operr(ldb);
 	}
 
-	if (add_time_element(msg, "whenChanged", t) != 0) {
+	if (add_time_element(msg, "whenChanged", t) != LDB_SUCCESS) {
 		return ldb_operr(ldb);
 	}
 
 	/* Get a sequence number from the backend */
 	ret = ldb_sequence_number(ldb, LDB_SEQ_NEXT, &seq_num);
 	if (ret == LDB_SUCCESS) {
-		if (add_uint64_element(msg, "uSNChanged", seq_num) != 0) {
+		if (add_uint64_element(ldb, msg, "uSNChanged",
+				       seq_num) != LDB_SUCCESS) {
 			return ldb_operr(ldb);
 		}
 	}
diff --git a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c
index 0ee7996..1544c89 100644
--- a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c
+++ b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c
@@ -511,6 +511,7 @@ static int add_time_element(struct ldb_message *msg, const char *attr, time_t t)
 {
 	struct ldb_message_element *el;
 	char *s;
+	int ret;
 
 	if (ldb_msg_find_element(msg, attr) != NULL) {
 		return LDB_SUCCESS;
@@ -521,8 +522,9 @@ static int add_time_element(struct ldb_message *msg, const char *attr, time_t t)
 		return LDB_ERR_OPERATIONS_ERROR;
 	}
 
-	if (ldb_msg_add_string(msg, attr, s) != LDB_SUCCESS) {
-		return LDB_ERR_OPERATIONS_ERROR;
+	ret = ldb_msg_add_string(msg, attr, s);
+	if (ret != LDB_SUCCESS) {
+		return ret;
 	}
 
 	el = ldb_msg_find_element(msg, attr);
@@ -536,16 +538,19 @@ static int add_time_element(struct ldb_message *msg, const char *attr, time_t t)
 /*
   add a uint64_t element to a record
 */
-static int add_uint64_element(struct ldb_message *msg, const char *attr, uint64_t v)
+static int add_uint64_element(struct ldb_context *ldb, struct ldb_message *msg,
+			      const char *attr, uint64_t v)
 {
 	struct ldb_message_element *el;
+	int ret;
 
 	if (ldb_msg_find_element(msg, attr) != NULL) {
 		return LDB_SUCCESS;
 	}
 
-	if (ldb_msg_add_fmt(msg, attr, "%llu", (unsigned long long)v) != LDB_SUCCESS) {
-		return LDB_ERR_OPERATIONS_ERROR;
+	ret = samdb_msg_add_uint64(ldb, msg, msg, attr, v);
+	if (ret != LDB_SUCCESS) {
+		return ret;
 	}
 
 	el = ldb_msg_find_element(msg, attr);
@@ -2227,12 +2232,14 @@ static int replmd_modify(struct ldb_module *module, struct ldb_request *req)
 	/* we only change whenChanged and uSNChanged if the seq_num
 	   has changed */
 	if (ac->seq_num != 0) {
-		if (add_time_element(msg, "whenChanged", t) != LDB_SUCCESS) {
+		ret = add_time_element(msg, "whenChanged", t);
+		if (ret != LDB_SUCCESS) {
 			talloc_free(ac);
 			return ret;
 		}
 
-		if (add_uint64_element(msg, "uSNChanged", ac->seq_num) != LDB_SUCCESS) {
+		ret = add_uint64_element(ldb, msg, "uSNChanged", ac->seq_num);
+		if (ret != LDB_SUCCESS) {
 			talloc_free(ac);
 			return ret;
 		}
@@ -2342,12 +2349,14 @@ static int replmd_rename_callback(struct ldb_request *req, struct ldb_reply *are
 	}
 	talloc_steal(down_req, msg);
 
-	if (add_time_element(msg, "whenChanged", t) != LDB_SUCCESS) {
+	ret = add_time_element(msg, "whenChanged", t);
+	if (ret != LDB_SUCCESS) {
 		talloc_free(ac);
 		return ret;
 	}
 
-	if (add_uint64_element(msg, "uSNChanged", ac->seq_num) != LDB_SUCCESS) {
+	ret = add_uint64_element(ldb, msg, "uSNChanged", ac->seq_num);
+	if (ret != LDB_SUCCESS) {
 		talloc_free(ac);
 		return ret;
 	}
@@ -4063,7 +4072,8 @@ linked_attributes[0]:
 		return ldb_operr(ldb);
 	}
 
-	if (add_uint64_element(msg, "uSNChanged", seq_num) != LDB_SUCCESS) {
+	if (add_uint64_element(ldb, msg, "uSNChanged",
+			       seq_num) != LDB_SUCCESS) {
 		talloc_free(tmp_ctx);
 		return ldb_operr(ldb);
 	}
diff --git a/source4/dsdb/samdb/ldb_modules/rootdse.c b/source4/dsdb/samdb/ldb_modules/rootdse.c
index 5c6090f..b986f77 100644
--- a/source4/dsdb/samdb/ldb_modules/rootdse.c
+++ b/source4/dsdb/samdb/ldb_modules/rootdse.c
@@ -373,23 +373,24 @@ static int rootdse_add_dynamic(struct ldb_module *module, struct ldb_message *ms
 	}
 
 	if (do_attribute(attrs, "domainFunctionality")) {
-		if (ldb_msg_add_fmt(msg, "domainFunctionality",
-				    "%d", dsdb_functional_level(ldb)) != LDB_SUCCESS) {
+		if (samdb_msg_add_int(ldb, msg, msg, "domainFunctionality",
+				      dsdb_functional_level(ldb)) != LDB_SUCCESS) {
 			goto failed;
 		}
 	}
 
 	if (do_attribute(attrs, "forestFunctionality")) {
-		if (ldb_msg_add_fmt(msg, "forestFunctionality",
-				    "%d", dsdb_forest_functional_level(ldb)) != LDB_SUCCESS) {
+		if (samdb_msg_add_int(ldb, msg, msg, "forestFunctionality",
+				      dsdb_forest_functional_level(ldb)) != LDB_SUCCESS) {
 			goto failed;
 		}
 	}
 
 	if (do_attribute(attrs, "domainControllerFunctionality")
 	    && (val = talloc_get_type(ldb_get_opaque(ldb, "domainControllerFunctionality"), int))) {
-		if (ldb_msg_add_fmt(msg, "domainControllerFunctionality",
-				    "%d", *val) != LDB_SUCCESS) {
+		if (samdb_msg_add_int(ldb, msg, msg,
+				      "domainControllerFunctionality",
+				      *val) != LDB_SUCCESS) {
 			goto failed;
 		}
 	}
diff --git a/source4/dsdb/samdb/ldb_modules/util.c b/source4/dsdb/samdb/ldb_modules/util.c
index 57066d9..14fccb9 100644
--- a/source4/dsdb/samdb/ldb_modules/util.c
+++ b/source4/dsdb/samdb/ldb_modules/util.c
@@ -746,7 +746,7 @@ int dsdb_module_save_partition_usn(struct ldb_module *module, struct ldb_dn *dn,
 		return ldb_module_oom(module);
 	}
 
-	ret = ldb_msg_add_fmt(msg, "uSNHighest", "%llu", (unsigned long long)uSN);
+	ret = samdb_msg_add_uint64(ldb, msg, msg, "uSNHighest", uSN);
 	if (ret != LDB_SUCCESS) {
 		talloc_free(msg);
 		return ret;
@@ -755,7 +755,8 @@ int dsdb_module_save_partition_usn(struct ldb_module *module, struct ldb_dn *dn,
 
 	/* urgent_uSN is optional so may not be stored */
 	if (urgent_uSN) {
-		ret = ldb_msg_add_fmt(msg, "uSNUrgent", "%llu", (unsigned long long)urgent_uSN);
+		ret = samdb_msg_add_uint64(ldb, msg, msg, "uSNUrgent",
+					   urgent_uSN);
 		if (ret != LDB_SUCCESS) {
 			talloc_free(msg);
 			return ret;
diff --git a/source4/libnet/libnet_join.c b/source4/libnet/libnet_join.c
index 6c030be..50b5c1f 100644
--- a/source4/libnet/libnet_join.c
+++ b/source4/libnet/libnet_join.c
@@ -332,9 +332,8 @@ static NTSTATUS libnet_JoinADSDomain(struct libnet_context *ctx, struct libnet_J
 	}
 	msg->dn = res->msgs[0]->dn;
 
-	rtn = ldb_msg_add_fmt(msg, "msDS-SupportedEncryptionTypes",
-			      "%lu",
-			      (long unsigned int)(ENC_ALL_TYPES));
+	rtn = samdb_msg_add_uint(remote_ldb, msg, msg,
+				 "msDS-SupportedEncryptionTypes", ENC_ALL_TYPES);
 	if (rtn != LDB_SUCCESS) {
 		r->out.error_string = NULL;
 		talloc_free(tmp_ctx);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list