Ensure to normalise distinguishedName too
authorAndrew Bartlett <abartlet@samba.org>
Fri, 12 Dec 2008 06:43:54 +0000 (17:43 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 12 Dec 2008 06:46:11 +0000 (17:46 +1100)
source4/dsdb/samdb/ldb_modules/extended_dn_out.c

index ce1a9028135ebc002691169c0f16749ccc854724..058c51bdb88834814d58fe20d86a02d1d0e1b8fe 100644 (file)
@@ -139,7 +139,6 @@ static int inject_extended_dn_out(struct ldb_reply *ares,
                                  bool remove_sid)
 {
        int ret;
-       const struct ldb_val *val;
        const DATA_BLOB *guid_blob;
        const DATA_BLOB *sid_blob;
 
@@ -170,16 +169,6 @@ static int inject_extended_dn_out(struct ldb_reply *ares,
                ldb_msg_remove_attr(ares->message, "objectSID");
        }
 
-       val = ldb_msg_find_ldb_val(ares->message, "distinguishedName");
-       if (val) {
-               ldb_msg_remove_attr(ares->message, "distinguishedName");
-               ret = ldb_msg_add_steal_string(ares->message, "distinguishedName", 
-                                              ldb_dn_get_extended_linearized(ares->message, ares->message->dn, type));
-               if (ret != LDB_SUCCESS) {
-                       ldb_oom(ldb);
-                       return LDB_ERR_OPERATIONS_ERROR;
-               }
-       }
        return LDB_SUCCESS;
 }
 
@@ -282,6 +271,13 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares)
                break;
        }
 
+       if (private && private->normalise) {
+               ret = fix_dn(ares->message->dn);
+               if (ret != LDB_SUCCESS) {
+                       return ldb_module_done(ac->req, NULL, NULL, ret);
+               }
+       }
+                       
        if (ac->inject) {
                /* for each record returned post-process to add any derived
                   attributes that have been asked for */
@@ -293,6 +289,24 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares)
                }
        }
 
+       if ((private && private->normalise) || ac->inject) {
+               const struct ldb_val *val = ldb_msg_find_ldb_val(ares->message, "distinguishedName");
+               if (val) {
+                       ldb_msg_remove_attr(ares->message, "distinguishedName");
+                       if (ac->inject) {
+                               ret = ldb_msg_add_steal_string(ares->message, "distinguishedName", 
+                                                              ldb_dn_get_extended_linearized(ares->message, ares->message->dn, ac->extended_type));
+                       } else {
+                               ret = ldb_msg_add_string(ares->message, "distinguishedName", 
+                                                        ldb_dn_get_linearized(ares->message->dn));
+                       }
+                       if (ret != LDB_SUCCESS) {
+                               ldb_oom(ac->module->ldb);
+                               return LDB_ERR_OPERATIONS_ERROR;
+                       }
+               }
+       }
+
        if (private && private->dereference) {
                control = ldb_reply_get_control(ares, DSDB_OPENLDAP_DEREFERENCE_CONTROL);
        
@@ -304,10 +318,6 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares)
        /* Walk the retruned elements (but only if we have a schema to interpret the list with) */
        for (i = 0; ac->schema && i < msg->num_elements; i++) {
                const struct dsdb_attribute *attribute;
-               /* distinguishedName has been dealt with above */
-               if (ldb_attr_cmp(msg->elements[i].name, "distinguishedName") == 0) {
-                       continue;
-               }
                attribute = dsdb_attribute_by_lDAPDisplayName(ac->schema, msg->elements[i].name);
                if (!attribute) {
                        continue;
@@ -324,6 +334,11 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares)
                        }
                }
 
+               /* distinguishedName has been dealt with above */
+               if (ldb_attr_cmp(msg->elements[i].name, "distinguishedName") == 0) {
+                       continue;
+               }
+
                /* Look to see if this attributeSyntax is a DN */
                if (strcmp(attribute->attributeSyntax_oid, "2.5.5.1") != 0) {
                        continue;