]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/result.c
Fixup bdb_entry_release now that entry_decode uses two memory blocks
[openldap] / servers / slapd / result.c
index a4890e8fc68d876114f4e16a646db22473ac1baa..c71972fe50a3e83212e0594eee245a580033a1e9 100644 (file)
@@ -95,87 +95,6 @@ static ber_tag_t req2res( ber_tag_t tag )
        return tag;
 }
 
-static void trim_refs_urls(
-       struct berval **refs )
-{
-       unsigned i;
-
-       if( refs == NULL ) return;
-
-       for( i=0; refs[i] != NULL; i++ ) {
-               if(     refs[i]->bv_len > sizeof("ldap://")-1 &&
-                       strncasecmp( refs[i]->bv_val, "ldap://",
-                               sizeof("ldap://")-1 ) == 0 )
-               {
-                       unsigned j;
-                       for( j=sizeof("ldap://")-1; j<refs[i]->bv_len ; j++ ) {
-                               if( refs[i]->bv_val[j] == '/' ) {
-                                       refs[i]->bv_val[j] = '\0';
-                                       refs[i]->bv_len = j;
-                                       break;
-                               }
-                       }
-               }
-       }
-}
-
-struct berval **get_entry_referrals(
-       Backend *be,
-       Connection *conn,
-       Operation *op,
-       Entry *e )
-{
-       Attribute *attr;
-       struct berval **refs;
-       unsigned i, j;
-
-       AttributeDescription *ad_ref = slap_schema.si_ad_ref;
-
-       attr = attr_find( e->e_attrs, ad_ref );
-
-       if( attr == NULL ) return NULL;
-
-       for( i=0; attr->a_vals[i] != NULL; i++ ) {
-               /* count references */
-       }
-
-       if( i < 1 ) return NULL;
-
-       refs = ch_malloc( (i + 1) * sizeof(struct berval *));
-
-       for( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
-               unsigned k;
-               struct berval *ref = ber_bvdup( attr->a_vals[i] );
-
-               /* trim the label */
-               for( k=0; k<ref->bv_len; k++ ) {
-                       if( isspace(ref->bv_val[k]) ) {
-                               ref->bv_val[k] = '\0';
-                               ref->bv_len = k;
-                               break;
-                       }
-               }
-
-               if(     ref->bv_len > 0 ) {
-                       refs[j++] = ref;
-
-               } else {
-                       ber_bvfree( ref );
-               }
-       }
-
-       refs[j] = NULL;
-
-       if( j == 0 ) {
-               ber_bvecfree( refs );
-               refs = NULL;
-       }
-
-       /* we should check that a referral value exists... */
-
-       return refs;
-}
-
 static long send_ldap_ber(
        Connection *conn,
        BerElement *ber )
@@ -323,6 +242,8 @@ send_ldap_response(
                ber_free(ber, 1);
                return;
            }
+       }
+       if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
            rc = ber_printf( ber, "{is{t{ess",
                msgid, "", tag, err,
                matched == NULL ? "" : matched,
@@ -365,7 +286,7 @@ send_ldap_response(
                rc = ber_printf( ber, "N}N}" );
        }
 #ifdef LDAP_CONNECTIONLESS
-       if( conn->c_is_udp && rc != -1 ) {
+       if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
                rc = ber_printf( ber, "N}" );
        }
 #endif
@@ -501,23 +422,18 @@ send_ldap_result(
        if( ref ) {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
-                          "send_ldap_result: referral=\"%s\"\n",
-                          ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
+                       "send_ldap_result: referral=\"%s\"\n",
+                       ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL" ));
 #else
                Debug( LDAP_DEBUG_ARGS,
                        "send_ldap_result: referral=\"%s\"\n",
                        ref[0] && ref[0]->bv_val ? ref[0]->bv_val : "NULL",
                        NULL, NULL );
 #endif
-
        }
 
        assert( err != LDAP_PARTIAL_RESULTS );
 
-       if( op->o_tag != LDAP_REQ_SEARCH ) {
-               trim_refs_urls( ref );
-       }
-
        if ( err == LDAP_REFERRAL ) {
                if( ref == NULL ) {
                        err = LDAP_NO_SUCH_OBJECT;
@@ -652,8 +568,6 @@ send_search_result(
 
        assert( err != LDAP_PARTIAL_RESULTS );
 
-       trim_refs_urls( refs );
-
        if( op->o_protocol < LDAP_VERSION3 ) {
                /* send references in search results */
                if( err == LDAP_REFERRAL ) {
@@ -772,6 +686,8 @@ send_search_entry(
                ber_free(ber, 1);
                return;
            }
+       }
+       if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
            rc = ber_printf( ber, "{is{t{s{",
                op->o_msgid, "", LDAP_RES_SEARCH_ENTRY, e->e_dn );
        } else
@@ -806,7 +722,7 @@ send_search_entry(
 
        for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
                AttributeDescription *desc = a->a_desc;
-               char *type = desc->ad_cname->bv_val;
+               char *type = desc->ad_cname.bv_val;
 
                if ( attrs == NULL ) {
                        /* all addrs request, skip operational attributes */
@@ -832,10 +748,10 @@ send_search_entry(
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
                                   "send_search_entry: conn %d  access to attribute %s not allowed\n",
-                                  op->o_connid, desc->ad_cname->bv_val ));
+                                  op->o_connid, desc->ad_cname.bv_val ));
 #else
                        Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
-                           desc->ad_cname->bv_val, 0, 0 );
+                           desc->ad_cname.bv_val, 0, 0 );
 #endif
 
                        continue;
@@ -864,11 +780,11 @@ send_search_entry(
 #ifdef NEW_LOGGING
                                        LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
                                                   "send_search_entry: conn %d  access to attribute %s, value %d not allowed\n",
-                                                  op->o_connid, desc->ad_cname->bv_val, i ));
+                                                  op->o_connid, desc->ad_cname.bv_val, i ));
 #else
                                        Debug( LDAP_DEBUG_ACL,
                                                "acl: access to attribute %s, value %d not allowed\n",
-                                       desc->ad_cname->bv_val, i, 0 );
+                                       desc->ad_cname.bv_val, i, 0 );
 #endif
 
                                        continue;
@@ -939,16 +855,16 @@ send_search_entry(
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
                                   "send_search_entry: conn %s  access to attribute %s not allowed\n",
-                                  op->o_connid, desc->ad_cname->bv_val ));
+                                  op->o_connid, desc->ad_cname.bv_val ));
 #else
                        Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s not allowed\n",
-                           desc->ad_cname->bv_val, 0, 0 );
+                           desc->ad_cname.bv_val, 0, 0 );
 #endif
 
                        continue;
                }
 
-               rc = ber_printf( ber, "{s[" /*]}*/ , desc->ad_cname->bv_val );
+               rc = ber_printf( ber, "{s[" /*]}*/ , desc->ad_cname.bv_val );
                if ( rc == -1 ) {
 #ifdef NEW_LOGGING
                        LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
@@ -961,6 +877,7 @@ send_search_entry(
                        ber_free( ber, 1 );
                        send_ldap_result( conn, op, LDAP_OTHER,
                            NULL, "encoding description error", NULL, NULL );
+                       attrs_free( aa );
                        goto error_return;
                }
 
@@ -972,11 +889,11 @@ send_search_entry(
 #ifdef NEW_LOGGING
                                        LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
                                                   "send_search_entry: conn %d access to %s, value %d not allowed\n",
-                                                  op->o_connid, desc->ad_cname->bv_val, i ));
+                                                  op->o_connid, desc->ad_cname.bv_val, i ));
 #else
                                        Debug( LDAP_DEBUG_ACL,
                                                "acl: access to attribute %s, value %d not allowed\n",
-                                       desc->ad_cname->bv_val, i, 0 );
+                                       desc->ad_cname.bv_val, i, 0 );
 #endif
 
                                        continue;
@@ -996,6 +913,7 @@ send_search_entry(
                                        ber_free( ber, 1 );
                                        send_ldap_result( conn, op, LDAP_OTHER,
                                                NULL, "encoding values error", NULL, NULL );
+                                       attrs_free( aa );
                                        goto error_return;
                                }
                        }
@@ -1013,6 +931,7 @@ send_search_entry(
                        ber_free( ber, 1 );
                        send_ldap_result( conn, op, LDAP_OTHER,
                            NULL, "encode end error", NULL, NULL );
+                       attrs_free( aa );
                        goto error_return;
                }
        }
@@ -1022,7 +941,7 @@ send_search_entry(
        rc = ber_printf( ber, /*{{{*/ "}N}N}" );
 
 #ifdef LDAP_CONNECTIONLESS
-       if (conn->c_is_udp && rc != -1)
+       if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1)
                rc = ber_printf( ber, "}" );
 #endif
        if ( rc == -1 ) {
@@ -1088,7 +1007,6 @@ send_search_reference(
     Operation  *op,
     Entry      *e,
        struct berval **refs,
-       int scope,
        LDAPControl **ctrls,
     struct berval ***v2refs
 )
@@ -1102,8 +1020,8 @@ send_search_reference(
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
-                  "send_search_reference: conn %d  dn=\"%s\"\n",
-                  op->o_connid, e->e_dn ));
+               "send_search_reference: conn %d  dn=\"%s\"\n",
+               op->o_connid, e->e_dn ));
 #else
        Debug( LDAP_DEBUG_TRACE,
                "=> send_search_reference: dn=\"%s\"\n",
@@ -1116,8 +1034,8 @@ send_search_reference(
        {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
-                          "send_search_reference: conn %d      access to entry %s not allowed\n",
-                          op->o_connid, e->e_dn ));
+                       "send_search_reference: conn %d access to entry %s not allowed\n",
+                       op->o_connid, e->e_dn ));
 #else
                Debug( LDAP_DEBUG_ACL,
                        "send_search_reference: access to entry not allowed\n",
@@ -1132,8 +1050,8 @@ send_search_reference(
        {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "acl", LDAP_LEVEL_INFO,
-                          "send_search_reference: conn %d access to reference not allowed.\n",
-                          op->o_connid ));
+                       "send_search_reference: conn %d access to reference not allowed.\n",
+                       op->o_connid ));
 #else
                Debug( LDAP_DEBUG_ACL,
                        "send_search_reference: access to reference not allowed\n",
@@ -1146,8 +1064,8 @@ send_search_reference(
        if( refs == NULL ) {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                          "send_search_reference: null ref in (%s).\n",
-                          op->o_connid, e->e_dn ));
+                       "send_search_reference: null ref in (%s).\n",
+                       op->o_connid, e->e_dn ));
 #else
                Debug( LDAP_DEBUG_ANY,
                        "send_search_reference: null ref in (%s)\n", 
@@ -1170,8 +1088,8 @@ send_search_reference(
        if ( ber == NULL ) {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                          "send_search_reference: conn %d ber_alloc failed\n",
-                          op->o_connid ));
+                       "send_search_reference: conn %d ber_alloc failed\n",
+                       op->o_connid ));
 #else
                Debug( LDAP_DEBUG_ANY,
                        "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
@@ -1188,8 +1106,8 @@ send_search_reference(
        if ( rc == -1 ) {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                          "send_search_reference: conn %d      ber_printf failed.\n",
-                          op->o_connid ));
+                       "send_search_reference: conn %d ber_printf failed.\n",
+                       op->o_connid ));
 #else
                Debug( LDAP_DEBUG_ANY,
                        "send_search_reference: ber_printf failed\n", 0, 0, 0 );
@@ -1210,17 +1128,16 @@ send_search_reference(
        num_pdu_sent++;
        ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
 
-       Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
-           (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
+       Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld REF dn=\"%s\"\n",
+               (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
-                  "send_search_reference: conn %d exit.\n", op->o_connid ));
+               "send_search_reference: conn %d exit.\n", op->o_connid ));
 #else
        Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
 #endif
 
-
        return 0;
 }