dsdb-linked_attributes: Do not crash if the target GUID can not be found
[obnox/samba/samba-obnox.git] / source4 / dsdb / samdb / ldb_modules / linked_attributes.c
index d54060b29323c18f355b7705b991a29fc93b6a75..eb57f91e6d84a24f0f4428b3b93e507839681d33 100644 (file)
@@ -3,6 +3,8 @@
 
    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2007
    Copyright (C) Simo Sorce <idra@samba.org> 2008
+   Copyright (C) Matthieu Patou <mat@matws.net> 2011
+   Copyright (C) Andrew Tridgell 2009
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -45,7 +47,6 @@ struct la_op_store {
        enum la_op {LA_OP_ADD, LA_OP_DEL} op;
        struct GUID guid;
        char *name;
-       char *value;
 };
 
 struct replace_context {
@@ -59,14 +60,64 @@ struct la_context {
        const struct dsdb_schema *schema;
        struct ldb_module *module;
        struct ldb_request *req;
-       struct ldb_dn *add_dn;
-       struct ldb_dn *del_dn;
+       struct ldb_dn *mod_dn;
        struct replace_context *rc;
        struct la_op_store *ops;
        struct ldb_extended *op_response;
        struct ldb_control **op_controls;
+       /*
+        * For futur use
+        * will tell which GC to use for resolving links
+        */
+       char *gc_dns_name;
 };
 
+
+static int handle_verify_name_control(TALLOC_CTX *ctx, struct ldb_context *ldb,
+                                       struct ldb_control *control, struct la_context *ac)
+{
+       /*
+        * If we are a GC let's remove the control,
+        * if there is a specified GC check that is us.
+        */
+       struct ldb_verify_name_control *lvnc = (struct ldb_verify_name_control *)control->data;
+       if (samdb_is_gc(ldb)) {
+               /* Because we can't easily talloc a struct ldb_dn*/
+               struct ldb_dn **dn = talloc_array(ctx, struct ldb_dn *, 1);
+               int ret = samdb_server_reference_dn(ldb, ctx, dn);
+               const char *dns;
+
+               if (ret != LDB_SUCCESS) {
+                       return ldb_operr(ldb);
+               }
+
+               dns = samdb_dn_to_dnshostname(ldb, ctx, *dn);
+               if (!dns) {
+                       return ldb_operr(ldb);
+               }
+               if (!lvnc->gc || strcasecmp(dns, lvnc->gc) == 0) {
+                       if (!ldb_save_controls(control, ctx, NULL)) {
+                               return ldb_operr(ldb);
+                       }
+               } else {
+                       control->critical = true;
+               }
+               talloc_free(dn);
+       } else {
+               /* For the moment we don't remove the control is this case in order
+                * to fail the request. It's better than having the client thinking
+                * that we honnor its control.
+                * Hopefully only a very small set of usecase should hit this problem.
+                */
+               if (lvnc->gc) {
+                       ac->gc_dns_name = talloc_strdup(ac, lvnc->gc);
+               }
+               control->critical = true;
+       }
+
+       return LDB_SUCCESS;
+}
+
 static struct la_context *linked_attributes_init(struct ldb_module *module,
                                                 struct ldb_request *req)
 {
@@ -91,7 +142,9 @@ static struct la_context *linked_attributes_init(struct ldb_module *module,
 /*
   turn a DN into a GUID
  */
-static int la_guid_from_dn(struct la_context *ac, struct ldb_dn *dn, struct GUID *guid)
+static int la_guid_from_dn(struct ldb_module *module,
+                          struct ldb_request *parent,
+                          struct ldb_dn *dn, struct GUID *guid)
 {
        NTSTATUS status;
        int ret;
@@ -103,10 +156,10 @@ static int la_guid_from_dn(struct la_context *ac, struct ldb_dn *dn, struct GUID
        if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
                DEBUG(4,(__location__ ": Unable to parse GUID for dn %s\n",
                         ldb_dn_get_linearized(dn)));
-               return ldb_operr(ldb_module_get_ctx(ac->module));
+               return ldb_operr(ldb_module_get_ctx(module));
        }
 
-       ret = dsdb_find_guid_by_dn(ldb_module_get_ctx(ac->module), dn, guid);
+       ret = dsdb_module_guid_by_dn(module, dn, guid, parent);
        if (ret != LDB_SUCCESS) {
                DEBUG(4,(__location__ ": Failed to find GUID for dn %s\n",
                         ldb_dn_get_linearized(dn)));
@@ -143,7 +196,7 @@ static int la_store_op(struct la_context *ac,
 
        os->op = op;
 
-       ret = la_guid_from_dn(ac, op_dn, &os->guid);
+       ret = la_guid_from_dn(ac->module, ac->req, op_dn, &os->guid);
        talloc_free(op_dn);
        if (ret == LDB_ERR_NO_SUCH_OBJECT && ac->req->operation == LDB_DELETE) {
                /* we are deleting an object, and we've found it has a
@@ -190,6 +243,7 @@ static int linked_attributes_add(struct ldb_module *module, struct ldb_request *
        const char *attr_name;
        struct ldb_control *ctrl;
        unsigned int i, j;
+       struct ldb_control *control;
        int ret;
 
        ldb = ldb_module_get_ctx(module);
@@ -199,23 +253,33 @@ static int linked_attributes_add(struct ldb_module *module, struct ldb_request *
                return ldb_next_request(module, req);
        }
 
+       ac = linked_attributes_init(module, req);
+       if (!ac) {
+               return ldb_operr(ldb);
+       }
+
+       control = ldb_request_get_control(req, LDB_CONTROL_VERIFY_NAME_OID);
+       if (control != NULL && control->data != NULL) {
+               ret = handle_verify_name_control(req, ldb, control, ac);
+               if (ret != LDB_SUCCESS) {
+                       return ldb_operr(ldb);
+               }
+       }
+
        if (!(ctrl = ldb_request_get_control(req, DSDB_CONTROL_APPLY_LINKS))) {
                /* don't do anything special for linked attributes, repl_meta_data has done it */
+               talloc_free(ac);
                return ldb_next_request(module, req);
        }
        ctrl->critical = false;
 
-       ac = linked_attributes_init(module, req);
-       if (!ac) {
-               return ldb_operr(ldb);
-       }
-
        if (!ac->schema) {
                /* without schema, this doesn't make any sense */
                talloc_free(ac);
                return ldb_next_request(module, req);
        }
 
+
        /* Need to ensure we only have forward links being specified */
        for (i=0; i < req->op.add.message->num_elements; i++) {
                const struct ldb_message_element *el = &req->op.add.message->elements[i];
@@ -223,23 +287,23 @@ static int linked_attributes_add(struct ldb_module *module, struct ldb_request *
                        = dsdb_attribute_by_lDAPDisplayName(ac->schema, el->name);
                if (!schema_attr) {
                        ldb_asprintf_errstring(ldb,
-                                              "attribute %s is not a valid attribute in schema", el->name);
+                                              "%s: attribute %s is not a valid attribute in schema",
+                                              __FUNCTION__,
+                                              el->name);
                        return LDB_ERR_OBJECT_CLASS_VIOLATION;
                }
-               /* We have a valid attribute, now find out if it is a forward link */
-               if ((schema_attr->linkID == 0)) {
+
+               /* this could be a link with no partner, in which case
+                  there is no special work to do */
+               if (schema_attr->linkID == 0) {
                        continue;
                }
 
-               if ((schema_attr->linkID & 1) == 1) {
-                       unsigned int functional_level;
-
-                       functional_level = dsdb_functional_level(ldb);
-                       SMB_ASSERT(functional_level > DS_DOMAIN_FUNCTION_2000);
-               }
+               /* this part of the code should only be handling forward links */
+               SMB_ASSERT((schema_attr->linkID & 1) == 0);
 
                /* Even link IDs are for the originating attribute */
-               target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID + 1);
+               target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID ^ 1);
                if (!target_attr) {
                        /*
                         * windows 2003 has a broken schema where
@@ -317,7 +381,7 @@ static int la_mod_search_callback(struct ldb_request *req, struct ldb_reply *are
                                                LDB_ERR_OPERATIONS_ERROR);
                }
 
-               ac->add_dn = ac->del_dn = talloc_steal(ac, ares->message->dn);
+               ac->mod_dn = talloc_steal(ac, ares->message->dn);
 
                /* We don't populate 'rc' for ADD - it can't be deleting elements anyway */
                for (i = 0; rc && i < rc->num_elements; i++) {
@@ -325,7 +389,8 @@ static int la_mod_search_callback(struct ldb_request *req, struct ldb_reply *are
                        schema_attr = dsdb_attribute_by_lDAPDisplayName(ac->schema, rc->el[i].name);
                        if (!schema_attr) {
                                ldb_asprintf_errstring(ldb,
-                                       "attribute %s is not a valid attribute in schema",
+                                       "%s: attribute %s is not a valid attribute in schema",
+                                       __FUNCTION__,
                                        rc->el[i].name);
                                talloc_free(ares);
                                return ldb_module_done(ac->req, NULL, NULL,
@@ -342,7 +407,7 @@ static int la_mod_search_callback(struct ldb_request *req, struct ldb_reply *are
                                continue;
                        }
 
-                       target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID + 1);
+                       target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID ^ 1);
                        if (!target_attr) {
                                /*
                                 * windows 2003 has a broken schema where
@@ -409,6 +474,7 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
        /* Determine the effect of the modification */
        /* Apply the modify to the linked entry */
 
+       struct ldb_control *control;
        struct ldb_context *ldb;
        unsigned int i, j;
        struct la_context *ac;
@@ -424,17 +490,26 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                return ldb_next_request(module, req);
        }
 
+       ac = linked_attributes_init(module, req);
+       if (!ac) {
+               return ldb_operr(ldb);
+       }
+
+       control = ldb_request_get_control(req, LDB_CONTROL_VERIFY_NAME_OID);
+       if (control != NULL && control->data != NULL) {
+               ret = handle_verify_name_control(req, ldb, control, ac);
+               if (ret != LDB_SUCCESS) {
+                       return ldb_operr(ldb);
+               }
+       }
+
        if (!(ctrl = ldb_request_get_control(req, DSDB_CONTROL_APPLY_LINKS))) {
                /* don't do anything special for linked attributes, repl_meta_data has done it */
+               talloc_free(ac);
                return ldb_next_request(module, req);
        }
        ctrl->critical = false;
 
-       ac = linked_attributes_init(module, req);
-       if (!ac) {
-               return ldb_operr(ldb);
-       }
-
        if (!ac->schema) {
                /* without schema, this doesn't make any sense */
                return ldb_next_request(module, req);
@@ -454,7 +529,9 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                        = dsdb_attribute_by_lDAPDisplayName(ac->schema, el->name);
                if (!schema_attr) {
                        ldb_asprintf_errstring(ldb,
-                                              "attribute %s is not a valid attribute in schema", el->name);
+                                              "%s: attribute %s is not a valid attribute in schema",
+                                              __FUNCTION__,
+                                              el->name);
                        return LDB_ERR_OBJECT_CLASS_VIOLATION;
                }
                /* We have a valid attribute, now find out if it is a forward link
@@ -463,14 +540,11 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                        continue;
                }
 
-               if ((schema_attr->linkID & 1) == 1) {
-                       unsigned int functional_level;
+               /* this part of the code should only be handling forward links */
+               SMB_ASSERT((schema_attr->linkID & 1) == 0);
 
-                       functional_level = dsdb_functional_level(ldb);
-                       SMB_ASSERT(functional_level > DS_DOMAIN_FUNCTION_2000);
-               }
                /* Now find the target attribute */
-               target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID + 1);
+               target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID ^ 1);
                if (!target_attr) {
                        /*
                         * windows 2003 has a broken schema where
@@ -567,9 +641,9 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
 
                /* We need to figure out our own extended DN, to fill in as the backlink target */
                if (ret == LDB_SUCCESS) {
-                       ret = ldb_request_add_control(search_req,
-                                                     LDB_CONTROL_EXTENDED_DN_OID,
-                                                     false, NULL);
+                       ret = dsdb_request_add_controls(search_req,
+                                                       DSDB_SEARCH_SHOW_DELETED |
+                                                       DSDB_SEARCH_SHOW_EXTENDED_DN);
                }
                if (ret == LDB_SUCCESS) {
                        talloc_steal(search_req, attrs);
@@ -587,9 +661,11 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
 }
 
 static int linked_attributes_fix_links(struct ldb_module *module,
+                                      struct GUID self_guid,
                                       struct ldb_dn *old_dn, struct ldb_dn *new_dn,
                                       struct ldb_message_element *el, struct dsdb_schema *schema,
-                                      const struct dsdb_attribute *schema_attr)
+                                      const struct dsdb_attribute *schema_attr,
+                                      struct ldb_request *parent)
 {
        unsigned int i, j;
        TALLOC_CTX *tmp_ctx = talloc_new(module);
@@ -612,6 +688,7 @@ static int linked_attributes_fix_links(struct ldb_module *module,
                struct ldb_result *res;
                struct ldb_message *msg;
                struct ldb_message_element *el2;
+               struct GUID link_guid;
 
                dsdb_dn = dsdb_dn_parse(tmp_ctx, ldb, &el->values[i], schema_attr->syntax->ldap_oid);
                if (dsdb_dn == NULL) {
@@ -619,21 +696,54 @@ static int linked_attributes_fix_links(struct ldb_module *module,
                        return LDB_ERR_INVALID_DN_SYNTAX;
                }
 
-               ret = dsdb_module_search_dn(module, tmp_ctx, &res, dsdb_dn->dn,
-                                           attrs,
-                                           DSDB_FLAG_NEXT_MODULE |
-                                           DSDB_SEARCH_SHOW_RECYCLED |
-                                           DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT |
-                                           DSDB_SEARCH_REVEAL_INTERNALS);
+               ret = la_guid_from_dn(module, parent, dsdb_dn->dn, &link_guid);
+               if (ret != LDB_SUCCESS) {
+                       ldb_asprintf_errstring(ldb, "Linked attribute %s->%s between %s and %s - GUID not found - %s",
+                                              el->name, target->lDAPDisplayName,
+                                              ldb_dn_get_linearized(old_dn),
+                                              ldb_dn_get_linearized(dsdb_dn->dn),
+                                              ldb_errstring(ldb));
+                       talloc_free(tmp_ctx);
+                       return ret;
+               }
+
+               /*
+                * get the existing message from the db for the object with
+                * this GUID, returning attribute being modified. We will then
+                * use this msg as the basis for a modify call
+                */
+               ret = dsdb_module_search(module, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE, attrs,
+                                        DSDB_FLAG_NEXT_MODULE |
+                                        DSDB_SEARCH_SEARCH_ALL_PARTITIONS |
+                                        DSDB_SEARCH_SHOW_RECYCLED |
+                                        DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT |
+                                        DSDB_SEARCH_REVEAL_INTERNALS,
+                                        parent,
+                                        "objectGUID=%s", GUID_string(tmp_ctx, &link_guid));
                if (ret != LDB_SUCCESS) {
-                       ldb_asprintf_errstring(ldb, "Linked attribute %s->%s between %s and %s - remote not found - %s",
+                       ldb_asprintf_errstring(ldb, "Linked attribute %s->%s between %s and %s - target GUID %s not found - %s",
                                               el->name, target->lDAPDisplayName,
                                               ldb_dn_get_linearized(old_dn),
                                               ldb_dn_get_linearized(dsdb_dn->dn),
+                                              GUID_string(tmp_ctx, &link_guid),
                                               ldb_errstring(ldb));
                        talloc_free(tmp_ctx);
                        return ret;
                }
+               if (res->count == 0) {
+                       /* Forward link without backlink object remaining - nothing to do here */
+                       continue;
+               }
+               if (res->count != 1) {
+                       ldb_asprintf_errstring(ldb, "Linked attribute %s->%s between %s and %s - target GUID %s found more than once!",
+                                              el->name, target->lDAPDisplayName,
+                                              ldb_dn_get_linearized(old_dn),
+                                              ldb_dn_get_linearized(dsdb_dn->dn),
+                                              GUID_string(tmp_ctx, &link_guid));
+                       talloc_free(tmp_ctx);
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
+
                msg = res->msgs[0];
 
                if (msg->num_elements == 0) {
@@ -657,14 +767,34 @@ static int linked_attributes_fix_links(struct ldb_module *module,
                /* find our DN in the values */
                for (j=0; j<el2->num_values; j++) {
                        struct dsdb_dn *dsdb_dn2;
+                       struct GUID link_guid2;
+
                        dsdb_dn2 = dsdb_dn_parse(msg, ldb, &el2->values[j], target->syntax->ldap_oid);
                        if (dsdb_dn2 == NULL) {
                                talloc_free(tmp_ctx);
                                return LDB_ERR_INVALID_DN_SYNTAX;
                        }
-                       if (ldb_dn_compare(old_dn, dsdb_dn2->dn) != 0) {
+
+                       ret = la_guid_from_dn(module, parent, dsdb_dn2->dn, &link_guid2);
+                       if (ret != LDB_SUCCESS) {
+                               talloc_free(tmp_ctx);
+                               return ret;
+                       }
+
+                       /*
+                        * By comparing using the GUID we ensure that
+                        * even if somehow the name has got out of
+                        * sync, this rename will fix it.
+                        *
+                        * If somehow we don't have a GUID on the DN
+                        * in the DB, the la_guid_from_dn call will be
+                        * more costly, but still give us a GUID.
+                        * dbcheck will fix this if run.
+                        */
+                       if (!GUID_equal(&self_guid, &link_guid2)) {
                                continue;
                        }
+
                        ret = ldb_dn_update_components(dsdb_dn2->dn, new_dn);
                        if (ret != LDB_SUCCESS) {
                                talloc_free(tmp_ctx);
@@ -681,7 +811,11 @@ static int linked_attributes_fix_links(struct ldb_module *module,
                        return ret;
                }
 
-               ret = dsdb_module_modify(module, msg, DSDB_FLAG_NEXT_MODULE | DSDB_MODIFY_RELAX);
+               /* we may be putting multiple values in an attribute -
+                  disable checking for this attribute */
+               el2->flags |= LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK;
+
+               ret = dsdb_module_modify(module, msg, DSDB_FLAG_NEXT_MODULE, parent);
                if (ret != LDB_SUCCESS) {
                        ldb_asprintf_errstring(ldb, "Linked attribute %s->%s between %s and %s - update failed - %s",
                                               el->name, target->lDAPDisplayName,
@@ -707,6 +841,8 @@ static int linked_attributes_rename(struct ldb_module *module, struct ldb_reques
        struct ldb_context *ldb = ldb_module_get_ctx(module);
        struct dsdb_schema *schema;
        int ret;
+       struct GUID guid;
+
        /*
           - load the current msg
           - find any linked attributes
@@ -716,7 +852,8 @@ static int linked_attributes_rename(struct ldb_module *module, struct ldb_reques
        ret = dsdb_module_search_dn(module, req, &res, req->op.rename.olddn,
                                    NULL,
                                    DSDB_FLAG_NEXT_MODULE |
-                                   DSDB_SEARCH_SHOW_RECYCLED);
+                                   DSDB_SEARCH_SHOW_EXTENDED_DN |
+                                   DSDB_SEARCH_SHOW_RECYCLED, req);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
@@ -728,6 +865,11 @@ static int linked_attributes_rename(struct ldb_module *module, struct ldb_reques
 
        msg = res->msgs[0];
 
+       ret = la_guid_from_dn(module, req, msg->dn, &guid);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
        for (i=0; i<msg->num_elements; i++) {
                struct ldb_message_element *el = &msg->elements[i];
                const struct dsdb_attribute *schema_attr
@@ -735,8 +877,8 @@ static int linked_attributes_rename(struct ldb_module *module, struct ldb_reques
                if (!schema_attr || schema_attr->linkID == 0) {
                        continue;
                }
-               ret = linked_attributes_fix_links(module, msg->dn, req->op.rename.newdn, el,
-                                                 schema, schema_attr);
+               ret = linked_attributes_fix_links(module, guid, msg->dn, req->op.rename.newdn, el,
+                                                 schema, schema_attr, req);
                if (ret != LDB_SUCCESS) {
                        talloc_free(res);
                        return ret;
@@ -857,9 +999,9 @@ static int la_add_callback(struct ldb_request *req, struct ldb_reply *ares)
                LDB_REQ_SET_LOCATION(search_req);
 
                if (ret == LDB_SUCCESS) {
-                       ret = ldb_request_add_control(search_req,
-                                                     LDB_CONTROL_EXTENDED_DN_OID,
-                                                     false, NULL);
+                       ret = dsdb_request_add_controls(search_req,
+                                                       DSDB_SEARCH_SHOW_DELETED |
+                                                       DSDB_SEARCH_SHOW_EXTENDED_DN);
                }
                if (ret != LDB_SUCCESS) {
                        return ldb_module_done(ac->req, NULL, NULL,
@@ -920,7 +1062,7 @@ static int la_down_req(struct la_context *ac)
 static int la_find_dn_target(struct ldb_module *module, struct la_context *ac,
                             struct GUID *guid, struct ldb_dn **dn)
 {
-       return dsdb_find_dn_by_guid(ldb_module_get_ctx(ac->module), ac, guid, dn);
+       return dsdb_module_dn_by_guid(ac->module, ac, guid, dn, ac->req);
 }
 
 /* apply one la_context op change */
@@ -931,6 +1073,11 @@ static int la_do_op_request(struct ldb_module *module, struct la_context *ac, st
        struct ldb_context *ldb;
        int ret;
 
+       if (ac->mod_dn == NULL) {
+               /* we didn't find the DN that we searched for */
+               return LDB_SUCCESS;
+       }
+
        ldb = ldb_module_get_ctx(ac->module);
 
        /* Create the modify request */
@@ -959,11 +1106,14 @@ static int la_do_op_request(struct ldb_module *module, struct la_context *ac, st
                return ldb_oom(ldb);
        }
        ret_el->num_values = 1;
-       if (op->op == LA_OP_ADD) {
-               ret_el->values[0] = data_blob_string_const(ldb_dn_get_extended_linearized(new_msg, ac->add_dn, 1));
-       } else {
-               ret_el->values[0] = data_blob_string_const(ldb_dn_get_extended_linearized(new_msg, ac->del_dn, 1));
-       }
+       ret_el->values[0] = data_blob_string_const(ldb_dn_get_extended_linearized(new_msg, ac->mod_dn, 1));
+
+       /* a backlink should never be single valued. Unfortunately the
+          exchange schema has a attribute
+          msExchBridgeheadedLocalConnectorsDNBL which is single
+          valued and a backlink. We need to cope with that by
+          ignoring the single value flag */
+       ret_el->flags |= LDB_FLAG_INTERNAL_DISABLE_SINGLE_VALUE_CHECK;
 
 #if 0
        ldb_debug(ldb, LDB_DEBUG_WARNING,
@@ -977,9 +1127,9 @@ static int la_do_op_request(struct ldb_module *module, struct la_context *ac, st
                         ldb_ldif_message_string(ldb, op, LDB_CHANGETYPE_MODIFY, new_msg)));
        }
 
-       ret = dsdb_module_modify(module, new_msg, DSDB_FLAG_NEXT_MODULE);
+       ret = dsdb_module_modify(module, new_msg, DSDB_FLAG_NEXT_MODULE, ac->req);
        if (ret != LDB_SUCCESS) {
-               ldb_debug(ldb, LDB_DEBUG_WARNING, "Failed to apply linked attribute change '%s'\n%s\n",
+               ldb_debug(ldb, LDB_DEBUG_WARNING, __location__ ": failed to apply linked attribute change '%s'\n%s\n",
                          ldb_errstring(ldb),
                          ldb_ldif_message_string(ldb, op, LDB_CHANGETYPE_MODIFY, new_msg));
        }
@@ -1077,12 +1227,27 @@ static int linked_attributes_del_transaction(struct ldb_module *module)
        return ldb_next_del_trans(module);
 }
 
+static int linked_attributes_ldb_init(struct ldb_module *module)
+{
+       int ret;
+
+       ret = ldb_mod_register_control(module, LDB_CONTROL_VERIFY_NAME_OID);
+       if (ret != LDB_SUCCESS) {
+               ldb_debug(ldb_module_get_ctx(module), LDB_DEBUG_ERROR,
+                       "verify_name: Unable to register control with rootdse!\n");
+               return ldb_operr(ldb_module_get_ctx(module));
+       }
+
+       return ldb_next_init(module);
+}
+
 
 static const struct ldb_module_ops ldb_linked_attributes_module_ops = {
        .name              = "linked_attributes",
        .add               = linked_attributes_add,
        .modify            = linked_attributes_modify,
        .rename            = linked_attributes_rename,
+       .init_context      = linked_attributes_ldb_init,
        .start_transaction = linked_attributes_start_transaction,
        .prepare_commit    = linked_attributes_prepare_commit,
        .del_transaction   = linked_attributes_del_transaction,