fcec0f3fd81c2e667a0cc5b014aeff0a85884db1
[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 struct private_data {
40
41         char *some_private_data;
42 };
43
44 /* search */
45 static int skel_search(struct ldb_module *module, const struct ldb_dn *base,
46                        enum ldb_scope scope, struct ldb_parse_tree *tree,
47                        const char * const *attrs, struct ldb_result **res)
48 {
49         return ldb_next_search(module, base, scope, tree, 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 struct ldb_dn *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 struct ldb_dn *olddn, const struct ldb_dn *newdn)
72 {
73         return ldb_next_rename_record(module, olddn, newdn);
74 }
75
76 /* start a transaction */
77 static int skel_start_trans(struct ldb_module *module)
78 {
79         return ldb_next_start_trans(module);
80 }
81
82 /* end a transaction */
83 static int skel_end_trans(struct ldb_module *module)
84 {
85         return ldb_next_end_trans(module);
86 }
87
88 /* delete a transaction */
89 static int skel_del_trans(struct ldb_module *module)
90 {
91         return ldb_next_del_trans(module);
92 }
93
94 static int skel_destructor(void *module_ctx)
95 {
96         struct ldb_module *ctx = talloc_get_type(module_ctx, struct ldb_module);
97         struct private_data *data = talloc_get_type(ctx->private_data, struct private_data);
98         /* put your clean-up functions here */
99         if (data->some_private_data) talloc_free(data->some_private_data);
100         return 0;
101 }
102
103 static int skel_request(struct ldb_module *module, struct ldb_request *req)
104 {
105         switch (req->operation) {
106
107         case LDB_REQ_SEARCH:
108                 return skel_search_bytree(module,
109                                           req->op.search->base,
110                                           req->op.search->scope, 
111                                           req->op.search->tree, 
112                                           req->op.search->attrs, 
113                                           req->op.search->res);
114
115         case LDB_REQ_ADD:
116                 return skel_add(module, req->op.add->message);
117
118         case LDB_REQ_MODIFY:
119                 return skel_modify(module, req->op.mod->message);
120
121         case LDB_REQ_DELETE:
122                 return skel_delete(module, req->op.del->dn);
123
124         case LDB_REQ_RENAME:
125                 return skel_rename(module,
126                                         req->op.rename->olddn,
127                                         req->op.rename->newdn);
128
129         default:
130                 return ldb_next_request(module, req);
131
132         }
133 }
134
135 static const struct ldb_module_ops skel_ops = {
136         .name              = "skel",
137         .request           = skel_request,
138         .start_transaction = skel_start_trans,
139         .end_transaction   = skel_end_trans,
140         .del_transaction   = skel_del_trans,
141 };
142
143 struct ldb_module *skel_module_init(struct ldb_context *ldb, const char *options[])
144 {
145         struct ldb_module *ctx;
146         struct private_data *data;
147
148         ctx = talloc(ldb, struct ldb_module);
149         if (!ctx)
150                 return NULL;
151
152         data = talloc(ctx, struct private_data);
153         if (data == NULL) {
154                 talloc_free(ctx);
155                 return NULL;
156         }
157
158         data->some_private_data = NULL;
159         ctx->private_data = data;
160
161         ctx->ldb = ldb;
162         ctx->prev = ctx->next = NULL;
163         ctx->ops = &skel_ops;
164
165         talloc_set_destructor (ctx, skel_destructor);
166
167         return ctx;
168 }