Back to index

openldap  2.4.31
pbind.c
Go to the documentation of this file.
00001 /* pbind.c - passthru Bind overlay */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2003-2012 The OpenLDAP Foundation.
00006  * Portions Copyright 2003-2010 Howard Chu.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in the file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 /* ACKNOWLEDGEMENTS:
00018  * This work was initially developed by the Howard Chu for inclusion
00019  * in OpenLDAP Software.
00020  */
00021 
00022 #include "portable.h"
00023 
00024 #include <stdio.h>
00025 
00026 #include <ac/string.h>
00027 #include <ac/socket.h>
00028 
00029 #include "lutil.h"
00030 #include "slap.h"
00031 #include "back-ldap.h"
00032 #include "config.h"
00033 
00034 static BackendInfo   *lback;
00035 
00036 static slap_overinst ldappbind;
00037 
00038 static int
00039 ldap_pbind_bind(
00040        Operation     *op,
00041        SlapReply     *rs )
00042 {
00043        slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
00044        void *private = op->o_bd->be_private;
00045        void *bi = op->o_bd->bd_info;
00046        int rc;
00047 
00048        op->o_bd->bd_info = lback;
00049        op->o_bd->be_private = on->on_bi.bi_private;
00050        rc = lback->bi_op_bind( op, rs );
00051        op->o_bd->be_private = private;
00052        op->o_bd->bd_info = bi;
00053 
00054        return rc;
00055 }
00056 
00057 static int
00058 ldap_pbind_db_init(
00059        BackendDB *be,
00060        ConfigReply *cr )
00061 {
00062        slap_overinst *on = (slap_overinst *)be->bd_info;
00063        ConfigOCs     *be_cf_ocs = be->be_cf_ocs;
00064        void          *private = be->be_private;
00065        int rc;
00066 
00067        if ( lback == NULL ) {
00068               lback = backend_info( "ldap" );
00069 
00070               if ( lback == NULL ) {
00071                      return 1;
00072               }
00073        }
00074 
00075        rc = lback->bi_db_init( be, cr );
00076        on->on_bi.bi_private = be->be_private;
00077        be->be_cf_ocs = be_cf_ocs;
00078        be->be_private = private;
00079 
00080        return rc;
00081 }
00082 
00083 static int
00084 ldap_pbind_db_open(
00085        BackendDB     *be,
00086        ConfigReply   *cr )
00087 {
00088        slap_overinst *on = (slap_overinst *) be->bd_info;
00089        void   *private = be->be_private;
00090        int           rc;
00091        int           monitoring;
00092 
00093     be->be_private = on->on_bi.bi_private;
00094        monitoring = ( SLAP_DBFLAGS( be ) & SLAP_DBFLAG_MONITORING );
00095        SLAP_DBFLAGS( be ) &= ~SLAP_DBFLAG_MONITORING;
00096        rc = lback->bi_db_open( be, cr );
00097        SLAP_DBFLAGS( be ) |= monitoring;
00098        be->be_private = private;
00099 
00100        return rc;
00101 }
00102 
00103 static int
00104 ldap_pbind_db_close(
00105        BackendDB     *be,
00106        ConfigReply   *cr )
00107 {
00108        slap_overinst *on = (slap_overinst *) be->bd_info;
00109        void   *private = be->be_private;
00110        int           rc;
00111 
00112     be->be_private = on->on_bi.bi_private;
00113        rc = lback->bi_db_close( be, cr );
00114        be->be_private = private;
00115 
00116        return rc;
00117 }
00118 
00119 static int
00120 ldap_pbind_db_destroy(
00121        BackendDB     *be,
00122        ConfigReply   *cr )
00123 {
00124        slap_overinst *on = (slap_overinst *) be->bd_info;
00125        void   *private = be->be_private;
00126        int           rc;
00127 
00128     be->be_private = on->on_bi.bi_private;
00129        rc = lback->bi_db_close( be, cr );
00130        on->on_bi.bi_private = be->be_private;
00131        be->be_private = private;
00132 
00133        return rc;
00134 }
00135 
00136 static int
00137 ldap_pbind_connection_destroy(
00138        BackendDB *be,
00139        Connection *conn
00140 )
00141 {
00142        slap_overinst *on = (slap_overinst *) be->bd_info;
00143        void                 *private = be->be_private;
00144        int                         rc;
00145 
00146        be->be_private = on->on_bi.bi_private;
00147        rc = lback->bi_connection_destroy( be, conn );
00148        be->be_private = private;
00149 
00150        return rc;
00151 }
00152 
00153 int
00154 pbind_initialize( void )
00155 {
00156        int rc;
00157 
00158        ldappbind.on_bi.bi_type = "pbind";
00159        ldappbind.on_bi.bi_db_init = ldap_pbind_db_init;
00160        ldappbind.on_bi.bi_db_open = ldap_pbind_db_open;
00161        ldappbind.on_bi.bi_db_close = ldap_pbind_db_close;
00162        ldappbind.on_bi.bi_db_destroy = ldap_pbind_db_destroy;
00163 
00164        ldappbind.on_bi.bi_op_bind = ldap_pbind_bind;
00165        ldappbind.on_bi.bi_connection_destroy = ldap_pbind_connection_destroy;
00166 
00167        rc = ldap_pbind_init_cf( &ldappbind.on_bi );
00168        if ( rc ) {
00169               return rc;
00170        }
00171 
00172        return overlay_register( &ldappbind );
00173 }