1 /* pbind.c - passthru Bind overlay */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 *
5 * Copyright 2003-2021 The OpenLDAP Foundation.
6 * Portions Copyright 2003-2010 Howard Chu.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
11 * Public License.
12 *
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
16 */
17 /* ACKNOWLEDGEMENTS:
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software.
20 */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25
26 #include <ac/string.h>
27 #include <ac/socket.h>
28
29 #include "lutil.h"
30 #include "slap.h"
31 #include "back-ldap.h"
32 #include "config.h"
33
34 static BackendInfo *lback;
35
36 static slap_overinst ldappbind;
37
38 static int
ldap_pbind_bind(Operation * op,SlapReply * rs)39 ldap_pbind_bind(
40 Operation *op,
41 SlapReply *rs )
42 {
43 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
44 void *private = op->o_bd->be_private;
45 void *bi = op->o_bd->bd_info;
46 int rc;
47
48 op->o_bd->bd_info = lback;
49 op->o_bd->be_private = on->on_bi.bi_private;
50 rc = lback->bi_op_bind( op, rs );
51 op->o_bd->be_private = private;
52 op->o_bd->bd_info = bi;
53
54 return rc;
55 }
56
57 static int
ldap_pbind_db_init(BackendDB * be,ConfigReply * cr)58 ldap_pbind_db_init(
59 BackendDB *be,
60 ConfigReply *cr )
61 {
62 slap_overinst *on = (slap_overinst *)be->bd_info;
63 ConfigOCs *be_cf_ocs = be->be_cf_ocs;
64 void *private = be->be_private;
65 int rc;
66
67 if ( lback == NULL ) {
68 lback = backend_info( "ldap" );
69
70 if ( lback == NULL ) {
71 return 1;
72 }
73 }
74
75 rc = lback->bi_db_init( be, cr );
76 on->on_bi.bi_private = be->be_private;
77 be->be_cf_ocs = be_cf_ocs;
78 be->be_private = private;
79
80 return rc;
81 }
82
83 static int
ldap_pbind_db_open(BackendDB * be,ConfigReply * cr)84 ldap_pbind_db_open(
85 BackendDB *be,
86 ConfigReply *cr )
87 {
88 slap_overinst *on = (slap_overinst *) be->bd_info;
89 void *private = be->be_private;
90 int rc;
91 int monitoring;
92
93 be->be_private = on->on_bi.bi_private;
94 monitoring = ( SLAP_DBFLAGS( be ) & SLAP_DBFLAG_MONITORING );
95 SLAP_DBFLAGS( be ) &= ~SLAP_DBFLAG_MONITORING;
96 rc = lback->bi_db_open( be, cr );
97 SLAP_DBFLAGS( be ) |= monitoring;
98 be->be_private = private;
99
100 return rc;
101 }
102
103 static int
ldap_pbind_db_close(BackendDB * be,ConfigReply * cr)104 ldap_pbind_db_close(
105 BackendDB *be,
106 ConfigReply *cr )
107 {
108 slap_overinst *on = (slap_overinst *) be->bd_info;
109 void *private = be->be_private;
110 int rc;
111
112 be->be_private = on->on_bi.bi_private;
113 rc = lback->bi_db_close( be, cr );
114 be->be_private = private;
115
116 return rc;
117 }
118
119 static int
ldap_pbind_db_destroy(BackendDB * be,ConfigReply * cr)120 ldap_pbind_db_destroy(
121 BackendDB *be,
122 ConfigReply *cr )
123 {
124 slap_overinst *on = (slap_overinst *) be->bd_info;
125 void *private = be->be_private;
126 int rc;
127
128 be->be_private = on->on_bi.bi_private;
129 rc = lback->bi_db_close( be, cr );
130 on->on_bi.bi_private = be->be_private;
131 be->be_private = private;
132
133 return rc;
134 }
135
136 static int
ldap_pbind_connection_destroy(BackendDB * be,Connection * conn)137 ldap_pbind_connection_destroy(
138 BackendDB *be,
139 Connection *conn
140 )
141 {
142 slap_overinst *on = (slap_overinst *) be->bd_info;
143 void *private = be->be_private;
144 int rc;
145
146 be->be_private = on->on_bi.bi_private;
147 rc = lback->bi_connection_destroy( be, conn );
148 be->be_private = private;
149
150 return rc;
151 }
152
153 int
pbind_initialize(void)154 pbind_initialize( void )
155 {
156 int rc;
157
158 ldappbind.on_bi.bi_type = "pbind";
159 ldappbind.on_bi.bi_db_init = ldap_pbind_db_init;
160 ldappbind.on_bi.bi_db_open = ldap_pbind_db_open;
161 ldappbind.on_bi.bi_db_close = ldap_pbind_db_close;
162 ldappbind.on_bi.bi_db_destroy = ldap_pbind_db_destroy;
163
164 ldappbind.on_bi.bi_op_bind = ldap_pbind_bind;
165 ldappbind.on_bi.bi_connection_destroy = ldap_pbind_connection_destroy;
166
167 rc = ldap_pbind_init_cf( &ldappbind.on_bi );
168 if ( rc ) {
169 return rc;
170 }
171
172 return overlay_register( &ldappbind );
173 }
174