]> git.sur5r.net Git - openldap/blob - servers/slapd/back-null/null.c
Fix prev commit, return generated passwd
[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-2003 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                 fprintf( stderr,
96 "%s: line %d: unknown directive \"%s\" in null database definition (ignored)\n",
97                          fname, lineno, argv[0] );
98         }
99
100         return 0;
101 }
102
103
104 int
105 null_back_db_init( BackendDB *be )
106 {
107         struct null_info *ni;
108
109         ni = ch_calloc( 1, sizeof(struct null_info) );
110         ni->bind_allowed = 0;
111         be->be_private = ni;
112         return 0;
113 }
114
115 int
116 null_back_db_destroy(
117     Backend     *be
118 )
119 {
120         free( be->be_private );
121         return 0;
122 }
123
124
125 int
126 null_back_initialize(
127     BackendInfo *bi
128 )
129 {
130         bi->bi_open = 0;
131         bi->bi_close = 0;
132         bi->bi_config = 0;
133         bi->bi_destroy = 0;
134
135         bi->bi_db_init = null_back_db_init;
136         bi->bi_db_config = null_back_db_config;
137         bi->bi_db_open = 0;
138         bi->bi_db_close = 0;
139         bi->bi_db_destroy = null_back_db_destroy;
140
141         bi->bi_op_bind = null_back_bind;
142         bi->bi_op_unbind = 0;
143         bi->bi_op_search = null_back_success;
144         bi->bi_op_compare = null_back_false;
145         bi->bi_op_modify = null_back_success;
146         bi->bi_op_modrdn = null_back_success;
147         bi->bi_op_add = null_back_success;
148         bi->bi_op_delete = null_back_success;
149         bi->bi_op_abandon = 0;
150
151         bi->bi_extended = 0;
152
153         bi->bi_chk_referrals = 0;
154
155         bi->bi_connection_init = 0;
156         bi->bi_connection_destroy = 0;
157
158         return 0;
159 }
160
161 #ifdef SLAPD_NULL_DYNAMIC
162 int back_null_LTX_init_module(
163         int argc,
164         char *argv[] )
165 {
166     BackendInfo bi;
167
168     memset( &bi, '\0', sizeof(bi) );
169     bi.bi_type = "null";
170     bi.bi_init = null_back_initialize;
171
172     backend_add(&bi);
173     return 0;
174 }
175 #endif /* SLAPD_NULL_DYNAMIC */