]> git.sur5r.net Git - openldap/blobdiff - libraries/librewrite/info.c
don't trust strchr/strrchr with bervals
[openldap] / libraries / librewrite / info.c
index 723cdbc1ecb90f8cf02a4c8bc0da9509f4fc0ff3..32b5544ebf08dbc21068374863126f4702e5acc0 100644 (file)
@@ -1,26 +1,21 @@
-/******************************************************************************
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright (C) 2000 Pierangelo Masarati, <ando@sys-net.it>
+ * Copyright 2000-2005 The OpenLDAP Foundation.
  * All rights reserved.
  *
- * Permission is granted to anyone to use this software for any purpose
- * on any computer system, and to alter it and redistribute it, subject
- * to the following restrictions:
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
  *
- * 1. The author is not responsible for the consequences of use of this
- * software, no matter how awful, even if they arise from flaws in it.
- *
- * 2. The origin of this software must not be misrepresented, either by
- * explicit claim or by omission.  Since few users ever read sources,
- * credits should appear in the documentation.
- *
- * 3. Altered versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.  Since few users
- * ever read sources, credits should appear in the documentation.
- * 
- * 4. This notice may not be removed or altered.
- *
- ******************************************************************************/
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENT:
+ * This work was initially developed by Pierangelo Masarati for
+ * inclusion in OpenLDAP Software.
+ */
 
 #include <portable.h>
 
@@ -72,6 +67,7 @@ rewrite_info_init(
 
        info->li_state = REWRITE_DEFAULT;
        info->li_max_passes = REWRITE_MAX_PASSES;
+       info->li_max_passes_per_rule = REWRITE_MAX_PASSES;
        info->li_rewrite_mode = mode;
 
        /*
@@ -85,10 +81,13 @@ rewrite_info_init(
 
 #ifdef USE_REWRITE_LDAP_PVT_THREADS
        if ( ldap_pvt_thread_rdwr_init( &info->li_cookies_mutex ) ) {
+               avl_free( info->li_context, rewrite_context_free );
                free( info );
                return NULL;
        }
        if ( ldap_pvt_thread_rdwr_init( &info->li_params_mutex ) ) {
+               ldap_pvt_thread_rdwr_destroy( &info->li_cookies_mutex );
+               avl_free( info->li_context, rewrite_context_free );
                free( info );
                return NULL;
        }
@@ -120,7 +119,7 @@ rewrite_info_delete(
        if ( info->li_maps ) {
                avl_free( info->li_maps, rewrite_builtin_map_free );
        }
-       info->li_context = NULL;
+       info->li_maps = NULL;
 
        rewrite_session_destroy( info );
 
@@ -210,13 +209,16 @@ rewrite_session(
                case REWRITE_MODE_ERR:
                        rc = REWRITE_REGEXEC_ERR;
                        goto rc_return;
+                       
                case REWRITE_MODE_OK:
                        rc = REWRITE_REGEXEC_OK;
                        goto rc_return;
+
                case REWRITE_MODE_COPY_INPUT:
                        *result = strdup( string );
                        rc = REWRITE_REGEXEC_OK;
                        goto rc_return;
+
                case REWRITE_MODE_USE_DEFAULT:
                        context = rewrite_context_find( info,
                                        REWRITE_DEFAULT_CONTEXT );
@@ -261,11 +263,15 @@ rewrite_session(
         */
        case REWRITE_REGEXEC_UNWILLING:
        case REWRITE_REGEXEC_ERR:
-       default:
                if ( *result != NULL ) {
-                       free( *result );
+                       if ( *result != string ) {
+                               free( *result );
+                       }
                        *result = NULL;
                }
+
+       default:
+               break;
        }
 
 rc_return:;