s4-dsdb: pass parent request to dsdb_module_*() functions
[samba.git] / source4 / dsdb / samdb / ldb_modules / linked_attributes.c
index d2a435ef507d490d7776b6a8832a39b9a615dcf3..324faa2c2a91cd5421c11ca3d02129e2aa20f4d7 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    ldb database library
 
    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2007
@@ -8,12 +8,12 @@
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -93,8 +93,8 @@ static struct la_context *linked_attributes_init(struct ldb_module *module,
  */
 static int la_guid_from_dn(struct la_context *ac, struct ldb_dn *dn, struct GUID *guid)
 {
-       int ret;
        NTSTATUS status;
+       int ret;
 
        status = dsdb_get_extended_dn_guid(dn, guid, "GUID");
        if (NT_STATUS_IS_OK(status)) {
@@ -103,7 +103,7 @@ 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_ERR_OPERATIONS_ERROR;
+               return ldb_operr(ldb_module_get_ctx(ac->module));
        }
 
        ret = dsdb_find_guid_by_dn(ldb_module_get_ctx(ac->module), dn, guid);
@@ -131,15 +131,14 @@ static int la_store_op(struct la_context *ac,
 
        op_dn = ldb_dn_from_ldb_val(ac, ldb, dn);
        if (!op_dn) {
-               ldb_asprintf_errstring(ldb, 
+               ldb_asprintf_errstring(ldb,
                                       "could not parse attribute as a DN");
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
 
        os = talloc_zero(ac, struct la_op_store);
        if (!os) {
-               ldb_oom(ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb);
        }
 
        os->op = op;
@@ -162,8 +161,7 @@ static int la_store_op(struct la_context *ac,
 
        os->name = talloc_strdup(os, name);
        if (!os->name) {
-               ldb_oom(ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb);
        }
 
        /* Do deletes before adds */
@@ -191,8 +189,8 @@ static int linked_attributes_add(struct ldb_module *module, struct ldb_request *
        struct la_context *ac;
        const char *attr_name;
        struct ldb_control *ctrl;
+       unsigned int i, j;
        int ret;
-       int i, j;
 
        ldb = ldb_module_get_ctx(module);
 
@@ -209,7 +207,7 @@ static int linked_attributes_add(struct ldb_module *module, struct ldb_request *
 
        ac = linked_attributes_init(module, req);
        if (!ac) {
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_operr(ldb);
        }
 
        if (!ac->schema) {
@@ -224,9 +222,11 @@ static int linked_attributes_add(struct ldb_module *module, struct ldb_request *
                const struct dsdb_attribute *schema_attr
                        = 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);
-                       return LDB_ERR_OBJECT_CLASS_VIOLATION;                  
+                       ldb_asprintf_errstring(ldb,
+                                              "%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)) {
@@ -235,11 +235,11 @@ static int linked_attributes_add(struct ldb_module *module, struct ldb_request *
 
                if ((schema_attr->linkID & 1) == 1) {
                        unsigned int functional_level;
-                       
+
                        functional_level = dsdb_functional_level(ldb);
                        SMB_ASSERT(functional_level > DS_DOMAIN_FUNCTION_2000);
                }
-               
+
                /* Even link IDs are for the originating attribute */
                target_attr = dsdb_attribute_by_linkID(ac->schema, schema_attr->linkID + 1);
                if (!target_attr) {
@@ -289,7 +289,7 @@ static int la_mod_search_callback(struct ldb_request *req, struct ldb_reply *are
        struct replace_context *rc;
        struct la_context *ac;
        const char *attr_name;
-       int i, j;
+       unsigned int i, j;
        int ret = LDB_SUCCESS;
 
        ac = talloc_get_type(req->context, struct la_context);
@@ -310,8 +310,8 @@ static int la_mod_search_callback(struct ldb_request *req, struct ldb_reply *are
        case LDB_REPLY_ENTRY:
 
                if (ldb_dn_compare(ares->message->dn, ac->req->op.mod.message->dn) != 0) {
-                       ldb_asprintf_errstring(ldb, 
-                                              "linked_attributes: %s is not the DN we were looking for", 
+                       ldb_asprintf_errstring(ldb,
+                                              "linked_attributes: %s is not the DN we were looking for",
                                               ldb_dn_get_linearized(ares->message->dn));
                        /* Guh?  We only asked for this DN */
                        talloc_free(ares);
@@ -327,7 +327,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,
@@ -412,12 +413,11 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
        /* Apply the modify to the linked entry */
 
        struct ldb_context *ldb;
-       int i, j;
+       unsigned int i, j;
        struct la_context *ac;
        struct ldb_request *search_req;
        const char **attrs;
        struct ldb_control *ctrl;
-
        int ret;
 
        ldb = ldb_module_get_ctx(module);
@@ -435,7 +435,7 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
 
        ac = linked_attributes_init(module, req);
        if (!ac) {
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_operr(ldb);
        }
 
        if (!ac->schema) {
@@ -445,8 +445,7 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
 
        ac->rc = talloc_zero(ac, struct replace_context);
        if (!ac->rc) {
-               ldb_oom(ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb);
        }
 
        for (i=0; i < req->op.mod.message->num_elements; i++) {
@@ -457,9 +456,11 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                const struct dsdb_attribute *schema_attr
                        = 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);
-                       return LDB_ERR_OBJECT_CLASS_VIOLATION;                  
+                       ldb_asprintf_errstring(ldb,
+                                              "%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
                   (Even link IDs are for the originating attribute) */
@@ -469,7 +470,7 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
 
                if ((schema_attr->linkID & 1) == 1) {
                        unsigned int functional_level;
-                       
+
                        functional_level = dsdb_functional_level(ldb);
                        SMB_ASSERT(functional_level > DS_DOMAIN_FUNCTION_2000);
                }
@@ -487,7 +488,7 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                }
 
                attr_name = target_attr->lDAPDisplayName;
-       
+
                switch (el->flags & LDB_FLAG_MOD_MASK) {
                case LDB_FLAG_MOD_REPLACE:
                        /* treat as just a normal add the delete part is handled by the callback */
@@ -537,8 +538,7 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                                                   struct ldb_message_element,
                                                   ac->rc->num_elements +1);
                        if (!search_el) {
-                               ldb_oom(ldb);
-                               return LDB_ERR_OPERATIONS_ERROR;
+                               return ldb_oom(ldb);
                        }
                        ac->rc->el = search_el;
 
@@ -546,21 +546,20 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                        ac->rc->num_elements++;
                }
        }
-       
+
        if (ac->ops || ac->rc->el) {
                /* both replace and delete without values are handled in the callback
                 * after the search on the entry to be modified is performed */
-               
+
                attrs = talloc_array(ac->rc, const char *, ac->rc->num_elements + 1);
                if (!attrs) {
-                       ldb_oom(ldb);
-                       return LDB_ERR_OPERATIONS_ERROR;
+                       return ldb_oom(ldb);
                }
                for (i = 0; ac->rc && i < ac->rc->num_elements; i++) {
                        attrs[i] = ac->rc->el[i].name;
                }
                attrs[i] = NULL;
-               
+
                /* The callback does all the hard work here */
                ret = ldb_build_search_req(&search_req, ldb, ac,
                                           req->op.mod.message->dn,
@@ -569,6 +568,7 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                                           NULL,
                                           ac, la_mod_search_callback,
                                           req);
+               LDB_REQ_SET_LOCATION(search_req);
 
                /* We need to figure out our own extended DN, to fill in as the backlink target */
                if (ret == LDB_SUCCESS) {
@@ -578,7 +578,7 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
                }
                if (ret == LDB_SUCCESS) {
                        talloc_steal(search_req, attrs);
-                       
+
                        ret = ldb_next_request(module, search_req);
                }
 
@@ -594,13 +594,15 @@ static int linked_attributes_modify(struct ldb_module *module, struct ldb_reques
 static int linked_attributes_fix_links(struct ldb_module *module,
                                       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;
+       unsigned int i, j;
        TALLOC_CTX *tmp_ctx = talloc_new(module);
        struct ldb_context *ldb = ldb_module_get_ctx(module);
        const struct dsdb_attribute *target;
        const char *attrs[2];
+       int ret;
 
        target = dsdb_attribute_by_linkID(schema, schema_attr->linkID ^ 1);
        if (target == NULL) {
@@ -613,8 +615,6 @@ static int linked_attributes_fix_links(struct ldb_module *module,
 
        for (i=0; i<el->num_values; i++) {
                struct dsdb_dn *dsdb_dn;
-               unsigned int j;
-               int ret;
                struct ldb_result *res;
                struct ldb_message *msg;
                struct ldb_message_element *el2;
@@ -627,9 +627,10 @@ static int linked_attributes_fix_links(struct ldb_module *module,
 
                ret = dsdb_module_search_dn(module, tmp_ctx, &res, dsdb_dn->dn,
                                            attrs,
-                                           DSDB_SEARCH_SHOW_DELETED |
+                                           DSDB_FLAG_NEXT_MODULE |
+                                           DSDB_SEARCH_SHOW_RECYCLED |
                                            DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT |
-                                           DSDB_SEARCH_REVEAL_INTERNALS);
+                                           DSDB_SEARCH_REVEAL_INTERNALS, parent);
                if (ret != LDB_SUCCESS) {
                        ldb_asprintf_errstring(ldb, "Linked attribute %s->%s between %s and %s - remote not found - %s",
                                               el->name, target->lDAPDisplayName,
@@ -641,9 +642,17 @@ static int linked_attributes_fix_links(struct ldb_module *module,
                }
                msg = res->msgs[0];
 
-               if (msg->num_elements != 1 ||
-                   ldb_attr_cmp(msg->elements[0].name, target->lDAPDisplayName) != 0) {
-                       ldb_set_errstring(ldb, "Bad msg elements in linked_attributes_fix_links");
+               if (msg->num_elements == 0) {
+                       /* Forward link without backlink remaining - nothing to do here */
+                       continue;
+               } else if (msg->num_elements != 1) {
+                       ldb_asprintf_errstring(ldb, "Bad msg elements - got %u elements, expected one element to be returned in linked_attributes_fix_links for %s",
+                                              msg->num_elements, ldb_dn_get_linearized(msg->dn));
+                       talloc_free(tmp_ctx);
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
+               if (ldb_attr_cmp(msg->elements[0].name, target->lDAPDisplayName) != 0) {
+                       ldb_asprintf_errstring(ldb, "Bad returned attribute in linked_attributes_fix_links: got %s, expected %s for %s", msg->elements[0].name, target->lDAPDisplayName, ldb_dn_get_linearized(msg->dn));
                        talloc_free(tmp_ctx);
                        return LDB_ERR_OPERATIONS_ERROR;
                }
@@ -678,7 +687,11 @@ static int linked_attributes_fix_links(struct ldb_module *module,
                        return ret;
                }
 
-               ret = dsdb_module_modify(module, msg, 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,
@@ -701,9 +714,9 @@ static int linked_attributes_rename(struct ldb_module *module, struct ldb_reques
        struct ldb_result *res;
        struct ldb_message *msg;
        unsigned int i;
-       int ret;
        struct ldb_context *ldb = ldb_module_get_ctx(module);
        struct dsdb_schema *schema;
+       int ret;
        /*
           - load the current msg
           - find any linked attributes
@@ -711,15 +724,16 @@ static int linked_attributes_rename(struct ldb_module *module, struct ldb_reques
           - modify the target linked attributes with the new DN
        */
        ret = dsdb_module_search_dn(module, req, &res, req->op.rename.olddn,
-                                   NULL, DSDB_SEARCH_SHOW_DELETED);
+                                   NULL,
+                                   DSDB_FLAG_NEXT_MODULE |
+                                   DSDB_SEARCH_SHOW_RECYCLED, req);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
 
        schema = dsdb_get_schema(ldb, res);
        if (!schema) {
-               ldb_oom(ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb);
        }
 
        msg = res->msgs[0];
@@ -732,7 +746,7 @@ static int linked_attributes_rename(struct ldb_module *module, struct ldb_reques
                        continue;
                }
                ret = linked_attributes_fix_links(module, msg->dn, req->op.rename.newdn, el,
-                                                 schema, schema_attr);
+                                                 schema, schema_attr, req);
                if (ret != LDB_SUCCESS) {
                        talloc_free(res);
                        return ret;
@@ -749,12 +763,12 @@ static int linked_attributes_rename(struct ldb_module *module, struct ldb_reques
    structure */
 static int la_queue_mod_request(struct la_context *ac)
 {
-       struct la_private *la_private = 
+       struct la_private *la_private =
                talloc_get_type(ldb_module_get_private(ac->module), struct la_private);
 
        if (la_private == NULL) {
                ldb_debug(ldb_module_get_ctx(ac->module), LDB_DEBUG_ERROR, __location__ ": No la_private transaction setup\n");
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_operr(ldb_module_get_ctx(ac->module));
        }
 
        talloc_steal(la_private, ac);
@@ -767,9 +781,9 @@ static int la_queue_mod_request(struct la_context *ac)
 /* Having done the original operation, then try to fix up all the linked attributes for modify and delete */
 static int la_mod_del_callback(struct ldb_request *req, struct ldb_reply *ares)
 {
-       int ret;
        struct la_context *ac;
        struct ldb_context *ldb;
+       int ret;
 
        ac = talloc_get_type(req->context, struct la_context);
        ldb = ldb_module_get_ctx(ac->module);
@@ -790,13 +804,13 @@ static int la_mod_del_callback(struct ldb_request *req, struct ldb_reply *ares)
                return ldb_module_done(ac->req, NULL, NULL,
                                        LDB_ERR_OPERATIONS_ERROR);
        }
-       
+
        ac->op_controls = talloc_steal(ac, ares->controls);
        ac->op_response = talloc_steal(ac, ares->response);
 
        /* If we have modfies to make, this is the time to do them for modify and delete */
        ret = la_queue_mod_request(ac);
-       
+
        if (ret != LDB_SUCCESS) {
                return ldb_module_done(ac->req, NULL, NULL, ret);
        }
@@ -813,9 +827,9 @@ static int la_mod_del_callback(struct ldb_request *req, struct ldb_reply *ares)
  */
 static int la_add_callback(struct ldb_request *req, struct ldb_reply *ares)
 {
-       int ret;
        struct la_context *ac;
        struct ldb_context *ldb;
+       int ret;
 
        ac = talloc_get_type(req->context, struct la_context);
        ldb = ldb_module_get_ctx(ac->module);
@@ -836,11 +850,11 @@ static int la_add_callback(struct ldb_request *req, struct ldb_reply *ares)
                return ldb_module_done(ac->req, NULL, NULL,
                                        LDB_ERR_OPERATIONS_ERROR);
        }
-       
+
        if (ac->ops) {
                struct ldb_request *search_req;
                static const char *attrs[] = { NULL };
-               
+
                /* The callback does all the hard work here - we need
                 * the objectGUID and SID of the added record */
                ret = ldb_build_search_req(&search_req, ldb, ac,
@@ -850,7 +864,8 @@ static int la_add_callback(struct ldb_request *req, struct ldb_reply *ares)
                                           NULL,
                                           ac, la_mod_search_callback,
                                           ac->req);
-               
+               LDB_REQ_SET_LOCATION(search_req);
+
                if (ret == LDB_SUCCESS) {
                        ret = ldb_request_add_control(search_req,
                                                      LDB_CONTROL_EXTENDED_DN_OID,
@@ -865,7 +880,7 @@ static int la_add_callback(struct ldb_request *req, struct ldb_reply *ares)
                ac->op_response = talloc_steal(ac, ares->response);
 
                return ldb_next_request(ac->module, search_req);
-               
+
        } else {
                return ldb_module_done(ac->req, ares->controls,
                                       ares->response, ares->error);
@@ -876,8 +891,8 @@ static int la_add_callback(struct ldb_request *req, struct ldb_reply *ares)
 static int la_down_req(struct la_context *ac)
 {
        struct ldb_request *down_req;
-       int ret;
        struct ldb_context *ldb;
+       int ret;
 
        ldb = ldb_module_get_ctx(ac->module);
 
@@ -888,6 +903,7 @@ static int la_down_req(struct la_context *ac)
                                        ac->req->controls,
                                        ac, la_add_callback,
                                        ac->req);
+               LDB_REQ_SET_LOCATION(down_req);
                break;
        case LDB_MODIFY:
                ret = ldb_build_mod_req(&down_req, ldb, ac,
@@ -895,6 +911,7 @@ static int la_down_req(struct la_context *ac)
                                        ac->req->controls,
                                        ac, la_mod_del_callback,
                                        ac->req);
+               LDB_REQ_SET_LOCATION(down_req);
                break;
        default:
                ret = LDB_ERR_OPERATIONS_ERROR;
@@ -910,7 +927,7 @@ static int la_down_req(struct la_context *ac)
   use the GUID part of an extended DN to find the target DN, in case
   it has moved
  */
-static int la_find_dn_target(struct ldb_module *module, 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);
@@ -929,8 +946,7 @@ static int la_do_op_request(struct ldb_module *module, struct la_context *ac, st
        /* Create the modify request */
        new_msg = ldb_msg_new(ac);
        if (!new_msg) {
-               ldb_oom(ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb);
        }
 
        ret = la_find_dn_target(module, ac, &op->guid, &new_msg->dn);
@@ -950,8 +966,7 @@ static int la_do_op_request(struct ldb_module *module, struct la_context *ac, st
        }
        ret_el->values = talloc_array(new_msg, struct ldb_val, 1);
        if (!ret_el->values) {
-               ldb_oom(ldb);
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb);
        }
        ret_el->num_values = 1;
        if (op->op == LA_OP_ADD) {
@@ -962,17 +977,17 @@ static int la_do_op_request(struct ldb_module *module, struct la_context *ac, st
 
 #if 0
        ldb_debug(ldb, LDB_DEBUG_WARNING,
-                 "link on %s %s: %s %s\n", 
-                 ldb_dn_get_linearized(new_msg->dn), ret_el->name, 
+                 "link on %s %s: %s %s\n",
+                 ldb_dn_get_linearized(new_msg->dn), ret_el->name,
                  ret_el->values[0].data, ac->ops->op == LA_OP_ADD ? "added" : "deleted");
-#endif 
+#endif
 
        if (DEBUGLVL(4)) {
                DEBUG(4,("Applying linked attribute change:\n%s\n",
                         ldb_ldif_message_string(ldb, op, LDB_CHANGETYPE_MODIFY, new_msg)));
        }
 
-       ret = dsdb_module_modify(module, new_msg, 0);
+       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_errstring(ldb),
@@ -1001,7 +1016,7 @@ static int la_do_mod_request(struct ldb_module *module, struct la_context *ac)
 
 
 /*
-  we hook into the transaction operations to allow us to 
+  we hook into the transaction operations to allow us to
   perform the linked attribute updates at the end of the whole
   transaction. This allows a forward linked attribute to be created
   before the target is created, as long as the target is created
@@ -1015,7 +1030,7 @@ static int linked_attributes_start_transaction(struct ldb_module *module)
        talloc_free(la_private);
        la_private = talloc(module, struct la_private);
        if (la_private == NULL) {
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb_module_get_ctx(module));
        }
        la_private->la_list = NULL;
        ldb_module_set_private(module, la_private);
@@ -1028,7 +1043,7 @@ static int linked_attributes_start_transaction(struct ldb_module *module)
  */
 static int linked_attributes_prepare_commit(struct ldb_module *module)
 {
-       struct la_private *la_private = 
+       struct la_private *la_private =
                talloc_get_type(ldb_module_get_private(module), struct la_private);
        struct la_context *ac;
 
@@ -1052,20 +1067,20 @@ static int linked_attributes_prepare_commit(struct ldb_module *module)
                if (ret != LDB_SUCCESS) {
                        DEBUG(0,(__location__ ": Failed mod request ret=%d\n", ret));
                        talloc_free(la_private);
-                       ldb_module_set_private(module, NULL);   
+                       ldb_module_set_private(module, NULL);
                        return ret;
                }
        }
 
        talloc_free(la_private);
-       ldb_module_set_private(module, NULL);   
+       ldb_module_set_private(module, NULL);
 
        return ldb_next_prepare_commit(module);
 }
 
 static int linked_attributes_del_transaction(struct ldb_module *module)
 {
-       struct la_private *la_private = 
+       struct la_private *la_private =
                talloc_get_type(ldb_module_get_private(module), struct la_private);
        talloc_free(la_private);
        ldb_module_set_private(module, NULL);
@@ -1073,7 +1088,7 @@ static int linked_attributes_del_transaction(struct ldb_module *module)
 }
 
 
-_PUBLIC_ const struct ldb_module_ops ldb_linked_attributes_module_ops = {
+static const struct ldb_module_ops ldb_linked_attributes_module_ops = {
        .name              = "linked_attributes",
        .add               = linked_attributes_add,
        .modify            = linked_attributes_modify,
@@ -1082,3 +1097,9 @@ _PUBLIC_ const struct ldb_module_ops ldb_linked_attributes_module_ops = {
        .prepare_commit    = linked_attributes_prepare_commit,
        .del_transaction   = linked_attributes_del_transaction,
 };
+
+int ldb_linked_attributes_module_init(const char *version)
+{
+       LDB_MODULE_CHECK_VERSION(version);
+       return ldb_register_module(&ldb_linked_attributes_module_ops);
+}