9fb01941c97c4ea01681393ed9b5bbde98d1abe0
[sfrench/samba-autobuild/.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 const struct private_data {
40
41         const char *error_string;
42 };
43
44 /* search */
45 static int skel_search(struct ldb_module *module, const char *base,
46                        enum ldb_scope scope, const char *expression,
47                        const char * const *attrs, struct ldb_message ***res)
48 {
49         return ldb_next_search(module, base, scope, expression, attrs, res); 
50 }
51
52 /* add_record */
53 static int skel_add_record(struct ldb_module *module, const struct ldb_message *msg)
54 {
55         return ldb_next_add_record(module, msg);
56 }
57
58 /* modify_record */
59 static int skel_modify_record(struct ldb_module *module, const struct ldb_message *msg)
60 {
61         return ldb_next_modify_record(module, msg);
62 }
63
64 /* delete_record */
65 static int skel_delete_record(struct ldb_module *module, const char *dn)
66 {
67         return ldb_next_delete_record(module, dn);
68 }
69
70 /* rename_record */
71 static int skel_rename_record(struct ldb_module *module, const char *olddn, const char *newdn)
72 {
73         return ldb_next_rename_record(module, olddn, newdn);
74 }
75
76 /* named_lock */
77 static int skel_named_lock(struct ldb_module *module, const char *lockname)
78 {
79         return ldb_next_named_lock(module, lockname);
80 }
81
82 /* named_unlock */
83 static int skel_named_unlock(struct ldb_module *module, const char *lockname)
84 {
85         return ldb_next_named_unlock(module, lockname);
86 }
87
88 /* return extended error information */
89 static const char *skel_errstring(struct ldb_module *module)
90 {
91         return ldb_next_errstring(module);
92 }
93
94 static int skel_destructor(void *module_ctx)
95 {
96         struct ldb_module *ctx = module_ctx;
97         /* put your clean-up functions here */
98         return 0;
99 }
100
101 static const struct ldb_module_ops skel_ops = {
102         "skel",
103         skel_search,
104         skel_add_record,
105         skel_modify_record,
106         skel_delete_record,
107         skel_rename_record,
108         skel_named_lock,
109         skel_named_unlock,
110         skel_errstring
111 };
112
113 #ifdef HAVE_DLOPEN_DISABLED
114 struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
115 #else
116 struct ldb_module *skel_module_init(struct ldb_context *ldb, const char *options[])
117 #endif
118 {
119         struct ldb_module *ctx;
120         struct private_data *data;
121
122         ctx = talloc(ldb, struct ldb_module);
123         if (!ctx)
124                 return NULL;
125
126         data = talloc(ctx, struct private_data);
127         if (data == NULL) {
128                 talloc_free(ctx);
129                 return NULL;
130         }
131
132         data->error_string = NULL;
133         ctx->private_data = data;
134
135         ctx->ldb = ldb;
136         ctx->prev = ctx->next = NULL;
137         ctx->ops = &skel_ops;
138
139         talloc_set_destructor (ctx, skel_destructor);
140
141         return ctx;
142 }