diff --git a/include/lber.h b/include/lber.h index 327c40acb3..cd986f72b0 100644 --- a/include/lber.h +++ b/include/lber.h @@ -549,12 +549,11 @@ ber_bvdup LDAP_P(( LDAP_CONST struct berval *bv )); LBER_F( struct berval * ) -ber_bvstr LDAP_P(( - LDAP_CONST char * )); +ber_str2bv LDAP_P(( + LDAP_CONST char *, int dup, struct berval *bv )); -LBER_F( struct berval * ) -ber_bvstrdup LDAP_P(( - LDAP_CONST char * )); +#define ber_bvstr(a) ber_str2bv(a, 0, NULL) +#define ber_bvstrdup(a) ber_str2bv(a, 1, NULL) LBER_F( char * ) ber_strdup LDAP_P(( diff --git a/libraries/liblber/memory.c b/libraries/liblber/memory.c index d836dcc6ea..0e8f4e071a 100644 --- a/libraries/liblber/memory.c +++ b/libraries/liblber/memory.c @@ -483,8 +483,8 @@ ber_bvdup( } struct berval * -ber_bvstr( - LDAP_CONST char *s ) +ber_str2bv( + LDAP_CONST char *s, int dup, struct berval *bv ) { struct berval *new; @@ -495,47 +495,33 @@ ber_bvstr( return NULL; } - if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) { - ber_errno = LBER_ERROR_MEMORY; - return NULL; + if( bv ) { + new = bv; + } else { + if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) { + ber_errno = LBER_ERROR_MEMORY; + return NULL; + } } - new->bv_val = (char *) s; new->bv_len = strlen( s ); + if ( dup ) { + if ( (new->bv_val = LBER_MALLOC( new->bv_len+1 )) == NULL ) { + ber_errno = LBER_ERROR_MEMORY; + if ( !bv ) + LBER_FREE( new ); + return NULL; + } + + AC_MEMCPY( new->bv_val, s, new->bv_len ); + new->bv_val[new->bv_len] = '\0'; + } else { + new->bv_val = (char *) s; + } return( new ); } -struct berval * -ber_bvstrdup( - LDAP_CONST char *s ) -{ - struct berval *new; - char *p; - - ber_int_options.lbo_valid = LBER_INITIALIZED; - - if( s == NULL ) { - ber_errno = LBER_ERROR_PARAM; - return NULL; - } - - p = LBER_STRDUP( s ); - - if( p == NULL ) { - ber_errno = LBER_ERROR_MEMORY; - return NULL; - } - - new = ber_bvstr( p ); - - if( new == NULL || *p == '\0' ) { - LBER_FREE( p ); - } - - return new; -} - char * ber_strdup( LDAP_CONST char *s ) { diff --git a/servers/slapd/aclparse.c b/servers/slapd/aclparse.c index e9039552ad..8405490590 100644 --- a/servers/slapd/aclparse.c +++ b/servers/slapd/aclparse.c @@ -172,24 +172,16 @@ parse_acl( } } else if ( strcasecmp( style, "base" ) == 0 ) { a->acl_dn_style = ACL_STYLE_BASE; - a->acl_dn_pat.bv_val = ch_strdup( right ); - a->acl_dn_pat.bv_len = strlen( right ); - + ber_str2bv( right, 1, &a->acl_dn_pat ); } else if ( strcasecmp( style, "one" ) == 0 ) { a->acl_dn_style = ACL_STYLE_ONE; - a->acl_dn_pat.bv_val = ch_strdup( right ); - a->acl_dn_pat.bv_len = strlen( right ); - + ber_str2bv( right, 1, &a->acl_dn_pat ); } else if ( strcasecmp( style, "subtree" ) == 0 ) { a->acl_dn_style = ACL_STYLE_SUBTREE; - a->acl_dn_pat.bv_val = ch_strdup( right ); - a->acl_dn_pat.bv_len = strlen( right ); - + ber_str2bv( right, 1, &a->acl_dn_pat ); } else if ( strcasecmp( style, "children" ) == 0 ) { a->acl_dn_style = ACL_STYLE_CHILDREN; - a->acl_dn_pat.bv_val = ch_strdup( right ); - a->acl_dn_pat.bv_len = strlen( right ); - + ber_str2bv( right, 1, &a->acl_dn_pat ); } else { fprintf( stderr, "%s: line %d: unknown dn style \"%s\" in to clause\n", @@ -366,8 +358,7 @@ parse_acl( acl_usage(); } else { - bv.bv_val = ch_strdup( right ); - bv.bv_len = strlen( right ); + ber_str2bv( right, 1, &bv ); } } else { @@ -479,8 +470,7 @@ parse_acl( b->a_group_pat = bv; } else { struct berval *ndn = NULL; - bv.bv_val = right; - bv.bv_len = strlen( right ); + ber_str2bv( right, 0, &bv ); dnNormalize( NULL, &bv, &ndn ); b->a_group_pat = *ndn; free(ndn); @@ -712,8 +702,7 @@ parse_acl( } b->a_set_style = sty; - b->a_set_pat.bv_val = ch_strdup(right); - b->a_set_pat.bv_len = strlen(right); + ber_str2bv( right, 1, &b->a_set_pat ); continue; } @@ -1205,7 +1194,7 @@ acl_regex_normalized_dn( for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) { /* DO NOTHING */ ; } - AC_MEMCPY( &p[ 1 ], &q[ 0 ], strlen( q ) + 1 ); + AC_MEMCPY( p+1, q, pattern->bv_len-(q-str)+1); } } }