]> git.sur5r.net Git - openldap/blob - servers/slapd/back-null/null.c
8d8127785201b0e2a53d0be60826bc0e71511a7d
[openldap] / servers / slapd / back-null / null.c
1 /* null.c - the null backend */
2 /*
3  * Copyright 2002 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10 #include <ac/string.h>
11
12 #include "slap.h"
13 #include "external.h"
14
15 struct null_info {
16         int bind_allowed;
17 };
18
19 int
20 null_back_bind(
21         Backend                 *be,
22         Connection              *conn,
23         Operation               *op,
24         struct berval   *dn,
25         struct berval   *ndn,
26         int                             method,
27         struct berval   *cred,
28         struct berval   *edn
29 )
30 {
31         struct null_info *ni = (struct null_info *) be->be_private;
32
33         if( ni->bind_allowed )
34                 /* front end with send result on success (0) */
35                 return 0;
36         send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
37                           NULL, NULL, NULL, NULL );
38         return LDAP_INVALID_CREDENTIALS;
39 }
40
41 int
42 null_back_add(
43         BackendDB       *be,
44         Connection      *conn,
45         Operation       *op,
46         Entry           *e )
47 {
48         send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL );
49         return 0;
50 }
51
52 int
53 null_back_compare(
54         BackendDB               *be,
55         Connection              *conn,
56         Operation               *op,
57         struct berval   *dn,
58         struct berval   *ndn,
59         AttributeAssertion *ava
60 )
61 {
62         send_ldap_result( conn, op, LDAP_COMPARE_FALSE, NULL, NULL, NULL, NULL );
63         return 0;
64 }
65
66 int
67 null_back_delete(
68         BackendDB               *be,
69         Connection              *conn,
70         Operation               *op,
71         struct berval   *dn,
72         struct berval   *ndn
73 )
74 {
75         send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL );
76         return 0;
77 }
78
79 int
80 null_back_modify(
81         BackendDB               *be,
82         Connection              *conn,
83         Operation               *op,
84         struct berval   *dn,
85         struct berval   *ndn,
86         Modifications   *modlist )
87 {
88         send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL );
89         return 0;
90 }
91
92 int
93 null_back_modrdn(
94         Backend                 *be,
95         Connection              *conn,
96         Operation               *op,
97         struct berval   *dn,
98         struct berval   *ndn,
99         struct berval   *newrdn,
100         struct berval   *nnewrdn,
101         int                             deleteoldrdn,
102         struct berval   *newSuperior,
103         struct berval   *nnewSuperior )
104 {
105         send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL );
106         return 0;
107 }
108
109 int
110 null_back_search(
111         BackendDB               *be,
112         Connection              *conn,
113         Operation               *op,
114         struct berval   *base,
115         struct berval   *nbase,
116         int                             scope,
117         int                             deref,
118         int                             slimit,
119         int                             tlimit,
120         Filter                  *filter,
121         struct berval   *filterstr,
122         AttributeName   *attrs,
123         int                             attrsonly )
124 {
125         send_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL, 0 );
126         return 1;
127 }
128
129
130 int
131 null_back_db_config(
132         BackendDB       *be,
133         const char      *fname,
134         int                     lineno,
135         int                     argc,
136         char            **argv )
137 {
138         struct null_info *ni = (struct null_info *) be->be_private;
139
140         if ( ni == NULL ) {
141                 fprintf( stderr, "%s: line %d: null database info is null!\n",
142                         fname, lineno );
143                 return 1;
144         }
145
146         /* bind requests allowed */
147         if ( strcasecmp( argv[0], "bind" ) == 0 ) {
148                 if ( argc < 2 ) {
149                         fprintf( stderr,
150         "%s: line %d: missing <on/off> in \"bind <on/off>\" line\n",
151                                  fname, lineno );
152                         return 1;
153                 }
154                 ni->bind_allowed = strcasecmp( argv[1], "off" );
155
156         /* anything else */
157         } else {
158                 fprintf( stderr,
159 "%s: line %d: unknown directive \"%s\" in null database definition (ignored)\n",
160                          fname, lineno, argv[0] );
161         }
162
163         return 0;
164 }
165
166
167 int
168 null_back_db_init( BackendDB *be )
169 {
170         be->be_private = ch_calloc( 1, sizeof(struct null_info) );
171         return 0;
172 }
173
174 int
175 null_back_db_destroy(
176     Backend     *be
177 )
178 {
179         free( be->be_private );
180         return 0;
181 }
182
183
184 int
185 null_back_initialize(
186     BackendInfo *bi
187 )
188 {
189         bi->bi_open = 0;
190         bi->bi_close = 0;
191         bi->bi_config = 0;
192         bi->bi_destroy = 0;
193
194         bi->bi_db_init = null_back_db_init;
195         bi->bi_db_config = null_back_db_config;
196         bi->bi_db_open = 0;
197         bi->bi_db_close = 0;
198         bi->bi_db_destroy = null_back_db_destroy;
199
200         bi->bi_op_bind = null_back_bind;
201         bi->bi_op_unbind = 0;
202         bi->bi_op_search = null_back_search;
203         bi->bi_op_compare = null_back_compare;
204         bi->bi_op_modify = null_back_modify;
205         bi->bi_op_modrdn = null_back_modrdn;
206         bi->bi_op_add = null_back_add;
207         bi->bi_op_delete = null_back_delete;
208         bi->bi_op_abandon = 0;
209
210         bi->bi_extended = 0;
211
212         bi->bi_acl_group = 0;
213         bi->bi_acl_attribute = 0;
214         bi->bi_chk_referrals = 0;
215
216         bi->bi_connection_init = 0;
217         bi->bi_connection_destroy = 0;
218
219         return 0;
220 }
221
222 #ifdef SLAPD_NULL_DYNAMIC
223 int back_null_LTX_init_module(
224         int argc,
225         char *argv[] )
226 {
227     BackendInfo bi;
228
229     memset( &bi, '\0', sizeof(bi) );
230     bi.bi_type = "null";
231     bi.bi_init = null_back_initialize;
232
233     backend_add(&bi);
234     return 0;
235 }
236 #endif /* SLAPD_NULL_DYNAMIC */