]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/result.c
Fix pkiUser
[openldap] / servers / slapd / result.c
index 83906f6418c7538558df630128cc334b8479e640..d2def63547477610f7dab2e16c2fcd3d26729537 100644 (file)
@@ -236,14 +236,14 @@ send_ldap_response(
            }
        }
        if (conn->c_is_udp && op->o_protocol == LDAP_VERSION2) {
-           rc = ber_printf( ber, "{is{t{ess",
+           rc = ber_printf( ber, "{is{t{ess" /*"}}}"*/,
                msgid, "", tag, err,
                matched == NULL ? "" : matched,
                text == NULL ? "" : text );
        } else
 #endif
        {
-           rc = ber_printf( ber, "{it{ess",
+           rc = ber_printf( ber, "{it{ess" /*"}}"*/,
                msgid, tag, err,
                matched == NULL ? "" : matched,
                text == NULL ? "" : text );
@@ -275,11 +275,11 @@ send_ldap_response(
        }
 
        if( rc != -1 ) {
-               rc = ber_printf( ber, "N}N}" );
+               rc = ber_printf( ber, /*"{{"*/ "N}N}" );
        }
 #ifdef LDAP_CONNECTIONLESS
        if( conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
-               rc = ber_printf( ber, "N}" );
+               rc = ber_printf( ber, /*"{"*/ "N}" );
        }
 #endif
 
@@ -727,7 +727,7 @@ send_search_entry(
                : an_find( attrs, &AllOper );
 
        /* create an array of arrays of flags. Each flag corresponds
-        * to particular value of attribute an equals 1 if value matches
+        * to particular value of attribute and equals 1 if value matches
         * to ValuesReturnFilter or 0 if not
         */     
        for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next ) i++;
@@ -736,17 +736,20 @@ send_search_entry(
        for ( a = e->e_attrs, i=0; a != NULL; a = a->a_next, i++ ) {
                for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
 
-               a_flags = ch_calloc ( j, sizeof(char) );
-               /* If no ValuesReturnFilter control return everything */
-               if ( op->vrFilter == NULL ){
-                   memset(a_flags, 1, j);
+               if( j ) {
+                       a_flags = ch_calloc ( j, sizeof(char) );
+                       /* If no ValuesReturnFilter control return everything */
+                       if ( op->vrFilter == NULL ) {
+                               memset(a_flags, 1, j);
+                       }
+               } else {
+                       a_flags = NULL;
                }
                e_flags[i] = a_flags; 
        }
 
-       if ( op->vrFilter != NULL ){
-
-               rc = filter_matched_values(be, conn, op, e, &e_flags) ; 
+       if ( op->vrFilter != NULL ) { 
+               rc = filter_matched_values(be, conn, op, e->e_attrs, &e_flags) ; 
            
                if ( rc == -1 ) {
 #ifdef NEW_LOGGING
@@ -917,8 +920,50 @@ send_search_entry(
        /* eventually will loop through generated operational attributes */
        /* only have subschemaSubentry implemented */
        aa = backend_operational( be, conn, op, e, attrs, opattrs );
+
+       for ( a = aa, i=0; a != NULL; a = a->a_next ) i++;
+       e_flags = ch_malloc ( i * sizeof(a_flags) );
        
-       for (a = aa ; a != NULL; a = a->a_next ) {
+       for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
+               for ( j = 0; a->a_vals[j].bv_val != NULL; j++ );
+
+               a_flags = ch_calloc ( j, sizeof(char) );
+               /* If no ValuesReturnFilter control return everything */
+               if ( op->vrFilter == NULL ){
+                   memset(a_flags, 1, j);
+               }
+               e_flags[i] = a_flags; 
+       }
+
+       if ( op->vrFilter != NULL ) {
+               rc = filter_matched_values(be, conn, op, aa, &e_flags) ; 
+           
+               if ( rc == -1 ) {
+#ifdef NEW_LOGGING
+                       LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
+                               "send_search_entry: conn %lu "
+                               "matched values filtering failed\n",
+                               conn ? conn->c_connid : 0 ));
+#else
+               Debug( LDAP_DEBUG_ANY,
+                               "matched values filtering failed\n", 0, 0, 0 );
+#endif
+                       ber_free( ber, 1 );
+
+                       /* free e_flags */
+                       for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
+                               free( e_flags[i] );
+                       }
+                       free( e_flags );
+
+                       send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "matched values filtering error", 
+                               NULL, NULL );
+                       goto error_return;
+               }
+       }
+
+       for (a = aa, j=0; a != NULL; a = a->a_next, j++ ) {
                AttributeDescription *desc = a->a_desc;
 
                if ( attrs == NULL ) {
@@ -974,6 +1019,12 @@ send_search_entry(
                        ber_free_buf( ber );
                        send_ldap_result( conn, op, LDAP_OTHER,
                            NULL, "encoding description error", NULL, NULL );
+                       /* free e_flags */
+                       for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
+                               free( e_flags[i] );
+                       }
+                       free( e_flags );
+
                        attrs_free( aa );
                        goto error_return;
                }
@@ -1000,6 +1051,10 @@ send_search_entry(
                                        continue;
                                }
 
+                               if ( e_flags[j][i] == 0 ){
+                                       continue;
+                               }
+
                                if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
 #ifdef NEW_LOGGING
                                        LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
@@ -1016,6 +1071,12 @@ send_search_entry(
                                        send_ldap_result( conn, op, LDAP_OTHER,
                                                NULL, "encoding values error", 
                                                NULL, NULL );
+                                       /* free e_flags */
+                                       for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
+                                               free( e_flags[i] );
+                                       }
+                                       free( e_flags );
+
                                        attrs_free( aa );
                                        goto error_return;
                                }
@@ -1035,13 +1096,24 @@ send_search_entry(
                        ber_free_buf( ber );
                        send_ldap_result( conn, op, LDAP_OTHER,
                            NULL, "encode end error", NULL, NULL );
+                       /* free e_flags */
+                       for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
+                               free( e_flags[i] );
+                       }
+                       free( e_flags );
+
                        attrs_free( aa );
                        goto error_return;
                }
        }
 
-       attrs_free( aa );
+       /* free e_flags */
+       for ( a = aa, i=0; a != NULL; a = a->a_next, i++ ) {
+               free( e_flags[i] );
+       }
+       free( e_flags );
 
+       attrs_free( aa );
        rc = ber_printf( ber, /*{{{*/ "}N}N}" );
 
 #ifdef LDAP_CONNECTIONLESS
@@ -1069,11 +1141,11 @@ send_search_entry(
        if ( bytes < 0 ) {
 #ifdef NEW_LOGGING
                LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
-                          "send_ldap_response: conn %lu  ber write failed.\n",
+                          "send_search_entry: conn %lu  ber write failed.\n",
                           op->o_connid ));
 #else
                Debug( LDAP_DEBUG_ANY,
-                       "send_ldap_response: ber write failed\n",
+                       "send_search_entry: ber write failed\n",
                        0, 0, 0 );
 #endif
 
@@ -1259,7 +1331,6 @@ str2result(
                    s, 0, 0 );
 #endif
 
-
                return( -1 );
        }