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