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