Slapi_Entry *
slapi_str2entry(
char *s,
- int check_dup )
+ int flags )
{
#ifdef LDAP_SLAPI
Slapi_Entry *e = NULL;
char *ldn )
{
#ifdef LDAP_SLAPI
- struct berval dn = { 0, NULL };
+ struct berval dn = BER_BVNULL;
dn.bv_val = ldn;
dn.bv_len = strlen( ldn );
}
if ( attr->a_vals != NULL && attr->a_vals[0].bv_len != 0 ) {
- return slapi_ch_strdup( attr->a_vals[0].bv_val );
+ const char *p;
+
+ p = slapi_value_get_string( &attr->a_vals[0] );
+ if ( p != NULL ) {
+ return slapi_ch_strdup( (char *)p );
+ }
}
return NULL;
#endif
}
+int
+slapi_entry_has_children(const Slapi_Entry *e)
+{
+#ifdef LDAP_SLAPI
+ Connection *pConn;
+ Operation *op;
+ int hasSubordinates = 0;
+
+ pConn = slapi_int_init_connection( NULL, LDAP_REQ_SEARCH );
+ if ( pConn == NULL ) {
+ return 0;
+ }
+
+ op = (Operation *)pConn->c_pending_ops.stqh_first;
+ op->o_bd = select_backend( (struct berval *)&e->e_nname, 0, 0 );
+ if ( op->o_bd == NULL ) {
+ return 0;
+ }
+
+ op->o_bd->be_has_subordinates( op, (Entry *)e, &hasSubordinates );
+
+ slapi_int_connection_destroy( &pConn );
+
+ return ( hasSubordinates == LDAP_COMPARE_TRUE );
+#else
+ return 0;
+#endif
+}
+
+/*
+ * Return approximate size of the entry rounded to the nearest
+ * 1K. Only the size of the attribute values are counted in the
+ * Sun implementation.
+ *
+ * http://docs.sun.com/source/816-6701-10/funcref.html#1017388
+ */
+size_t slapi_entry_size(Slapi_Entry *e)
+{
+#ifdef LDAP_SLAPI
+ size_t size;
+ Attribute *a;
+ int i;
+
+ for ( size = 0, a = e->e_attrs; a != NULL; a->a_next ) {
+ for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
+ size += a->a_vals[i].bv_len + 1;
+ }
+ }
+
+ size += 1023;
+ size -= (size % 1024);
+
+ return size;
+#else
+ return 0;
+#endif /* LDAP_SLAPI */
+}
+
/*
* Add values to entry.
*
if ( vals == NULL ) {
/* Apparently vals can be NULL
- * FIXME: sm_bvalues = NULL ? */
- mod.sm_bvalues = (BerVarray)ch_malloc( sizeof(struct berval) );
- mod.sm_bvalues->bv_val = NULL;
+ * FIXME: sm_values = NULL ? */
+ mod.sm_values = (BerVarray)ch_malloc( sizeof(struct berval) );
+ mod.sm_values->bv_val = NULL;
} else {
- rc = bvptr2obj( vals, &mod.sm_bvalues );
+ rc = bvptr2obj( vals, &mod.sm_values );
if ( rc != LDAP_SUCCESS ) {
return LDAP_CONSTRAINT_VIOLATION;
}
rc = modify_add_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
- ch_free( mod.sm_bvalues );
+ ch_free( mod.sm_values );
return (rc == LDAP_SUCCESS) ? LDAP_SUCCESS : LDAP_CONSTRAINT_VIOLATION;
#else
return attr_delete( &e->e_attrs, mod.sm_desc ) ? LDAP_OTHER : LDAP_SUCCESS;
}
- rc = bvptr2obj( vals, &mod.sm_bvalues );
+ rc = bvptr2obj( vals, &mod.sm_values );
if ( rc != LDAP_SUCCESS ) {
return LDAP_CONSTRAINT_VIOLATION;
}
rc = modify_delete_values( e, &mod, 0, &text, textbuf, sizeof(textbuf) );
- ch_free( mod.sm_bvalues );
+ ch_free( mod.sm_values );
return rc;
#else
rs.sr_attrs = an;
rs.sr_entry = e;
rs.sr_v2ref = NULL;
+ rs.sr_flags = 0;
if ( slapi_pblock_get( pb, SLAPI_OPERATION, (void *)&pOp ) != 0 ) {
return LDAP_OTHER;
char *opAuthType;
if ( op->o_bd != NULL ) {
- isRoot = be_isroot( op->o_bd, &op->o_ndn );
- isUpdateDn = be_isupdate( op->o_bd, &op->o_ndn );
+ isRoot = be_isroot( op );
+ isUpdateDn = be_isupdate( op );
}
rc = slapi_int_pblock_set_backend( pb, op->o_bd );
mp = ml->sml_next;
/* just free the containing array */
- slapi_ch_free( (void **)&ml->sml_bvalues );
+ slapi_ch_free( (void **)&ml->sml_values );
slapi_ch_free( (void **)&ml );
}
modp->mod_type = ml->sml_type.bv_val;
ml->sml_type.bv_val = NULL;
- if ( ml->sml_bvalues != NULL ) {
- for( j = 0; ml->sml_bvalues[j].bv_val != NULL; j++ )
+ if ( ml->sml_values != NULL ) {
+ for( j = 0; ml->sml_values[j].bv_val != NULL; j++ )
;
modp->mod_bvalues = (struct berval **)ch_malloc( (j + 1) *
sizeof(struct berval *) );
- for( j = 0; ml->sml_bvalues[j].bv_val != NULL; j++ ) {
+ for( j = 0; ml->sml_values[j].bv_val != NULL; j++ ) {
/* Take ownership of original values. */
modp->mod_bvalues[j] = (struct berval *)ch_malloc( sizeof(struct berval) );
- modp->mod_bvalues[j]->bv_len = ml->sml_bvalues[j].bv_len;
- modp->mod_bvalues[j]->bv_val = ml->sml_bvalues[j].bv_val;
- ml->sml_bvalues[j].bv_len = 0;
- ml->sml_bvalues[j].bv_val = NULL;
+ 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] = NULL;
} else {
}
if ( i == 0 ) {
- mod->sml_bvalues = NULL;
+ mod->sml_values = NULL;
} else {
- mod->sml_bvalues = (BerVarray) ch_malloc( (i + 1) * sizeof(struct berval) );
+ mod->sml_values = (BerVarray) ch_malloc( (i + 1) * sizeof(struct berval) );
/* NB: This implicitly trusts a plugin to return valid modifications. */
if ( (*modp)->mod_op & LDAP_MOD_BVALUES ) {
for( i = 0, bvp = (*modp)->mod_bvalues; bvp != NULL && *bvp != NULL; bvp++, i++ ) {
- mod->sml_bvalues[i].bv_val = (*bvp)->bv_val;
- mod->sml_bvalues[i].bv_len = (*bvp)->bv_len;
+ mod->sml_values[i].bv_val = (*bvp)->bv_val;
+ mod->sml_values[i].bv_len = (*bvp)->bv_len;
}
} else {
for( i = 0, p = (*modp)->mod_values; p != NULL && *p != NULL; p++, i++ ) {
- mod->sml_bvalues[i].bv_val = *p;
- mod->sml_bvalues[i].bv_len = strlen( *p );
+ mod->sml_values[i].bv_val = *p;
+ mod->sml_values[i].bv_len = strlen( *p );
}
}
- mod->sml_bvalues[i].bv_val = NULL;
- mod->sml_bvalues[i].bv_len = 0;
+ mod->sml_values[i].bv_val = NULL;
+ mod->sml_values[i].bv_len = 0;
}
mod->sml_nvalues = NULL;
* Modification list. Do free the containing array.
*/
if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
- for ( j = 0; mods[i]->mod_bvalues != NULL && mods[i]->mod_bvalues[j] != NULL; j++ ) {
- ch_free( mods[i]->mod_bvalues[j] );
+ for ( j = 0; mods[i]->mod_values != NULL && mods[i]->mod_values[j] != NULL; j++ ) {
+ ch_free( mods[i]->mod_values[j] );
}
- ch_free( mods[i]->mod_bvalues );
+ ch_free( mods[i]->mod_values );
} else {
ch_free( mods[i]->mod_values );
}
#endif /* LDAP_SLAPI */
}
+/*
+ * There is no documentation for this.
+ */
+int slapi_rdn2typeval( char *rdn, char **type, struct berval *bv )
+{
+#ifdef LDAP_SLAPI
+ LDAPRDN lrdn;
+ LDAPAVA *ava;
+ int rc;
+ char *p;
+
+ *type = NULL;
+
+ bv->bv_len = 0;
+ bv->bv_val = NULL;
+
+ rc = ldap_str2rdn( rdn, &lrdn, &p, LDAP_DN_FORMAT_LDAPV3 );
+ if ( rc != LDAP_SUCCESS ) {
+ return -1;
+ }
+
+ if ( lrdn[1] != NULL ) {
+ return -1; /* not single valued */
+ }
+
+ ava = lrdn[0];
+
+ *type = slapi_ch_strdup( ava->la_attr.bv_val );
+ ber_dupbv( bv, &ava->la_value );
+
+ ldap_rdnfree(lrdn);
+
+ return 0;
+#else
+ return -1;
+#endif /* LDAP_SLAPI */
+}
+
+char *slapi_dn_plus_rdn( const char *dn, const char *rdn )
+{
+#ifdef LDAP_SLAPI
+ struct berval new_dn, parent_dn, newrdn;
+
+ new_dn.bv_val = NULL;
+
+ parent_dn.bv_val = (char *)dn;
+ parent_dn.bv_len = strlen( dn );
+
+ newrdn.bv_val = (char *)rdn;
+ newrdn.bv_len = strlen( rdn );
+
+ build_new_dn( &new_dn, &parent_dn, &newrdn, NULL );
+
+ return new_dn.bv_val;
+#else
+ return NULL;
+#endif /* LDAP_SLAPI */
+}
+
+int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e )
+{
+#ifdef LDAP_SLAPI
+ Backend *be;
+ const char *text;
+ char textbuf[SLAP_TEXT_BUFLEN] = { '\0' };
+ size_t textlen = sizeof textbuf;
+ int rc;
+
+ if ( slapi_pblock_get( pb, SLAPI_BACKEND, (void **)&be ) != 0 )
+ return -1;
+
+ rc = entry_schema_check( be, e, NULL, &text, textbuf, textlen );
+
+ return ( rc == LDAP_SUCCESS ) ? 0 : 1;
+#else
+ return -1;
+#endif /* LDAP_SLAPI */
+}
+
+int slapi_entry_rdn_values_present( const Slapi_Entry *e )
+{
+#ifdef LDAP_SLAPI
+ LDAPDN dn;
+ int rc;
+ int i = 0, match = 0;
+ char *dn_str;
+
+ dn_str = slapi_entry_get_dn( (Slapi_Entry *) e );
+ rc = ldap_str2dn( dn_str, &dn, LDAP_DN_FORMAT_LDAPV3 );
+ if ( rc != LDAP_SUCCESS ) {
+ return 0;
+ }
+
+ if ( dn[0] != NULL ) {
+ LDAPRDN rdn = dn[0];
+
+ for ( i = 0; rdn[i] != NULL; i++ ) {
+ LDAPAVA *ava = &rdn[0][i];
+ Slapi_Attr *a = NULL;
+
+ if ( slapi_entry_attr_find( (Slapi_Entry *)e, ava->la_attr.bv_val, &a ) == 0 &&
+ slapi_attr_value_find( a, &ava->la_value ) == 0 )
+ match++;
+ }
+ }
+
+ ldap_dnfree( dn );
+
+ return ( i == match );
+#else
+ return 0;
+#endif /* LDAP_SLAPI */
+}
+
+int slapi_entry_add_rdn_values( Slapi_Entry *e )
+{
+#ifdef LDAP_SLAPI
+ LDAPDN dn;
+ int i, rc;
+ char *dn_str;
+
+ dn_str = slapi_entry_get_dn( e );
+ rc = ldap_str2dn( dn_str, &dn, LDAP_DN_FORMAT_LDAPV3 );
+ if ( rc != LDAP_SUCCESS ) {
+ return rc;
+ }
+
+ if ( dn[0] != NULL ) {
+ LDAPRDN rdn = dn[0];
+ struct berval *vals[2];
+
+ for ( i = 0; rdn[i] != NULL; i++ ) {
+ LDAPAVA *ava = &rdn[0][i];
+ Slapi_Attr *a = NULL;
+
+ if ( slapi_entry_attr_find( e, ava->la_attr.bv_val, &a ) == 0 &&
+ slapi_attr_value_find( a, &ava->la_value ) == 0 )
+ continue;
+
+ vals[0] = &ava->la_value;
+ vals[1] = NULL;
+
+ slapi_entry_attr_merge( e, ava->la_attr.bv_val, vals );
+ }
+ }
+
+ ldap_dnfree( dn );
+
+ return LDAP_SUCCESS;
+#else
+ return LDAP_OTHER;
+#endif /* LDAP_SLAPI */
+}
+