]> git.sur5r.net Git - openldap/commitdiff
Fix slap_callback processing, make sure it's safe for callbacks to
authorHoward Chu <hyc@openldap.org>
Sun, 30 Oct 2005 09:50:48 +0000 (09:50 +0000)
committerHoward Chu <hyc@openldap.org>
Sun, 30 Oct 2005 09:50:48 +0000 (09:50 +0000)
delete themselves at any time.

servers/slapd/result.c

index 6ee58c16a383e08d22a337ddaa91de0727a77059..0b33bd7f0836e77dfc3502129a4515f54c0d60d6 100644 (file)
@@ -300,21 +300,20 @@ send_ldap_response(
        }
 
        if ( op->o_callback ) {
-               int             first = 1;
-               slap_callback   *sc = op->o_callback,
-                               *sc_next = op->o_callback;
+               slap_callback   *sc = op->o_callback, **sc_prev = &op->o_callback,
+                       *sc_next;
 
                rc = SLAP_CB_CONTINUE;
                for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
                        sc_next = op->o_callback->sc_next;
                        if ( op->o_callback->sc_response ) {
                                rc = op->o_callback->sc_response( op, rs );
-                               if ( first && op->o_callback == NULL ) {
-                                       sc = NULL;
+                               if ( op->o_callback != *sc_prev ) {
+                                       *sc_prev = op->o_callback;
                                }
-                               if ( rc != SLAP_CB_CONTINUE ) break;
+                               if ( rc != SLAP_CB_CONTINUE || !op->o_callback ) break;
                        }
-                       first = 0;
+                       sc_prev = &op->o_callback->sc_next;
                }
 
                op->o_callback = sc;
@@ -456,18 +455,19 @@ cleanup:;
 
 clean2:;
        if ( op->o_callback ) {
-               int             first = 1;
-               slap_callback   *sc = op->o_callback, *sc_next;
+               slap_callback   *sc = op->o_callback, **sc_prev = &op->o_callback,
+                       *sc_next;
 
                for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
                        sc_next = op->o_callback->sc_next;
                        if ( op->o_callback->sc_cleanup ) {
                                (void)op->o_callback->sc_cleanup( op, rs );
-                               if ( first && op->o_callback != sc ) {
-                                       sc = op->o_callback;
+                               if ( op->o_callback != *sc_prev ) {
+                                       *sc_prev = op->o_callback;
                                }
+                               if ( !op->o_callback ) break;
                        }
-                       first = 0;
+                       sc_prev = &op->o_callback->sc_next;
                }
                op->o_callback = sc;
        }
@@ -700,9 +700,8 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
        }
 
        if ( op->o_callback ) {
-               int             first = 1;
-               slap_callback   *sc = op->o_callback,
-                               *sc_next = op->o_callback;
+               slap_callback   *sc = op->o_callback, **sc_prev = &op->o_callback,
+                       *sc_next;
 
                rc = SLAP_CB_CONTINUE;
                for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next )
@@ -710,12 +709,12 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
                        sc_next = op->o_callback->sc_next;
                        if ( op->o_callback->sc_response ) {
                                rc = op->o_callback->sc_response( op, rs );
-                               if ( first && op->o_callback == NULL ) {
-                                       sc = NULL;
+                               if ( op->o_callback != *sc_prev ) {
+                                       *sc_prev = op->o_callback;
                                }
-                               if ( rc != SLAP_CB_CONTINUE ) break;
+                               if ( rc != SLAP_CB_CONTINUE || !op->o_callback ) break;
                        }
-                       first = 0;
+                       sc_prev = &op->o_callback->sc_next;
                }
 
                op->o_callback = sc;
@@ -1148,18 +1147,19 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
 
 error_return:;
        if ( op->o_callback ) {
-               int             first = 1;
-               slap_callback   *sc = op->o_callback, *sc_next;
+               slap_callback   *sc = op->o_callback, **sc_prev = &op->o_callback,
+                       *sc_next;
 
                for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
                        sc_next = op->o_callback->sc_next;
                        if ( op->o_callback->sc_cleanup ) {
                                (void)op->o_callback->sc_cleanup( op, rs );
-                               if ( first && op->o_callback != sc ) {
-                                       sc = op->o_callback;
+                               if ( op->o_callback != *sc_prev ) {
+                                       *sc_prev = op->o_callback;
                                }
+                               if ( !op->o_callback ) break;
                        }
-                       first = 0;
+                       sc_prev = &op->o_callback->sc_next;
                }
                op->o_callback = sc;
        }
@@ -1205,21 +1205,20 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
 
        rs->sr_type = REP_SEARCHREF;
        if ( op->o_callback ) {
-               int             first = 1;
-               slap_callback   *sc = op->o_callback,
-                               *sc_next = op->o_callback;
+               slap_callback   *sc = op->o_callback, **sc_prev = &op->o_callback,
+                       *sc_next;
 
                rc = SLAP_CB_CONTINUE;
                for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
                        sc_next = op->o_callback->sc_next;
                        if ( op->o_callback->sc_response ) {
                                rc = op->o_callback->sc_response( op, rs );
-                               if ( first && op->o_callback == NULL ) {
-                                       sc = NULL;
+                               if ( op->o_callback != *sc_prev ) {
+                                       *sc_prev = op->o_callback;
                                }
-                               if ( rc != SLAP_CB_CONTINUE ) break;
+                               if ( rc != SLAP_CB_CONTINUE || !op->o_callback ) break;
                        }
-                       first = 0;
+                       sc_prev = &op->o_callback->sc_next;
                }
 
                op->o_callback = sc;
@@ -1351,18 +1350,19 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
 
 rel:
        if ( op->o_callback ) {
-               int             first = 1;
-               slap_callback   *sc = op->o_callback, *sc_next;
+               slap_callback   *sc = op->o_callback, **sc_prev = &op->o_callback,
+                       *sc_next;
 
                for ( sc_next = op->o_callback; sc_next; op->o_callback = sc_next) {
                        sc_next = op->o_callback->sc_next;
                        if ( op->o_callback->sc_cleanup ) {
                                (void)op->o_callback->sc_cleanup( op, rs );
-                               if ( first && op->o_callback != sc ) {
-                                       sc = op->o_callback;
+                               if ( op->o_callback != *sc_prev ) {
+                                       *sc_prev = op->o_callback;
                                }
+                               if ( rc != SLAP_CB_CONTINUE || !op->o_callback ) break;
                        }
-                       first = 0;
+                       sc_prev = &op->o_callback->sc_next;
                }
                op->o_callback = sc;
        }