update to lib/ldb/modules/skel.c

Maurice Massar massar at unix-ag.uni-kl.de
Sun May 22 10:17:18 GMT 2005


hi,

I found that skel.c no longer works, because the return-type of
named_lock/unlock changed from "const char *" to int. I made some
changes based on what schema.c and timestamps.c look like now.

cu
Maurice
-------------- next part --------------
Index: modules/skel.c
===================================================================
--- modules/skel.c	(revision 6903)
+++ modules/skel.c	(working copy)
@@ -36,12 +36,16 @@
 #include "ldb/include/ldb.h"
 #include "ldb/include/ldb_private.h"
 
+struct private_data {
+	const char *error_string;
+};
+
 /* search */
 static int skel_search(struct ldb_module *module, const char *base,
 		       enum ldb_scope scope, const char *expression,
 		       const char * const *attrs, struct ldb_message ***res)
 {
-	return ldb_next_search(module, base, scope, expression, attrs, res); 
+	return ldb_next_search(module, base, scope, expression, attrs, res);
 }
 
 /* add_record */
@@ -69,13 +73,13 @@
 }
 
 /* named_lock */
-static const char *skel_named_lock(struct ldb_module *module, const char *lockname)
+static int skel_named_lock(struct ldb_module *module, const char *lockname)
 {
 	return ldb_next_named_lock(module, lockname);
 }
 
 /* named_unlock */
-static const char *skel_named_unlock(struct ldb_module *module, const char *lockname)
+static int skel_named_unlock(struct ldb_module *module, const char *lockname)
 {
 	return ldb_next_named_unlock(module, lockname);
 }
@@ -83,12 +87,22 @@
 /* return extended error information */
 static const char *skel_errstring(struct ldb_module *module)
 {
+	struct private_data *data = (struct private_data *)module->private_data;
+
+	if (data->error_string) {
+		const char *error;
+
+		error = data->error_string;
+		data->error_string = NULL;
+		return error;
+	}
+
 	return ldb_next_errstring(module);
 }
 
 static int skel_destructor(void *module_ctx)
 {
-	struct ldb_module *ctx = module_ctx;
+	/*struct ldb_module *ctx = module_ctx;*/
 	/* put your clean-up functions here */
 	return 0;
 }
@@ -105,21 +119,31 @@
 	skel_errstring
 };
 
-#ifdef HAVE_DLOPEN
- struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
+#ifdef HAVE_DLOPEN_DISABLED
+struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
 #else
-struct ldb_module *skel_plugin_init(struct ldb_context *ldb, const char *options[])
+struct ldb_module *skel_module_init(struct ldb_context *ldb, const char *options[])
 #endif
 {
 	struct ldb_module *ctx;
+	struct private_data *data;
 
-	ctx = (struct ldb_module *)malloc(sizeof(struct ldb_module));
-	if (!ctx)
+	ctx = talloc(ldb, struct ldb_module);
+	if (!ctx) {
 		return NULL;
+	}
 
+	data = talloc(ctx, struct private_data);
+	if (data == NULL) {
+		talloc_free(ctx);
+		return NULL;
+	}
+
+	data->error_string = NULL;
+	ctx->private_data = data;
+
 	ctx->ldb = ldb;
 	ctx->prev = ctx->next = NULL;
-	ctx->private_data = NULL;
 	ctx->ops = &skel_ops;
 
 	talloc_set_destructor (ctx, skel_destructor);


More information about the samba-technical mailing list