s4:ldb Add function to add controls to an LDB reply
authorAndrew Bartlett <abartlet@samba.org>
Wed, 14 Oct 2009 23:45:44 +0000 (10:45 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 21 Oct 2009 11:43:53 +0000 (22:43 +1100)
source4/lib/ldb/common/ldb_controls.c
source4/lib/ldb/include/ldb_module.h

index a8dd6b585984a0b3c3fcfb9e9eebafad37229bf6..0ecb1eb62cfed8b7f0dda79922a33de2cfccf927 100644 (file)
@@ -160,6 +160,40 @@ int ldb_request_add_control(struct ldb_request *req, const char *oid, bool criti
        return LDB_SUCCESS;
 }
 
+int ldb_reply_add_control(struct ldb_reply *ares, const char *oid, bool critical, void *data)
+{
+       unsigned n;
+       struct ldb_control **ctrls;
+       struct ldb_control *ctrl;
+
+       for (n=0; ares->controls && ares->controls[n];) { 
+               /* having two controls of the same OID makes no sense */
+               if (strcmp(oid, ares->controls[n]->oid) == 0) {
+                       return LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
+               }
+               n++; 
+       }
+
+       ctrls = talloc_realloc(ares, ares->controls,
+                              struct ldb_control *,
+                              n + 2);
+       if (!ctrls) return LDB_ERR_OPERATIONS_ERROR;
+       ares->controls = ctrls;
+       ctrls[n] = NULL;
+       ctrls[n+1] = NULL;
+
+       ctrl = talloc(ctrls, struct ldb_control);
+       if (!ctrl) return LDB_ERR_OPERATIONS_ERROR;
+
+       ctrl->oid       = talloc_strdup(ctrl, oid);
+       if (!ctrl->oid) return LDB_ERR_OPERATIONS_ERROR;
+       ctrl->critical  = critical;
+       ctrl->data      = data;
+
+       ctrls[n] = ctrl;
+       return LDB_SUCCESS;
+}
+
 /* Parse controls from the format used on the command line and in ejs */
 
 struct ldb_control **ldb_parse_control_strings(struct ldb_context *ldb, void *mem_ctx, const char **control_strings)
index ae8c4d50df5740b67db1a7ea9f357edca1676da4..7a125ba211e8a95d92cc99f5de0b162c8c6fae3e 100644 (file)
@@ -170,5 +170,16 @@ int ldb_module_done(struct ldb_request *req,
 int ldb_mod_register_control(struct ldb_module *module, const char *oid);
 
 void ldb_set_default_dns(struct ldb_context *ldb);
+/**
+  Add a ldb_control to a ldb_reply
+
+  \param ares the reply 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_reply_add_control(struct ldb_reply *ares, const char *oid, bool critical, void *data);
 
 #endif