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