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((
}
struct berval *
-ber_bvstr(
- LDAP_CONST char *s )
+ber_str2bv(
+ LDAP_CONST char *s, int dup, struct berval *bv )
{
struct berval *new;
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;
+ }
- 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 );
+ AC_MEMCPY( new->bv_val, s, new->bv_len );
+ new->bv_val[new->bv_len] = '\0';
+ } else {
+ new->bv_val = (char *) s;
}
- return new;
+ return( new );
}
char *
}
} 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",
acl_usage();
} else {
- bv.bv_val = ch_strdup( right );
- bv.bv_len = strlen( right );
+ ber_str2bv( right, 1, &bv );
}
} else {
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);
}
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;
}
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);
}
}
}