s4:dsdb - use the more safe "samdb_msg_add_(u)int*" calls always where possible
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Sun, 24 Oct 2010 17:30:12 +0000 (19:30 +0200)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Sun, 24 Oct 2010 17:57:06 +0000 (17:57 +0000)
This should prevent all possible integer storage problems in future.

source4/dsdb/samdb/ldb_modules/objectguid.c
source4/dsdb/samdb/ldb_modules/repl_meta_data.c
source4/dsdb/samdb/ldb_modules/rootdse.c
source4/dsdb/samdb/ldb_modules/util.c
source4/libnet/libnet_join.c

index bf730d9da324286bf3c051f60cb275af865a3153..cb8f683b4092545036615fc6d517092727958dea 100644 (file)
@@ -80,7 +80,8 @@ 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;
 
@@ -88,7 +89,7 @@ static int add_uint64_element(struct ldb_message *msg, const char *attr, uint64_
                return 0;
        }
 
-       if (ldb_msg_add_fmt(msg, attr, "%llu", (unsigned long long)v) != 0) {
+       if (samdb_msg_add_uint64(ldb, msg, msg, attr, v) != LDB_SUCCESS) {
                return -1;
        }
 
@@ -188,8 +189,8 @@ 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) != 0 ||
+                   add_uint64_element(ldb, msg, "uSNChanged", seq_num) != 0) {
                        return ldb_operr(ldb);
                }
        }
@@ -248,7 +249,7 @@ static int objectguid_modify(struct ldb_module *module, struct ldb_request *req)
        /* 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) != 0) {
                        return ldb_operr(ldb);
                }
        }
index 0ee7996a9958428d0365e519399cbe195e478cf0..5188a66efb0bc6dd6f3dfdfb4e99fd870652dc20 100644 (file)
@@ -536,16 +536,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);
@@ -2232,7 +2235,8 @@ static int replmd_modify(struct ldb_module *module, struct ldb_request *req)
                        return ret;
                }
 
-               if (add_uint64_element(msg, "uSNChanged", ac->seq_num) != LDB_SUCCESS) {
+               if (add_uint64_element(ldb, msg, "uSNChanged",
+                                      ac->seq_num) != LDB_SUCCESS) {
                        talloc_free(ac);
                        return ret;
                }
@@ -2347,7 +2351,8 @@ static int replmd_rename_callback(struct ldb_request *req, struct ldb_reply *are
                return ret;
        }
 
-       if (add_uint64_element(msg, "uSNChanged", ac->seq_num) != LDB_SUCCESS) {
+       if (add_uint64_element(ldb, msg, "uSNChanged",
+                              ac->seq_num) != LDB_SUCCESS) {
                talloc_free(ac);
                return ret;
        }
@@ -4063,7 +4068,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);
        }
index 5c6090fc68f483663540a05982c7e173f47c0546..b986f778714fad12d3211898a89c5311690370c3 100644 (file)
@@ -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;
                }
        }
index 57066d9c88d655bcbc7ce534d2e1064705b651c9..14fccb9658121d3d1c15bf13f8bdf4eb4b3a2651 100644 (file)
@@ -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;
index 6c030be72834dd7b5b59daf144599920204d2085..50b5c1f473057d4ed8c2a243f507be96d251a539 100644 (file)
@@ -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);