]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/mr.c
Fixed exit code processing. passwd.c never committed its password change
[openldap] / servers / slapd / mr.c
index f40535436a61a9f2ea2f8319216c22233555e287..2ec9ebcc15090d8222362c7e24578197eda60f74 100644 (file)
@@ -36,7 +36,7 @@ mr_index_cmp(
 
 static int
 mr_index_name_cmp(
-    char               *name,
+    char               *name,
     struct mindexrec   *mir
 )
 {
@@ -49,12 +49,24 @@ mr_find( const char *mrname )
        struct mindexrec        *mir = NULL;
 
        if ( (mir = (struct mindexrec *) avl_find( mr_index, mrname,
-            (AVL_CMP) mr_index_name_cmp )) != NULL ) {
+           (AVL_CMP) mr_index_name_cmp )) != NULL ) {
                return( mir->mir_mr );
        }
        return( NULL );
 }
 
+void
+mr_destroy( void )
+{
+       MatchingRule *m, *n;
+
+       avl_free(mr_index, ldap_memfree);
+       for (m=mr_list; m; m=n) {
+               n = m->smr_next;
+               ldap_matchingrule_free((LDAPMatchingRule *)m);
+       }
+}
+
 static int
 mr_insert(
     MatchingRule       *smr,
@@ -90,7 +102,7 @@ mr_insert(
                while ( *names ) {
                        mir = (struct mindexrec *)
                                ch_calloc( 1, sizeof(struct mindexrec) );
-                       mir->mir_name = ch_strdup(*names);
+                       mir->mir_name = *names;
                        mir->mir_mr = smr;
                        if ( avl_insert( &mr_index, (caddr_t) mir,
                                         (AVL_CMP) mr_index_cmp,
@@ -116,6 +128,7 @@ mr_add(
     slap_mr_match_func *match,
        slap_mr_indexer_func *indexer,
     slap_mr_filter_func        *filter,
+       MatchingRule    *amr,
     const char         **err
 )
 {
@@ -124,7 +137,7 @@ mr_add(
        int             code;
 
        smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
-       memcpy( &smr->smr_mrule, mr, sizeof(LDAPMatchingRule));
+       AC_MEMCPY( &smr->smr_mrule, mr, sizeof(LDAPMatchingRule));
 
        smr->smr_usage = usage;
        smr->smr_convert = convert;
@@ -132,6 +145,7 @@ mr_add(
        smr->smr_match = match;
        smr->smr_indexer = indexer;
        smr->smr_filter = filter;
+       smr->smr_associated = amr;
 
        if ( smr->smr_syntax_oid ) {
                if ( (syn = syn_find(smr->smr_syntax_oid)) ) {
@@ -157,34 +171,79 @@ register_matching_rule(
        slap_mr_normalize_func *normalize,
        slap_mr_match_func *match,
        slap_mr_indexer_func *indexer,
-       slap_mr_filter_func *filter )
+       slap_mr_filter_func *filter,
+       const char* associated )
 {
        LDAPMatchingRule *mr;
+       MatchingRule *amr = NULL;
        int             code;
        const char      *err;
 
        if( usage == SLAP_MR_NONE ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
+                          "register_matching_rule: %s not usable\n", desc ));
+#else
                Debug( LDAP_DEBUG_ANY, "register_matching_rule: not usable %s\n",
                    desc, 0, 0 );
+#endif
+
                return -1;
        }
 
+       if( associated != NULL ) {
+               amr = mr_find( associated );
+
+#if 0
+               /* ignore for now */
+
+               if( amr == NULL ) {
+#ifdef NEW_LOGGING
+                       LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
+                                  "register_matching_rule: could not locate associated matching rule %s for %s\n",
+                                  associated, desc ));
+#else
+                       Debug( LDAP_DEBUG_ANY, "register_matching_rule: could not locate "
+                               "associated matching rule %s for %s\n",
+                               associated, desc, 0 );
+#endif
+
+                       return -1;
+               }
+#endif
+
+       }
+
        mr = ldap_str2matchingrule( desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL);
        if ( !mr ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
+                          "register_matching_rule: %s before %s in %s.\n",
+                          ldap_scherr2str(code), err, desc ));
+#else
                Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s before %s in %s\n",
                    ldap_scherr2str(code), err, desc );
+#endif
+
                return( -1 );
        }
 
        code = mr_add( mr, usage,
-               convert, normalize, match, indexer, filter,
+               convert, normalize, match, indexer, filter, amr,
                &err );
 
        ldap_memfree( mr );
 
        if ( code ) {
-               Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s for %s in %s\n",
+#ifdef NEW_LOGGING
+               LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
+                          "register_matching_rule: %s for %s in %s.\n",
+                          scherr2str(code), err, desc ));
+#else
+               Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s for %s in %s\n",
                    scherr2str(code), err, desc );
+#endif
+
                return( -1 );
        }
 
@@ -206,6 +265,11 @@ int mr_schema_info( Entry *e )
        vals[1] = NULL;
 
        for ( mr = mr_list; mr; mr = mr->smr_next ) {
+               if ( ! mr->smr_match ) {
+                       /* skip rules without matching functions */
+                       continue;
+               }
+
                val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
 
                if ( val.bv_val == NULL ) {