]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
fix ITS#3499
authorPierangelo Masarati <ando@openldap.org>
Thu, 20 Jan 2005 23:09:12 +0000 (23:09 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 20 Jan 2005 23:09:12 +0000 (23:09 +0000)
servers/slapd/back-ldap/add.c
servers/slapd/back-ldap/map.c
servers/slapd/back-ldap/modify.c

index 82d334bd92013a9dba5e7ce10ecc98ac0223544c..5b958a2921c9a80c23fa77b0eec642bbdeb2a4df 100644 (file)
@@ -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;
index 45a2d81bce41af964433af38d45335e55c69d262..1300cafba1bcabee9e06a4bf3b39a6efd592923e 100644 (file)
@@ -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
index 7d13583964130062d4e3459759ad40454f09db5c..ecce4e8fcdff2206ab87cc2a9c1a961c54a1483d 100644 (file)
@@ -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++);