]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/search.c
Commit of the Proxy Cache contribution (ITS#2062)
[openldap] / servers / slapd / search.c
index 720992c58b2e14f3792ffae16b837475651bdb78..fd7ea25a024b3c9f55137add6170074dec872b2f 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 #include "portable.h"
-#include "slapi_common.h"
 
 #include <stdio.h>
 
@@ -26,9 +25,9 @@
 #include "ldap_pvt.h"
 #include "lutil.h"
 #include "slap.h"
-#include "slapi.h"
 
 #ifdef LDAP_SLAPI
+#include "slapi.h"
 static char **anlist2charray( AttributeName *an );
 static Slapi_PBlock *initSearchPlugin( Backend *be, Connection *conn, Operation *op,
        struct berval *base, int scope, int deref, int sizelimit, int timelimit,
@@ -36,7 +35,7 @@ static Slapi_PBlock *initSearchPlugin( Backend *be, Connection *conn, Operation
        int attrsonly, int managedsait );
 static int doPreSearchPluginFNs( Backend *be, Slapi_PBlock *pb );
 static int doSearchRewriteFNs( Backend *be, Slapi_PBlock *pb, Filter **filter, struct berval *fstr );
-static int doPostSearchPluginFNs( Backend *be, Slapi_PBlock *pb );
+static void doPostSearchPluginFNs( Backend *be, Slapi_PBlock *pb );
 #endif /* LDAPI_SLAPI */
 
 int
@@ -229,14 +228,18 @@ do_search(
 
        if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
                char abuf[BUFSIZ/2], *ptr = abuf;
-               int len = 0;
+               int len = 0, alen;
 
                Statslog( LDAP_DEBUG_STATS,
                        "conn=%lu op=%lu SRCH base=\"%s\" scope=%d filter=\"%s\"\n",
                        op->o_connid, op->o_opid, pbase.bv_val, scope, fstr.bv_val );
 
                for ( i = 0; i<siz; i++ ) {
-                       if (len + 1 + an[i].an_name.bv_len > sizeof(abuf)) {
+                       alen = an[i].an_name.bv_len;
+                       if (alen >= sizeof(abuf)) {
+                               alen = sizeof(abuf)-1;
+                       }
+                       if (len && (len + 1 + alen >= sizeof(abuf))) {
                                Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu SRCH attr=%s\n",
                                    op->o_connid, op->o_opid, abuf, 0, 0 );
                                len = 0;
@@ -246,8 +249,9 @@ do_search(
                                *ptr++ = ' ';
                                len++;
                        }
-                       ptr = lutil_strcopy(ptr, an[i].an_name.bv_val);
-                       len += an[i].an_name.bv_len;
+                       ptr = lutil_strncopy(ptr, an[i].an_name.bv_val, alen);
+                       len += alen;
+                       *ptr = '\0';
                }
                if (len) {
                        Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu SRCH attr=%s\n",
@@ -378,9 +382,6 @@ do_search(
                goto return_results;
        }
 
-       /* deref the base if needed */
-       suffix_alias( be, &nbase );
-
 #ifdef LDAP_SLAPI
        attrs = anlist2charray( an );
        pb = initSearchPlugin( be, conn, op, &pbase,
@@ -411,20 +412,28 @@ do_search(
 #endif /* LDAP_SLAPI */
 
 return_results:;
+
 #ifdef LDAP_CLIENT_UPDATE
-       if ( !( op->o_clientupdate_type & SLAP_LCUP_PERSIST ) )
-#endif /* LDAP_CLIENT_UPDATE */
-       {
-               if( pbase.bv_val != NULL) free( pbase.bv_val );
-               if( nbase.bv_val != NULL) free( nbase.bv_val );
+       if ( ( op->o_clientupdate_type & SLAP_LCUP_PERSIST ) )
+               return rc;
+#endif
+#if defined(LDAP_CLIENT_UPDATE) && defined(LDAP_SYNC)
+       else
+#endif
+#ifdef LDAP_SYNC
+       if ( ( op->o_sync_mode & SLAP_SYNC_PERSIST ) )
+               return rc;
+#endif
+
+       if( pbase.bv_val != NULL) free( pbase.bv_val );
+       if( nbase.bv_val != NULL) free( nbase.bv_val );
 
-               if( fstr.bv_val != NULL) free( fstr.bv_val );
-               if( filter != NULL) filter_free( filter );
-               if( an != NULL ) free( an );
+       if( fstr.bv_val != NULL) free( fstr.bv_val );
+       if( filter != NULL) filter_free( filter );
+       if( an != NULL ) free( an );
 #ifdef LDAP_SLAPI
-               if( attrs != NULL) ch_free( attrs );
+       if( attrs != NULL) ch_free( attrs );
 #endif /* LDAP_SLAPI */
-       }
 
        return rc;
 }
@@ -526,7 +535,7 @@ static int doSearchRewriteFNs( Backend *be, Slapi_PBlock *pb, Filter **filter, s
        return LDAP_SUCCESS;
 }
 
-static int doPostSearchPluginFNs( Backend *be, Slapi_PBlock *pb )
+static void doPostSearchPluginFNs( Backend *be, Slapi_PBlock *pb )
 {
        if ( doPluginFNs( be, SLAPI_PLUGIN_POST_SEARCH_FN, pb ) != 0 ) {
 #ifdef NEW_LOGGING
@@ -537,8 +546,6 @@ static int doPostSearchPluginFNs( Backend *be, Slapi_PBlock *pb )
                                "failed.\n", 0, 0, 0);
 #endif
        }
-
-       return LDAP_SUCCESS;
 }
 
 void dummy(void)