]> git.sur5r.net Git - openldap/commitdiff
DNS SRV meat (a work in progress)
authorKurt Zeilenga <kurt@openldap.org>
Wed, 10 May 2000 21:48:18 +0000 (21:48 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 10 May 2000 21:48:18 +0000 (21:48 +0000)
libraries/libldap/dnssrv.c
servers/slapd/back-dnssrv/request.c

index d5597c57ecf7d7094be50c67cda75948f1cf59b4..11e3ed5b00b8dedd06d654fc617d6eee24c2ea6b 100644 (file)
@@ -37,8 +37,90 @@ int ldap_dn2domain(
        LDAP_CONST char *dn_in,
        char **domainp)
 {
-       /* not yet implemented */
-       return LDAP_NOT_SUPPORTED;
+       int i;
+       char* domain = NULL;
+       char ** dn;
+
+       if( dn_in == NULL || domainp == NULL ) {
+               return -1;
+       }
+
+       dn = ldap_explode_dn( dn_in, 0 );
+
+       if( dn == NULL ) {
+               return -2;
+       }
+
+       for( i=0; dn[i] != NULL; i++ ) {
+               char ** rdn = ldap_explode_rdn( dn[i], 0 );
+
+               if( rdn == NULL || *rdn == NULL ) {
+                       LDAP_FREE( rdn );
+                       LDAP_FREE( domain );
+                       LDAP_VFREE( dn );
+                       return -3;
+               }
+
+#define LDAP_DC "dc="
+#define LDAP_DCOID "0.9.2342.19200300.100.1.25="
+
+               if( *rdn[1] == NULL ) {
+                       char *dc;
+                       /* single RDN */
+
+                       if( strncasecmp( rdn[0],
+                               LDAP_DC, sizeof(LDAP_DC)-1 ) == 0 )
+                       {
+                               dc = &rdn[0][sizeof(LDAP_DC)-1];
+
+                       } else if( strncmp( rdn[0],
+                               LDAP_DCOID, sizeof(LDAP_DCOID)-1 ) == 0 )
+                       {
+                               dc = &rdn[0][sizeof(LDAP_DCOID)-1];
+
+                       } else {
+                               dc == NULL;
+                       }
+
+                       if( dc != NULL ) {
+                               char *ndomain;
+
+                               if( *dc == '\0' ) {
+                                       /* dc value is empty! */
+                                       LDAP_FREE( rdn );
+                                       LDAP_FREE( domain );
+                                       LDAP_VFREE( dn );
+                                       LDAP_VFREE( rdn );
+                                       return -4;
+                               }
+
+                               ndomain = realloc( domain,
+                                       strlen(domain) + strlen(dc) + 2 );
+
+                               if( ndomain == NULL ) {
+                                       LDAP_FREE( rdn );
+                                       LDAP_FREE( domain );
+                                       LDAP_VFREE( dn );
+                                       LDAP_VFREE( rdn );
+                                       return -5;
+                               }
+
+                               if( domain != NULL ) {
+                                       strcat( ndomain, "." );
+                               }
+                               strcat( ndomain, dc );
+                               domain = ndomain;
+                               continue;
+                       }
+               }
+
+               LDAP_VFREE( rdn );
+               LDAP_FREE( domain );
+               domain = NULL;
+       } 
+
+       *domainp = domain;
+       return 0;
 }
 
 int ldap_domain2dn(
index cab7f129944b887b160b43450e8120ac41128bfc..963a9023df0da9f0de84cbe6c815c97c116d6665 100644 (file)
@@ -23,5 +23,56 @@ dnssrv_back_request(
     const char *dn,
     const char *ndn )
 {
-       return -1;
+       int i;
+       char *domain = NULL;
+       char *hostlist = NULL;
+       char **hosts = NULL;
+       struct berval **urls = NULL;
+
+       if( ldap_dn2domain( dn, &domain ) ) {
+               send_ldap_result( conn, op, LDAP_REFERRAL,
+                       NULL, NULL, default_referral, NULL );
+               goto done;
+       }
+       
+       if( ldap_domain2hostlist( dn, &domain ) ) {
+               send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
+                       NULL, NULL, NULL, NULL );
+               goto done;
+       }
+
+       hosts = str2charray( hostlist, " " );
+
+       if( hosts == NULL ) {
+               send_ldap_result( conn, op, LDAP_OTHER,
+                       NULL, NULL, NULL, NULL );
+               goto done;
+       }
+
+       for( i=0; hosts[i] != NULL; i++) {
+               struct berval *url = ch_malloc( sizeof( struct berval ) );
+
+               url->bv_len = sizeof("ldap://") + strlen(hosts[i]);
+               url->bv_val = ch_malloc( url->bv_len );
+
+               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, NULL, NULL, NULL );
+                       goto done;
+               }
+       }
+
+       send_ldap_result( conn, op, LDAP_REFERRAL,
+               NULL, NULL, urls, NULL );
+
+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;
 }