r6934: thanks to HotaruT for pointing out skel.c was not in line with the rest of...
[abartlet/samba.git/.git] / source4 / lib / ldb / modules / skel.c
1 /* 
2    ldb database library
3
4    Copyright (C) Simo Sorce  2004
5
6      ** NOTE! The following LGPL license applies to the ldb
7      ** library. This does NOT imply that all of Samba is released
8      ** under the LGPL
9    
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2 of the License, or (at your option) any later version.
14
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24
25 /*
26  *  Name: ldb
27  *
28  *  Component: ldb skel module
29  *
30  *  Description: example module
31  *
32  *  Author: Simo Sorce
33  */
34
35 #include "includes.h"
36 #include "ldb/include/ldb.h"
37 #include "ldb/include/ldb_private.h"
38
39 static struct private_data {
40         const char *error_string;
41 };
42
43 /* search */
44 static int skel_search(struct ldb_module *module, const char *base,
45                        enum ldb_scope scope, const char *expression,
46                        const char * const *attrs, struct ldb_message ***res)
47 {
48         return ldb_next_search(module, base, scope, expression, attrs, res); 
49 }
50
51 /* add_record */
52 static int skel_add_record(struct ldb_module *module, const struct ldb_message *msg)
53 {
54         return ldb_next_add_record(module, msg);
55 }
56
57 /* modify_record */
58 static int skel_modify_record(struct ldb_module *module, const struct ldb_message *msg)
59 {
60         return ldb_next_modify_record(module, msg);
61 }
62
63 /* delete_record */
64 static int skel_delete_record(struct ldb_module *module, const char *dn)
65 {
66         return ldb_next_delete_record(module, dn);
67 }
68
69 /* rename_record */
70 static int skel_rename_record(struct ldb_module *module, const char *olddn, const char *newdn)
71 {
72         return ldb_next_rename_record(module, olddn, newdn);
73 }
74
75 /* named_lock */
76 static int skel_named_lock(struct ldb_module *module, const char *lockname)
77 {
78         return ldb_next_named_lock(module, lockname);
79 }
80
81 /* named_unlock */
82 static int skel_named_unlock(struct ldb_module *module, const char *lockname)
83 {
84         return ldb_next_named_unlock(module, lockname);
85 }
86
87 /* return extended error information */
88 static const char *skel_errstring(struct ldb_module *module)
89 {
90         return ldb_next_errstring(module);
91 }
92
93 static int skel_destructor(void *module_ctx)
94 {
95         struct ldb_module *ctx = module_ctx;
96         /* put your clean-up functions here */
97         return 0;
98 }
99
100 static const struct ldb_module_ops skel_ops = {
101         "skel",
102         skel_search,
103         skel_add_record,
104         skel_modify_record,
105         skel_delete_record,
106         skel_rename_record,
107         skel_named_lock,
108         skel_named_unlock,
109         skel_errstring
110 };
111
112 #ifdef HAVE_DLOPEN_DISABLED
113 struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
114 #else
115 struct ldb_module *skel_module_init(struct ldb_context *ldb, const char *options[])
116 #endif
117 {
118         struct ldb_module *ctx;
119         struct private_data *data;
120
121         ctx = talloc(ldb, struct ldb_module);
122         if (!ctx)
123                 return NULL;
124
125         data = talloc(ctx, struct private_data);
126         if (data == NULL) {
127                 talloc_free(ctx);
128                 return NULL;
129         }
130
131         data->error_string = NULL;
132         ctx->private_data = data;
133
134         ctx->ldb = ldb;
135         ctx->prev = ctx->next = NULL;
136         ctx->private_data = NULL;
137         ctx->ops = &skel_ops;
138
139         talloc_set_destructor (ctx, skel_destructor);
140
141         return ctx;
142 }