/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2002-2005 The OpenLDAP Foundation.
+ * Copyright 2002-2007 The OpenLDAP Foundation.
* Portions Copyright 1997,2002-2003 IBM Corporation.
* All rights reserved.
*
int
bvptr2obj(
struct berval **bvptr,
- BerVarray *bvobj )
+ BerVarray *bvobj,
+ unsigned *num )
{
int rc = LDAP_SUCCESS;
int i;
for ( i = 0; bvptr != NULL && bvptr[i] != NULL; i++ ) {
; /* EMPTY */
}
+ if ( num )
+ *num = i;
tmpberval = (BerVarray)slapi_ch_malloc( (i + 1)*sizeof(struct berval));
if ( tmpberval == NULL ) {
char *s,
int flags )
{
- Slapi_Entry *e = NULL;
- char *pTmpS;
-
- pTmpS = slapi_ch_strdup( s );
- if ( pTmpS != NULL ) {
- e = str2entry( pTmpS );
- slapi_ch_free( (void **)&pTmpS );
- }
-
- return e;
+ return str2entry( s );
}
char *
Slapi_Entry *e,
int *len )
{
- char *ret;
+ char *ret = NULL;
+ char *s;
ldap_pvt_thread_mutex_lock( &entry2str_mutex );
- ret = entry2str( e, len );
+ s = entry2str( e, len );
+ if ( s != NULL )
+ ret = slapi_ch_strdup( s );
ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
return ret;
Slapi_Entry *
slapi_entry_alloc( void )
{
- return (Slapi_Entry *)slapi_ch_calloc( 1, sizeof(Slapi_Entry) );
+ return (Slapi_Entry *)entry_alloc();
}
void
BerVarray bv;
int rc;
- rc = bvptr2obj( vals, &bv );
+ rc = slap_str2ad( type, &ad, &text );
if ( rc != LDAP_SUCCESS ) {
return -1;
}
- rc = slap_str2ad( type, &ad, &text );
+ rc = bvptr2obj( vals, &bv, NULL );
if ( rc != LDAP_SUCCESS ) {
return -1;
}
- rc = attr_merge_normalize_one( e, ad, bv, NULL );
+ rc = attr_merge_normalize( e, ad, bv, NULL );
ch_free( bv );
return rc;
p = slapi_value_get_string( &attr->a_vals[0] );
if ( p != NULL ) {
- return slapi_ch_strdup( (char *)p );
+ return slapi_ch_strdup( p );
}
}
slapi_pblock_set( pb, SLAPI_TARGET_DN, slapi_entry_get_dn( (Entry *)e ) );
- pb->pb_op->o_bd = select_backend( (struct berval *)&e->e_nname, 0, 0 );
+ pb->pb_op->o_bd = select_backend( (struct berval *)&e->e_nname, 0 );
if ( pb->pb_op->o_bd != NULL ) {
pb->pb_op->o_bd->be_has_subordinates( pb->pb_op, (Entry *)e, &hasSubordinates );
}
* FIXME: sm_values = NULL ? */
mod.sm_values = (BerVarray)ch_malloc( sizeof(struct berval) );
mod.sm_values->bv_val = NULL;
+ mod.sm_numvals = 0;
} else {
- rc = bvptr2obj( vals, &mod.sm_values );
+ rc = bvptr2obj( vals, &mod.sm_values, &mod.sm_numvals );
if ( rc != LDAP_SUCCESS ) {
return LDAP_CONSTRAINT_VIOLATION;
}
return attr_delete( &e->e_attrs, mod.sm_desc ) ? LDAP_OTHER : LDAP_SUCCESS;
}
- rc = bvptr2obj( vals, &mod.sm_values );
+ rc = bvptr2obj( vals, &mod.sm_values, &mod.sm_numvals );
if ( rc != LDAP_SUCCESS ) {
return LDAP_CONSTRAINT_VIOLATION;
}
attr_delete( &e->e_attrs, ad );
- rc = bvptr2obj( vals, &bv );
+ rc = bvptr2obj( vals, &bv, NULL );
if ( rc != LDAP_SUCCESS ) {
return -1;
}
{
struct berval dn, prettyDN;
struct berval parentDN;
+ char *ret;
if ( _dn == NULL ) {
return NULL;
dnParent( &prettyDN, &parentDN ); /* in-place */
- slapi_ch_free( (void **)&prettyDN.bv_val );
-
if ( parentDN.bv_len == 0 ) {
+ slapi_ch_free_string( &prettyDN.bv_val );
return NULL;
}
- return slapi_ch_strdup( parentDN.bv_val );
+ ret = slapi_ch_strdup( parentDN.bv_val );
+ slapi_ch_free_string( &prettyDN.bv_val );
+
+ return ret;
}
int slapi_dn_isbesuffix( Slapi_PBlock *pb, char *ldn )
ndn.bv_len = strlen( ldn );
ndn.bv_val = ldn;
- be = select_backend( &pb->pb_op->o_req_ndn, 0, 0 );
+ be = select_backend( &pb->pb_op->o_req_ndn, 0 );
if ( be == NULL ) {
return 0;
}
return NULL;
}
- be = select_backend( &pb->pb_op->o_req_ndn, 0, 0 );
+ be = select_backend( &pb->pb_op->o_req_ndn, 0 );
if ( be == NULL || be_issuffix( be, &normalizedDN ) == 0 ) {
dnParent( &prettyDN, &parentDN );
struct berval *
slapi_ch_bvdup(const struct berval *v)
{
- struct berval *bv;
-
- bv = (struct berval *) slapi_ch_malloc( sizeof(struct berval) );
- bv->bv_len = v->bv_len;
- bv->bv_val = slapi_ch_malloc( bv->bv_len );
- AC_MEMCPY( bv->bv_val, v->bv_val, bv->bv_len );
-
- return bv;
+ return ber_dupbv(NULL, (struct berval *)v);
}
struct berval **
}
char *
-slapi_ch_strdup( char *s )
+slapi_ch_strdup( const char *s )
{
- return ch_strdup( (const char *)s );
+ return ch_strdup( s );
}
size_t
-slapi_ch_stlen( char *s )
+slapi_ch_stlen( const char *s )
{
- return strlen( (const char *)s );
+ return strlen( s );
}
int
} else {
if ( pb->pb_op->o_tag == LDAP_REQ_SEARCH )
rs->sr_nentries = nentries;
+ if ( urls != NULL )
+ bvptr2obj( urls, &rs->sr_ref, NULL );
send_ldap_result( pb->pb_op, rs );
+
+ if ( urls != NULL )
+ slapi_ch_free( (void **)&rs->sr_ref );
}
}
int attrsonly )
{
SlapReply rs = { REP_SEARCH };
- int i = 0;
+ int i = 0, j = 0;
AttributeName *an = NULL;
const char *text;
int rc;
}
if ( i ) {
- an = (AttributeName *) slapi_ch_malloc( (i+1) * sizeof(AttributeName) );
+ an = (AttributeName *) slapi_ch_calloc( i + 1, sizeof(AttributeName) );
for ( i = 0; attrs[i] != NULL; i++ ) {
- an[i].an_name.bv_val = attrs[i];
- an[i].an_name.bv_len = strlen( attrs[i] );
- an[i].an_desc = NULL;
- rs.sr_err = slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
- if ( rs.sr_err != LDAP_SUCCESS) {
- slapi_ch_free( (void **)&an );
- return -1;
+ an[j].an_name.bv_val = attrs[i];
+ an[j].an_name.bv_len = strlen( attrs[i] );
+ an[j].an_desc = NULL;
+ if ( slap_bv2ad( &an[j].an_name, &an[j].an_desc, &text ) == LDAP_SUCCESS) {
+ j++;
}
}
- an[i].an_name.bv_len = 0;
- an[i].an_name.bv_val = NULL;
+ an[j].an_name.bv_len = 0;
+ an[j].an_name.bv_val = NULL;
}
rs.sr_err = LDAP_SUCCESS;
rs.sr_matched = NULL;
rs.sr_text = NULL;
- rc = bvptr2obj( references, &rs.sr_ref );
+ rc = bvptr2obj( references, &rs.sr_ref, NULL );
if ( rc != LDAP_SUCCESS ) {
return rc;
}
rs.sr_entry = e;
if ( v2refs != NULL ) {
- rc = bvptr2obj( v2refs, &rs.sr_v2ref );
+ rc = bvptr2obj( v2refs, &rs.sr_v2ref, NULL );
if ( rc != LDAP_SUCCESS ) {
slapi_ch_free( (void **)&rs.sr_ref );
return rc;
Slapi_Filter *
slapi_filter_dup( Slapi_Filter *filter )
{
- Filter *f;
-
- f = (Filter *) slapi_ch_malloc( sizeof(Filter) );
- f->f_next = NULL;
- f->f_choice = filter->f_choice;
-
- switch ( f->f_choice ) {
- case LDAP_FILTER_AND:
- case LDAP_FILTER_NOT:
- case LDAP_FILTER_OR: {
- Filter *pFilter, **ppF;
-
- for ( pFilter = filter->f_list, ppF = &f->f_list;
- pFilter != NULL;
- pFilter = pFilter->f_next, ppF = &f->f_next )
- {
- *ppF = slapi_filter_dup( pFilter );
- if ( *ppF == NULL )
- break;
- }
- break;
- }
- case LDAP_FILTER_PRESENT:
- f->f_desc = filter->f_desc;
- break;
- case LDAP_FILTER_EQUALITY:
- case LDAP_FILTER_GE:
- case LDAP_FILTER_LE:
- case LDAP_FILTER_APPROX:
- f->f_ava = (AttributeAssertion *)slapi_ch_malloc( sizeof(AttributeAssertion) );
- f->f_ava->aa_desc = filter->f_ava->aa_desc;
- ber_dupbv( &f->f_ava->aa_value, &filter->f_ava->aa_value );
- break;
- case LDAP_FILTER_EXT:
- f->f_mra = (MatchingRuleAssertion *)slapi_ch_malloc( sizeof(MatchingRuleAssertion) );
- f->f_mra->ma_rule = filter->f_mra->ma_rule;
- f->f_mra->ma_rule_text = filter->f_mra->ma_rule_text; /* struct copy */
- f->f_mra->ma_desc = filter->f_mra->ma_desc;
- f->f_mra->ma_dnattrs = filter->f_mra->ma_dnattrs;
- ber_dupbv( &f->f_mra->ma_value, &filter->f_mra->ma_value );
- break;
- case LDAP_FILTER_SUBSTRINGS: {
- int i;
-
- f->f_sub = (SubstringsAssertion *)slapi_ch_malloc( sizeof(SubstringsAssertion) );
- f->f_sub->sa_desc = filter->f_sub->sa_desc;
- ber_dupbv( &f->f_sub_initial, &filter->f_sub_initial );
- if ( filter->f_sub_any != NULL ) {
- for ( i = 0; filter->f_sub_any[i].bv_val != NULL; i++ )
- ;
- f->f_sub_any = (BerVarray)slapi_ch_malloc( (i + 1) * (sizeof(struct berval)) );
- for ( i = 0; filter->f_sub_any[i].bv_val != NULL; i++ ) {
- ber_dupbv( &f->f_sub_any[i], &filter->f_sub_any[i] );
- }
- f->f_sub_any[i].bv_val = NULL;
- } else {
- f->f_sub_any = NULL;
- }
- ber_dupbv( &f->f_sub_final, &filter->f_sub_final );
- break;
- }
- case SLAPD_FILTER_COMPUTED:
- f->f_result = filter->f_result;
- break;
- default:
- slapi_ch_free( (void **)&f );
- f = NULL;
- break;
- }
-
- return f;
+ return filter_dup( filter, NULL );
}
int
int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v )
{
- MatchingRule *mr;
- struct berval *bv;
- int j;
- const char *text;
int rc;
- int ret;
if ( a ->a_vals == NULL ) {
return -1;
}
- mr = a->a_desc->ad_type->sat_equality;
- for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
- rc = value_match( &ret, a->a_desc, mr,
- SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, bv, v, &text );
- if ( rc != LDAP_SUCCESS ) {
- return -1;
- }
- if ( ret == 0 ) {
- return 0;
- }
- }
- return -1;
+ rc = attr_valfind( (Attribute *)a, SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, v,
+ NULL, NULL );
+ return rc == 0 ? 0 : -1;
}
int slapi_attr_type_cmp( const char *t1, const char *t2, int opt )
Slapi_Value *slapi_value_init_string(Slapi_Value *v, const char *s)
{
- v->bv_val = slapi_ch_strdup( (char *)s );
+ v->bv_val = slapi_ch_strdup( s );
v->bv_len = strlen( s );
return v;
BerVarray vp = *vs;
ber_bvarray_free( vp );
- slapi_ch_free( (void **)&vp );
+ vp = NULL;
- *vs = NULL;
+ slapi_ch_free( (void **)&vp );
}
}
vp = *vs;
+ if ( vp == NULL )
+ return 0;
+
for ( i = 0; vp[i].bv_val != NULL; i++ )
;
if ( pb == NULL || pb->pb_op == NULL )
return LDAP_PARAM_ERROR;
- ml = slapi_int_ldapmods2modifications( mods, NULL );
+ ml = slapi_int_ldapmods2modifications( pb->pb_op, mods );
if ( ml == NULL ) {
return LDAP_OTHER;
}
/*
* Synthesise an LDAPMod array from a Modifications list to pass
- * to SLAPI. This synthesis is destructive and as such the
- * Modifications list may not be used after calling this
- * function.
- *
- * This function must also be called before slap_mods_check().
+ * to SLAPI.
*/
-LDAPMod **slapi_int_modifications2ldapmods(
- Modifications **pmodlist,
- void *memctx
-)
+LDAPMod **slapi_int_modifications2ldapmods( Modifications *modlist )
{
- Modifications *ml, *modlist;
+ Modifications *ml;
LDAPMod **mods, *modp;
int i, j;
- modlist = *pmodlist;
-
for( i = 0, ml = modlist; ml != NULL; i++, ml = ml->sml_next )
;
- mods = (LDAPMod **)slap_sl_malloc( (i + 1) * sizeof(LDAPMod *), memctx );
+ mods = (LDAPMod **)slapi_ch_malloc( (i + 1) * sizeof(LDAPMod *) );
for( i = 0, ml = modlist; ml != NULL; ml = ml->sml_next ) {
- mods[i] = (LDAPMod *)slap_sl_malloc( sizeof(LDAPMod), memctx );
+ mods[i] = (LDAPMod *)slapi_ch_malloc( sizeof(LDAPMod) );
modp = mods[i];
modp->mod_op = ml->sml_op | LDAP_MOD_BVALUES;
- modp->mod_type = slapi_ch_strdup( ml->sml_type.bv_val );
- ml->sml_type.bv_val = NULL;
+ if ( BER_BVISNULL( &ml->sml_type ) ) {
+ /* may happen for internally generated mods */
+ assert( ml->sml_desc != NULL );
+ modp->mod_type = slapi_ch_strdup( ml->sml_desc->ad_cname.bv_val );
+ } else {
+ modp->mod_type = slapi_ch_strdup( ml->sml_type.bv_val );
+ }
if ( ml->sml_values != NULL ) {
for( j = 0; ml->sml_values[j].bv_val != NULL; j++ )
;
- modp->mod_bvalues = (struct berval **)slap_sl_malloc( (j + 1) *
- sizeof(struct berval *), memctx );
+ modp->mod_bvalues = (struct berval **)slapi_ch_malloc( (j + 1) *
+ sizeof(struct berval *) );
for( j = 0; ml->sml_values[j].bv_val != NULL; j++ ) {
- /* Take ownership of original values. */
- modp->mod_bvalues[j] = (struct berval *)slap_sl_malloc(
- sizeof(struct berval), memctx );
- modp->mod_bvalues[j]->bv_len = ml->sml_values[j].bv_len;
- modp->mod_bvalues[j]->bv_val = ml->sml_values[j].bv_val;
- ml->sml_values[j].bv_len = 0;
- ml->sml_values[j].bv_val = NULL;
+ modp->mod_bvalues[j] = (struct berval *)slapi_ch_malloc(
+ sizeof(struct berval) );
+ ber_dupbv( modp->mod_bvalues[j], &ml->sml_values[j] );
}
modp->mod_bvalues[j] = NULL;
- slapi_ch_free( (void **)&ml->sml_values );
} else {
modp->mod_bvalues = NULL;
}
mods[i] = NULL;
- slap_mods_free( modlist, 1 );
- *pmodlist = NULL;
-
return mods;
}
* before prettying (and we can't easily get out of calling
* slap_mods_check() because we need normalized values).
*/
-Modifications *slapi_int_ldapmods2modifications ( LDAPMod **mods, void *memctx )
+Modifications *slapi_int_ldapmods2modifications ( Operation *op, LDAPMod **mods )
{
Modifications *modlist = NULL, **modtail;
LDAPMod **modp;
continue;
}
- mod = (Modifications *) slap_sl_malloc( sizeof(Modifications), memctx );
+ mod = (Modifications *) slapi_ch_malloc( sizeof(Modifications) );
mod->sml_op = lmod->mod_op & ~(LDAP_MOD_BVALUES);
mod->sml_flags = 0;
mod->sml_type = ad->ad_cname;
i++;
}
}
+ mod->sml_numvals = i;
if ( i == 0 ) {
mod->sml_values = NULL;
} else {
- mod->sml_values = (BerVarray) slap_sl_malloc( (i + 1) * sizeof(struct berval), memctx );
+ mod->sml_values = (BerVarray) slapi_ch_malloc( (i + 1) * sizeof(struct berval) );
/* NB: This implicitly trusts a plugin to return valid modifications. */
if ( lmod->mod_op & LDAP_MOD_BVALUES ) {
}
} else {
for ( i = 0; lmod->mod_values[i] != NULL; i++ ) {
- mod->sml_values[i].bv_val = dup ? slapi_ch_strdup( lmod->mod_values[i] ) :
- lmod->mod_values[i];
+ mod->sml_values[i].bv_val = slapi_ch_strdup( lmod->mod_values[i] );
mod->sml_values[i].bv_len = strlen( lmod->mod_values[i] );
}
}
modtail = &mod->sml_next;
}
- if ( slap_mods_check( modlist, &text, textbuf, sizeof( textbuf ), memctx ) != LDAP_SUCCESS ) {
+ if ( slap_mods_check( op, modlist, &text, textbuf, sizeof( textbuf ), NULL ) != LDAP_SUCCESS ) {
slap_mods_free( modlist, 1 );
modlist = NULL;
}
return modlist;
}
-/*
- * This function only frees the parts of the mods array that
- * are not shared with the Modification list that was created
- * by slapi_int_ldapmods2modifications() (if dup == 0).
- */
-void
-slapi_int_free_ldapmods ( LDAPMod **mods )
-{
- int i, j;
-
- if ( mods == NULL )
- return;
-
- for ( i = 0; mods[i] != NULL; i++ ) {
- /*
- * Don't free values themselves; they're owned by the
- * Modification list. Do free the containing array.
- */
- if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
- if ( mods[i]->mod_bvalues != NULL ) {
- for ( j = 0; mods[i]->mod_bvalues[j] != NULL; j++ )
- slapi_ch_free( (void **)&mods[i]->mod_bvalues[j] );
- slapi_ch_free( (void **)&mods[i]->mod_bvalues );
- }
- } else {
- slapi_ch_free( (void **)&mods[i]->mod_values );
- }
- slapi_ch_free_string( &mods[i]->mod_type );
- slapi_ch_free( (void **)&mods[i] );
- }
- slapi_ch_free( (void **)&mods );
-}
-
/*
* Sun ONE DS 5.x computed attribute support. Computed attributes
* allow for dynamically generated operational attributes, a very
break;
}
- rc = slapi_int_get_plugins( op->o_bd, SLAPI_PLUGIN_ACL_ALLOW_ACCESS, (SLAPI_FUNC **)&tmpPlugin );
+ rc = slapi_int_get_plugins( frontendDB, SLAPI_PLUGIN_ACL_ALLOW_ACCESS, (SLAPI_FUNC **)&tmpPlugin );
if ( rc != LDAP_SUCCESS || tmpPlugin == NULL ) {
/* nothing to do; allowed access */
return 1;
be_orig = pb->pb_op->o_bd;
- pb->pb_op->o_bd = select_backend( &e->e_nname, 0, 0 );
+ pb->pb_op->o_bd = select_backend( &e->e_nname, 0 );
if ( pb->pb_op->o_bd != NULL ) {
- rc = entry_schema_check( pb->pb_op, e, NULL, 0,
+ rc = entry_schema_check( pb->pb_op, e, NULL, 0, 0,
&text, textbuf, textlen );
}
pb->pb_op->o_bd = be_orig;
int rc;
size = sizeof("ldap:///");
- if ( secure )
+ if ( secure ) {
size++;
+ }
size += strlen( ldaphost );
- if ( ldapport != 0 )
+ if ( ldapport != 0 ) {
size += 32;
+ }
url = slapi_ch_malloc( size );
if ( ldapport != 0 ) {
- sprintf( url, "ldap%s://%s:%d/", ( secure ? "s" : "" ), ldaphost, ldapport );
+ rc = snprintf( url, size, "ldap%s://%s:%d/", ( secure ? "s" : "" ), ldaphost, ldapport );
} else {
- sprintf( url, "ldap%s://%s/", ( secure ? "s" : "" ), ldaphost );
+ rc = snprintf( url, size, "ldap%s://%s/", ( secure ? "s" : "" ), ldaphost );
}
- rc = ldap_initialize( &ld, url );
+ if ( rc > 0 && rc < size ) {
+ rc = ldap_initialize( &ld, url );
+ } else {
+ ld = NULL;
+ }
slapi_ch_free_string( &url );
return type;
}
+void slapi_be_set_readonly( Slapi_Backend *be, int readonly )
+{
+ if ( be == NULL )
+ return;
+
+ if ( readonly )
+ be->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
+ else
+ be->be_restrictops &= ~(SLAP_RESTRICT_OP_WRITES);
+}
+
+int slapi_be_get_readonly( Slapi_Backend *be )
+{
+ if ( be == NULL )
+ return 0;
+
+ return ( (be->be_restrictops & SLAP_RESTRICT_OP_WRITES) == SLAP_RESTRICT_OP_WRITES );
+}
+
+const char *slapi_x_be_get_updatedn( Slapi_Backend *be )
+{
+ if ( be == NULL )
+ return NULL;
+
+ return be->be_update_ndn.bv_val;
+}
+
+Slapi_Backend *slapi_be_select( const Slapi_DN *sdn )
+{
+ Slapi_Backend *be;
+
+ slapi_sdn_get_ndn( sdn );
+
+ be = select_backend( (struct berval *)&sdn->ndn, 0 );
+
+ return be;
+}
+
#if 0
void
slapi_operation_set_flag(Slapi_Operation *op, unsigned long flag)