]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/search.c
modify be_referral to use struct berval DNs.
[openldap] / servers / slapd / back-ldbm / search.c
index ef0b4ab268710ad2916fcac0eb4f88116411ef66..bc5e67989c27158f2550073f9d04359e05a0a6fc 100644 (file)
@@ -37,7 +37,7 @@ ldbm_back_search(
     int                tlimit,
     Filter     *filter,
     const char *filterstr,
-    char       **attrs,
+    struct berval      **attrs,
     int                attrsonly )
 {
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
@@ -67,8 +67,7 @@ ldbm_back_search(
 
        if ( *nbase == '\0' ) {
                /* DIT root special case */
-               static const Entry root = { NOID, "", "", NULL, NULL };
-               e = (Entry *) &root;
+               e = (Entry *) &slap_entry_root;
 
                /* need normalized dn below */
                realbase = ch_strdup( e->e_ndn );
@@ -207,15 +206,15 @@ searchit:
        }
 
        /* if not root, get appropriate limits */
-       if ( be_isroot( be, op->o_ndn ) ) {
+       if ( be_isroot( be, &op->o_ndn ) ) {
                isroot = 1;
        } else {
-               ( void ) get_limits( be, op->o_ndn, &limit );
+               ( void ) get_limits( be, &op->o_ndn, &limit );
        }
 
        /* if candidates exceed to-be-checked entries, abort */
        if ( !isroot && limit->lms_s_unchecked != -1 ) {
-               if ( ID_BLOCK_NIDS( candidates ) > limit->lms_s_unchecked ) {
+               if ( ID_BLOCK_NIDS( candidates ) > (unsigned) limit->lms_s_unchecked ) {
                        send_search_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
                                        NULL, NULL, NULL, NULL, 0 );
                        rc = 0;
@@ -223,59 +222,65 @@ searchit:
                }
        }
        
-       /* if no time limit requested, use soft limit (unless root!) */
-       if ( tlimit <= 0 ) {
-               if ( isroot ) {
-                       tlimit = -1;    /* allow root to set no limit */
-               } else {
-                       tlimit = limit->lms_t_soft;
-               }
-               
-       /* if requested limit higher than hard limit, abort */
-       } else if ( tlimit > limit->lms_t_hard ) {
-               /* no hard limit means use soft instead */
-               if ( limit->lms_t_hard == 0 ) {
-                       tlimit = limit->lms_t_soft;
-                       
-               /* positive hard limit means abort */
-               } else if ( limit->lms_t_hard > 0 ) {
-                       send_search_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
-                                       NULL, NULL, NULL, NULL, 0 );
-                       rc = 0; 
-                       goto done;
+       /* if root an no specific limit is required, allow unlimited search */
+       if ( isroot ) {
+               if ( tlimit == 0 ) {
+                       tlimit = -1;
                }
 
-               /* negative hard limit means no limit */
-       }
+               if ( slimit == 0 ) {
+                       slimit = -1;
+               }
 
-       /* compute it anyway; root does not use it */
-       stoptime = op->o_time + tlimit;
+       } else {
+               /* if no limit is required, use soft limit */
+               if ( tlimit <= 0 ) {
+                       tlimit = limit->lms_t_soft;
+               
+               /* if requested limit higher than hard limit, abort */
+               } else if ( tlimit > limit->lms_t_hard ) {
+                       /* no hard limit means use soft instead */
+                       if ( limit->lms_t_hard == 0 ) {
+                               tlimit = limit->lms_t_soft;
+                       
+                       /* positive hard limit means abort */
+                       } else if ( limit->lms_t_hard > 0 ) {
+                               send_search_result( conn, op, 
+                                               LDAP_UNWILLING_TO_PERFORM,
+                                               NULL, NULL, NULL, NULL, 0 );
+                               rc = 0; 
+                               goto done;
+                       }
 
-       /* if no size limit requested, use soft limit (unless root!) */
-       if ( slimit == 0 ) {
-               if ( isroot ) {
-                       slimit = -1;    /* allow root to set no limit */
-               } else {
-                       slimit = limit->lms_s_soft;
+                       /* negative hard limit means no limit */
                }
-       
-       /* if requested limit higher than hard limit, abort */
-       } else if ( slimit > limit->lms_s_hard ) {
-               /* no hard limit means use soft instead */
-               if ( limit->lms_s_hard == 0 ) {
+
+               /* if no limit is required, use soft limit */
+               if ( slimit <= 0 ) {
                        slimit = limit->lms_s_soft;
 
-               /* positive hard limit means abort */
-               } else if ( limit->lms_s_hard > 0 ) {
-                       send_search_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
-                                       NULL, NULL, NULL, NULL, 0 );
-                       rc = 0;
-                       goto done;
-               }
+               /* if requested limit higher than hard limit, abort */
+               } else if ( slimit > limit->lms_s_hard ) {
+                       /* no hard limit means use soft instead */
+                       if ( limit->lms_s_hard == 0 ) {
+                               slimit = limit->lms_s_soft;
+
+                       /* positive hard limit means abort */
+                       } else if ( limit->lms_s_hard > 0 ) {
+                               send_search_result( conn, op,
+                                               LDAP_UNWILLING_TO_PERFORM,
+                                               NULL, NULL, NULL, NULL, 0 );
+                               rc = 0;
+                               goto done;
+                       }
 
-               /* negative hard limit means no limit */
+                       /* negative hard limit means no limit */
+               }
        }
 
+       /* compute it anyway; root does not use it */
+       stoptime = op->o_time + tlimit;
+
        for ( id = idl_firstid( candidates, &cursor ); id != NOID;
            id = idl_nextid( candidates, &cursor ) )
        {
@@ -341,7 +346,6 @@ searchit:
                                                free( pdn );
                                                goto loop_continue;
                                        }
-                                       free(pdn);
                                }
 
                        } else if ( dn_issuffix( e->e_ndn, realbase ) ) {
@@ -374,12 +378,9 @@ searchit:
                        /* check scope */
                        if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
                                if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) {
-                                       (void) dn_normalize( dn );
                                        scopeok = (dn == realbase)
                                                ? 1
                                                : (strcmp( dn, realbase ) ? 0 : 1 );
-                                       free( dn );
-
                                } else {
                                        scopeok = (realbase == NULL || *realbase == '\0');
                                }
@@ -396,8 +397,10 @@ searchit:
                        if( scopeok ) {
                                struct berval **erefs = get_entry_referrals(
                                        be, conn, op, e, NULL, cscope );
-                               struct berval **refs = referral_rewrite( erefs, e->e_dn,
-                                       NULL, scope );
+                               struct berval **refs = referral_rewrite( erefs, e->e_dn, NULL,
+                                       scope == LDAP_SCOPE_SUBTREE
+                                               ? LDAP_SCOPE_SUBTREE
+                                               : LDAP_SCOPE_BASE );
 
                                send_search_reference( be, conn, op,
                                        e, refs, NULL, &v2refs );
@@ -426,12 +429,9 @@ searchit:
                        /* check scope */
                        if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
                                if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) {
-                                       (void) dn_normalize( dn );
                                        scopeok = (dn == realbase)
                                                ? 1
                                                : (strcmp( dn, realbase ) ? 0 : 1 );
-                                       free( dn );
-
                                } else {
                                        scopeok = (realbase == NULL || *realbase == '\0');
                                }