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