]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-dnssrv/referral.c
Converted ch_calloc and ch_malloc calls to SLAP_CALLOC and SLAP_MALLOC.
[openldap] / servers / slapd / back-dnssrv / referral.c
index a1e483d9457d76c9eebfc93c98f6735c3442816a..9aaf23c79c84509c3fa8d649e7e85b27c6b7d285 100644 (file)
@@ -1,7 +1,7 @@
 /* referral.c - DNS SRV backend referral handler */
 /* $OpenLDAP$ */
 /*
- * Copyright 2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 2000-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -20,8 +20,8 @@ dnssrv_back_referrals(
     Backend    *be,
     Connection *conn,
     Operation  *op,
-    const char *dn,
-    const char *ndn,
+    struct berval *dn,
+    struct berval *ndn,
        const char **text )
 {
        int i;
@@ -29,9 +29,9 @@ dnssrv_back_referrals(
        char *domain = NULL;
        char *hostlist = NULL;
        char **hosts = NULL;
-       struct berval **urls = NULL;
+       BerVarray urls = NULL;
 
-       if( ndn == NULL || *ndn == '\0' ) {
+       if( ndn->bv_len == 0 ) {
                *text = "DNS SRV operation upon null (empty) DN disallowed";
                return LDAP_UNWILLING_TO_PERFORM;
        }
@@ -45,26 +45,25 @@ dnssrv_back_referrals(
                return LDAP_OTHER;
        } 
 
-       if( ldap_dn2domain( dn, &domain ) ) {
+       if( ldap_dn2domain( dn->bv_val, &domain ) || domain == NULL ) {
                send_ldap_result( conn, op, LDAP_REFERRAL,
                        NULL, NULL, default_referral, NULL );
                return LDAP_REFERRAL;
        }
 
        Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> domain=\"%s\"\n",
-               dn == NULL ? "" : dn,
-               domain == NULL ? "" : domain,
-               0 );
+               dn->bv_val, domain, 0 );
 
-       if( rc = ldap_domain2hostlist( domain, &hostlist ) ) {
-               Debug( LDAP_DEBUG_TRACE, "DNSSRV: domain2hostlist returned %d\n",
-                       rc, 0, 0 );
+       if( ( rc = ldap_domain2hostlist( domain, &hostlist ) ) ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "DNSSRV: domain2hostlist(%s) returned %d\n",
+                       domain, rc, 0 );
                *text = "no DNS SRV RR available for DN";
                rc = LDAP_NO_SUCH_OBJECT;
                goto done;
        }
 
-       hosts = str2charray( hostlist, " " );
+       hosts = ldap_str2charray( hostlist, " " );
 
        if( hosts == NULL ) {
                Debug( LDAP_DEBUG_TRACE, "DNSSRV: str2charrary error\n", 0, 0, 0 );
@@ -73,28 +72,28 @@ dnssrv_back_referrals(
        }
 
        for( i=0; hosts[i] != NULL; i++) {
-               struct berval *url = ch_malloc( sizeof( struct berval ) ); 
+               struct berval url;
 
-               url->bv_len = sizeof("ldap://")-1 + strlen(hosts[i]);
-               url->bv_val = ch_malloc( url->bv_len + 1 );
+               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] );
+               strcpy( url.bv_val, "ldap://" );
+               strcpy( &url.bv_val[sizeof("ldap://")-1], hosts[i] );
 
-               if( ber_bvecadd( &urls, url ) < 0 ) {
-                       ber_bvfree( url );
+               if ( ber_bvarray_add( &urls, &url ) < 0 ) {
+                       free( url.bv_val );
                        *text = "problem processing DNS SRV records for DN";
                        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 );
+           "conn=%lu op=%lu DNSSRV p=%d dn=\"%s\" url=\"%s\"\n",
+           op->o_connid, op->o_opid, op->o_protocol,
+               dn->bv_val, urls[0].bv_val );
 
        Debug( LDAP_DEBUG_TRACE, "DNSSRV: dn=\"%s\" -> url=\"%s\"\n",
-               dn == NULL ? "" : dn,
-               urls[0]->bv_val, 0 );
+               dn->bv_val, urls[0].bv_val, 0 );
 
        send_ldap_result( conn, op, rc = LDAP_REFERRAL,
                NULL, "DNS SRV generated referrals", urls, NULL );
@@ -102,7 +101,7 @@ dnssrv_back_referrals(
 done:
        if( domain != NULL ) ch_free( domain );
        if( hostlist != NULL ) ch_free( hostlist );
-       if( hosts != NULL ) charray_free( hosts );
-       ber_bvecfree( urls );
+       if( hosts != NULL ) ldap_charray_free( hosts );
+       ber_bvarray_free( urls );
        return rc;
 }