]> git.sur5r.net Git - openldap/blobdiff - libraries/librewrite/map.c
Fix up abandon merge. Hallvard will holler if I get this wrong. :-)
[openldap] / libraries / librewrite / map.c
index f22bb925870f08a26ac68fb477e843db7ab85469..8db54af13711b89701804bb6fdcf5a214cf20012 100644 (file)
@@ -24,7 +24,9 @@
 
 #include <portable.h>
 
+#ifdef HAVE_PWD_H
 #include <pwd.h>
+#endif
 
 #include "rewrite-int.h"
 #include "rewrite-map.h"
@@ -123,7 +125,7 @@ rewrite_xmap_parse(
 
                l = p - s - c;
                filename = calloc( sizeof( char ), l + 1 );
-               strncpy( filename, s + c, l );
+               AC_MEMCPY( filename, s + c, l );
                filename[ l ] = '\0';
                
                map->lm_args = ( void * )fopen( filename, "r" );
@@ -177,7 +179,7 @@ rewrite_xmap_parse(
                 */
                l = p - s - c;
                url = calloc( sizeof( char ), l + 3 );
-               strncpy( url, s + c, l );
+               AC_MEMCPY( url, s + c, l );
                url[ l ] = '\0';
 
                /*
@@ -185,7 +187,7 @@ rewrite_xmap_parse(
                 */
                p = strchr( url, '%' );
                if ( p != NULL ) {
-                       memmove( p + 3, p + 1, strlen( p + 1 ) + 1 );
+                       AC_MEMCPY( p + 3, p + 1, strlen( p + 1 ) + 1 );
                        p[ 1 ] = '2';
                        p[ 2 ] = '5';
                }
@@ -243,19 +245,20 @@ rewrite_map_parse(
        for ( p = string, cnt = 1; p[ 0 ] != '\0' && cnt > 0; p++ ) {
                if ( p[ 0 ] == REWRITE_SUBMATCH_ESCAPE ) {
                        /*
-                        * '\' marks the beginning of a new map
+                        * '%' marks the beginning of a new map
                         */
                        if ( p[ 1 ] == '{' ) {
                                cnt++;
                        /*
-                        * '\' followed by a digit may mark the beginning
+                        * '%' followed by a digit may mark the beginning
                         * of an old map
                         */
-                       } else if ( isdigit( p[ 1 ] ) && p[ 2 ] == '{' ) {
+                       } else if ( isdigit( (unsigned char) p[ 1 ] ) && p[ 2 ] == '{' ) {
                                cnt++;
                                p++;
                        }
-                       p++;
+                       if ( p[ 1 ] != '\0' )
+                               p++;
                } else if ( p[ 0 ] == '}' ) {
                        cnt--;
                }
@@ -270,7 +273,7 @@ rewrite_map_parse(
         */
        l = p - string - 1;
        s = calloc( sizeof( char ), l + 1 );
-       strncpy( s, string, l );
+       AC_MEMCPY( s, string, l );
        s[ l ] = 0;
 
        /*
@@ -327,12 +330,12 @@ rewrite_map_parse(
        /*
         * Check the syntax of the variable name
         */
-       if ( !isalpha( p[ 0 ] ) ) {
+       if ( !isalpha( (unsigned char) p[ 0 ] ) ) {
                free( s );
                return NULL;
        }
        for ( p++; p[ 0 ] != '\0'; p++ ) {
-               if ( !isalnum( p[ 0 ] ) ) {
+               if ( !isalnum( (unsigned char) p[ 0 ] ) ) {
                        free( s );
                        return NULL;
                }
@@ -519,6 +522,7 @@ rewrite_xmap_apply(
        val->bv_len = 0;
        
        switch ( map->lm_type ) {
+#ifdef HAVE_GETPWNAM
        case REWRITE_MAP_XPWDMAP: {
                struct passwd *pwd;
 
@@ -562,6 +566,7 @@ rewrite_xmap_apply(
                        
                break;
        }
+#endif /* HAVE_GETPWNAM*/
        
        case REWRITE_MAP_XFILEMAP: {
                char buf[1024];
@@ -696,7 +701,7 @@ rewrite_xmap_apply(
        }
        }
 
-rc_return:
+rc_return:;
        return rc;
 }