s4:dsdb - use LDB results in "add_time_element" and "add_uint64_element"
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Sun, 24 Oct 2010 17:39:26 +0000 (19:39 +0200)
committerMatthias Dieter Wallnöfer <mdw@samba.org>
Sun, 24 Oct 2010 18:39:43 +0000 (18:39 +0000)
In both the "objectguid" and the "repl_meta_data" DSDB module.

Autobuild-User: Matthias Dieter Wallnöfer <mdw@samba.org>
Autobuild-Date: Sun Oct 24 18:39:43 UTC 2010 on sn-devel-104

source4/dsdb/samdb/ldb_modules/objectguid.c
source4/dsdb/samdb/ldb_modules/repl_meta_data.c

index cb8f683b4092545036615fc6d517092727958dea..d7dc88500360738fc5aa08446e11f56ada45134e 100644 (file)
@@ -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,7 +76,7 @@ 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;
 }
 
 /*
@@ -84,13 +86,15 @@ 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 (samdb_msg_add_uint64(ldb, msg, msg, attr, v) != LDB_SUCCESS) {
-               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);
@@ -98,7 +102,7 @@ static int add_uint64_element(struct ldb_context *ldb, struct ldb_message *msg,
           is ignored */
        el->flags = LDB_FLAG_MOD_REPLACE;
 
-       return 0;
+       return LDB_SUCCESS;
 }
 
 struct og_context {
@@ -175,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);
        }
 
@@ -189,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(ldb, msg, "uSNCreated", seq_num) != 0 ||
-                   add_uint64_element(ldb, 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);
                }
        }
@@ -242,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(ldb, msg, "uSNChanged", seq_num) != 0) {
+               if (add_uint64_element(ldb, msg, "uSNChanged",
+                                      seq_num) != LDB_SUCCESS) {
                        return ldb_operr(ldb);
                }
        }
index 5188a66efb0bc6dd6f3dfdfb4e99fd870652dc20..1544c89170474db57f22bcfad651d0f4b9d8177e 100644 (file)
@@ -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);
@@ -2230,13 +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(ldb, 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;
                }
@@ -2346,13 +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(ldb, 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;
        }