]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/search.c
Fix IRIX sc_mask conflict
[openldap] / servers / slapd / back-bdb / search.c
index 5dabe6b49f15f923cd584d7cbc75bf706b4ef9bc..3bea37794c7c29de6cfcd5e97767fc7a143e7632 100644 (file)
@@ -63,7 +63,7 @@ bdb_search(
        DB_LOCK         lock;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "search", LDAP_LEVEL_ENTRY,"bdb_back_search\n"));
+       LDAP_LOG ( OPERATION, ENTRY, "bdb_back_search\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> bdb_back_search\n",
                0, 0, 0);
@@ -127,7 +127,6 @@ dn2entry_retry:
 
                if ( matched != NULL ) {
                        BerVarray erefs;
-
                        ber_dupbv( &matched_dn, &matched->e_name );
 
                        erefs = is_entry_referral( matched )
@@ -176,7 +175,8 @@ dn2entry_retry:
                }
 
 #ifdef NEW_LOGGING
-               LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: entry is referral\n"));
+               LDAP_LOG ( OPERATION, RESULTS, 
+                       "bdb_search: entry is referral\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
                        0, 0, 0 );
@@ -289,7 +289,7 @@ dn2entry_retry:
 
        if ( candidates[0] == 0 ) {
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: no candidates\n"));
+       LDAP_LOG ( OPERATION, RESULTS, "bdb_search: no candidates\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
                        0, 0, 0 );
@@ -341,8 +341,8 @@ id2entry_retry:
                        send_ldap_result( conn, op, rc=LDAP_BUSY,
                                NULL, "ldap server busy", NULL, NULL );
                        goto done;
-               }
-               else if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED ) {
+
+               else if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED ) {
                        goto id2entry_retry;    
                }
 
@@ -350,7 +350,8 @@ id2entry_retry:
                        if( !BDB_IDL_IS_RANGE(candidates) ) {
                                /* only complain for non-range IDLs */
 #ifdef NEW_LOGGING
-                               LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: candidate %ld not found\n", (long) id));
+                               LDAP_LOG ( OPERATION, RESULTS,
+                                       "bdb_search: candidate %ld not found\n", (long) id, 0, 0);
 #else
                                Debug( LDAP_DEBUG_TRACE,
                                        "bdb_search: candidate %ld not found\n",
@@ -412,7 +413,8 @@ id2entry_retry:
                        } else if ( dnIsSuffix( &e->e_nname, &realbase ) ) {
                                /* alias is within scope */
 #ifdef NEW_LOGGING
-                               LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: \"%s\" in subtree\n", e->edn));
+                               LDAP_LOG ( OPERATION, RESULTS,
+                                       "bdb_search: \"%s\" in subtree\n", e->edn, 0, 0);
 #else
                                Debug( LDAP_DEBUG_TRACE,
                                        "bdb_search: \"%s\" in subtree\n",
@@ -433,18 +435,49 @@ id2entry_retry:
                if ( !manageDSAit && scope != LDAP_SCOPE_BASE &&
                        is_entry_referral( e ) )
                {
-                       BerVarray erefs = get_entry_referrals(
-                               be, conn, op, e );
-                       BerVarray refs = referral_rewrite( erefs,
-                               &e->e_name, NULL,
-                               scope == LDAP_SCOPE_SUBTREE 
-                                       ? LDAP_SCOPE_SUBTREE
-                                       : LDAP_SCOPE_BASE );
+                       struct berval   dn;
+
+                       /* check scope */
+                       if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
+                               if ( !be_issuffix( be, &e->e_nname ) ) {
+                                       dnParent( &e->e_nname, &dn );
+                                       scopeok = dn_match( &dn, &realbase );
+                               } else {
+                                       scopeok = (realbase.bv_len == 0);
+                               }
+
+                       } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
+                               scopeok = dnIsSuffix( &e->e_nname, &realbase );
+
+                       } else {
+                               scopeok = 1;
+                       }
+
+                       if( scopeok ) {
+                               BerVarray erefs = get_entry_referrals(
+                                       be, conn, op, e );
+                               BerVarray refs = referral_rewrite( erefs,
+                                       &e->e_name, NULL,
+                                       scope == LDAP_SCOPE_SUBTREE
+                                               ? LDAP_SCOPE_SUBTREE
+                                               : LDAP_SCOPE_BASE );
+
+                               send_search_reference( be, conn, op,
+                                       e, refs, NULL, &v2refs );
 
-                       send_search_reference( be, conn, op,
-                               e, refs, NULL, &v2refs );
+                               ber_bvarray_free( refs );
 
-                       ber_bvarray_free( refs );
+                       } else {
+#ifdef NEW_LOGGING
+                               LDAP_LOG(OPERATION, DETAIL2, 
+                                       "bdb_search: candidate referral %ld scope not okay\n",
+                                       id, 0, 0 );
+#else
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "bdb_search: candidate referral %ld scope not okay\n",
+                                       id, 0, 0 );
+#endif
+                       }
 
                        goto loop_continue;
                }
@@ -506,7 +539,8 @@ id2entry_retry:
                                }
                        } else {
 #ifdef NEW_LOGGING
-                               LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: %ld scope not okay\n", (long) id));
+                               LDAP_LOG ( OPERATION, RESULTS,
+                                       "bdb_search: %ld scope not okay\n", (long) id, 0, 0);
 #else
                                Debug( LDAP_DEBUG_TRACE,
                                        "bdb_search: %ld scope not okay\n",
@@ -515,7 +549,8 @@ id2entry_retry:
                        }
                } else {
 #ifdef NEW_LOGGING
-                               LDAP_LOG (( "search", LDAP_LEVEL_RESULTS,"bdb_search: %ld does match filter\n", (long) id));
+                               LDAP_LOG ( OPERATION, RESULTS,
+                                       "bdb_search: %ld does match filter\n", (long) id, 0, 0);
 #else
                        Debug( LDAP_DEBUG_TRACE,
                                "bdb_search: %ld does match filter\n",
@@ -559,7 +594,8 @@ static int base_candidate(
        ID              *ids )
 {
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "search", LDAP_LEVEL_ENTRY,"base_candidate: base: \"%s\" (0x%08lx)\n", e->e_dn, (long) e->e_id));
+       LDAP_LOG ( OPERATION, ENTRY,
+               "base_candidate: base: \"%s\" (0x%08lx)\n", e->e_dn, (long) e->e_id, 0);
 #else
        Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
                e->e_dn, (long) e->e_id, 0);
@@ -639,7 +675,9 @@ static int search_candidates(
         */
 
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "search", LDAP_LEVEL_ENTRY,"search_candidates: base=\"%s\" (0x%08lx) scope=%d\n", e->e_dn, (long) e->e_id, scope));
+       LDAP_LOG ( OPERATION, ENTRY,
+               "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n", 
+               e->e_dn, (long) e->e_id, scope);
 #else
        Debug(LDAP_DEBUG_TRACE,
                "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
@@ -703,15 +741,16 @@ static int search_candidates(
 #endif
 
        /* Allocate IDL stack, plus 1 more for former tmp */
-       stack = malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
+       stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
 
        rc = bdb_filter_candidates( be, &f, ids, stack, stack+BDB_IDL_UM_SIZE );
 
-       free( stack );
+       ch_free( stack );
 
        if( rc ) {
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "search", LDAP_LEVEL_DETAIL1,"bdb_search_candidates: failed (rc=%d)\n", rc));
+               LDAP_LOG ( OPERATION, DETAIL1,
+                       "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0  );
 #else
                Debug(LDAP_DEBUG_TRACE,
                        "bdb_search_candidates: failed (rc=%d)\n",
@@ -720,7 +759,10 @@ static int search_candidates(
 
        } else {
 #ifdef NEW_LOGGING
-               LDAP_LOG (( "search", LDAP_LEVEL_DETAIL1,"bdb_search_candidates: id=%ld first=%ld last=%ld\n", (long) ids[0], (long) BDB_IDL_FIRST(ids), (long) BDB_IDL_LAST(ids)));
+               LDAP_LOG ( OPERATION, DETAIL1,
+                       "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
+                       (long) ids[0], (long) BDB_IDL_FIRST(ids), 
+                       (long) BDB_IDL_LAST(ids));
 #else
                Debug(LDAP_DEBUG_TRACE,
                        "bdb_search_candidates: id=%ld first=%ld last=%ld\n",