]> git.sur5r.net Git - openldap/commitdiff
allow undefined schema items to be returned by back-ldap and remapped by the rwm...
authorPierangelo Masarati <ando@openldap.org>
Wed, 1 Dec 2004 21:47:13 +0000 (21:47 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 1 Dec 2004 21:47:13 +0000 (21:47 +0000)
servers/slapd/back-ldap/search.c
servers/slapd/oc.c
servers/slapd/overlays/rwm.c
servers/slapd/overlays/rwmconf.c
servers/slapd/schema_prep.c

index 408fb61a2d68a539b731f39616dc7a91efdcb88c..e60d6bfc5488eabab8e3ec359d38b6e3c251074e 100644 (file)
@@ -420,15 +420,24 @@ ldap_build_entry(
                        if ( pretty ) {
                                rc = pretty( attr->a_desc->ad_type->sat_syntax,
                                        &attr->a_vals[i], &pval, NULL );
+
                        } else {
                                rc = validate( attr->a_desc->ad_type->sat_syntax,
                                        &attr->a_vals[i] );
                        }
 
                        if ( rc != LDAP_SUCCESS ) {
-                               attr->a_nvals = NULL;
-                               attr_free( attr );
-                               goto next_attr;
+                               /* check if, by chance, it's an undefined objectClass */
+                               if ( attr->a_desc == slap_schema.si_ad_objectClass &&
+                                               oc_bvfind_undef( &attr->a_vals[i] ) != NULL )
+                               {
+                                       ber_dupbv( &pval, &attr->a_vals[i] );
+
+                               } else {
+                                       attr->a_nvals = NULL;
+                                       attr_free( attr );
+                                       goto next_attr;
+                               }
                        }
 
                        if ( pretty ) {
@@ -539,7 +548,7 @@ ldap_back_entry_get(
 
 retry:
        rc = ldap_search_ext_s( lc->lc_ld, ndn->bv_val, LDAP_SCOPE_BASE, filter,
-                               gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
+                               at ? gattr : NULL, 0, NULL, NULL, LDAP_NO_LIMIT,
                                LDAP_NO_LIMIT, &result );
        if ( rc != LDAP_SUCCESS ) {
                if ( rc == LDAP_SERVER_DOWN && do_retry ) {
index fcefc34449aa2ff4aa07a6b50251f79a65838134..651041f93486f8ca10dad35905cf2bb151373e85 100644 (file)
@@ -170,6 +170,47 @@ oc_bvfind( struct berval *ocname )
        return( NULL );
 }
 
+static LDAP_SLIST_HEAD(OCUList, slap_object_class) oc_undef_list
+       = LDAP_SLIST_HEAD_INITIALIZER(&oc_undef_list);
+
+ObjectClass *
+oc_bvfind_undef( struct berval *ocname )
+{
+       ObjectClass     *oc = oc_bvfind( ocname );
+
+       if ( oc ) {
+               return oc;
+       }
+
+       LDAP_SLIST_FOREACH( oc, &oc_undef_list, soc_next ) {
+               int     d = oc->soc_cname.bv_len - ocname->bv_len;
+
+               if ( d ) {
+                       continue;
+               }
+
+               if ( strcasecmp( oc->soc_cname.bv_val, ocname->bv_val ) == 0 ) {
+                       break;
+               }
+       }
+       
+       if ( oc ) {
+               return oc;
+       }
+       
+       oc = ch_malloc( sizeof( ObjectClass ) + ocname->bv_len + 1 );
+       memset( oc, 0, sizeof( ObjectClass ) );
+
+       oc->soc_cname.bv_len = ocname->bv_len;
+       oc->soc_cname.bv_val = (char *)&oc[ 1 ];
+       AC_MEMCPY( oc->soc_cname.bv_val, ocname->bv_val, ocname->bv_len );
+
+       LDAP_SLIST_NEXT( oc, soc_next ) = NULL;
+       LDAP_SLIST_INSERT_HEAD( &oc_undef_list, oc, soc_next );
+
+       return oc;
+}
+
 static int
 oc_create_required(
     ObjectClass                *soc,
@@ -337,6 +378,13 @@ oc_destroy( void )
                if (o->soc_allowed) ldap_memfree(o->soc_allowed);
                ldap_objectclass_free((LDAPObjectClass *)o);
        }
+       
+       while( !LDAP_SLIST_EMPTY(&oc_undef_list) ) {
+               o = LDAP_SLIST_FIRST(&oc_undef_list);
+               LDAP_SLIST_REMOVE_HEAD(&oc_undef_list, soc_next);
+
+               ch_free( (ObjectClass *)o );
+       }
 }
 
 static int
index 11b4da663534c10c7e8e0694c767d8364f2db17b..fc4634703dc1bbfa159f3dba1b1bf0914ac55bbb 100644 (file)
@@ -771,7 +771,9 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first )
                        goto cleanup_attr;
                }
 
-               if ( (*ap)->a_desc->ad_type->sat_no_user_mod ) {
+               if ( (*ap)->a_desc->ad_type->sat_no_user_mod 
+                       && (*ap)->a_desc->ad_type != slap_schema.si_at_undefined )
+               {
                        goto next_attr;
                }
 
index ba20bc35a7282f64c7444a3becb1227bd691d629..8ec26196f063f6670b8274c743b5378415d462d6 100644 (file)
@@ -142,10 +142,19 @@ rwm_map_config(
        "is not defined in schema\n",
                                fname, lineno, dst );
 
+                       mapping[0].m_dst_oc = oc_bvfind_undef( &mapping[0].m_dst );
+                       if ( mapping[0].m_dst_oc == NULL ) {
+                               fprintf( stderr, "%s: line %d: unable to mimic destination objectClass '%s'\n",
+                                       fname, lineno, dst );
+                               return 1;
+                       }
+
+#if 0
                        mapping[0].m_dst_oc = ch_malloc( sizeof( ObjectClass ) );
                        memset( mapping[0].m_dst_oc, 0, sizeof( ObjectClass ) );
                        mapping[0].m_dst_oc->soc_cname = mapping[0].m_dst;
                        mapping[0].m_flags |= RWMMAP_F_FREE_DST;
+#endif
                }
                mapping[1].m_src_oc = mapping[0].m_dst_oc;
 
index e81009a57b8da271d0d1c40acd35736cb770d82b..ce794edc4a42329b272b2f090974b3eafd6ea8b9 100644 (file)
@@ -1248,7 +1248,7 @@ slap_schema_load( void )
                }
        }
 
-       slap_at_undefined.sat_syntax = slap_schema.si_syn_distinguishedName;
+       slap_at_undefined.sat_syntax = slap_schema.si_syn_octetString;
        slap_schema.si_at_undefined = &slap_at_undefined;
 
        return LDAP_SUCCESS;