]> git.sur5r.net Git - openldap/blob - servers/slapd/back-null/null.c
Fix ITS#3424
[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-2004 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 Howard Chu 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 /*
29  * former external.h
30  */
31
32 extern BI_init                  null_back_initialize;
33
34 extern BI_db_init               null_back_db_init;
35 extern BI_db_destroy            null_back_db_destroy;
36 extern BI_db_config             null_back_db_config;
37
38 extern BI_op_bind               null_back_bind;
39 extern BI_op_search             null_back_search;
40 extern BI_op_compare            null_back_compare;
41 extern BI_op_modify             null_back_modify;
42 extern BI_op_modrdn             null_back_modrdn;
43 extern BI_op_add                null_back_add;
44 extern BI_op_delete             null_back_delete;
45
46 struct null_info {
47         int bind_allowed;
48 };
49
50 int
51 null_back_bind( Operation *op, SlapReply *rs )
52 {
53         struct null_info *ni = (struct null_info *) op->o_bd->be_private;
54
55         if ( ni->bind_allowed ) {
56                 /* front end will send result on success (0) */
57                 return 0;
58         }
59
60         rs->sr_err = LDAP_INVALID_CREDENTIALS;
61         send_ldap_result( op, rs );
62
63         return 1;
64 }
65
66 /* add, delete, modify, modrdn, search */
67 int
68 null_back_success( Operation *op, SlapReply *rs )
69 {
70         rs->sr_err = LDAP_SUCCESS;
71         send_ldap_result( op, rs );
72         return 0;
73 }
74
75 /* compare */
76 int
77 null_back_false( Operation *op, SlapReply *rs )
78 {
79         rs->sr_err = LDAP_COMPARE_FALSE;
80         send_ldap_result( op, rs );
81         return 0;
82 }
83
84 int
85 null_back_db_config(
86         BackendDB       *be,
87         const char      *fname,
88         int                     lineno,
89         int                     argc,
90         char            **argv )
91 {
92         struct null_info *ni = (struct null_info *) be->be_private;
93
94         if ( ni == NULL ) {
95                 fprintf( stderr, "%s: line %d: null database info is null!\n",
96                         fname, lineno );
97                 return 1;
98         }
99
100         /* bind requests allowed */
101         if ( strcasecmp( argv[0], "bind" ) == 0 ) {
102                 if ( argc < 2 ) {
103                         fprintf( stderr,
104         "%s: line %d: missing <on/off> in \"bind <on/off>\" line\n",
105                                  fname, lineno );
106                         return 1;
107                 }
108                 ni->bind_allowed = strcasecmp( argv[1], "off" );
109
110         /* anything else */
111         } else {
112                 return SLAP_CONF_UNKNOWN;
113         }
114
115         return 0;
116 }
117
118
119 int
120 null_back_db_init( BackendDB *be )
121 {
122         struct null_info *ni;
123
124         ni = ch_calloc( 1, sizeof(struct null_info) );
125         ni->bind_allowed = 0;
126         be->be_private = ni;
127         return 0;
128 }
129
130 int
131 null_back_db_destroy(
132     Backend     *be
133 )
134 {
135         free( be->be_private );
136         return 0;
137 }
138
139
140 int
141 null_back_initialize(
142     BackendInfo *bi
143 )
144 {
145         bi->bi_open = 0;
146         bi->bi_close = 0;
147         bi->bi_config = 0;
148         bi->bi_destroy = 0;
149
150         bi->bi_db_init = null_back_db_init;
151         bi->bi_db_config = null_back_db_config;
152         bi->bi_db_open = 0;
153         bi->bi_db_close = 0;
154         bi->bi_db_destroy = null_back_db_destroy;
155
156         bi->bi_op_bind = null_back_bind;
157         bi->bi_op_unbind = 0;
158         bi->bi_op_search = null_back_success;
159         bi->bi_op_compare = null_back_false;
160         bi->bi_op_modify = null_back_success;
161         bi->bi_op_modrdn = null_back_success;
162         bi->bi_op_add = null_back_success;
163         bi->bi_op_delete = null_back_success;
164         bi->bi_op_abandon = 0;
165
166         bi->bi_extended = 0;
167
168         bi->bi_chk_referrals = 0;
169
170         bi->bi_connection_init = 0;
171         bi->bi_connection_destroy = 0;
172
173         return 0;
174 }
175
176 #if SLAPD_NULL == SLAPD_MOD_DYNAMIC
177
178 /* conditionally define the init_module() function */
179 SLAP_BACKEND_INIT_MODULE( null )
180
181 #endif /* SLAPD_NULL == SLAPD_MOD_DYNAMIC */