]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/result.c
Treat references as labeled URI. Trim as needed.
[openldap] / servers / slapd / result.c
index 211bcd6b95ed14e507fd88ba5eb55452f7d18915..00cbca44d36dd7bd9423537e1fe5ea6439d8379b 100644 (file)
@@ -69,6 +69,39 @@ static ber_tag_t req2res( ber_tag_t tag )
        return tag;
 }
 
+void trim_refs(
+       struct berval **refs,
+       int trimurl )
+{
+       int i;
+       assert( refs != NULL );
+
+       for( i=0; refs[i] != NULL; i++ ) {
+               unsigned long j;
+
+               /* trim URI label */
+               for( j=0; j<refs[i]->bv_len; j++ ) {
+                       if( isspace(refs[i]->bv_val[j]) ) {
+                               refs[i]->bv_val[j] = '\0';
+                               refs[i]->bv_len = j;
+                               break;
+                       }
+               }
+
+               if(     trimurl && refs[i]->bv_len > sizeof("ldap://") &&
+                       strncasecmp( refs[i]->bv_val, "ldap://",
+                               sizeof("ldap://")-1 ) == 0 )
+               {
+                       for( j=sizeof("ldap://"); j<refs[i]->bv_len ; j++ ) {
+                               if( refs[i]->bv_val[j] = '/' ) {
+                                       refs[i]->bv_val[j] = '\0';
+                                       refs[i]->bv_len = j;
+                                       break;
+                               }
+                       }
+               }
+       }
+}
 
 long send_ldap_ber(
        Connection *conn,
@@ -286,6 +319,10 @@ send_ldap_result(
 
        assert( err != LDAP_PARTIAL_RESULTS );
 
+       if ( ref != NULL ) {
+               trim_refs( ref, 0 );
+       }
+
        if ( err == LDAP_REFERRAL ) {
                if( ref == NULL ) {
                        err = LDAP_NO_SUCH_OBJECT;
@@ -346,6 +383,10 @@ send_search_result(
 
        assert( err != LDAP_PARTIAL_RESULTS );
 
+       if ( refs != NULL ) {
+               trim_refs( refs, 1 );
+       }
+
        if( op->o_protocol < LDAP_VERSION3 ) {
                /* send references in search results */
                if( err == LDAP_REFERRAL ) {