]> git.sur5r.net Git - openldap/blob - servers/slapd/back-null/null.c
ITS#5328 - cosmetic cleanup
[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-2008 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 #include "config.h"
28
29 struct null_info {
30         int     ni_bind_allowed;
31         ID      ni_nextid;
32 };
33
34
35 /* LDAP operations */
36
37 static int
38 null_back_bind( Operation *op, SlapReply *rs )
39 {
40         struct null_info *ni = (struct null_info *) op->o_bd->be_private;
41
42         if ( ni->ni_bind_allowed || be_isroot_pw( op ) ) {
43                 /* front end will send result on success (0) */
44                 return LDAP_SUCCESS;
45         }
46
47         rs->sr_err = LDAP_INVALID_CREDENTIALS;
48         send_ldap_result( op, rs );
49
50         return rs->sr_err;
51 }
52
53 /* add, delete, modify, modrdn, search */
54 static int
55 null_back_success( Operation *op, SlapReply *rs )
56 {
57         rs->sr_err = LDAP_SUCCESS;
58         send_ldap_result( op, rs );
59         return 0;
60 }
61
62 /* compare */
63 static int
64 null_back_false( Operation *op, SlapReply *rs )
65 {
66         rs->sr_err = LDAP_COMPARE_FALSE;
67         send_ldap_result( op, rs );
68         return 0;
69 }
70
71
72 /* for overlays */
73 static int
74 null_back_entry_get(
75         Operation *op,
76         struct berval *ndn,
77         ObjectClass *oc,
78         AttributeDescription *at,
79         int rw,
80         Entry **ent )
81 {
82         assert( *ent == NULL );
83
84         /* don't admit the object isn't there */
85         return oc || at ? LDAP_NO_SUCH_ATTRIBUTE : LDAP_BUSY;
86 }
87
88
89 /* Slap tools */
90
91 static int
92 null_tool_entry_open( BackendDB *be, int mode )
93 {
94         return 0;
95 }
96
97 static int
98 null_tool_entry_close( BackendDB *be )
99 {
100         assert( be != NULL );
101         return 0;
102 }
103
104 static ID
105 null_tool_entry_next( BackendDB *be )
106 {
107         return NOID;
108 }
109
110 static Entry *
111 null_tool_entry_get( BackendDB *be, ID id )
112 {
113         assert( slapMode & SLAP_TOOL_MODE );
114         return NULL;
115 }
116
117 static ID
118 null_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
119 {
120         assert( slapMode & SLAP_TOOL_MODE );
121         assert( text != NULL );
122         assert( text->bv_val != NULL );
123         assert( text->bv_val[0] == '\0' );      /* overconservative? */
124
125         e->e_id = ((struct null_info *) be->be_private)->ni_nextid++;
126         return e->e_id;
127 }
128
129
130 /* Setup */
131
132 static int
133 null_back_db_config(
134         BackendDB       *be,
135         const char      *fname,
136         int             lineno,
137         int             argc,
138         char            **argv )
139 {
140         struct null_info *ni = (struct null_info *) be->be_private;
141
142         if ( ni == NULL ) {
143                 fprintf( stderr, "%s: line %d: null database info is null!\n",
144                         fname, lineno );
145                 return 1;
146         }
147
148         /* bind requests allowed */
149         if ( strcasecmp( argv[0], "bind" ) == 0 ) {
150                 if ( argc < 2 ) {
151                         fprintf( stderr,
152         "%s: line %d: missing <on/off> in \"bind <on/off>\" line\n",
153                                  fname, lineno );
154                         return 1;
155                 }
156                 ni->ni_bind_allowed = strcasecmp( argv[1], "off" );
157
158         /* anything else */
159         } else {
160                 return SLAP_CONF_UNKNOWN;
161         }
162
163         return 0;
164 }
165
166 static int
167 null_back_db_init( BackendDB *be, ConfigReply *cr )
168 {
169         struct null_info *ni = ch_calloc( 1, sizeof(struct null_info) );
170         ni->ni_bind_allowed = 0;
171         ni->ni_nextid = 1;
172         be->be_private = ni;
173         return 0;
174 }
175
176 static int
177 null_back_db_destroy( Backend *be, ConfigReply *cr )
178 {
179         free( be->be_private );
180         return 0;
181 }
182
183
184 int
185 null_back_initialize( BackendInfo *bi )
186 {
187         bi->bi_open = 0;
188         bi->bi_close = 0;
189         bi->bi_config = 0;
190         bi->bi_destroy = 0;
191
192         bi->bi_db_init = null_back_db_init;
193         bi->bi_db_config = null_back_db_config;
194         bi->bi_db_open = 0;
195         bi->bi_db_close = 0;
196         bi->bi_db_destroy = null_back_db_destroy;
197
198         bi->bi_op_bind = null_back_bind;
199         bi->bi_op_unbind = 0;
200         bi->bi_op_search = null_back_success;
201         bi->bi_op_compare = null_back_false;
202         bi->bi_op_modify = null_back_success;
203         bi->bi_op_modrdn = null_back_success;
204         bi->bi_op_add = null_back_success;
205         bi->bi_op_delete = null_back_success;
206         bi->bi_op_abandon = 0;
207
208         bi->bi_extended = 0;
209
210         bi->bi_chk_referrals = 0;
211
212         bi->bi_connection_init = 0;
213         bi->bi_connection_destroy = 0;
214
215         bi->bi_entry_get_rw = null_back_entry_get;
216
217         bi->bi_tool_entry_open = null_tool_entry_open;
218         bi->bi_tool_entry_close = null_tool_entry_close;
219         bi->bi_tool_entry_first = null_tool_entry_next;
220         bi->bi_tool_entry_next = null_tool_entry_next;
221         bi->bi_tool_entry_get = null_tool_entry_get;
222         bi->bi_tool_entry_put = null_tool_entry_put;
223
224         return 0;
225 }
226
227 #if SLAPD_NULL == SLAPD_MOD_DYNAMIC
228
229 /* conditionally define the init_module() function */
230 SLAP_BACKEND_INIT_MODULE( null )
231
232 #endif /* SLAPD_NULL == SLAPD_MOD_DYNAMIC */