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