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