]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-dnssrv/search.c
Merge remote-tracking branch 'origin/mdb.master'
[openldap] / servers / slapd / back-dnssrv / search.c
index 40c03230f0bcb9b181dbd4b7b910a6a4f31d1dc9..a9b1751cabe984fb1e79204f42296a929f7ce9bc 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2004 The OpenLDAP Foundation.
+ * Copyright 2000-2012 The OpenLDAP Foundation.
  * Portions Copyright 2000-2003 Kurt D. Zeilenga.
  * All rights reserved.
  *
@@ -28,7 +28,7 @@
 #include <ac/time.h>
 
 #include "slap.h"
-#include "external.h"
+#include "proto-dnssrv.h"
 
 int
 dnssrv_back_search(
@@ -47,11 +47,25 @@ dnssrv_back_search(
 
        rs->sr_ref = NULL;
 
+       if ( BER_BVISEMPTY( &op->o_req_ndn ) ) {
+               /* FIXME: need some means to determine whether the database
+                * is a glue instance; if we got here with empty DN, then
+                * we passed this same test in dnssrv_back_referrals() */
+               if ( !SLAP_GLUE_INSTANCE( op->o_bd ) ) {
+                       rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+                       rs->sr_text = "DNS SRV operation upon null (empty) DN disallowed";
+
+               } else {
+                       rs->sr_err = LDAP_SUCCESS;
+               }
+               goto done;
+       }
+
        manageDSAit = get_manageDSAit( op );
        /*
         * FIXME: we may return a referral if manageDSAit is not set
         */
-       if ( ! manageDSAit ) {
+       if ( !manageDSAit ) {
                send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
                                "manageDSAit must be set" );
                goto done;
@@ -88,11 +102,11 @@ dnssrv_back_search(
        for( i=0; hosts[i] != NULL; i++) {
                struct berval url;
 
-               url.bv_len = sizeof("ldap://")-1 + strlen(hosts[i]);
+               url.bv_len = STRLENOF( "ldap://" ) + 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[STRLENOF( "ldap://" )], hosts[i] );
 
                if( ber_bvarray_add( &urls, &url ) < 0 ) {
                        free( url.bv_val );
@@ -151,83 +165,64 @@ dnssrv_back_search(
                send_ldap_error( op, rs, LDAP_SUCCESS, NULL );
 
        } else {
-               struct berval   vals[2];
-               Entry *e = ch_calloc( 1, sizeof(Entry) );
+               Entry e = { 0 };
                AttributeDescription *ad_objectClass
                        = slap_schema.si_ad_objectClass;
                AttributeDescription *ad_ref = slap_schema.si_ad_ref;
-               e->e_name.bv_val = strdup( op->o_req_dn.bv_val );
-               e->e_name.bv_len = op->o_req_dn.bv_len;
-               e->e_nname.bv_val = strdup( op->o_req_ndn.bv_val );
-               e->e_nname.bv_len = op->o_req_ndn.bv_len;
-
-               e->e_attrs = NULL;
-               e->e_private = NULL;
-
-               vals[1].bv_val = NULL;
+               e.e_name.bv_val = ch_strdup( op->o_req_dn.bv_val );
+               e.e_name.bv_len = op->o_req_dn.bv_len;
+               e.e_nname.bv_val = ch_strdup( op->o_req_ndn.bv_val );
+               e.e_nname.bv_len = op->o_req_ndn.bv_len;
 
-               vals[0].bv_val = "top";
-               vals[0].bv_len = sizeof("top")-1;
-               attr_mergeit( e, ad_objectClass, vals );
+               e.e_attrs = NULL;
+               e.e_private = NULL;
 
-               vals[0].bv_val = "referral";
-               vals[0].bv_len = sizeof("referral")-1;
-               attr_mergeit( e, ad_objectClass, vals );
+               attr_merge_one( &e, ad_objectClass, &slap_schema.si_oc_referral->soc_cname, NULL );
+               attr_merge_one( &e, ad_objectClass, &slap_schema.si_oc_extensibleObject->soc_cname, NULL );
 
-               vals[0].bv_val = "extensibleObject";
-               vals[0].bv_len = sizeof("extensibleObject")-1;
-               attr_mergeit( e, ad_objectClass, vals );
+               if ( ad_dc ) {
+                       char            *p;
+                       struct berval   bv;
 
-               {
-                       AttributeDescription *ad = NULL;
-                       const char *text;
+                       bv.bv_val = domain;
 
-                       rc = slap_str2ad( "dc", &ad, &text );
+                       p = strchr( bv.bv_val, '.' );
+                                       
+                       if ( p == bv.bv_val ) {
+                               bv.bv_len = 1;
 
-                       if( rc == LDAP_SUCCESS ) {
-                               char *p;
-                               vals[0].bv_val = ch_strdup( domain );
+                       } else if ( p != NULL ) {
+                               bv.bv_len = p - bv.bv_val;
 
-                               p = strchr( vals[0].bv_val, '.' );
-                                       
-                               if( p == vals[0].bv_val ) {
-                                       vals[0].bv_val[1] = '\0';
-                               } else if ( p != NULL ) {
-                                       *p = '\0';
-                               }
-
-                               vals[0].bv_len = strlen(vals[0].bv_val);
-                               attr_mergeit( e, ad, vals );
+                       } else {
+                               bv.bv_len = strlen( bv.bv_val );
                        }
-               }
 
-               {
-                       AttributeDescription *ad = NULL;
-                       const char *text;
+                       attr_merge_normalize_one( &e, ad_dc, &bv, NULL );
+               }
 
-                       rc = slap_str2ad( "associatedDomain", &ad, &text );
+               if ( ad_associatedDomain ) {
+                       struct berval   bv;
 
-                       if( rc == LDAP_SUCCESS ) {
-                               vals[0].bv_val = domain;
-                               vals[0].bv_len = strlen(domain);
-                               attr_mergeit( e, ad, vals );
-                       }
+                       ber_str2bv( domain, 0, 0, &bv );
+                       attr_merge_normalize_one( &e, ad_associatedDomain, &bv, NULL );
                }
 
-               attr_mergeit( e, ad_ref, urls );
+               attr_merge_normalize_one( &e, ad_ref, urls, NULL );
 
-               rc = test_filter( op, e, op->oq_search.rs_filter ); 
+               rc = test_filter( op, &e, op->oq_search.rs_filter ); 
 
                if( rc == LDAP_COMPARE_TRUE ) {
-                       rs->sr_entry = e;
+                       rs->sr_entry = &e;
                        rs->sr_attrs = op->oq_search.rs_attrs;
                        rs->sr_flags = REP_ENTRY_MODIFIABLE;
                        send_search_entry( op, rs );
                        rs->sr_entry = NULL;
                        rs->sr_attrs = NULL;
+                       rs->sr_flags = 0;
                }
 
-               entry_free( e );
+               entry_clean( &e );
 
                rs->sr_err = LDAP_SUCCESS;
                send_ldap_result( op, rs );
@@ -243,4 +238,3 @@ done:
        if( urls != NULL ) ber_bvarray_free( urls );
        return 0;
 }
-