]> git.sur5r.net Git - openldap/blob - servers/slapd/back-null/null.c
c7ffc0eb235538172ebbb7c309800329ba65b674
[openldap] / servers / slapd / back-null / null.c
1 /* null.c - the null backend */
2 /*
3  * Copyright 2002-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10 #include <ac/string.h>
11
12 #include "slap.h"
13 #include "external.h"
14
15 struct null_info {
16         int bind_allowed;
17 };
18
19 int
20 null_back_bind( Operation *op, SlapReply *rs )
21 {
22         struct null_info *ni = (struct null_info *) op->o_bd->be_private;
23
24         if ( ni->bind_allowed ) {
25                 /* front end will send result on success (0) */
26                 return 0;
27         }
28
29         rs->sr_err = LDAP_INVALID_CREDENTIALS;
30         send_ldap_result( op, rs );
31
32         return 1;
33 }
34
35 /* add, delete, modify, modrdn, search */
36 int
37 null_back_success( Operation *op, SlapReply *rs )
38 {
39         rs->sr_err = LDAP_SUCCESS;
40         send_ldap_result( op, rs );
41         return 0;
42 }
43
44 /* compare */
45 int
46 null_back_false( Operation *op, SlapReply *rs )
47 {
48         rs->sr_err = LDAP_COMPARE_FALSE;
49         send_ldap_result( op, rs );
50         return 0;
51 }
52
53 int
54 null_back_db_config(
55         BackendDB       *be,
56         const char      *fname,
57         int                     lineno,
58         int                     argc,
59         char            **argv )
60 {
61         struct null_info *ni = (struct null_info *) be->be_private;
62
63         if ( ni == NULL ) {
64                 fprintf( stderr, "%s: line %d: null database info is null!\n",
65                         fname, lineno );
66                 return 1;
67         }
68
69         /* bind requests allowed */
70         if ( strcasecmp( argv[0], "bind" ) == 0 ) {
71                 if ( argc < 2 ) {
72                         fprintf( stderr,
73         "%s: line %d: missing <on/off> in \"bind <on/off>\" line\n",
74                                  fname, lineno );
75                         return 1;
76                 }
77                 ni->bind_allowed = strcasecmp( argv[1], "off" );
78
79         /* anything else */
80         } else {
81                 fprintf( stderr,
82 "%s: line %d: unknown directive \"%s\" in null database definition (ignored)\n",
83                          fname, lineno, argv[0] );
84         }
85
86         return 0;
87 }
88
89
90 int
91 null_back_db_init( BackendDB *be )
92 {
93         struct null_info *ni;
94
95         ni = ch_calloc( 1, sizeof(struct null_info) );
96         ni->bind_allowed = 0;
97         be->be_private = ni;
98         return 0;
99 }
100
101 int
102 null_back_db_destroy(
103     Backend     *be
104 )
105 {
106         free( be->be_private );
107         return 0;
108 }
109
110
111 int
112 null_back_initialize(
113     BackendInfo *bi
114 )
115 {
116         bi->bi_open = 0;
117         bi->bi_close = 0;
118         bi->bi_config = 0;
119         bi->bi_destroy = 0;
120
121         bi->bi_db_init = null_back_db_init;
122         bi->bi_db_config = null_back_db_config;
123         bi->bi_db_open = 0;
124         bi->bi_db_close = 0;
125         bi->bi_db_destroy = null_back_db_destroy;
126
127         bi->bi_op_bind = null_back_bind;
128         bi->bi_op_unbind = 0;
129         bi->bi_op_search = null_back_success;
130         bi->bi_op_compare = null_back_false;
131         bi->bi_op_modify = null_back_success;
132         bi->bi_op_modrdn = null_back_success;
133         bi->bi_op_add = null_back_success;
134         bi->bi_op_delete = null_back_success;
135         bi->bi_op_abandon = 0;
136
137         bi->bi_extended = 0;
138
139         bi->bi_chk_referrals = 0;
140
141         bi->bi_connection_init = 0;
142         bi->bi_connection_destroy = 0;
143
144         return 0;
145 }
146
147 #ifdef SLAPD_NULL_DYNAMIC
148 int back_null_LTX_init_module(
149         int argc,
150         char *argv[] )
151 {
152     BackendInfo bi;
153
154     memset( &bi, '\0', sizeof(bi) );
155     bi.bi_type = "null";
156     bi.bi_init = null_back_initialize;
157
158     backend_add(&bi);
159     return 0;
160 }
161 #endif /* SLAPD_NULL_DYNAMIC */