r13786: [merge] Add registration functions for LDB modules
[sfrench/samba-autobuild/.git] / source4 / dsdb / samdb / ldb_modules / kludge_acl.c
index 0d0a266119f527dd09293202202d1daa5814e1f6..4c680df3e6132256b2fae894854e09d7ca43e935 100644 (file)
@@ -135,7 +135,7 @@ static int kludge_acl_change(struct ldb_module *module, struct ldb_request *req)
        case ADMINISTRATOR:
                return ldb_next_request(module, req);
        default:
-               ldb_set_errstring(module, 
+               ldb_set_errstring(module->ldb
                                  talloc_asprintf(req, "kludge_acl_change: "
                                                  "attempted database modify not permitted. User %s is not SYSTEM or an administrator",
                                                  user_name(req, module)));
@@ -175,7 +175,7 @@ static int kludge_acl_request(struct ldb_module *module, struct ldb_request *req
        }
 }
 
-static int kludge_acl_init_2(struct ldb_module *module)
+static int kludge_acl_init(struct ldb_module *module)
 {
        int ret, i;
        TALLOC_CTX *mem_ctx = talloc_new(module);
@@ -184,8 +184,15 @@ static int kludge_acl_init_2(struct ldb_module *module)
        struct ldb_message *msg;
        struct ldb_message_element *password_attributes;
 
-       struct kludge_private_data *data = talloc_get_type(module->private_data, struct kludge_private_data);
+       struct kludge_private_data *data;
+
+       data = talloc(module, struct kludge_private_data);
+       if (data == NULL) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
        data->password_attrs = NULL;
+       module->private_data = data;
 
        if (!mem_ctx) {
                return LDB_ERR_OPERATIONS_ERROR;
@@ -196,14 +203,11 @@ static int kludge_acl_init_2(struct ldb_module *module)
                         NULL, attrs,
                         &res);
        if (ret != LDB_SUCCESS) {
-               talloc_free(mem_ctx);
-               return ret;
+               goto done;
        }
        talloc_steal(mem_ctx, res);
        if (res->count == 0) {
-               talloc_free(mem_ctx);
-               data->password_attrs = NULL;
-               return LDB_SUCCESS;
+               goto done;
        }
 
        if (res->count > 1) {
@@ -215,8 +219,7 @@ static int kludge_acl_init_2(struct ldb_module *module)
 
        password_attributes = ldb_msg_find_element(msg, "passwordAttribute");
        if (!password_attributes) {
-               talloc_free(mem_ctx);
-               return LDB_SUCCESS;
+               goto done;
        }
        data->password_attrs = talloc_array(data, const char *, password_attributes->num_values + 1);
        if (!data->password_attrs) {
@@ -228,8 +231,10 @@ static int kludge_acl_init_2(struct ldb_module *module)
                talloc_steal(data->password_attrs, password_attributes->values[i].data);
        }
        data->password_attrs[i] = NULL;
+
+done:
        talloc_free(mem_ctx);
-       return LDB_SUCCESS;
+       return ldb_next_init(module);
 }
 
 static const struct ldb_module_ops kludge_acl_ops = {
@@ -238,30 +243,10 @@ static const struct ldb_module_ops kludge_acl_ops = {
        .start_transaction = kludge_acl_start_trans,
        .end_transaction   = kludge_acl_end_trans,
        .del_transaction   = kludge_acl_del_trans,
-       .second_stage_init = kludge_acl_init_2
+       .init_context      = kludge_acl_init
 };
 
-struct ldb_module *kludge_acl_module_init(struct ldb_context *ldb, const char *options[])
+int ldb_kludge_acl_init(void)
 {
-       struct ldb_module *ctx;
-       struct kludge_private_data *data;
-
-       ctx = talloc(ldb, struct ldb_module);
-       if (!ctx)
-               return NULL;
-
-       data = talloc(ctx, struct kludge_private_data);
-       if (data == NULL) {
-               talloc_free(ctx);
-               return NULL;
-       }
-
-       data->password_attrs = NULL;
-       ctx->private_data = data;
-
-       ctx->ldb = ldb;
-       ctx->prev = ctx->next = NULL;
-       ctx->ops = &kludge_acl_ops;
-
-       return ctx;
+       return ldb_register_module(&kludge_acl_ops);
 }