s4-ldb: Added ldb_request_replace_control
authorNadezhda Ivanova <nivanova@samba.org>
Mon, 27 Sep 2010 17:01:09 +0000 (10:01 -0700)
committerAndrew Tridgell <tridge@samba.org>
Mon, 27 Sep 2010 19:00:38 +0000 (19:00 +0000)
It is the same as ldb_request_add_control, except it will replace
an existing control.

Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Mon Sep 27 19:00:38 UTC 2010 on sn-devel-104

source4/dsdb/samdb/ldb_modules/extended_dn_in.c
source4/lib/ldb/common/ldb_controls.c
source4/lib/ldb/include/ldb.h

index c1afbea177089b3b816d74a434b5a2b0d7a97009..400c37faf207d80aeb122ad2aea82c4487809ecf 100644 (file)
@@ -370,7 +370,7 @@ static int extended_dn_in_fix(struct ldb_module *module, struct ldb_request *req
                        struct ldb_search_options_control *control;
                        control = talloc(down_req, struct ldb_search_options_control);
                        control->search_options = 2;
-                       ret = ldb_request_add_control(down_req,
+                       ret = ldb_request_replace_control(down_req,
                                                      LDB_CONTROL_SEARCH_OPTIONS_OID,
                                                      true, control);
                        if (ret != LDB_SUCCESS) {
index 769761dfd4ea001772e041149462b6f492a0ef50..a63357de7fe6dc0de037bc563216eb8ddcf94cc3 100644 (file)
@@ -234,6 +234,28 @@ int ldb_reply_add_control(struct ldb_reply *ares, const char *oid, bool critical
        return LDB_SUCCESS;
 }
 
+/* Add a control to the request, replacing the old one if it is already in the request */
+int ldb_request_replace_control(struct ldb_request *req, const char *oid, bool critical, void *data)
+{
+       unsigned int n;
+       int ret;
+
+       ret = ldb_request_add_control(req, oid, critical, data);
+       if (ret != LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS) {
+               return ret;
+       }
+
+       for (n=0; req->controls[n];n++) {
+               if (strcmp(oid, req->controls[n]->oid) == 0) {
+                       req->controls[n]->critical = critical;
+                       req->controls[n]->data = data;
+                       return LDB_SUCCESS;
+               }
+       }
+
+       return LDB_ERR_OPERATIONS_ERROR;
+}
+
 /* Parse controls from the format used on the command line and in ejs */
 
 struct ldb_control **ldb_parse_control_strings(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char **control_strings)
index 4bc793b9cc241f003ce8d9a6563118c7dfc3c5a8..d29aed491abd76d50a5f4556146934cc03ba7bc8 100644 (file)
@@ -1217,6 +1217,18 @@ int ldb_build_rename_req(struct ldb_request **ret_req,
 */
 int ldb_request_add_control(struct ldb_request *req, const char *oid, bool critical, void *data);
 
+/**
+  replace a ldb_control in a ldb_request
+
+  \param req the request struct where to add the control
+  \param oid the object identifier of the control as string
+  \param critical whether the control should be critical or not
+  \param data a talloc pointer to the control specific data
+
+  \return result code (LDB_SUCCESS on success, or a failure code)
+*/
+int ldb_request_replace_control(struct ldb_request *req, const char *oid, bool critical, void *data);
+
 /**
    check if a control with the specified "oid" exist and return it 
   \param req the request struct where to add the control