]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/mr.c
Patch: Delete the buggy surrogate parent code (ITS#1815)
[openldap] / servers / slapd / mr.c
index 605dbe8f84a6969619586bc7b29c9597489889ec..069b72b370f685df24595810b1df211e6440d566 100644 (file)
@@ -146,8 +146,27 @@ mr_add(
 {
        MatchingRule    *smr;
        Syntax          *syn;
+       Syntax          **compat_syn = NULL;
        int             code;
 
+       if( def->mrd_compat_syntaxes ) {
+               int i;
+               for( i=0; def->mrd_compat_syntaxes[i]; i++ ) {
+                       /* just count em */
+               }
+
+               compat_syn = ch_malloc( sizeof(Syntax *) * (i+1) );
+
+               for( i=0; def->mrd_compat_syntaxes[i]; i++ ) {
+                       compat_syn[i] = syn_find( def->mrd_compat_syntaxes[i] );
+                       if( compat_syn[i] == NULL ) {
+                               return SLAP_SCHERR_SYN_NOT_FOUND;
+                       }
+               }
+
+               compat_syn[i] = NULL;
+       }
+
        smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
        AC_MEMCPY( &smr->smr_mrule, mr, sizeof(LDAPMatchingRule));
 
@@ -158,6 +177,7 @@ mr_add(
        smr->smr_bvoid.bv_val = smr->smr_mrule.mr_oid;
        smr->smr_oidlen = strlen( mr->mr_oid );
        smr->smr_usage = def->mrd_usage;
+       smr->smr_compat_syntaxes = compat_syn;
        smr->smr_convert = def->mrd_convert;
        smr->smr_normalize = def->mrd_normalize;
        smr->smr_match = def->mrd_match;
@@ -189,7 +209,9 @@ register_matching_rule(
        int             code;
        const char      *err;
 
-       if( def->mrd_usage == SLAP_MR_NONE ) {
+       if( def->mrd_usage == SLAP_MR_NONE &&
+               def->mrd_compat_syntaxes == NULL )
+       {
 #ifdef NEW_LOGGING
                LDAP_LOG( OPERATION, ERR, 
                        "register_matching_rule: %s not usable\n", def->mrd_desc, 0, 0 );
@@ -211,7 +233,8 @@ register_matching_rule(
 #ifdef NEW_LOGGING
                        LDAP_LOG( OPERATION, ERR,
                           "register_matching_rule: could not locate associated "
-                          "matching rule %s for %s\n",  def->mrd_associated, def->mrd_desc, 0 );
+                          "matching rule %s for %s\n",
+                               def->mrd_associated, def->mrd_desc, 0 );
 #else
                        Debug( LDAP_DEBUG_ANY, "register_matching_rule: could not locate "
                                "associated matching rule %s for %s\n",
@@ -221,17 +244,18 @@ register_matching_rule(
                        return -1;
                }
 #endif
-
        }
 
-       mr = ldap_str2matchingrule( def->mrd_desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL);
+       mr = ldap_str2matchingrule( def->mrd_desc, &code, &err,
+               LDAP_SCHEMA_ALLOW_ALL );
        if ( !mr ) {
 #ifdef NEW_LOGGING
                LDAP_LOG( OPERATION, ERR, 
                        "register_matching_rule: %s before %s in %s.\n",
                        ldap_scherr2str(code), err, def->mrd_desc );
 #else
-               Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s before %s in %s\n",
+               Debug( LDAP_DEBUG_ANY,
+                       "Error in register_matching_rule: %s before %s in %s\n",
                    ldap_scherr2str(code), err, def->mrd_desc );
 #endif
 
@@ -248,7 +272,8 @@ register_matching_rule(
                        "register_matching_rule: %s for %s in %s.\n",
                        scherr2str(code), err, def->mrd_desc );
 #else
-               Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s for %s in %s\n",
+               Debug( LDAP_DEBUG_ANY,
+                       "Error in register_matching_rule: %s for %s in %s\n",
                    scherr2str(code), err, def->mrd_desc );
 #endif
 
@@ -317,8 +342,17 @@ matching_rule_use_init( void )
                        continue;
                }
 
-               /* hide rules with no type */
-               if ( um == SLAP_MR_NONE ) {
+               /* hide rules not marked as designed for extensibility */
+               /* MR_EXT means can be used any attribute type whose
+                * syntax is same as the assertion syntax.
+                * Another mechanism is needed where rule can be used
+                * with attribute of other syntaxes.
+                * Framework doesn't support this (yet).
+                */
+
+               if (!( ( mr->smr_usage & SLAP_MR_EXT )
+                       || mr->smr_compat_syntaxes ) )
+               {
                        continue;
                }
 
@@ -346,132 +380,13 @@ matching_rule_use_init( void )
                                mru->smru_names ? mru->smru_names[ 0 ] : "", 0 );
 #endif
 
-               switch ( um ) {
-               case SLAP_MR_EQUALITY:
-                       at = NULL;
-                       if ( usm == SLAP_MR_EQUALITY_APPROX ) {
-#ifdef NEW_LOGGING
-                               LDAP_LOG( OPERATION, INFO, "APPROX%s\n",
-                                               ( mr->smr_usage & SLAP_MR_EXT ) ? " (EXT)" : "",
-                                               0, 0 );
-#else
-                               Debug( LDAP_DEBUG_TRACE, "APPROX%s\n",
-                                               ( mr->smr_usage & SLAP_MR_EXT ) ? " (EXT)" : "",
-                                               0, 0 );
-#endif
-
-                               for ( at_start( &at ); at; at_next( &at ) ) {
-                                       if ( mr == at->sat_approx ) {
-#ifdef NEW_LOGGING
-                                               LDAP_LOG( OPERATION, INFO, "        %s (%s)\n",
-                                                               at->sat_oid,
-                                                               at->sat_cname.bv_val, 0 );
-#else
-                                               Debug( LDAP_DEBUG_TRACE, "        %s (%s)\n",
-                                                               at->sat_oid,
-                                                               at->sat_cname.bv_val, 0 );
-#endif
-                                               ldap_charray_add( &applies_oids,
-                                                               at->sat_oid );
-                                       }
-                               }
-
-                       } else {
-#ifdef NEW_LOGGING
-                               LDAP_LOG( OPERATION, INFO, "EQUALITY%s\n",
-                                               ( mr->smr_usage & SLAP_MR_EXT ) ? " (EXT)" : "",
-                                               0, 0 );
-#else
-                               Debug( LDAP_DEBUG_TRACE, "EQUALITY%s\n",
-                                               ( mr->smr_usage & SLAP_MR_EXT ) ? " (EXT)" : "",
-                                               0, 0 );
-#endif
-                               for ( at_start( &at ); at; at_next( &at ) ) {
-                                       if ( mr == at->sat_equality ) {
-#ifdef NEW_LOGGING
-                                               LDAP_LOG( OPERATION, INFO, "        %s (%s)\n",
-                                                               at->sat_oid,
-                                                               at->sat_cname.bv_val, 0 );
-#else
-                                               Debug( LDAP_DEBUG_TRACE, "        %s (%s)\n",
-                                                               at->sat_oid,
-                                                               at->sat_cname.bv_val, 0 );
-#endif
-                                               ldap_charray_add( &applies_oids,
-                                                               at->sat_oid );
-                                       }
-                               }
-                       }
-                       break;
-
-               case SLAP_MR_ORDERING:
-#ifdef NEW_LOGGING
-                       LDAP_LOG( OPERATION, INFO, "ORDERING%s\n",
-                                       ( mr->smr_usage & SLAP_MR_EXT ) ? " (EXT)" : "",
-                                       0, 0 );
-#else
-                       Debug( LDAP_DEBUG_TRACE, "ORDERING%s\n",
-                                       ( mr->smr_usage & SLAP_MR_EXT ) ? " (EXT)" : "",
-                                       0, 0 );
-#endif
-                       at = NULL;
-                       for ( at_start( &at ); at; at_next( &at ) ) {
-                               if ( mr == at->sat_ordering ) {
-#ifdef NEW_LOGGING
-                                       LDAP_LOG( OPERATION, INFO, "        %s (%s)\n",
-                                                       at->sat_oid,
-                                                       at->sat_cname.bv_val, 0 );
-#else
-                                       Debug( LDAP_DEBUG_TRACE, "        %s (%s)\n",
-                                                       at->sat_oid,
-                                                       at->sat_cname.bv_val, 0 );
-#endif
-                                       ldap_charray_add( &applies_oids,
-                                                       at->sat_oid );
-                               }
-                       }
-                       break;
+               at = NULL;
+               for ( at_start( &at ); at; at_next( &at ) ) {
+                       if( at->sat_flags & SLAP_AT_HIDE ) continue;
 
-               case SLAP_MR_SUBSTR:
-#ifdef NEW_LOGGING
-                       LDAP_LOG( OPERATION, INFO, "SUBSTR%s\n",
-                                       ( mr->smr_usage & SLAP_MR_EXT ) ? " (EXT)" : "",
-                                       0, 0 );
-#else
-                       Debug( LDAP_DEBUG_TRACE, "SUBSTR%s\n",
-                                       ( mr->smr_usage & SLAP_MR_EXT ) ? " (EXT)" : "",
-                                       0, 0 );
-#endif
-                       at = NULL;
-                       for ( at_start( &at ); at; at_next( &at ) ) {
-                               if ( mr == at->sat_substr ) {
-#ifdef NEW_LOGGING
-                                       LDAP_LOG( OPERATION, INFO, "        %s (%s)\n",
-                                                       at->sat_oid,
-                                                       at->sat_cname.bv_val, 0 );
-#else
-                                       Debug( LDAP_DEBUG_TRACE, "        %s (%s)\n",
-                                                       at->sat_oid,
-                                                       at->sat_cname.bv_val, 0 );
-#endif
-                                       ldap_charray_add( &applies_oids,
-                                                       at->sat_oid );
-                               }
+                       if( mr_usable_with_at( mr, at )) {
+                               ldap_charray_add( &applies_oids, at->sat_cname.bv_val );
                        }
-                       break;
-
-               default:
-#ifdef NEW_LOGGING
-                       LDAP_LOG( OPERATION, ERR, "        unknown matching rule type "
-                                       "(type mask %d, subtype mask %d%s)\n", um, usm,
-                                       ( mr->smr_usage & SLAP_MR_EXT ) ? ", EXT" : "" );
-#else
-                       Debug( LDAP_DEBUG_ANY, "        unknown matching rule type "
-                                       "(type mask %d, subtype mask %d%s)\n", um, usm,
-                                       ( mr->smr_usage & SLAP_MR_EXT ) ? ", EXT" : "" );
-#endif
-                       fprintf ( stderr, "    %d (%d)\n", um, usm );
-                       assert( 0 );
                }
 
                /*
@@ -483,13 +398,13 @@ matching_rule_use_init( void )
                        mru->smru_applies_oids = applies_oids;
 #ifdef NEW_LOGGING
                        {
-                               char    *str = ldap_matchingruleuse2str( &mru->smru_mruleuse );
+                               char *str = ldap_matchingruleuse2str( &mru->smru_mruleuse );
                                LDAP_LOG( OPERATION, INFO, "matchingRuleUse: %s\n", str, 0, 0 );
                                ldap_memfree( str );
                        }
 #else
                        {
-                               char    *str = ldap_matchingruleuse2str( &mru->smru_mruleuse );
+                               char *str = ldap_matchingruleuse2str( &mru->smru_mruleuse );
                                Debug( LDAP_DEBUG_TRACE, "matchingRuleUse: %s\n", str, 0, 0 );
                                ldap_memfree( str );
                        }
@@ -510,8 +425,27 @@ matching_rule_use_init( void )
        return( 0 );
 }
 
+int mr_usable_with_at(
+       MatchingRule *mr,
+       AttributeType *at )
+{
+       if( mr->smr_usage & SLAP_MR_EXT && ( 
+               mr->smr_syntax == at->sat_syntax ||
+               mr == at->sat_equality || mr == at->sat_approx ) )
+       {
+               return 1;
+       }
 
-#if defined( SLAPD_SCHEMA_DN )
+       if ( mr->smr_compat_syntaxes ) {
+               int i;
+               for( i=0; mr->smr_compat_syntaxes[i]; i++ ) {
+                       if( at->sat_syntax == mr->smr_compat_syntaxes[i] ) {
+                               return 1;
+                       }
+               }
+       }
+       return 0;
+}
 
 int mr_schema_info( Entry *e )
 {
@@ -570,5 +504,3 @@ int mru_schema_info( Entry *e )
        }
        return 0;
 }
-
-#endif