]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/config.c
Cleanup up LDAP_CLIENT_UPDATE code... including some bug fixing.
[openldap] / servers / slapd / back-ldap / config.c
index a8e82ad0eacd6c612c246ca2760630c0d1bce8c8..42e44659bfd049f8a02f4155f16d5227871b39f9 100644 (file)
@@ -44,6 +44,7 @@
 
 #include "slap.h"
 #include "back-ldap.h"
+#include "lutil.h"
 
 int
 ldap_back_db_config(
@@ -325,18 +326,18 @@ suffix_massage_regexize( const char *s )
 
        res = ch_calloc( sizeof( char ), strlen( s ) + 4 + 4*i + 1 );
 
-       ptr = slap_strcopy( res, "(.*)" );
+       ptr = lutil_strcopy( res, "(.*)" );
        for ( i = 0, p = s;
                        ( r = strchr( p, ',' ) ) != NULL;
                        p = r + 1 , i++ ) {
-               ptr = slap_strncopy( ptr, p, r - p + 1 );
-               ptr = slap_strcopy( ptr, "[ ]?" );
+               ptr = lutil_strncopy( ptr, p, r - p + 1 );
+               ptr = lutil_strcopy( ptr, "[ ]?" );
 
                if ( r[ 1 ] == ' ' ) {
                        r++;
                }
        }
-       slap_strcopy( ptr, p );
+       lutil_strcopy( ptr, p );
 
        return res;
 }
@@ -430,10 +431,40 @@ suffix_massage_config(
                 * walk the filter looking for DN-valued attributes,
                 * and only rewrite those that require rewriting
                 */
-               char vbuf[LDAP_FILT_MAXSIZ], rbuf[LDAP_FILT_MAXSIZ];
+               char    vbuf_[BUFSIZ], *vbuf = vbuf_,
+                       rbuf_[BUFSIZ], *rbuf = rbuf_;
+               int     len;
+
+               len = snprintf( vbuf, sizeof( vbuf_ ), 
+                               "(.*)%s\\)(.*)", nvnc->bv_val );
+               if ( len == -1 ) {
+                       /* 
+                        * traditional behavior: snprintf returns -1 
+                        * if buffer is insufficient
+                        */
+                       return -1;
+
+               } else if ( len >= sizeof( vbuf_ ) ) {
+                       /* 
+                        * C99: snprintf returns the required size 
+                        */
+                       vbuf = ch_malloc( len + 1 );
+                       len = snprintf( vbuf, len,
+                                       "(.*)%s\\)(.*)", nvnc->bv_val );
+                       assert( len > 0 );
+               }
+
+               len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2", 
+                               nrnc->bv_val );
+               if ( len == -1 ) {
+                       return -1;
 
-               snprintf( vbuf, sizeof( vbuf ), "(.*)%s\\)(.*)", nvnc->bv_val );
-               snprintf( rbuf, sizeof( rbuf ), "%%1%s)%%2", nrnc->bv_val );
+               } else if ( len >= sizeof( rbuf_ ) ) {
+                       rbuf = ch_malloc( len + 1 );
+                       len = snprintf( rbuf, sizeof( rbuf_ ), "%%1%s)%%2", 
+                                       nrnc->bv_val );
+                       assert( len > 0 );
+               }
                
                rargv[ 0 ] = "rewriteRule";
                rargv[ 1 ] = vbuf;
@@ -441,6 +472,14 @@ suffix_massage_config(
                rargv[ 3 ] = ":";
                rargv[ 4 ] = NULL;
                rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
+
+               if ( vbuf != vbuf_ ) {
+                       ch_free( vbuf );
+               }
+
+               if ( rbuf != rbuf_ ) {
+                       ch_free( rbuf );
+               }
        }
 #endif /* rewrite filters */