isupdate = be_shadow_update( op );
for (i=0, a=op->oq_add.rs_e->e_attrs; a; a=a->a_next) {
+ int is_oc = 0;
+
if ( !isupdate && a->a_desc->ad_type->sat_no_user_mod ) {
continue;
}
- ldap_back_map(&li->rwmap.rwm_at, &a->a_desc->ad_cname, &mapped,
- BACKLDAP_MAP);
- if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
- continue;
+ if ( a->a_desc == slap_schema.si_ad_objectClass
+ || a->a_desc == slap_schema.si_ad_structuralObjectClass )
+ {
+ is_oc = 1;
+ mapped = a->a_desc->ad_cname;
+
+ } else {
+ ldap_back_map(&li->rwmap.rwm_at, &a->a_desc->ad_cname, &mapped,
+ BACKLDAP_MAP);
+ if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
+ continue;
+ }
}
attrs[i] = (LDAPMod *)ch_malloc(sizeof(LDAPMod));
attrs[i]->mod_op = LDAP_MOD_BVALUES;
attrs[i]->mod_type = mapped.bv_val;
- if ( a->a_desc->ad_type->sat_syntax ==
- slap_schema.si_syn_distinguishedName ) {
- /*
- * FIXME: rewrite could fail; in this case
- * the operation should give up, right?
- */
- (void)ldap_dnattr_rewrite( &dc, a->a_vals );
+ if ( is_oc ) {
+ for ( j = 0; !BER_BVISNULL( &a->a_vals[ j ] ); j++ )
+ ;
+
+ attrs[ i ]->mod_bvalues =
+ (struct berval **)ch_malloc( ( j + 1 ) *
+ sizeof( struct berval * ) );
+
+ for ( j = 0; !BER_BVISNULL( &a->a_vals[ j ] ); ) {
+ struct ldapmapping *mapping;
+
+ ldap_back_mapping( &li->rwmap.rwm_oc,
+ &a->a_vals[ j ], &mapping, BACKLDAP_MAP );
+
+ if ( mapping == NULL ) {
+ if ( li->rwmap.rwm_oc.drop_missing ) {
+ continue;
+ }
+ attrs[ i ]->mod_bvalues[ j ] = &a->a_vals[ j ];
+
+ } else {
+ attrs[ i ]->mod_bvalues[ j ] = &mapping->dst;
+ }
+ j++;
+ }
+ attrs[ i ]->mod_bvalues[ j ] = NULL;
+
+ } else {
+ if ( a->a_desc->ad_type->sat_syntax ==
+ slap_schema.si_syn_distinguishedName )
+ {
+ /*
+ * FIXME: rewrite could fail; in this case
+ * the operation should give up, right?
+ */
+ (void)ldap_dnattr_rewrite( &dc, a->a_vals );
+ if ( a->a_vals == NULL || BER_BVISNULL( &a->a_vals[0] ) ) {
+ ch_free( attrs );
+ continue;
+ }
+ }
+
+ for (j=0; a->a_vals[j].bv_val; j++);
+ attrs[i]->mod_vals.modv_bvals = ch_malloc((j+1)*sizeof(struct berval *));
+ for (j=0; a->a_vals[j].bv_val; j++)
+ attrs[i]->mod_vals.modv_bvals[j] = &a->a_vals[j];
+ attrs[i]->mod_vals.modv_bvals[j] = NULL;
}
-
- for (j=0; a->a_vals[j].bv_val; j++);
- attrs[i]->mod_vals.modv_bvals = ch_malloc((j+1)*sizeof(struct berval *));
- for (j=0; a->a_vals[j].bv_val; j++)
- attrs[i]->mod_vals.modv_bvals[j] = &a->a_vals[j];
- attrs[i]->mod_vals.modv_bvals[j] = NULL;
i++;
}
attrs[i] = NULL;
*m = mapping;
}
-void
-ldap_back_map ( struct ldapmap *map, struct berval *s, struct berval *bv,
+int
+ldap_back_mapping ( struct ldapmap *map, struct berval *s, struct ldapmapping **m,
int remap )
{
Avlnode *tree;
- struct ldapmapping *mapping, fmapping;
+ struct ldapmapping fmapping;
- if (remap == BACKLDAP_REMAP)
+ assert( m );
+
+ if ( remap == BACKLDAP_REMAP ) {
tree = map->remap;
- else
+ } else {
tree = map->map;
+ }
- bv->bv_len = 0;
- bv->bv_val = NULL;
fmapping.src = *s;
- mapping = (struct ldapmapping *)avl_find( tree, (caddr_t)&fmapping, mapping_cmp );
- if (mapping != NULL) {
- if ( mapping->dst.bv_val )
+ *m = (struct ldapmapping *)avl_find( tree, (caddr_t)&fmapping, mapping_cmp );
+ if ( *m == NULL ) {
+ return map->drop_missing;
+ }
+
+ return 0;
+}
+
+void
+ldap_back_map ( struct ldapmap *map, struct berval *s, struct berval *bv,
+ int remap )
+{
+ struct ldapmapping *mapping;
+
+ BER_BVZERO( bv );
+ ( void )ldap_back_mapping( map, s, &mapping, remap );
+ if ( mapping != NULL ) {
+ if ( !BER_BVISNULL( &mapping->dst ) ) {
*bv = mapping->dst;
+ }
return;
}
- if (!map->drop_missing)
+ if ( !map->drop_missing ) {
*bv = *s;
-
- return;
+ }
}
int
}
if ( ml->sml_desc == slap_schema.si_ad_objectClass
- || ml->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
+ || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
+ {
is_oc = 1;
mapped = ml->sml_desc->ad_cname;
for (j = 0; ml->sml_values[j].bv_val; j++);
mods[i].mod_bvalues = (struct berval **)ch_malloc((j+1) *
sizeof(struct berval *));
- for (j = 0; ml->sml_values[j].bv_val; j++) {
- ldap_back_map(&li->rwmap.rwm_oc,
+ for (j = 0; ml->sml_values[j].bv_val; ) {
+ struct ldapmapping *mapping = NULL;
+
+ ldap_back_mapping(&li->rwmap.rwm_oc,
&ml->sml_values[j],
- &mapped, BACKLDAP_MAP);
- if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
- continue;
+ &mapping, BACKLDAP_MAP);
+ if ( mapping == NULL ) {
+ if ( li->rwmap.rwm_oc.drop_missing ) {
+ continue;
+ }
+ mods[i].mod_bvalues[j] = &ml->sml_values[j];
+
+ } else {
+ mods[i].mod_bvalues[j] = &mapping->dst;
}
- mods[i].mod_bvalues[j] = &mapped;
+ j++;
}
mods[i].mod_bvalues[j] = NULL;
} else {
if ( ml->sml_desc->ad_type->sat_syntax ==
- slap_schema.si_syn_distinguishedName ) {
+ slap_schema.si_syn_distinguishedName )
+ {
ldap_dnattr_rewrite( &dc, ml->sml_values );
- }
- if ( ml->sml_values == NULL ) {
- continue;
+ if ( ml->sml_values == NULL ) {
+ continue;
+ }
}
for (j = 0; ml->sml_values[j].bv_val; j++);