add back-relay (doesn't work yet)

This commit is contained in:
Pierangelo Masarati 2004-03-17 01:03:21 +00:00
parent e5ec72c2b9
commit ba470467af
8 changed files with 773 additions and 0 deletions

View File

@ -0,0 +1,41 @@
# Makefile.in for back-relay
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2004 The OpenLDAP Foundation.
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted only as authorized by the OpenLDAP
## Public License.
##
## A copy of this license is available in the file LICENSE in the
## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>.
SRCS = init.c config.c op.c
OBJS = init.lo config.lo op.lo
LDAP_INCDIR= ../../../include
LDAP_LIBDIR= ../../../libraries
BUILD_OPT = "--enable-relay"
BUILD_MOD = @BUILD_RELAY@
BUILD_MOD_DYNAMIC = @BUILD_RELAY_DYNAMIC@
mod_DEFS = -DSLAPD_IMPORT
MOD_DEFS = $(@BUILD_RELAY@_DEFS)
shared_LDAP_LIBS = $(LDAP_LIBLDAP_R_LA) $(LDAP_LIBLBER_LA)
NT_LINK_LIBS = -L.. -lslapd $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS) $(REWRITE)
UNIX_LINK_LIBS = $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS) $(REWRITE)
LIBBASE = back_relay
XINCPATH = -I.. -I$(srcdir)/..
XDEFS = $(MODULES_CPPFLAGS)
all-local-lib: ../.backend
../.backend: lib$(LIBBASE).a
@touch $@

View File

@ -0,0 +1,36 @@
/* back-relay.h - relay backend header file */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1999-2004 The OpenLDAP Foundation.
* Portions Copyright 2004 Pierangelo Masarati.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This work was initially developed by Pierangelo Masarati for inclusion
* in OpenLDAP Software.
*/
#ifndef SLAPD_RELAY_H
#define SLAPD_RELAY_H
#include "external.h"
/* String rewrite library */
LDAP_BEGIN_DECL
typedef struct relay_back_info {
BackendDB *ri_bd;
} relay_back_info;
LDAP_END_DECL
#endif /* SLAPD_RELAY_H */

View File

@ -0,0 +1,96 @@
/* config.c - relay backend configuration file routine */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2003-2004 The OpenLDAP Foundation.
* Portions Copyright 2004 Pierangelo Masarati.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This work was initially developed by Pierangelo Masaratifor inclusion
* in OpenLDAP Software.
*/
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include <ac/socket.h>
#include "slap.h"
#include "back-relay.h"
#include "lutil.h"
int
relay_back_db_config(
BackendDB *be,
const char *fname,
int lineno,
int argc,
char **argv
)
{
relay_back_info *ri = (struct relay_back_info *)be->be_private;
if ( ri == NULL ) {
fprintf( stderr, "%s: line %d: relay backend info is null!\n",
fname, lineno );
return( 1 );
}
/* real naming context */
if ( strcasecmp( argv[0], "relay" ) == 0 ) {
struct berval dn, ndn, pdn;
int rc;
if (argc != 2) {
fprintf( stderr,
"%s: line %d: missing relay suffix in \"relay <dn>\" line\n",
fname, lineno );
return( 1 );
}
dn.bv_val = argv[ 1 ];
dn.bv_len = strlen( argv[ 1 ] );
rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: line %d: "
"relay dn '%s' is invalid\n",
fname, lineno, argv[ 1 ] );
return 1;
}
ri->ri_bd = select_backend( &ndn, 0, 1 );
if ( ri->ri_bd == NULL ) {
fprintf( stderr, "%s: line %d: "
"cannot find database "
"of relay dn '%s'\n",
fname, lineno, argv[ 1 ] );
return 1;
}
if ( overlay_config( be, "rewrite-remap" ) ) {
fprintf( stderr, "unable to install "
"rewrite-remap overlay "
"in back-relay \"%s\" => \"%s\"\n",
be->be_suffix[0].bv_val,
ri->ri_bd->be_suffix[0].bv_val ?
ri->ri_bd->be_suffix[0].bv_val : "<unknown>" );
}
/* anything else */
} else {
return SLAP_CONF_UNKNOWN;
}
return 0;
}

View File

@ -0,0 +1,76 @@
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2001-2004 The OpenLDAP Foundation.
* Portions Copyright 2004 Pierangelo Masarati.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This work was initially developed by Pierangelo Masarati for inclusion
* in OpenLDAP Software.
*/
#ifndef RELAY_EXTERNAL_H
#define RELAY_EXTERNAL_H
LDAP_BEGIN_DECL
extern BI_init relay_back_initialize;
#if 0
extern BI_config relay_back_config;
extern BI_open relay_back_open;
extern BI_close relay_back_close;
extern BI_destroy relay_back_destroy;
#endif
extern BI_db_init relay_back_db_init;
extern BI_db_config relay_back_db_config;
extern BI_db_open relay_back_db_open;
extern BI_db_close relay_back_db_close;
extern BI_db_destroy relay_back_db_destroy;
extern BI_op_bind relay_back_op_bind;
extern BI_op_unbind relay_back_op_unbind;
extern BI_op_search relay_back_op_search;
extern BI_op_compare relay_back_op_compare;
extern BI_op_modify relay_back_op_modify;
extern BI_op_modrdn relay_back_op_modrdn;
extern BI_op_add relay_back_op_add;
extern BI_op_delete relay_back_op_delete;
extern BI_op_abandon relay_back_op_abandon;
extern BI_op_cancel relay_back_op_cancel;
extern BI_op_extended relay_back_op_extended;
extern BI_entry_release_rw relay_back_entry_release_rw;
extern BI_entry_get_rw relay_back_entry_get_rw;
extern BI_chk_referrals relay_back_chk_referrals;
extern BI_operational relay_back_operational;
extern BI_has_subordinates relay_back_has_subordinates;
extern BI_connection_init relay_back_connection_init;
extern BI_connection_destroy relay_back_connection_destroy;
#if 0
extern BI_tool_entry_open relay_back_tool_entry_open;
extern BI_tool_entry_close relay_back_tool_entry_close;
extern BI_tool_entry_first relay_back_tool_entry_first;
extern BI_tool_entry_next relay_back_tool_entry_next;
extern BI_tool_entry_get relay_back_tool_entry_get;
extern BI_tool_entry_put relay_back_tool_entry_put;
extern BI_tool_entry_reindex relay_back_tool_entry_reindex;
extern BI_tool_sync relay_back_tool_sync;
extern BI_tool_dn2id_get relay_back_tool_dn2id_get;
extern BI_tool_id2entry_get relay_back_tool_id2entry_get;
extern BI_tool_entry_modify relay_back_tool_entry_modify;
#endif
LDAP_END_DECL
#endif /* _MONITOR_EXTERNAL_H */

View File

@ -0,0 +1,145 @@
/* init.c - initialize relay backend */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2003-2004 The OpenLDAP Foundation.
* Portions Copyright 2004 Pierangelo Masarati.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This work was initially developed by Pierangelo Masarati for inclusion
* in OpenLDAP Software.
*/
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include <ac/socket.h>
#include "slap.h"
#include "back-relay.h"
#ifdef SLAPD_RELAY_DYNAMIC
int
init_module( int argc, char *argv[] ) {
BackendInfo bi;
memset( &bi, '\0', sizeof( bi ) );
bi.bi_type = "relay";
bi.bi_init = relay_back_initialize;
backend_add(&bi);
return 0;
}
#endif /* SLAPD_RELAY_DYNAMIC */
int
relay_back_initialize( BackendInfo *bi )
{
bi->bi_init = 0;
bi->bi_open = 0;
bi->bi_config = 0;
bi->bi_close = 0;
bi->bi_destroy = 0;
bi->bi_db_init = relay_back_db_init;
bi->bi_db_config = relay_back_db_config;
bi->bi_db_open = relay_back_db_open;
bi->bi_db_close = 0 /* relay_back_db_close */ ;
bi->bi_db_destroy = relay_back_db_destroy;
bi->bi_op_bind = relay_back_op_bind;
bi->bi_op_unbind = relay_back_op_unbind;
bi->bi_op_search = relay_back_op_search;
bi->bi_op_compare = relay_back_op_compare;
bi->bi_op_modify = relay_back_op_modify;
bi->bi_op_modrdn = relay_back_op_modrdn;
bi->bi_op_add = relay_back_op_add;
bi->bi_op_delete = relay_back_op_delete;
bi->bi_op_abandon = relay_back_op_abandon;
bi->bi_op_cancel = relay_back_op_cancel;
bi->bi_extended = relay_back_op_extended;
bi->bi_entry_release_rw = relay_back_entry_release_rw;
bi->bi_entry_get_rw = relay_back_entry_get_rw;
bi->bi_chk_referrals = relay_back_chk_referrals;
bi->bi_operational = relay_back_operational;
bi->bi_has_subordinates = relay_back_has_subordinates;
bi->bi_connection_init = relay_back_connection_init;
bi->bi_connection_destroy = relay_back_connection_destroy;
return 0;
}
int
relay_back_db_init( Backend *be )
{
relay_back_info *ri;
ri = (relay_back_info *)ch_calloc( 1, sizeof( relay_back_info ) );
if ( ri == NULL ) {
return -1;
}
ri->ri_bd = NULL;
be->be_private = (void *)ri;
return 0;
}
int
relay_back_db_open( Backend *be )
{
relay_back_info *ri = (relay_back_info *)be->be_private;
assert( ri != NULL );
#if 0
be->bd_info = ri->ri_bd->bd_info;
if ( !ri->ri_do_not_massage ) {
char *argv[ 4 ];
argv[ 0 ] = "suffixmassage";
argv[ 1 ] = be->be_suffix[0].bv_val;
argv[ 2 ] = ri->ri_bd->be_suffix[0].bv_val;
argv[ 3 ] = NULL;
if ( be->be_config( be, "back-relay", 1, 3, argv ) ) {
return 1;
}
}
#endif
return 0;
}
int
relay_back_db_close( Backend *be )
{
return 0;
}
int
relay_back_db_destroy( Backend *be )
{
relay_back_info *ri = (relay_back_info *)be->be_private;
if ( ri ) {
ch_free( ri );
}
return 0;
}

View File

@ -0,0 +1,341 @@
/* op.c - relay backend operations */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2003-2004 The OpenLDAP Foundation.
* Portions Copyright 2004 Pierangelo Masarati.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This work was initially developed by Pierangelo Masarati for inclusion
* in OpenLDAP Software.
*/
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include <ac/socket.h>
#include "slap.h"
#include "back-relay.h"
int
relay_back_op_bind( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_bind ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_bind )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_op_unbind( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_unbind ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_unbind )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_op_search( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_search ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_search )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_op_compare( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_compare ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_compare )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_op_modify( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_modify ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_modify )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_op_modrdn( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_modrdn ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_modrdn )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_op_add( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_add ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_add )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_op_delete( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_delete ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_delete )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_op_abandon( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_abandon ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_abandon )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_op_cancel( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_cancel ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_cancel )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_op_extended( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_extended ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_extended )( op, rs );
op->o_bd = be;
}
return rc;
}
int
relay_back_entry_release_rw( struct slap_op *op, Entry *e, int rw )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_release ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_release )( op, e, rw );
op->o_bd = be;
}
return rc;
}
int
relay_back_entry_get_rw( struct slap_op *op, struct berval *ndn,
ObjectClass *oc, AttributeDescription *at, int rw, Entry **e )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_fetch ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_fetch )( op, ndn, oc, at, rw, e );
op->o_bd = be;
}
return rc;
}
int relay_back_chk_referrals( struct slap_op *op, struct slap_rep *rs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_chk_referrals ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_chk_referrals )( op, rs );
op->o_bd = be;
}
return rc;
}
int relay_back_operational( struct slap_op *op, struct slap_rep *rs, int opattrs, Attribute **ap )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_operational ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_operational )( op, rs, opattrs, ap );
op->o_bd = be;
}
return rc;
}
int relay_back_has_subordinates( struct slap_op *op, Entry *e, int *hasSubs )
{
relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
int rc = 1;
if ( ri->ri_bd->be_has_subordinates ) {
BackendDB *be = op->o_bd;
op->o_bd = ri->ri_bd;
rc = ( ri->ri_bd->be_has_subordinates )( op, e, hasSubs );
op->o_bd = be;
}
return rc;
}
int
relay_back_connection_init( BackendDB *bd, struct slap_conn *c )
{
relay_back_info *ri = (relay_back_info *)bd->be_private;
if ( ri->ri_bd->be_connection_init ) {
return ( ri->ri_bd->be_connection_init )( ri->ri_bd, c );
}
return 1;
}
int
relay_back_connection_destroy( BackendDB *bd, struct slap_conn *c )
{
relay_back_info *ri = (relay_back_info *)bd->be_private;
if ( ri->ri_bd->be_connection_destroy ) {
return ( ri->ri_bd->be_connection_destroy )( ri->ri_bd, c );
}
return 1;
}

View File

@ -0,0 +1,32 @@
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2001-2004 The OpenLDAP Foundation.
* Portions Copyright 2004 Pierangelo Masarati.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This work was initially developed by Pierangelo Masarati for inclusion
* in OpenLDAP Software.
*/
#ifndef PROTO_BACK_RELAY
#define PROTO_BACK_RELAY
#include <ldap_cdefs.h>
#include "external.h"
LDAP_BEGIN_DECL
LDAP_END_DECL
#endif /* PROTO_BACK_RELAY */

View File

@ -81,6 +81,9 @@
#if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC)
#include "back-perl/external.h"
#endif
#if defined(SLAPD_RELAY) && !defined(SLAPD_RELAY_DYNAMIC)
#include "back-relay/external.h"
#endif
#if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC)
#include "back-shell/external.h"
#endif
@ -125,6 +128,9 @@ static BackendInfo binfo[] = {
#if defined(SLAPD_PERL) && !defined(SLAPD_PERL_DYNAMIC)
{"perl", perl_back_initialize},
#endif
#if defined(SLAPD_RELAY) && !defined(SLAPD_RELAY_DYNAMIC)
{"relay", relay_back_initialize},
#endif
#if defined(SLAPD_SHELL) && !defined(SLAPD_SHELL_DYNAMIC)
{"shell", shell_back_initialize},
#endif