]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/search.c
cleanup bind
[openldap] / servers / slapd / search.c
index c331ed45835082207ba85b7ca9551468ecd2818b..fd7ea25a024b3c9f55137add6170074dec872b2f 100644 (file)
@@ -25,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,
@@ -228,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;
@@ -245,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",
@@ -377,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,
@@ -410,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( fstr.bv_val != NULL) free( fstr.bv_val );
-               if( filter != NULL) filter_free( filter );
-               if( an != NULL ) free( an );
+       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 );
 #ifdef LDAP_SLAPI
-               if( attrs != NULL) ch_free( attrs );
+       if( attrs != NULL) ch_free( attrs );
 #endif /* LDAP_SLAPI */
-       }
 
        return rc;
 }