]> git.sur5r.net Git - openldap/commitdiff
slight improvements; doesn't work yet
authorPierangelo Masarati <ando@openldap.org>
Wed, 17 Mar 2004 09:25:59 +0000 (09:25 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 17 Mar 2004 09:25:59 +0000 (09:25 +0000)
servers/slapd/back-relay/config.c
servers/slapd/back-relay/init.c
servers/slapd/back-relay/op.c

index 791cd0801f0e97d615e305d8c65eb089ce644c89..a73eee0d6850b64073929c185bfa67a659c864bd 100644 (file)
@@ -50,6 +50,7 @@ relay_back_db_config(
        if ( strcasecmp( argv[0], "relay" ) == 0 ) {
                struct berval   dn, ndn, pdn;
                int             rc;
+               char            *cargv[ 4 ];
 
                if (argc != 2) {
                        fprintf( stderr,
@@ -63,7 +64,7 @@ relay_back_db_config(
                rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
                if ( rc != LDAP_SUCCESS ) {
                        fprintf( stderr, "%s: line %d: "
-                                       "relay dn '%s' is invalid\n",
+                                       "relay dn \"%s\" is invalid\n",
                                        fname, lineno, argv[ 1 ] );
                        return 1;
                }
@@ -72,11 +73,17 @@ relay_back_db_config(
                if ( ri->ri_bd == NULL ) {
                        fprintf( stderr, "%s: line %d: "
                                        "cannot find database "
-                                       "of relay dn '%s'\n",
+                                       "of relay dn \"%s\"\n",
                                        fname, lineno, argv[ 1 ] );
                        return 1;
-               }
-               
+
+               } else if ( ri->ri_bd == be ) {
+                       fprintf( stderr, "%s: line %d: "
+                                       "relay dn \"%s\" would call self\n",
+                                       fname, lineno, pdn.bv_val );
+                       return 1;
+               } 
+
                if ( overlay_config( be, "rewrite-remap" ) ) {
                        fprintf( stderr, "unable to install "
                                        "rewrite-remap overlay "
@@ -84,6 +91,16 @@ relay_back_db_config(
                                        be->be_suffix[0].bv_val,
                                        ri->ri_bd->be_suffix[0].bv_val ? 
                                        ri->ri_bd->be_suffix[0].bv_val : "<unknown>" );
+                       return 1;
+               }
+
+               cargv[ 0 ] = "suffixmassage";
+               cargv[ 1 ] = be->be_suffix[0].bv_val;
+               cargv[ 2 ] = ri->ri_bd->be_suffix[0].bv_val;
+               cargv[ 3 ] = NULL;
+
+               if ( be->be_config( be, "back-relay", 1, 3, cargv ) ) {
+                       return 1;
                }
 
        /* anything else */
index d36327578098b29eee83ee9ca971ef7e14269c4c..295b037090bcd5f6fea8b07411f964b0a128294b 100644 (file)
@@ -87,6 +87,8 @@ relay_back_db_init( Backend *be )
 {
        relay_back_info         *ri;
 
+       be->be_private = NULL;
+
        ri = (relay_back_info *)ch_calloc( 1, sizeof( relay_back_info ) );
        if ( ri == NULL ) {
                return -1;
@@ -107,8 +109,6 @@ relay_back_db_open( Backend *be )
        assert( ri != NULL );
 
 #if 0
-       be->bd_info = ri->ri_bd->bd_info;
-
        if ( !ri->ri_do_not_massage ) {
                char    *argv[ 4 ];
 
index 82d0492a56774c90225309ccc4c24cadadc78bb3..a07260432db2393fce9160221e097d50e97ecdc4 100644 (file)
@@ -36,20 +36,28 @@ relay_back_select_backend( struct slap_op *op, struct slap_rep *rs, int err )
 
        if ( bd == NULL ) {
                bd = select_backend( &op->o_req_ndn, 0, 1 );
+               if ( bd == op->o_bd ) {
+                       if ( err != LDAP_SUCCESS ) {
+                               send_ldap_error( op, rs,
+                                               LDAP_UNWILLING_TO_PERFORM, 
+                                               "would call self" );
+                       }
+                       return NULL;
+               }
        }
 
        if ( bd == NULL ) {
                if ( default_referral ) {
                        rs->sr_ref = referral_rewrite( default_referral,
                                NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
-                       if (!rs->sr_ref) {
+                       if ( !rs->sr_ref ) {
                                rs->sr_ref = default_referral;
                        }
 
                        rs->sr_err = LDAP_REFERRAL;
                        send_ldap_result( op, rs );
 
-                       if (rs->sr_ref != default_referral) {
+                       if ( rs->sr_ref != default_referral ) {
                                ber_bvarray_free( rs->sr_ref );
                        }
 
@@ -425,16 +433,12 @@ relay_back_entry_get_rw( struct slap_op *op, struct berval *ndn,
 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;
        BackendDB               *bd;
-       int                     rc = 1;
+       int                     rc = 0;
 
-       bd = ri->ri_bd;
-       if ( bd == NULL) {
-               bd = select_backend( &op->o_req_ndn, 0, 1 );
-               if ( bd == NULL ) {
-                       return 1;
-               }
+       bd = relay_back_select_backend( op, rs, LDAP_SUCCESS );
+       if ( bd == NULL ) {
+               return 0;
        }
 
        if ( bd->be_chk_referrals ) {
@@ -509,12 +513,16 @@ 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 );
+       bd = ri->ri_bd;
+       if ( bd == NULL ) {
+               return 0;
        }
 
-       return 1;
+       if ( bd->be_connection_init ) {
+               return ( bd->be_connection_init )( bd, c );
+       }
 
+       return 0;
 }
 
 int
@@ -522,11 +530,16 @@ 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 );
+       bd = ri->ri_bd;
+       if ( bd == NULL) {
+               return 0;
+       }
+
+       if ( bd->be_connection_destroy ) {
+               return ( bd->be_connection_destroy )( bd, c );
        }
 
-       return 1;
+       return 0;
 
 }