]> git.sur5r.net Git - openldap/commitdiff
Rework referral entry point with DNS SRV implementation (needs testing).
authorKurt Zeilenga <kurt@openldap.org>
Fri, 16 Jun 2000 03:50:02 +0000 (03:50 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 16 Jun 2000 03:50:02 +0000 (03:50 +0000)
15 files changed:
servers/slapd/add.c
servers/slapd/back-dnssrv/Makefile.in
servers/slapd/back-dnssrv/bind.c
servers/slapd/back-dnssrv/config.c
servers/slapd/back-dnssrv/external.h
servers/slapd/back-dnssrv/init.c
servers/slapd/back-dnssrv/search.c
servers/slapd/backend.c
servers/slapd/compare.c
servers/slapd/delete.c
servers/slapd/modify.c
servers/slapd/modrdn.c
servers/slapd/proto-slap.h
servers/slapd/search.c
servers/slapd/slap.h

index 3db0bf9d025af996c7e6a8bf04ab70cf98748a2b..c0b93363ceb242fb7f03b5660d798174969e0938 100644 (file)
@@ -44,7 +44,6 @@ do_add( Connection *conn, Operation *op )
        Modifications *mods = NULL;
        const char *text;
        int                     rc = LDAP_SUCCESS;
-       struct berval **urls = NULL;
 
        Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
 
@@ -157,6 +156,7 @@ do_add( Connection *conn, Operation *op )
 
        /* make sure this backend recongizes critical controls */
        rc = backend_check_controls( be, conn, op, &text ) ;
+
        if( rc != LDAP_SUCCESS ) {
                send_ldap_result( conn, op, rc,
                        NULL, text, NULL, NULL );
@@ -164,11 +164,10 @@ do_add( Connection *conn, Operation *op )
        }
 
        /* check for referrals */
-       rc = backend_check_referrals( be, conn, op, &urls, &text );
+       rc = backend_check_referrals( be, conn, op,
+               e->e_dn, e->e_ndn, &text );
+
        if ( rc != LDAP_SUCCESS ) {
-               send_ldap_result( conn, op, rc,
-                       NULL, text, urls, NULL );
-               ber_bvecfree( urls );
                goto done;
        }
 
index 8849ce38a0e9aa2335aaa44ec5696465271f779b..9d01c5a57be20a167e305b2864d34c345d1bf1dd 100644 (file)
 # DNSSRV backend written by Kurt Zeilenga
 ##########################################################################
 
-SRCS   = init.c bind.c search.c config.c compare.c \
-               modify.c add.c modrdn.c delete.c request.c
-OBJS   = init.lo bind.lo search.lo config.lo compare.lo \
-               modify.lo add.lo modrdn.lo delete.lo request.lo
+SRCS   = init.c bind.c search.c config.c referral.c
+OBJS   = init.lo bind.lo search.lo config.lo referral.lo
 
 LDAP_INCDIR= ../../../include       
 LDAP_LIBDIR= ../../../libraries
index 4739746a2e287e0da6c376341221928cfddac236..0dca311c896bac84d4451bf28a2e8a7c1dc33258 100644 (file)
@@ -14,7 +14,7 @@
 #include <ac/string.h>
 
 #include "slap.h"
-#include "back-dnssrv.h"
+#include "external.h"
 
 int
 dnssrv_back_bind(
index 5aaa66f558e0eaa9f1884f8ad68bbb0a8992c7c7..99dad353af788463dfd9ea49a67e742f7bf7f119 100644 (file)
@@ -13,7 +13,7 @@
 #include <ac/socket.h>
 
 #include "slap.h"
-#include "back-dnssrv.h"
+#include "external.h"
 
 int
 dnssrv_back_db_config(
index 3358a30827d2cec21aec360fe43e1f63cc689cc4..dfa4cc5c62671d81733d3061003b29afdb25b731 100644 (file)
@@ -39,23 +39,10 @@ extern int  dnssrv_back_compare LDAP_P((BackendDB *bd,
        Connection *conn, Operation *op,
        const char *dn, const char *ndn, AttributeAssertion *ava ));
 
-extern int     dnssrv_back_modify LDAP_P(( BackendDB *bd,
+extern int     dnssrv_back_referrals LDAP_P(( BackendDB *bd,
        Connection *conn, Operation *op,
        const char *dn, const char *ndn,
-       Modifications *ml ));
-
-extern int     dnssrv_back_modrdn LDAP_P(( BackendDB *bd,
-       Connection *conn, Operation *op,
-       const char *dn, const char *ndn,
-       const char *newrdn, int deleteoldrdn,
-       const char *newSuperior ));
-
-extern int     dnssrv_back_add LDAP_P(( BackendDB *bd,
-       Connection *conn, Operation *op, Entry *e ));
-
-extern int     dnssrv_back_delete LDAP_P(( BackendDB *bd,
-       Connection *conn, Operation *op,
-       const char *dn, const char *ndn ));
+       const char **text ));
 
 LDAP_END_DECL
 
index 46f2b162dabe93e02ba7d45b8993bd490b1b01e8..b75cced1b60512eab5f5bc002b675dd8e15af097 100644 (file)
@@ -12,7 +12,7 @@
 #include <ac/socket.h>
 
 #include "slap.h"
-#include "back-dnssrv.h"
+#include "external.h"
 
 #ifdef SLAPD_DNSSRV_DYNAMIC
 
@@ -56,16 +56,16 @@ dnssrv_back_initialize(
        bi->bi_op_unbind = 0;
        bi->bi_op_search = dnssrv_back_search;
        bi->bi_op_compare = dnssrv_back_compare;
-       bi->bi_op_modify = dnssrv_back_modify;
-       bi->bi_op_modrdn = dnssrv_back_modrdn;
-       bi->bi_op_add = dnssrv_back_add;
-       bi->bi_op_delete = dnssrv_back_delete;
+       bi->bi_op_modify = 0;
+       bi->bi_op_modrdn = 0;
+       bi->bi_op_add = 0;
+       bi->bi_op_delete = 0;
        bi->bi_op_abandon = 0;
 
        bi->bi_extended = 0;
 
        bi->bi_acl_group = 0;
-       bi->bi_chk_referrals = 0;
+       bi->bi_chk_referrals = dnssrv_back_referrals;
 
 #ifdef HAVE_CYRUS_SASL
        bi->bi_sasl_authorize = 0;
index d9dea2e3ed8fab39fa6a2f252058302ee63f5389..6658191cc8efb9ca58c21ed64a771c8699ef1127 100644 (file)
@@ -15,7 +15,7 @@
 #include <ac/time.h>
 
 #include "slap.h"
-#include "back-dnssrv.h"
+#include "external.h"
 
 int
 dnssrv_back_search(
@@ -31,9 +31,191 @@ dnssrv_back_search(
     Filter     *filter,
     const char *filterstr,
     char       **attrs,
-    int                attrsonly
-)
+    int                attrsonly )
 {
-       return dnssrv_back_request( be, conn, op, dn, ndn,
-               scope, filter, attrs, attrsonly );
+       int i;
+       int rc;
+       char *domain = NULL;
+       char *hostlist = NULL;
+       char **hosts = NULL;
+       char *refdn, *nrefdn;
+       struct berval **urls = NULL;
+
+       assert( get_manageDSAit( op ) );
+
+       if( ldap_dn2domain( dn, &domain ) ) {
+               send_ldap_result( conn, op, LDAP_REFERRAL,
+                       NULL, NULL, default_referral, NULL );
+               goto done;
+       }
+
+       Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> domain=\"%s\"\n",
+               dn == NULL ? "" : dn,
+               domain == NULL ? "" : domain,
+               0 );
+
+       if( rc = ldap_domain2hostlist( domain, &hostlist ) ) {
+               Debug( LDAP_DEBUG_TRACE, "DNSSRV: domain2hostlist returned %d\n",
+                       rc, 0, 0 );
+               send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
+                       NULL, "no DNS SRV RR available for DN", NULL, NULL );
+               goto done;
+       }
+
+       hosts = str2charray( hostlist, " " );
+
+       if( hosts == NULL ) {
+               Debug( LDAP_DEBUG_TRACE, "DNSSRV: str2charrary error\n", 0, 0, 0 );
+               send_ldap_result( conn, op, LDAP_OTHER,
+                       NULL, "problem processing DNS SRV records for DN", NULL, NULL );
+               goto done;
+       }
+
+       for( i=0; hosts[i] != NULL; i++) {
+               struct berval *url = ch_malloc( sizeof( struct berval ) ); 
+
+               url->bv_len = sizeof("ldap://")-1 + strlen(hosts[i]);
+               url->bv_val = ch_malloc( url->bv_len + 1 );
+
+               strcpy( url->bv_val, "ldap://" );
+               strcpy( &url->bv_val[sizeof("ldap://")-1], hosts[i] );
+
+               if( ber_bvecadd( &urls, url ) < 0 ) {
+                       ber_bvfree( url );
+                       send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "problem processing DNS SRV records for DN",
+                               NULL, NULL );
+                       goto done;
+               }
+       }
+
+       Statslog( LDAP_DEBUG_STATS,
+           "conn=%ld op=%d DNSSRV p=%d dn=\"%s\" url=\"%s\"\n",
+           op->o_connid, op->o_opid, op->o_protocol, dn, urls[0]->bv_val );
+
+       Debug( LDAP_DEBUG_TRACE, "DNSSRV: ManageDSAit dn=\"%s\" -> url=\"%s\"\n",
+               dn == NULL ? "" : dn,
+               urls[0]->bv_val, 0 );
+
+       rc = ldap_domain2dn(domain, &refdn);
+
+       if( rc != LDAP_SUCCESS ) {
+               send_ldap_result( conn, op, LDAP_OTHER,
+                       NULL, "DNS SRV problem processing manageDSAit control",
+                       NULL, NULL );
+               goto done;
+       }
+
+       nrefdn = ch_strdup( refdn );
+       dn_normalize(nrefdn);
+
+       if( strcmp( nrefdn, ndn ) != 0 ) {
+               /* requested dn is subordinate */
+
+               Debug( LDAP_DEBUG_TRACE,
+                               "DNSSRV: dn=\"%s\" subordindate to refdn=\"%s\"\n",
+                               dn == NULL ? "" : dn,
+                               refdn == NULL ? "" : refdn,
+                               NULL );
+
+               send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
+                       refdn, NULL,
+                       NULL, NULL );
+
+       } else if ( scope == LDAP_SCOPE_ONELEVEL ) {
+               send_ldap_result( conn, op, LDAP_SUCCESS,
+                       NULL, NULL, NULL, NULL );
+
+       } else {
+               struct berval   val;
+               struct berval   *vals[2];
+               Entry *e = ch_calloc( 1, sizeof(Entry) );
+               AttributeDescription *ad_objectClass
+                       = slap_schema.si_ad_objectClass;
+               AttributeDescription *ad_ref = slap_schema.si_ad_ref;
+               e->e_dn = strdup( dn );
+               e->e_ndn = strdup( ndn );
+
+               e->e_attrs = NULL;
+               e->e_private = NULL;
+
+               vals[0] = &val;
+               vals[1] = NULL;
+
+               val.bv_val = "top";
+               val.bv_len = sizeof("top")-1;
+               attr_merge( e, ad_objectClass, vals );
+
+               val.bv_val = "referral";
+               val.bv_len = sizeof("referral")-1;
+               attr_merge( e, ad_objectClass, vals );
+
+               val.bv_val = "extensibleObject";
+               val.bv_len = sizeof("extensibleObject")-1;
+               attr_merge( e, ad_objectClass, vals );
+
+               {
+                       AttributeDescription *ad = NULL;
+                       const char *text;
+
+                       rc = slap_str2ad( "dc", &ad, &text );
+
+                       if( rc == LDAP_SUCCESS ) {
+                               char *p;
+                               val.bv_val = ch_strdup( domain );
+
+                               p = strchr( val.bv_val, '.' );
+                                       
+                               if( p == val.bv_val ) {
+                                       val.bv_val[1] = '\0';
+                               } else if ( p != NULL ) {
+                                       *p = '\0';
+                               }
+
+                               val.bv_len = strlen(val.bv_val);
+                               attr_merge( e, ad, vals );
+
+                               ad_free( ad, 1 );
+                       }
+               }
+
+               {
+                       AttributeDescription *ad = NULL;
+                       const char *text;
+
+                       rc = slap_str2ad( "associatedDomain", &ad, &text );
+
+                       if( rc == LDAP_SUCCESS ) {
+                               val.bv_val = domain;
+                               val.bv_len = strlen(domain);
+                               attr_merge( e, ad, vals );
+
+                               ad_free( ad, 1 );
+                       }
+               }
+
+               attr_merge( e, ad_ref, urls );
+
+               rc = test_filter( be, conn, op, e, filter ); 
+
+               if( rc == LDAP_COMPARE_TRUE ) {
+                       send_search_entry( be, conn, op,
+                               e, attrs, attrsonly, NULL );
+               }
+
+               entry_free( e );
+                       
+               send_ldap_result( conn, op, LDAP_SUCCESS,
+                       NULL, NULL, NULL, NULL );
+       }
+
+       free( refdn );
+       free( nrefdn );
+
+done:
+       if( domain != NULL ) ch_free( domain );
+       if( hostlist != NULL ) ch_free( hostlist );
+       if( hosts != NULL ) charray_free( hosts );
+       if( urls != NULL ) ber_bvecfree( urls );
+       return 0;
 }
index d9023d509cb880a60dfb37adc859401a3facd3be..d1c0adaab9586ce1b2774793446ea9caf8a093d1 100644 (file)
@@ -619,17 +619,24 @@ int backend_check_referrals(
        Backend *be,
        Connection *conn,
        Operation *op,
-       struct berval ***bv,
+       const char *dn,
+       const char *ndn,
        const char **text )
 {
+       int rc = LDAP_SUCCESS;
        *bv = NULL;
 
        if( be->be_chk_referrals ) {
-               return be->be_chk_referrals( be,
-                       conn, op, bv, text );
+               rc = be->be_chk_referrals( be,
+                       conn, op, dn, ndn, text );
+
+               if( rc != LDAP_SUCCESS && rc != LDAP_REFERRAL ) {
+                       send_ldap_result( conn, op, rc,
+                               NULL, text, NULL, NULL );
+               }
        }
 
-       return LDAP_SUCCESS;
+       return rc;
 }
 
 int 
index b4b46ab83e9aca4c165b5f15f70eb91ccee4c4fa..6c1f8a6ed311c5366739243e63b21e34a9857a19 100644 (file)
@@ -36,7 +36,6 @@ do_compare(
        AttributeAssertion ava;
        Backend *be;
        int rc = LDAP_SUCCESS;
-       struct berval **urls = NULL;
        const char *text = NULL;
 
        ava.aa_desc = NULL;
@@ -108,6 +107,7 @@ do_compare(
 
        /* make sure this backend recongizes critical controls */
        rc = backend_check_controls( be, conn, op, &text ) ;
+
        if( rc != LDAP_SUCCESS ) {
                send_ldap_result( conn, op, rc,
                        NULL, text, NULL, NULL );
@@ -115,11 +115,10 @@ do_compare(
        }
 
        /* check for referrals */
-       rc = backend_check_referrals( be, conn, op, &urls, &text );
+       rc = backend_check_referrals( be, conn, op,
+               dn, ndn, &text );
+
        if ( rc != LDAP_SUCCESS ) {
-               send_ldap_result( conn, op, rc,
-                       NULL, text, urls, NULL );
-               ber_bvecfree( urls );
                goto cleanup;
        }
 
index 06eb38fb2d1c74f5f39c6f8705ed33bf9dfec8e5..324b3524c17bbc24b2879c55ff9a5ec3a6c85f9e 100644 (file)
@@ -33,7 +33,6 @@ do_delete(
 {
        char *dn, *ndn = NULL;
        const char *text;
-       struct berval **urls = NULL;
        Backend *be;
        int rc;
 
@@ -82,6 +81,7 @@ do_delete(
 
        /* make sure this backend recongizes critical controls */
        rc = backend_check_controls( be, conn, op, &text ) ;
+
        if( rc != LDAP_SUCCESS ) {
                send_ldap_result( conn, op, rc,
                        NULL, text, NULL, NULL );
@@ -89,11 +89,10 @@ do_delete(
        }
 
        /* check for referrals */
-       rc = backend_check_referrals( be, conn, op, &urls, &text );
+       rc = backend_check_referrals( be, conn, op,
+               dn, ndn, &text );
+
        if ( rc != LDAP_SUCCESS ) {
-               send_ldap_result( conn, op, rc,
-                       NULL, text, urls, NULL );
-               ber_bvecfree( urls );
                goto cleanup;
        }
 
index d648633f259514cb7bc8dc6dc034e492f43c3f80..d0427f7e7b02fb720c35e078b97a0b1eb5c2305b 100644 (file)
@@ -45,7 +45,6 @@ do_modify(
        Backend         *be;
        int rc;
        const char      *text;
-       struct berval **urls;
 
        Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
 
@@ -180,11 +179,10 @@ do_modify(
        }
 
        /* check for referrals */
-       rc = backend_check_referrals( be, conn, op, &urls, &text );
+       rc = backend_check_referrals( be, conn, op,
+               dn, ndn, &text );
+
        if ( rc != LDAP_SUCCESS ) {
-               send_ldap_result( conn, op, rc,
-                       NULL, text, urls, NULL );
-               ber_bvecfree( urls );
                goto cleanup;
        }
 
index cf56ae9e196bf67c8dc262a1005a9490bd01aa72..0ac91bdff44a5486e77a4326786420132fe63f28 100644 (file)
@@ -54,7 +54,6 @@ do_modrdn(
        ber_len_t       length;
        int rc;
        const char *text;
-       struct berval **urls = NULL;
 
        Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
 
@@ -168,6 +167,7 @@ do_modrdn(
 
        /* make sure this backend recongizes critical controls */
        rc = backend_check_controls( be, conn, op, &text ) ;
+
        if( rc != LDAP_SUCCESS ) {
                send_ldap_result( conn, op, rc,
                        NULL, text, NULL, NULL );
@@ -175,11 +175,10 @@ do_modrdn(
        }
 
        /* check for referrals */
-       rc = backend_check_referrals( be, conn, op, &urls, &text );
+       rc = backend_check_referrals( be, conn, op,
+               dn, ndn, &text );
+
        if ( rc != LDAP_SUCCESS ) {
-               send_ldap_result( conn, op, rc,
-                       NULL, text, urls, NULL );
-               ber_bvecfree( urls );
                goto cleanup;
        }
 
index 1fa51f44c1476cadbd4acfbe0026c6a7700f8567..9b6418045b9bf34c4a346259818719ffe9173a10 100644 (file)
@@ -159,7 +159,8 @@ LIBSLAPD_F( int )   backend_check_referrals LDAP_P((
        Backend *be,
        Connection *conn,
        Operation *op,
-       struct berval ***bv,
+       const char *dn,
+       const char *ndn,
        const char **text ));
 
 LIBSLAPD_F (int) backend_connection_init LDAP_P((Connection *conn));
index ed400b0718b923d72857afe7427c0632b23b9897..73db58b2e6f5f4940fc8ed8e088f329179d6ebf4 100644 (file)
@@ -39,7 +39,6 @@ do_search(
        Backend         *be;
        int                     rc;
        const char              *text;
-       struct berval **urls = NULL;
 
        Debug( LDAP_DEBUG_TRACE, "do_search\n", 0, 0, 0 );
 
@@ -224,11 +223,10 @@ do_search(
        }
 
        /* check for referrals */
-       rc = backend_check_referrals( be, conn, op, &urls, &text );
+       rc = backend_check_referrals( be, conn, op,
+               base, nbase, &text );
+
        if ( rc != LDAP_SUCCESS ) {
-               send_ldap_result( conn, op, rc,
-                       NULL, text, urls, NULL );
-               ber_bvecfree( urls );
                goto return_results;
        }
 
index 023ed076ef3920767b77ca767b7d63f6cde2fed0..105937c80745dd9ab6c5078e51c5aa093e8274bd 100644 (file)
@@ -910,7 +910,7 @@ struct slap_backend_info {
 
        int     (*bi_chk_referrals) LDAP_P((BackendDB *bd,
                struct slap_conn *c, struct slap_op *o,
-               struct berval ***urls,
+               const char *dn, const char *ndn,
                const char **text ));
 
        int     (*bi_acl_group)  LDAP_P((Backend *bd,