]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-monitor/search.c
prevent use of uninitialized var
[openldap] / servers / slapd / back-monitor / search.c
index 27b9fb5efc6b1b2d86ff1d8a6a3aae17395b2b61..2795ee7be1ba50b3c5fe8db7a1dc9242133987cb 100644 (file)
@@ -1,12 +1,9 @@
 /* search.c - monitor backend search function */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /*
- * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
- * 
  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
  * 
  * This work has beed deveolped for the OpenLDAP Foundation 
@@ -51,7 +48,7 @@ monitor_send_children(
        Connection      *conn,
        Operation       *op,
        Filter          *filter,
-       char            **attrs,
+       AttributeName   *attrs,
        int             attrsonly,
        Entry           *e_parent,
        int             sub,
@@ -59,7 +56,7 @@ monitor_send_children(
 )
 {
        struct monitorinfo      *mi = (struct monitorinfo *) be->be_private;
-       Entry                   *e, *e_tmp;
+       Entry                   *e, *e_tmp, *e_ch;
        struct monitorentrypriv *mp;
        int                     nentries;
        int                     rc;
@@ -67,14 +64,43 @@ monitor_send_children(
        mp = ( struct monitorentrypriv * )e_parent->e_private;
        e = mp->mp_children;
 
-       if ( e == NULL && MONITOR_HAS_VOLATILE_CH( mp ) ) {
-               monitor_entry_create( mi, NULL, e_parent, &e );
-               if ( e != NULL) {
-                       monitor_cache_lock( e );
-               }
+       e_ch = NULL;
+       if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
+               monitor_entry_create( mi, NULL, e_parent, &e_ch );
        }
        monitor_cache_release( mi, e_parent );
 
+       /* no volatile entries? */
+       if ( e_ch == NULL ) {
+               /* no persistent entries? return */
+               if ( e == NULL ) {
+                       return( 0 );
+               }
+       
+       /* volatile entries */
+       } else {
+               /* if no persistent, return only volatile */
+               if ( e == NULL ) {
+                       e = e_ch;
+                       monitor_cache_lock( e_ch );
+
+               /* else append persistent to volatile */
+               } else {
+                       e_tmp = e_ch;
+                       do {
+                               mp = ( struct monitorentrypriv * )e_tmp->e_private;
+                               e_tmp = mp->mp_next;
+       
+                               if ( e_tmp == NULL ) {
+                                       mp->mp_next = e;
+                                       break;
+                               }
+                       } while ( e_tmp );
+                       e = e_ch;
+               }
+       }
+
+       /* return entries */
        for ( nentries = *nentriesp; e != NULL; ) {
                mp = ( struct monitorentrypriv * )e->e_private;
 
@@ -111,40 +137,44 @@ monitor_send_children(
 int
 monitor_back_search(
        Backend         *be,
-       Connection      *conn,
-       Operation       *op,
-       const char      *base,
-       const char      *nbase,
-       int             scope,
-       int             deref,
-       int             slimit,
-       int             tlimit,
-       Filter          *filter,
-       const char      *filterstr,
-       char            **attrs,
-       int             attrsonly 
+       Connection      *conn,
+       Operation       *op,
+       struct berval   *base,
+       struct berval   *nbase,
+       int             scope,
+       int             deref,
+       int             slimit,
+       int             tlimit,
+       Filter          *filter,
+       struct berval   *filterstr,
+       AttributeName   *attrs,
+       int             attrsonly 
 )
 {
        struct monitorinfo      *mi = (struct monitorinfo *) be->be_private;
-       int             rc;
-       Entry           *e;
+       int             rc = LDAP_SUCCESS;
+       Entry           *e, *matched = NULL;
        int             nentries = 0;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
-                  "monitor_back_search: enter\n" ));
+       LDAP_LOG( BACK_MON, ENTRY,
+                  "monitor_back_search: enter\n", 0, 0, 0 );
 #else
        Debug(LDAP_DEBUG_TRACE, "=> monitor_back_search\n%s%s%s", "", "", "");
 #endif
 
 
        /* get entry with reader lock */
-       monitor_cache_dn2entry( mi, nbase, &e );
+       monitor_cache_dn2entry( mi, nbase, &e, &matched );
        if ( e == NULL ) {
                send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
-                       NULL, NULL, NULL, NULL );
+                       matched ? matched->e_dn : NULL, 
+                       NULL, NULL, NULL );
+               if ( matched ) {
+                       monitor_cache_release( mi, matched );
+               }
 
-               return( 0 );
+               return( rc );
        }
 
        nentries = 0;
@@ -157,6 +187,7 @@ monitor_back_search(
                                        attrsonly, NULL );
                        nentries = 1;
                }
+               rc = LDAP_SUCCESS;
                monitor_cache_release( mi, e );
                break;
 
@@ -165,7 +196,7 @@ monitor_back_search(
                                attrs, attrsonly,
                                e, 0, &nentries );
                if ( rc ) {
-                       // error
+                       rc = LDAP_OTHER;
                }               
                
                break;
@@ -183,14 +214,14 @@ monitor_back_search(
                                attrs, attrsonly,
                                e, 1, &nentries );
                if ( rc ) {
-                       // error
+                       rc = LDAP_OTHER;
                }
 
                break;
        }
        
-       send_search_result( conn, op, LDAP_SUCCESS,
+       send_search_result( conn, op, rc,
                        NULL, NULL, NULL, NULL, nentries );
 
-       return( 0 );
+       return( rc == LDAP_SUCCESS ? 0 : 1 );
 }