]> git.sur5r.net Git - openldap/blob - servers/slapd/back-null/null.c
Happy New Year (belated)
[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 int null_back_entry_get(
74         Operation *op,
75         struct berval *ndn,
76         ObjectClass *oc,
77         AttributeDescription *at,
78         int rw,
79         Entry **ent )
80 {
81         *ent = NULL;
82         return 1;
83 }
84
85
86 /* Slap tools */
87
88 static int
89 null_tool_entry_open( BackendDB *be, int mode )
90 {
91         return 0;
92 }
93
94 static int
95 null_tool_entry_close( BackendDB *be )
96 {
97         assert( be != NULL );
98         return 0;
99 }
100
101 static ID
102 null_tool_entry_next( BackendDB *be )
103 {
104         return NOID;
105 }
106
107 static Entry *
108 null_tool_entry_get( BackendDB *be, ID id )
109 {
110         assert( slapMode & SLAP_TOOL_MODE );
111         return NULL;
112 }
113
114 static ID
115 null_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
116 {
117         assert( slapMode & SLAP_TOOL_MODE );
118         assert( text != NULL );
119         assert( text->bv_val != NULL );
120         assert( text->bv_val[0] == '\0' );      /* overconservative? */
121
122         e->e_id = ((struct null_info *) be->be_private)->ni_nextid++;
123         return e->e_id;
124 }
125
126
127 /* Setup */
128
129 static int
130 null_back_db_config(
131         BackendDB       *be,
132         const char      *fname,
133         int             lineno,
134         int             argc,
135         char            **argv )
136 {
137         struct null_info *ni = (struct null_info *) be->be_private;
138
139         if ( ni == NULL ) {
140                 fprintf( stderr, "%s: line %d: null database info is null!\n",
141                         fname, lineno );
142                 return 1;
143         }
144
145         /* bind requests allowed */
146         if ( strcasecmp( argv[0], "bind" ) == 0 ) {
147                 if ( argc < 2 ) {
148                         fprintf( stderr,
149         "%s: line %d: missing <on/off> in \"bind <on/off>\" line\n",
150                                  fname, lineno );
151                         return 1;
152                 }
153                 ni->ni_bind_allowed = strcasecmp( argv[1], "off" );
154
155         /* anything else */
156         } else {
157                 return SLAP_CONF_UNKNOWN;
158         }
159
160         return 0;
161 }
162
163 static int
164 null_back_db_init( BackendDB *be, ConfigReply *cr )
165 {
166         struct null_info *ni = ch_calloc( 1, sizeof(struct null_info) );
167         ni->ni_bind_allowed = 0;
168         ni->ni_nextid = 1;
169         be->be_private = ni;
170         return 0;
171 }
172
173 static int
174 null_back_db_destroy( Backend *be, ConfigReply *cr )
175 {
176         free( be->be_private );
177         return 0;
178 }
179
180
181 int
182 null_back_initialize( BackendInfo *bi )
183 {
184         bi->bi_open = 0;
185         bi->bi_close = 0;
186         bi->bi_config = 0;
187         bi->bi_destroy = 0;
188
189         bi->bi_db_init = null_back_db_init;
190         bi->bi_db_config = null_back_db_config;
191         bi->bi_db_open = 0;
192         bi->bi_db_close = 0;
193         bi->bi_db_destroy = null_back_db_destroy;
194
195         bi->bi_op_bind = null_back_bind;
196         bi->bi_op_unbind = 0;
197         bi->bi_op_search = null_back_success;
198         bi->bi_op_compare = null_back_false;
199         bi->bi_op_modify = null_back_success;
200         bi->bi_op_modrdn = null_back_success;
201         bi->bi_op_add = null_back_success;
202         bi->bi_op_delete = null_back_success;
203         bi->bi_op_abandon = 0;
204
205         bi->bi_extended = 0;
206
207         bi->bi_chk_referrals = 0;
208
209         bi->bi_connection_init = 0;
210         bi->bi_connection_destroy = 0;
211
212         bi->bi_entry_get_rw = null_back_entry_get;
213
214         bi->bi_tool_entry_open = null_tool_entry_open;
215         bi->bi_tool_entry_close = null_tool_entry_close;
216         bi->bi_tool_entry_first = null_tool_entry_next;
217         bi->bi_tool_entry_next = null_tool_entry_next;
218         bi->bi_tool_entry_get = null_tool_entry_get;
219         bi->bi_tool_entry_put = null_tool_entry_put;
220
221         return 0;
222 }
223
224 #if SLAPD_NULL == SLAPD_MOD_DYNAMIC
225
226 /* conditionally define the init_module() function */
227 SLAP_BACKEND_INIT_MODULE( null )
228
229 #endif /* SLAPD_NULL == SLAPD_MOD_DYNAMIC */