From: Pierangelo Masarati Date: Thu, 20 Jan 2005 23:09:12 +0000 (+0000) Subject: fix ITS#3499 X-Git-Tag: OPENLDAP_REL_ENG_2_2_21~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0fa673f5a4f0d1e3ca79d4e40939236915e0b81c;p=thirdparty%2Fopenldap.git fix ITS#3499 --- diff --git a/servers/slapd/back-ldap/add.c b/servers/slapd/back-ldap/add.c index 82d334bd92..5b958a2921 100644 --- a/servers/slapd/back-ldap/add.c +++ b/servers/slapd/back-ldap/add.c @@ -93,14 +93,24 @@ ldap_back_add( 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)); @@ -111,20 +121,54 @@ ldap_back_add( 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; diff --git a/servers/slapd/back-ldap/map.c b/servers/slapd/back-ldap/map.c index 45a2d81bce..1300cafba1 100644 --- a/servers/slapd/back-ldap/map.c +++ b/servers/slapd/back-ldap/map.c @@ -80,32 +80,48 @@ ldap_back_map_init ( struct ldapmap *lm, struct ldapmapping **m ) *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 diff --git a/servers/slapd/back-ldap/modify.c b/servers/slapd/back-ldap/modify.c index 7d13583964..ecce4e8fcd 100644 --- a/servers/slapd/back-ldap/modify.c +++ b/servers/slapd/back-ldap/modify.c @@ -101,7 +101,8 @@ ldap_back_modify( } 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; @@ -123,25 +124,34 @@ ldap_back_modify( 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++);