]> git.sur5r.net Git - openldap/blob - servers/slapd/back-null/null.c
17b9254a5644cffa1f45383008f93b00e29fe1d6
[openldap] / servers / slapd / back-null / null.c
1 /* null.c - the null backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2002-2007 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was originally developed by Hallvard Furuseth for inclusion
18  * in OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #include <stdio.h>
24 #include <ac/string.h>
25
26 #include "slap.h"
27
28 struct null_info {
29         int     ni_bind_allowed;
30         ID      ni_nextid;
31 };
32
33
34 /* LDAP operations */
35
36 static int
37 null_back_bind( Operation *op, SlapReply *rs )
38 {
39         struct null_info *ni = (struct null_info *) op->o_bd->be_private;
40
41         if ( ni->ni_bind_allowed || be_isroot_pw( op ) ) {
42                 /* front end will send result on success (0) */
43                 return LDAP_SUCCESS;
44         }
45
46         rs->sr_err = LDAP_INVALID_CREDENTIALS;
47         send_ldap_result( op, rs );
48
49         return rs->sr_err;
50 }
51
52 /* add, delete, modify, modrdn, search */
53 static int
54 null_back_success( Operation *op, SlapReply *rs )
55 {
56         rs->sr_err = LDAP_SUCCESS;
57         send_ldap_result( op, rs );
58         return 0;
59 }
60
61 /* compare */
62 static int
63 null_back_false( Operation *op, SlapReply *rs )
64 {
65         rs->sr_err = LDAP_COMPARE_FALSE;
66         send_ldap_result( op, rs );
67         return 0;
68 }
69
70
71 /* for overlays */
72 int null_back_entry_get(
73         Operation *op,
74         struct berval *ndn,
75         ObjectClass *oc,
76         AttributeDescription *at,
77         int rw,
78         Entry **ent )
79 {
80         *ent = NULL;
81         return 1;
82 }
83
84
85 /* Slap tools */
86
87 static int
88 null_tool_entry_open( BackendDB *be, int mode )
89 {
90         return 0;
91 }
92
93 static int
94 null_tool_entry_close( BackendDB *be )
95 {
96         assert( be != NULL );
97         return 0;
98 }
99
100 static ID
101 null_tool_entry_next( BackendDB *be )
102 {
103         return NOID;
104 }
105
106 static Entry *
107 null_tool_entry_get( BackendDB *be, ID id )
108 {
109         assert( slapMode & SLAP_TOOL_MODE );
110         return NULL;
111 }
112
113 static ID
114 null_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
115 {
116         assert( slapMode & SLAP_TOOL_MODE );
117         assert( text != NULL );
118         assert( text->bv_val != NULL );
119         assert( text->bv_val[0] == '\0' );      /* overconservative? */
120
121         e->e_id = ((struct null_info *) be->be_private)->ni_nextid++;
122         return e->e_id;
123 }
124
125
126 /* Setup */
127
128 static int
129 null_back_db_config(
130         BackendDB       *be,
131         const char      *fname,
132         int             lineno,
133         int             argc,
134         char            **argv )
135 {
136         struct null_info *ni = (struct null_info *) be->be_private;
137
138         if ( ni == NULL ) {
139                 fprintf( stderr, "%s: line %d: null database info is null!\n",
140                         fname, lineno );
141                 return 1;
142         }
143
144         /* bind requests allowed */
145         if ( strcasecmp( argv[0], "bind" ) == 0 ) {
146                 if ( argc < 2 ) {
147                         fprintf( stderr,
148         "%s: line %d: missing <on/off> in \"bind <on/off>\" line\n",
149                                  fname, lineno );
150                         return 1;
151                 }
152                 ni->ni_bind_allowed = strcasecmp( argv[1], "off" );
153
154         /* anything else */
155         } else {
156                 return SLAP_CONF_UNKNOWN;
157         }
158
159         return 0;
160 }
161
162 static int
163 null_back_db_init( BackendDB *be )
164 {
165         struct null_info *ni = ch_calloc( 1, sizeof(struct null_info) );
166         ni->ni_bind_allowed = 0;
167         ni->ni_nextid = 1;
168         be->be_private = ni;
169         return 0;
170 }
171
172 static int
173 null_back_db_destroy( Backend *be )
174 {
175         free( be->be_private );
176         return 0;
177 }
178
179
180 int
181 null_back_initialize( BackendInfo *bi )
182 {
183         bi->bi_open = 0;
184         bi->bi_close = 0;
185         bi->bi_config = 0;
186         bi->bi_destroy = 0;
187
188         bi->bi_db_init = null_back_db_init;
189         bi->bi_db_config = null_back_db_config;
190         bi->bi_db_open = 0;
191         bi->bi_db_close = 0;
192         bi->bi_db_destroy = null_back_db_destroy;
193
194         bi->bi_op_bind = null_back_bind;
195         bi->bi_op_unbind = 0;
196         bi->bi_op_search = null_back_success;
197         bi->bi_op_compare = null_back_false;
198         bi->bi_op_modify = null_back_success;
199         bi->bi_op_modrdn = null_back_success;
200         bi->bi_op_add = null_back_success;
201         bi->bi_op_delete = null_back_success;
202         bi->bi_op_abandon = 0;
203
204         bi->bi_extended = 0;
205
206         bi->bi_chk_referrals = 0;
207
208         bi->bi_connection_init = 0;
209         bi->bi_connection_destroy = 0;
210
211         bi->bi_entry_get_rw = null_back_entry_get;
212
213         bi->bi_tool_entry_open = null_tool_entry_open;
214         bi->bi_tool_entry_close = null_tool_entry_close;
215         bi->bi_tool_entry_first = null_tool_entry_next;
216         bi->bi_tool_entry_next = null_tool_entry_next;
217         bi->bi_tool_entry_get = null_tool_entry_get;
218         bi->bi_tool_entry_put = null_tool_entry_put;
219
220         return 0;
221 }
222
223 #if SLAPD_NULL == SLAPD_MOD_DYNAMIC
224
225 /* conditionally define the init_module() function */
226 SLAP_BACKEND_INIT_MODULE( null )
227
228 #endif /* SLAPD_NULL == SLAPD_MOD_DYNAMIC */