}
} else if ( strcasecmp( style, "base" ) == 0 ) {
a->acl_dn_style = ACL_STYLE_BASE;
- ber_str2bv( right, 1, &a->acl_dn_pat );
+ ber_str2bv( right, 0, 1, &a->acl_dn_pat );
} else if ( strcasecmp( style, "one" ) == 0 ) {
a->acl_dn_style = ACL_STYLE_ONE;
- ber_str2bv( right, 1, &a->acl_dn_pat );
+ ber_str2bv( right, 0, 1, &a->acl_dn_pat );
} else if ( strcasecmp( style, "subtree" ) == 0 ) {
a->acl_dn_style = ACL_STYLE_SUBTREE;
- ber_str2bv( right, 1, &a->acl_dn_pat );
+ ber_str2bv( right, 0, 1, &a->acl_dn_pat );
} else if ( strcasecmp( style, "children" ) == 0 ) {
a->acl_dn_style = ACL_STYLE_CHILDREN;
- ber_str2bv( right, 1, &a->acl_dn_pat );
+ ber_str2bv( right, 0, 1, &a->acl_dn_pat );
} else {
fprintf( stderr,
"%s: line %d: unknown dn style \"%s\" in to clause\n",
bv.bv_len = 1;
} else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
- bv.bv_val = ch_strdup( "anonymous" );
- bv.bv_len = sizeof("anonymous")-1;
+ ber_str2bv("anonymous",
+ sizeof("anonymous")-1,
+ 1, &bv);
} else if ( strcasecmp( argv[i], "self" ) == 0 ) {
- bv.bv_val = ch_strdup( "self" );
- bv.bv_len = sizeof("self")-1;
+ ber_str2bv("self",
+ sizeof("self")-1,
+ 1, &bv);
} else if ( strcasecmp( argv[i], "users" ) == 0 ) {
- bv.bv_val = ch_strdup( "users" );
- bv.bv_len = sizeof("users")-1;
+ ber_str2bv("users",
+ sizeof("users")-1,
+ 1, &bv);
} else if ( strcasecmp( left, "dn" ) == 0 ) {
if ( sty == ACL_STYLE_REGEX ) {
b->a_dn_style = ACL_STYLE_REGEX;
if( right == NULL ) {
/* no '=' */
- bv.bv_val = ch_strdup( "users" );
- bv.bv_len = sizeof("users")-1;
-
+ ber_str2bv("users",
+ sizeof("users")-1,
+ 1, &bv);
} else if (*right == '\0' ) {
/* dn="" */
- bv.bv_val = ch_strdup( "anonymous" );
- bv.bv_len = sizeof("anonymous")-1;
-
+ ber_str2bv("anonymous",
+ sizeof("anonymous")-1,
+ 1, &bv);
} else if ( strcmp( right, "*" ) == 0 ) {
/* dn=* */
/* any or users? users for now */
- bv.bv_val = ch_strdup( "users" );
- bv.bv_len = sizeof("users")-1;
-
+ ber_str2bv("users",
+ sizeof("users")-1,
+ 1, &bv);
} else if ( strcmp( right, ".+" ) == 0
|| strcmp( right, "^.+" ) == 0
|| strcmp( right, ".+$" ) == 0
|| strcmp( right, ".+$$" ) == 0
|| strcmp( right, "^.+$$" ) == 0 )
{
- bv.bv_val = ch_strdup( "users" );
- bv.bv_len = sizeof("users")-1;
-
+ ber_str2bv("users",
+ sizeof("users")-1,
+ 1, &bv);
} else if ( strcmp( right, ".*" ) == 0
|| strcmp( right, "^.*" ) == 0
|| strcmp( right, ".*$" ) == 0
|| strcmp( right, ".*$$" ) == 0
|| strcmp( right, "^.*$$" ) == 0 )
{
- bv.bv_val = ch_strdup( "*" );
- bv.bv_len = 1;
+ ber_str2bv("*",
+ sizeof("*")-1,
+ 1, &bv);
} else {
bv.bv_val = right;
acl_usage();
} else {
- ber_str2bv( right, 1, &bv );
+ ber_str2bv( right, 0, 1, &bv );
}
} else {
b->a_group_pat = bv;
} else {
struct berval *ndn = NULL;
- ber_str2bv( right, 0, &bv );
+ ber_str2bv( right, 0, 0, &bv );
dnNormalize( NULL, &bv, &ndn );
b->a_group_pat = *ndn;
free(ndn);
}
b->a_set_style = sty;
- ber_str2bv( right, 1, &b->a_set_pat );
+ ber_str2bv( right, 0, 1, &b->a_set_pat );
continue;
}
Connection *conn,
BerElement *ber,
Filter **f,
- char **fstr,
+ struct berval *fstr,
const char **text );
static int get_substring_filter(
Connection *conn,
BerElement *ber,
Filter *f,
- char **fstr,
+ struct berval *fstr,
const char **text );
static int filter_escape_value(
Connection *conn,
BerElement *ber,
Filter **filt,
- char **fstr,
+ struct berval *fstr,
const char **text )
{
ber_tag_t tag;
ber_len_t len;
int err;
Filter *f;
- char *ftmp = NULL;
+ struct berval ftmp = { 0, NULL };
struct berval escaped;
#ifdef NEW_LOGGING
f->f_next = NULL;
err = LDAP_SUCCESS;
- *fstr = NULL;
+ *fstr = ftmp;
f->f_choice = tag;
switch ( f->f_choice ) {
filter_escape_value( f->f_av_value, &escaped );
- *fstr = ch_malloc( sizeof("(=)")
+ fstr->bv_len = sizeof("(=)")-1
+ f->f_av_desc->ad_cname.bv_len
- + escaped.bv_len );
+ + escaped.bv_len;
- sprintf( *fstr, "(%s=%s)",
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
+
+ sprintf( fstr->bv_val, "(%s=%s)",
f->f_av_desc->ad_cname.bv_val,
escaped.bv_val );
filter_escape_value( f->f_av_value, &escaped );
- *fstr = ch_malloc( sizeof("(>=)")
+ fstr->bv_len = sizeof("(>=)")-1
+ f->f_av_desc->ad_cname.bv_len
- + escaped.bv_len );
+ + escaped.bv_len;
+
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
- sprintf( *fstr, "(%s>=%s)",
+ sprintf( fstr->bv_val, "(%s>=%s)",
f->f_av_desc->ad_cname.bv_val,
escaped.bv_val );
filter_escape_value( f->f_av_value, &escaped );
- *fstr = ch_malloc( sizeof("(<=)")
+ fstr->bv_len = sizeof("(<=)")-1
+ f->f_av_desc->ad_cname.bv_len
- + escaped.bv_len );
+ + escaped.bv_len;
+
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
- sprintf( *fstr, "(%s<=%s)",
+ sprintf( fstr->bv_val, "(%s<=%s)",
f->f_av_desc->ad_cname.bv_val,
escaped.bv_val );
/* unrecognized attribute description or other error */
f->f_choice = SLAPD_FILTER_COMPUTED;
f->f_result = LDAP_COMPARE_FALSE;
- *fstr = ch_strdup( "(unrecogized=*)" );
+ ber_str2bv("(unrecognized=*)",
+ sizeof("(unrecognized=*)")-1, 1, fstr);
ch_free( type.bv_val );
err = LDAP_SUCCESS;
break;
ch_free( type.bv_val );
- *fstr = ch_malloc( sizeof("(=*)")
- + f->f_desc->ad_cname.bv_len );
- sprintf( *fstr, "(%s=*)",
+ fstr->bv_len = sizeof("(=*)") - 1
+ + f->f_desc->ad_cname.bv_len;
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1);
+ sprintf( fstr->bv_val, "(%s=*)",
f->f_desc->ad_cname.bv_val );
} break;
filter_escape_value( f->f_av_value, &escaped );
- *fstr = ch_malloc( sizeof("(~=)")
+ fstr->bv_len = sizeof("(~=)") - 1
+ f->f_av_desc->ad_cname.bv_len
- + escaped.bv_len );
+ + escaped.bv_len;
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1);
- sprintf( *fstr, "(%s~=%s)",
+ sprintf( fstr->bv_val, "(%s~=%s)",
f->f_av_desc->ad_cname.bv_val,
escaped.bv_val );
if ( err != LDAP_SUCCESS ) {
break;
}
- *fstr = ch_malloc( sizeof("(&)")
- + ( ftmp == NULL ? 0 : strlen( ftmp ) ) );
- sprintf( *fstr, "(&%s)",
- ftmp == NULL ? "" : ftmp );
+ fstr->bv_len = sizeof("(&)") - 1 + ftmp.bv_len;
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
+ sprintf( fstr->bv_val, "(&%s)",
+ ftmp.bv_len ? ftmp.bv_val : "" );
break;
case LDAP_FILTER_OR:
if ( err != LDAP_SUCCESS ) {
break;
}
- *fstr = ch_malloc( sizeof("(!)")
- + ( ftmp == NULL ? 0 : strlen( ftmp ) ) );
- sprintf( *fstr, "(|%s)",
- ftmp == NULL ? "" : ftmp );
+ fstr->bv_len = sizeof("(|)") - 1 + ftmp.bv_len;
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
+ sprintf( fstr->bv_val, "(|%s)",
+ ftmp.bv_len ? ftmp.bv_val : "" );
break;
case LDAP_FILTER_NOT:
if ( err != LDAP_SUCCESS ) {
break;
}
- *fstr = ch_malloc( sizeof("(!)")
- + ( ftmp == NULL ? 0 : strlen( ftmp ) ) );
- sprintf( *fstr, "(!%s)",
- ftmp == NULL ? "" : ftmp );
+ fstr->bv_len = sizeof("(!)") - 1 + ftmp.bv_len;
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
+ sprintf( fstr->bv_val, "(!%s)",
+ ftmp.bv_len ? ftmp.bv_val : "" );
break;
case LDAP_FILTER_EXT:
filter_escape_value( f->f_mr_value, &escaped );
- *fstr = ch_malloc( sizeof("(:dn::=)")
+ fstr->bv_len = sizeof("(:dn::=)") - 1
+ (f->f_mr_desc ? f->f_mr_desc->ad_cname.bv_len : 0)
- + (f->f_mr_rule_text ? strlen(f->f_mr_rule_text) : 0)
- + escaped.bv_len );
+ + f->f_mr_rule_text.bv_len
+ + escaped.bv_len;
- sprintf( *fstr, "(%s%s%s%s:=%s)",
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
+ sprintf( fstr->bv_val, "(%s%s%s%s:=%s)",
(f->f_mr_desc ? f->f_mr_desc->ad_cname.bv_val : ""),
(f->f_mr_dnattrs ? ":dn" : ""),
- (f->f_mr_rule_text ? ":" : ""),
- (f->f_mr_rule_text ? f->f_mr_rule_text : ""),
+ (f->f_mr_rule_text.bv_len ? ":" : ""),
+ (f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_val : ""),
escaped.bv_val );
ber_memfree( escaped.bv_val );
#endif
f->f_choice = SLAPD_FILTER_COMPUTED;
f->f_result = SLAPD_COMPARE_UNDEFINED;
- *fstr = ch_strdup( "(undefined)" );
+ ber_str2bv( "(undefined)", sizeof("(undefined)") - 1,
+ 1, fstr );
break;
}
- free( ftmp );
+ free( ftmp.bv_val );
if ( err != LDAP_SUCCESS ) {
- if ( *fstr != NULL ) {
- free( *fstr );
+ if ( fstr->bv_val != NULL ) {
+ free( fstr->bv_val );
}
if( err != SLAPD_DISCONNECT ) {
/* ignore error */
f->f_choice = SLAPD_FILTER_COMPUTED;
f->f_result = SLAPD_COMPARE_UNDEFINED;
- *fstr = ch_strdup( "(badfilter)" );
+ ber_str2bv( "(badfilter)", sizeof("(badfilter)") - 1,
+ 1, fstr );
err = LDAP_SUCCESS;
*filt = f;
static int
get_filter_list( Connection *conn, BerElement *ber,
- Filter **f, char **fstr,
+ Filter **f, struct berval *fstr,
const char **text )
{
Filter **new;
int err;
ber_tag_t tag;
ber_len_t len;
- char *last, *ftmp;
+ char *last;
+ struct berval ftmp;
#ifdef NEW_LOGGING
LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
#else
Debug( LDAP_DEBUG_FILTER, "begin get_filter_list\n", 0, 0, 0 );
#endif
- *fstr = NULL;
new = f;
for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
tag = ber_next_element( ber, &len, last ) )
if ( err != LDAP_SUCCESS )
return( err );
- if ( *fstr == NULL ) {
+ if ( !fstr->bv_len ) {
*fstr = ftmp;
} else {
- *fstr = ch_realloc( *fstr, strlen( *fstr ) +
- strlen( ftmp ) + 1 );
- strcat( *fstr, ftmp );
- free( ftmp );
+ int i = fstr->bv_len;
+ fstr->bv_len += ftmp.bv_len;
+ fstr->bv_val = ch_realloc( fstr->bv_val,
+ fstr->bv_len + 1 );
+ strcpy( fstr->bv_val+i, ftmp.bv_val );
+ free( ftmp.bv_val );
}
new = &(*new)->f_next;
}
Connection *conn,
BerElement *ber,
Filter *f,
- char **fstr,
+ struct berval *fstr,
const char **text
)
{
ch_free( f->f_sub );
f->f_choice = SLAPD_FILTER_COMPUTED;
f->f_result = SLAPD_COMPARE_UNDEFINED;
- *fstr = ch_strdup( "(undefined)" );
+ ber_str2bv( "(undefined)", sizeof("(undefined)")-1, 1, fstr );
return LDAP_SUCCESS;
}
f->f_sub_any = NULL;
f->f_sub_final = NULL;
- if( fstr ) {
- *fstr = ch_malloc( sizeof("(=" /*)*/) +
- f->f_sub_desc->ad_cname.bv_len );
- sprintf( *fstr, "(%s=" /*)*/, f->f_sub_desc->ad_cname.bv_val );
- }
+ fstr->bv_len = sizeof("(=" /*)*/) - 1 +
+ f->f_sub_desc->ad_cname.bv_len;
+ fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
+ sprintf( fstr->bv_val, "(%s=" /*)*/, f->f_sub_desc->ad_cname.bv_val );
for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
tag = ber_next_element( ber, &len, last ) )
f->f_sub_initial = value;
- if( fstr ) {
+ if( fstr->bv_val ) {
+ int i = fstr->bv_len;
filter_escape_value( value, &escaped );
- *fstr = ch_realloc( *fstr,
- strlen( *fstr ) + escaped.bv_len + 1 );
- strcat( *fstr, escaped.bv_val );
+ fstr->bv_len += escaped.bv_len;
+ fstr->bv_val = ch_realloc( fstr->bv_val,
+ fstr->bv_len + 1 );
+ strcpy( fstr->bv_val+i, escaped.bv_val );
ber_memfree( escaped.bv_val );
}
break;
goto return_error;
}
- if( fstr ) {
+ if( fstr->bv_val ) {
+ int i = fstr->bv_len;
filter_escape_value( value, &escaped );
- *fstr = ch_realloc( *fstr,
- strlen( *fstr ) + escaped.bv_len + 2 );
- strcat( *fstr, "*" );
- strcat( *fstr, escaped.bv_val );
+ fstr->bv_len += escaped.bv_len + 2;
+ fstr->bv_val = ch_realloc( fstr->bv_val,
+ fstr->bv_len + 1 );
+ strcpy( fstr->bv_val+i, "*" );
+ strcpy( fstr->bv_val+i+1, escaped.bv_val );
ber_memfree( escaped.bv_val );
}
break;
f->f_sub_final = value;
- if( fstr ) {
+ if( fstr->bv_val ) {
+ int i = fstr->bv_len;
filter_escape_value( value, &escaped );
- *fstr = ch_realloc( *fstr,
- strlen( *fstr ) + escaped.bv_len + 2 );
- strcat( *fstr, "*" );
- strcat( *fstr, escaped.bv_val );
+ fstr->bv_len += escaped.bv_len + 2;
+ fstr->bv_val = ch_realloc( fstr->bv_val,
+ fstr->bv_len + 1 );
+ strcpy( fstr->bv_val+i, "*" );
+ strcpy( fstr->bv_val+i+1, escaped.bv_val );
ber_memfree( escaped.bv_val );
}
break;
Debug( LDAP_DEBUG_FILTER, " error=%ld\n",
(long) rc, 0, 0 );
#endif
- if( fstr ) {
- free( *fstr );
- *fstr = NULL;
+ if( fstr->bv_val ) {
+ free( fstr->bv_val );
+ fstr->bv_val = NULL;
+ fstr->bv_len = 0;
}
ber_bvfree( f->f_sub_initial );
}
}
- if( fstr ) {
- *fstr = ch_realloc( *fstr, strlen( *fstr ) + 3 );
+ if( fstr->bv_val ) {
+ int i = fstr->bv_len;
+ fstr->bv_len += 3;
+ fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 3 );
if ( f->f_sub_final == NULL ) {
- strcat( *fstr, "*" );
+ strcpy( fstr->bv_val+i, "*" );
+ i++;
}
- strcat( *fstr, /*(*/ ")" );
+ strcpy( fstr->bv_val+i, /*(*/ ")" );
}
#ifdef NEW_LOGGING
struct berval base = { 0, NULL };
struct berval *pbase = NULL;
struct berval *nbase = NULL;
- char *fstr = NULL;
+ struct berval fstr = { 0, NULL };
Filter *filter = NULL;
struct berval **attrs = NULL;
Backend *be;
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
- "do_search: conn %d filter: %s\n", conn->c_connid, fstr ));
+ "do_search: conn %d filter: %s\n", conn->c_connid, fstr.bv_val ));
#else
- Debug( LDAP_DEBUG_ARGS, " filter: %s\n", fstr, 0, 0 );
+ Debug( LDAP_DEBUG_ARGS, " filter: %s\n", fstr.bv_val, 0, 0 );
#endif
Statslog( LDAP_DEBUG_STATS,
"conn=%ld op=%d SRCH base=\"%s\" scope=%d filter=\"%s\"\n",
- op->o_connid, op->o_opid, pbase->bv_val, scope, fstr );
+ op->o_connid, op->o_opid, pbase->bv_val, scope, fstr.bv_val );
manageDSAit = get_manageDSAit( op );
if ( be->be_search ) {
(*be->be_search)( be, conn, op, pbase->bv_val, nbase->bv_val,
scope, deref, sizelimit,
- timelimit, filter, fstr, attrs, attrsonly );
+ timelimit, filter, fstr.bv_val, attrs, attrsonly );
} else {
send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
NULL, "operation not supported within namingContext", NULL, NULL );
if( pbase != NULL) ber_bvfree( pbase );
if( nbase != NULL) ber_bvfree( nbase );
- if( fstr != NULL) free( fstr );
+ if( fstr.bv_val != NULL) free( fstr.bv_val );
if( filter != NULL) filter_free( filter );
if ( attrs != NULL ) {
ber_bvecfree( attrs );