Commit f52cc9ba authored by Howard Chu's avatar Howard Chu
Browse files

Change struct berval ** to BVarray

parent 81e9e868
......@@ -58,7 +58,7 @@ typedef struct AciSetCookie {
Operation *op;
} AciSetCookie;
char **aci_set_gather (void *cookie, char *name, struct berval *attr);
BVarray aci_set_gather (void *cookie, char *name, struct berval *attr);
static int aci_match_set ( struct berval *subj, Backend *be,
Entry *e, Connection *conn, Operation *op, int setref );
......@@ -1021,7 +1021,7 @@ acl_check_modlist(
Modifications *mlist
)
{
int i;
struct berval *bv;
assert( be != NULL );
......@@ -1098,9 +1098,9 @@ acl_check_modlist(
if ( mlist->sml_bvalues == NULL ) {
break;
}
for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
if ( ! access_allowed( be, conn, op, e,
mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
mlist->sml_desc, bv, ACL_WRITE ) )
{
return( 0 );
}
......@@ -1116,9 +1116,9 @@ acl_check_modlist(
}
break;
}
for ( i = 0; mlist->sml_bvalues[i] != NULL; i++ ) {
for ( bv = mlist->sml_bvalues; bv->bv_val != NULL; bv++ ) {
if ( ! access_allowed( be, conn, op, e,
mlist->sml_desc, mlist->sml_bvalues[i], ACL_WRITE ) )
mlist->sml_desc, bv, ACL_WRITE ) )
{
return( 0 );
}
......@@ -1202,12 +1202,11 @@ aci_get_part(
return(bv->bv_len);
}
char **
BVarray
aci_set_gather (void *cookie, char *name, struct berval *attr)
{
AciSetCookie *cp = cookie;
struct berval **bvals = NULL;
char **vals = NULL;
BVarray bvals = NULL;
struct berval bv, ndn;
int i;
......@@ -1224,21 +1223,10 @@ aci_set_gather (void *cookie, char *name, struct berval *attr)
if (slap_bv2ad(attr, &desc, &text) == LDAP_SUCCESS) {
backend_attribute(cp->be, NULL, NULL,
cp->e, &ndn, desc, &bvals);
if (bvals != NULL) {
for (i = 0; bvals[i] != NULL; i++) { }
vals = ch_calloc(i + 1, sizeof(char *));
if (vals != NULL) {
while (--i >= 0) {
vals[i] = bvals[i]->bv_val;
bvals[i]->bv_val = NULL;
}
}
ber_bvecfree(bvals);
}
}
free(ndn.bv_val);
}
return(vals);
return(bvals);
}
static int
......@@ -1251,16 +1239,16 @@ aci_match_set (
int setref
)
{
char *set = NULL;
struct berval set = { 0, NULL };
int rc = 0;
AciSetCookie cookie;
if (setref == 0) {
set = aci_bvstrdup(subj);
ber_dupbv( &set, subj );
} else {
struct berval subjdn, ndn = { 0, NULL };
struct berval setat;
struct berval **bvals;
BVarray bvals;
const char *text;
AttributeDescription *desc = NULL;
......@@ -1289,9 +1277,15 @@ aci_match_set (
backend_attribute(be, NULL, NULL, e,
&ndn, desc, &bvals);
if ( bvals != NULL ) {
if ( bvals[0] != NULL )
set = ch_strdup(bvals[0]->bv_val);
ber_bvecfree(bvals);
if ( bvals[0].bv_val != NULL ) {
int i;
set = bvals[0];
bvals[0].bv_val = NULL;
for (i=1;bvals[i].bv_val;i++);
bvals[0].bv_val = bvals[i-1].bv_val;
bvals[i-1].bv_val = NULL;
}
bvarray_free(bvals);
}
}
if (ndn.bv_val)
......@@ -1300,13 +1294,13 @@ aci_match_set (
ch_free(subjdn.bv_val);
}
if (set != NULL) {
if (set.bv_val != NULL) {
cookie.be = be;
cookie.e = e;
cookie.conn = conn;
cookie.op = op;
rc = (set_filter(aci_set_gather, &cookie, set, op->o_ndn.bv_val, e->e_ndn, NULL) > 0);
ch_free(set);
rc = (set_filter(aci_set_gather, &cookie, &set, op->o_ndn.bv_val, e->e_ndn, NULL) > 0);
ch_free(set.bv_val);
}
return(rc);
}
......
......@@ -552,13 +552,11 @@ parse_acl(
{
int rc;
struct berval val;
struct berval *vals[2];
struct berval vals[2];
val.bv_val = b->a_group_oc->soc_oid;
val.bv_len = strlen(val.bv_val);
vals[0] = &val;
vals[1] = NULL;
vals[0].bv_val = b->a_group_oc->soc_oid;
vals[0].bv_len = strlen(vals[0].bv_val);
vals[1].bv_val = NULL;
rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
......
......@@ -40,9 +40,9 @@ do_add( Connection *conn, Operation *op )
ber_tag_t tag;
Entry *e;
Backend *be;
LDAPModList *modlist = NULL;
LDAPModList **modtail = &modlist;
Modifications *mods = NULL;
Modifications *modlist = NULL;
Modifications **modtail = &modlist;
Modifications tmp;
const char *text;
int rc = LDAP_SUCCESS;
int manageDSAit;
......@@ -112,11 +112,9 @@ do_add( Connection *conn, Operation *op )
for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
tag = ber_next_element( ber, &len, last ) )
{
LDAPModList *mod = (LDAPModList *) ch_malloc( sizeof(LDAPModList) );
mod->ml_op = LDAP_MOD_ADD;
mod->ml_next = NULL;
Modifications *mod;
rc = ber_scanf( ber, "{a{V}}", &mod->ml_type, &mod->ml_bvalues );
rc = ber_scanf( ber, "{o{W}}", &tmp.sml_type, &tmp.sml_bvalues );
if ( rc == LBER_ERROR ) {
#ifdef NEW_LOGGING
......@@ -128,28 +126,36 @@ do_add( Connection *conn, Operation *op )
send_ldap_disconnect( conn, op,
LDAP_PROTOCOL_ERROR, "decoding error" );
rc = -1;
free( mod );
goto done;
}
if ( mod->ml_bvalues == NULL ) {
if ( tmp.sml_bvalues == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
"do_add: conn %d no values for type %s\n",
conn->c_connid, mod->ml_type ));
conn->c_connid, tmp.sml_type.bv_val ));
#else
Debug( LDAP_DEBUG_ANY, "no values for type %s\n",
mod->ml_type, 0, 0 );
tmp.sml_type.bv_val, 0, 0 );
#endif
send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
NULL, "no values for attribute type", NULL, NULL );
free( mod->ml_type );
free( mod );
free( tmp.sml_type.bv_val );
goto done;
}
mod = (Modifications *) ch_malloc( sizeof(Modifications)
+ tmp.sml_type.bv_len + 1);
mod->sml_op = LDAP_MOD_ADD;
mod->sml_next = NULL;
mod->sml_desc = NULL;
mod->sml_type.bv_val = (char *)(mod+1);
strcpy(mod->sml_type.bv_val, tmp.sml_type.bv_val);
mod->sml_type.bv_len = tmp.sml_type.bv_len;
mod->sml_bvalues = tmp.sml_bvalues;
*modtail = mod;
modtail = &mod->ml_next;
modtail = &mod->sml_next;
}
if ( ber_scanf( ber, /*{*/ "}") == LBER_ERROR ) {
......@@ -184,7 +190,7 @@ do_add( Connection *conn, Operation *op )
Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d ADD dn=\"%s\"\n",
op->o_connid, op->o_opid, e->e_dn, 0, 0 );
if( e->e_ndn == NULL || *e->e_ndn == '\0' ) {
if( e->e_nname.bv_len == 0 ) {
/* protocolError may be a more appropriate error */
send_ldap_result( conn, op, rc = LDAP_ALREADY_EXISTS,
NULL, "root DSE already exists",
......@@ -209,13 +215,13 @@ do_add( Connection *conn, Operation *op )
*/
be = select_backend( &e->e_nname, manageDSAit, 0 );
if ( be == NULL ) {
struct berval **ref = referral_rewrite( default_referral,
BVarray ref = referral_rewrite( default_referral,
NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
send_ldap_result( conn, op, rc = LDAP_REFERRAL,
NULL, NULL, ref ? ref : default_referral, NULL );
ber_bvecfree( ref );
bvarray_free( ref );
goto done;
}
......@@ -250,7 +256,7 @@ do_add( Connection *conn, Operation *op )
char textbuf[SLAP_TEXT_BUFLEN];
size_t textlen = sizeof textbuf;
rc = slap_modlist2mods( modlist, update, &mods, &text,
rc = slap_mods_check( modlist, update, &text,
textbuf, textlen );
if( rc != LDAP_SUCCESS ) {
......@@ -262,15 +268,14 @@ do_add( Connection *conn, Operation *op )
if ( (be->be_lastmod == ON || (be->be_lastmod == UNDEFINED &&
global_lastmod == ON)) && !repl_user )
{
Modifications **modstail;
for( modstail = &mods;
*modstail != NULL;
modstail = &(*modstail)->sml_next )
for( modtail = &modlist;
*modtail != NULL;
modtail = &(*modtail)->sml_next )
{
assert( (*modstail)->sml_op == LDAP_MOD_ADD );
assert( (*modstail)->sml_desc != NULL );
assert( (*modtail)->sml_op == LDAP_MOD_ADD );
assert( (*modtail)->sml_desc != NULL );
}
rc = slap_mods_opattrs( op, mods, modstail, &text,
rc = slap_mods_opattrs( op, modlist, modtail, &text,
textbuf, textlen );
if( rc != LDAP_SUCCESS ) {
send_ldap_result( conn, op, rc,
......@@ -279,7 +284,7 @@ do_add( Connection *conn, Operation *op )
}
}
rc = slap_mods2entry( mods, &e, &text );
rc = slap_mods2entry( modlist, &e, &text );
if( rc != LDAP_SUCCESS ) {
send_ldap_result( conn, op, rc,
NULL, text, NULL, NULL );
......@@ -299,15 +304,15 @@ do_add( Connection *conn, Operation *op )
#ifndef SLAPD_MULTIMASTER
} else {
struct berval **defref = be->be_update_refs
BVarray defref = be->be_update_refs
? be->be_update_refs : default_referral;
struct berval **ref = referral_rewrite( defref,
BVarray ref = referral_rewrite( defref,
NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
ref ? ref : defref, NULL );
ber_bvecfree( ref );
bvarray_free( ref );
#endif
}
} else {
......@@ -325,10 +330,7 @@ done:
free( dn.bv_val );
if( modlist != NULL ) {
slap_modlist_free( modlist );
}
if( mods != NULL ) {
slap_mods_free( mods );
slap_mods_free( modlist );
}
if( e != NULL ) {
entry_free( e );
......@@ -358,20 +360,20 @@ static int slap_mods2entry(
#ifdef SLURPD_FRIENDLY
ber_len_t i,j;
for( i=0; attr->a_vals[i]; i++ ) {
for( i=0; attr->a_vals[i].bv_val; i++ ) {
/* count them */
}
for( j=0; mods->sml_bvalues[j]; j++ ) {
for( j=0; mods->sml_bvalues[j].bv_val; j++ ) {
/* count them */
}
j++; /* NULL */
attr->a_vals = ch_realloc( attr->a_vals,
sizeof( struct berval * ) * (i+j) );
sizeof( struct berval ) * (i+j) );
/* should check for duplicates */
AC_MEMCPY( &attr->a_vals[i], mods->sml_bvalues,
sizeof( struct berval * ) * j );
sizeof( struct berval ) * j );
/* trim the mods array */
ch_free( mods->sml_bvalues );
......
......@@ -402,25 +402,23 @@ at_index_print( void )
int
at_schema_info( Entry *e )
{
struct berval val;
struct berval *vals[2];
struct berval vals[2];
AttributeType *at;
AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes;
vals[0] = &val;
vals[1] = NULL;
vals[1].bv_val = NULL;
for ( at = attr_list; at; at = at->sat_next ) {
if ( ldap_attributetype2bv( &at->sat_atype, &val ) == NULL ) {
if ( ldap_attributetype2bv( &at->sat_atype, vals ) == NULL ) {
return -1;
}
#if 0
Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n",
(long) val.bv_len, val.bv_val, 0 );
(long) vals[0].bv_len, vals[0].bv_val, 0 );
#endif
attr_merge( e, ad_attributeTypes, vals );
ldap_memfree( val.bv_val );
ldap_memfree( vals[0].bv_val );
}
return 0;
}
......
......@@ -29,7 +29,7 @@ static void at_index_print( void ) {};
void
attr_free( Attribute *a )
{
ber_bvecfree( a->a_vals );
bvarray_free( a->a_vals );
free( a );
}
......@@ -55,19 +55,18 @@ Attribute *attr_dup( Attribute *a )
if( a->a_vals != NULL ) {
int i;
for( i=0; a->a_vals[i] != NULL; i++ ) {
for( i=0; a->a_vals[i].bv_val != NULL; i++ ) {
/* EMPTY */ ;
}
tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval*));
tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval));
for( i=0; a->a_vals[i] != NULL; i++ ) {
tmp->a_vals[i] = ber_bvdup( a->a_vals[i] );
if( tmp->a_vals[i] == NULL ) break;
for( i=0; a->a_vals[i].bv_val != NULL; i++ ) {
ber_dupbv( &tmp->a_vals[i], &a->a_vals[i] );
if( tmp->a_vals[i].bv_val == NULL ) break;
}
tmp->a_vals[i] = NULL;
tmp->a_vals[i].bv_val = NULL;
} else {
tmp->a_vals = NULL;
......@@ -110,7 +109,7 @@ int
attr_merge(
Entry *e,
AttributeDescription *desc,
struct berval **vals )
BVarray vals )
{
Attribute **a;
......
......@@ -120,7 +120,7 @@ retry: rc = txn_abort( ltid );
if ( p == NULL ) {
char *matched_dn = NULL;
struct berval **refs;
BVarray refs;
if ( matched != NULL ) {
matched_dn = ch_strdup( matched->e_dn );
......@@ -141,7 +141,7 @@ retry: rc = txn_abort( ltid );
send_ldap_result( conn, op, rc = LDAP_REFERRAL,
matched_dn, NULL, refs, NULL );
ber_bvecfree( refs );
bvarray_free( refs );
ch_free( matched_dn );
goto done;
......@@ -169,7 +169,7 @@ retry: rc = txn_abort( ltid );
if ( is_entry_referral( p ) ) {
/* parent is a referral, don't allow add */
char *matched_dn = ch_strdup( p->e_dn );
struct berval **refs = is_entry_referral( p )
BVarray refs = is_entry_referral( p )
? get_entry_referrals( be, conn, op, p )
: NULL;
......@@ -179,7 +179,7 @@ retry: rc = txn_abort( ltid );
send_ldap_result( conn, op, rc = LDAP_REFERRAL,
matched_dn, NULL, refs, NULL );
ber_bvecfree( refs );
bvarray_free( refs );
free( matched_dn );
goto done;
}
......
......@@ -28,13 +28,13 @@ bdb_attribute(
Entry *target,
struct berval *entry_ndn,
AttributeDescription *entry_at,
struct berval ***vals )
BVarray *vals )
{
struct bdbinfo *li = (struct bdbinfo *) be->be_private;
Entry *e;
int i, j, rc;
Attribute *attr;
struct berval **v;
BVarray v;
const char *entry_at_name = entry_at->ad_cname.bv_val;
#ifdef NEW_LOGGING
......@@ -159,23 +159,23 @@ bdb_attribute(
goto return_results;
}
for ( i = 0; attr->a_vals[i] != NULL; i++ ) {
for ( i = 0; attr->a_vals[i].bv_val != NULL; i++ ) {
/* count them */
}
v = (struct berval **) ch_malloc( sizeof(struct berval *) * (i+1) );
v = (BVarray) ch_malloc( sizeof(struct berval) * (i+1) );
for ( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
for ( i=0, j=0; attr->a_vals[i].bv_val != NULL; i++ ) {
if( conn != NULL
&& op != NULL
&& access_allowed(be, conn, op, e, entry_at,
attr->a_vals[i], ACL_READ) == 0)
&attr->a_vals[i], ACL_READ) == 0)
{
continue;
}
v[j] = ber_bvdup( attr->a_vals[i] );
ber_dupbv( &v[j], &attr->a_vals[i] );
if( v[j] != NULL ) j++;
if( v[j].bv_val != NULL ) j++;
}
if( j == 0 ) {
......@@ -183,7 +183,8 @@ bdb_attribute(
*vals = NULL;
rc = LDAP_INSUFFICIENT_ACCESS;
} else {
v[j] = NULL;
v[j].bv_val = NULL;
v[j].bv_len = 0;
*vals = v;
rc = LDAP_SUCCESS;
}
......
......@@ -58,7 +58,7 @@ bdb_bind(
/* get entry with reader lock */
if ( e == NULL ) {
char *matched_dn = NULL;
struct berval **refs;
BVarray refs;
if( matched != NULL ) {
matched_dn = ch_strdup( matched->e_dn );
......@@ -100,7 +100,7 @@ bdb_bind(
NULL, NULL, NULL, NULL );
}
ber_bvecfree( refs );
bvarray_free( refs );
free( matched_dn );
return rc;
......@@ -123,7 +123,7 @@ bdb_bind(
if ( is_entry_referral( e ) ) {
/* entry is a referral, don't allow bind */
struct berval **refs = get_entry_referrals( be,
BVarray refs = get_entry_referrals( be,
conn, op, e );
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
......@@ -138,7 +138,7 @@ bdb_bind(
NULL, NULL, NULL, NULL );
}
ber_bvecfree( refs );
bvarray_free( refs );
goto done;
}
......
......@@ -46,7 +46,7 @@ bdb_compare(
if ( e == NULL ) {
char *matched_dn = NULL;
struct berval **refs;
BVarray refs;
if ( matched != NULL ) {
matched_dn = ch_strdup( matched->e_dn );
......@@ -64,7 +64,7 @@ bdb_compare(
send_ldap_result( conn, op, rc = LDAP_REFERRAL,
matched_dn, NULL, refs, NULL );
ber_bvecfree( refs );
bvarray_free( refs );
free( matched_dn );
goto done;
......@@ -72,7 +72,7 @@ bdb_compare(
if (!manageDSAit && is_entry_referral( e ) ) {
/* entry is a referral, don't allow add */
struct berval **refs = get_entry_referrals( be,
BVarray refs = get_entry_referrals( be,
conn, op, e );
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
......@@ -81,7 +81,7 @@ bdb_compare(
send_ldap_result( conn, op, rc = LDAP_REFERRAL,
e->e_dn, NULL, refs, NULL );
ber_bvecfree( refs );
bvarray_free( refs );
goto done;
}
......
......@@ -88,7 +88,7 @@ retry: /* transaction retry */
if ( e == NULL ) {
char *matched_dn = NULL;
struct berval **refs;
BVarray refs;
Debug( LDAP_DEBUG_ARGS,
"<=- bdb_delete: no such object %s\n",
......@@ -110,7 +110,7 @@ retry: /* transaction retry */
send_ldap_result( conn, op, LDAP_REFERRAL,
matched_dn, NULL, refs, NULL );
ber_bvecfree( refs );
bvarray_free( refs );
free( matched_dn );
rc = -1;
......@@ -196,7 +196,7 @@ retry: /* transaction retry */
if ( !manageDSAit && is_entry_referral( e ) ) {
/* parent is a referral, don't allow add */
/* parent is an alias, don't allow add */
struct berval **refs = get_entry_referrals( be,
BVarray refs = get_entry_referrals( be,
conn, op, e );
Debug( LDAP_DEBUG_TRACE,
......@@ -206,7 +206,7 @@ retry: /* transaction retry */
send_ldap_result( conn, op, LDAP_REFERRAL,
e->e_dn, NULL, refs, NULL );
ber_bvecfree( refs );
bvarray_free( refs );