s4-dsdb: In rootdse add extended dn info on all values for a given attribute
authorMatthieu Patou <mat@matws.net>
Fri, 13 May 2011 09:31:13 +0000 (13:31 +0400)
committerAndrew Tridgell <tridge@samba.org>
Thu, 21 Jul 2011 01:44:33 +0000 (11:44 +1000)
And not only on the fist value as it was the case up to this changeset.

source4/dsdb/samdb/ldb_modules/rootdse.c

index c584a11b2c6e9f389003feaec9f2014e3216ad64..9176b4e02b576b8054f38dd92703d468c35d643b 100644 (file)
@@ -76,6 +76,8 @@ static int expand_dn_in_message(struct ldb_module *module, struct ldb_message *m
        TALLOC_CTX *tmp_ctx = talloc_new(req);
        struct ldb_context *ldb;
        int edn_type = 0;
+       unsigned int i;
+       struct ldb_message_element *el;
 
        ldb = ldb_module_get_ctx(module);
 
@@ -84,76 +86,83 @@ static int expand_dn_in_message(struct ldb_module *module, struct ldb_message *m
                edn_type = edn->type;
        }
 
-       v = discard_const_p(struct ldb_val, ldb_msg_find_ldb_val(msg, attrname));
-       if (v == NULL) {
-               talloc_free(tmp_ctx);
+       el = ldb_msg_find_element(msg, attrname);
+       if (!el || el->num_values == 0) {
                return LDB_SUCCESS;
        }
 
-       dn_string = talloc_strndup(tmp_ctx, (const char *)v->data, v->length);
-       if (dn_string == NULL) {
-               talloc_free(tmp_ctx);
-               return ldb_operr(ldb);
-       }
+       for (i = 0; i < el->num_values; i++) {
+               v = &el->values[i];
+               if (v == NULL) {
+                       talloc_free(tmp_ctx);
+                       return LDB_SUCCESS;
+               }
 
-       res = talloc_zero(tmp_ctx, struct ldb_result);
-       if (res == NULL) {
-               talloc_free(tmp_ctx);
-               return ldb_operr(ldb);
-       }
+               dn_string = talloc_strndup(tmp_ctx, (const char *)v->data, v->length);
+               if (dn_string == NULL) {
+                       talloc_free(tmp_ctx);
+                       return ldb_operr(ldb);
+               }
 
-       dn = ldb_dn_new(tmp_ctx, ldb, dn_string);
-       if (dn == NULL) {
-               talloc_free(tmp_ctx);
-               return ldb_operr(ldb);
-       }
+               res = talloc_zero(tmp_ctx, struct ldb_result);
+               if (res == NULL) {
+                       talloc_free(tmp_ctx);
+                       return ldb_operr(ldb);
+               }
 
-       ret = ldb_build_search_req(&req2, ldb, tmp_ctx,
-                                  dn,
-                                  LDB_SCOPE_BASE,
-                                  NULL,
-                                  no_attrs,
-                                  NULL,
-                                  res, ldb_search_default_callback,
-                                  req);
-       LDB_REQ_SET_LOCATION(req2);
-       if (ret != LDB_SUCCESS) {
-               talloc_free(tmp_ctx);
-               return ret;
-       }
+               dn = ldb_dn_new(tmp_ctx, ldb, dn_string);
+               if (dn == NULL) {
+                       talloc_free(tmp_ctx);
+                       return ldb_operr(ldb);
+               }
+
+               ret = ldb_build_search_req(&req2, ldb, tmp_ctx,
+                                       dn,
+                                       LDB_SCOPE_BASE,
+                                       NULL,
+                                       no_attrs,
+                                       NULL,
+                                       res, ldb_search_default_callback,
+                                       req);
+               LDB_REQ_SET_LOCATION(req2);
+               if (ret != LDB_SUCCESS) {
+                       talloc_free(tmp_ctx);
+                       return ret;
+               }
 
 
-       ret = ldb_request_add_control(req2,
-                                     LDB_CONTROL_EXTENDED_DN_OID,
-                                     edn_control->critical, edn);
-       if (ret != LDB_SUCCESS) {
-               talloc_free(tmp_ctx);
-               return ret;
-       }
+               ret = ldb_request_add_control(req2,
+                                       LDB_CONTROL_EXTENDED_DN_OID,
+                                       edn_control->critical, edn);
+               if (ret != LDB_SUCCESS) {
+                       talloc_free(tmp_ctx);
+                       return ldb_error(ldb, ret, "Failed to add control");
+               }
 
-       ret = ldb_next_request(module, req2);
-       if (ret == LDB_SUCCESS) {
-               ret = ldb_wait(req2->handle, LDB_WAIT_ALL);
-       }
-       if (ret != LDB_SUCCESS) {
-               talloc_free(tmp_ctx);
-               return ret;
-       }
+               ret = ldb_next_request(module, req2);
+               if (ret == LDB_SUCCESS) {
+                       ret = ldb_wait(req2->handle, LDB_WAIT_ALL);
+               }
 
-       if (!res || res->count != 1) {
-               talloc_free(tmp_ctx);
-               return ldb_operr(ldb);
-       }
+               if (ret != LDB_SUCCESS) {
+                       talloc_free(tmp_ctx);
+                       return ret;
+               }
 
-       dn2 = res->msgs[0]->dn;
+               if (!res || res->count != 1) {
+                       talloc_free(tmp_ctx);
+                       return ldb_operr(ldb);
+               }
 
-       v->data = (uint8_t *)ldb_dn_get_extended_linearized(msg->elements, dn2, edn_type);
-       if (v->data == NULL) {
-               talloc_free(tmp_ctx);
-               return ldb_operr(ldb);
-       }
-       v->length = strlen((char *)v->data);
+               dn2 = res->msgs[0]->dn;
 
+               v->data = (uint8_t *)ldb_dn_get_extended_linearized(msg->elements, dn2, edn_type);
+               if (v->data == NULL) {
+                       talloc_free(tmp_ctx);
+                       return ldb_operr(ldb);
+               }
+               v->length = strlen((char *)v->data);
+       }
 
        talloc_free(tmp_ctx);