]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-passwd/search.c
ITS#3607 add automatic BDB recovery
[openldap] / servers / slapd / back-passwd / search.c
index 2f3266378ed7b57e676e390d5d21c98092872054..ab2c7c1a2262af6289fd10dcf39a556db774de9f 100644 (file)
@@ -1,5 +1,36 @@
 /* search.c - /etc/passwd backend search function */
 /* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2005 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* Portions Copyright (c) 1995 Regents of the University of Michigan.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of Michigan at Ann Arbor. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was originally developed by the University of Michigan
+ * (as part of U-MICH LDAP).  Additional significant contributors
+ * include:
+ *     Hallvard B. Furuseth
+ *     Howard Chu
+ *     Kurt D. Zeilenga
+ */
 
 #include "portable.h"
 
@@ -14,7 +45,6 @@
 
 #include "slap.h"
 #include "back-passwd.h"
-#include <ldap_pvt.h>
 
 static void pw_start( Backend *be );
 
@@ -33,18 +63,14 @@ passwd_back_search(
        char            *s;
        time_t          stoptime;
 
-       int sent = 0;
-
-       LDAPRDN *rdn = NULL;
-       struct berval parent = { 0, NULL };
+       LDAPRDN rdn = NULL;
+       struct berval parent = BER_BVNULL;
 
        AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
 
-       op->oq_search.rs_tlimit = (op->oq_search.rs_tlimit > op->o_bd->be_timelimit || op->oq_search.rs_tlimit < 1) ? op->o_bd->be_timelimit
-           : op->oq_search.rs_tlimit;
-       stoptime = op->o_time + op->oq_search.rs_tlimit;
-       op->oq_search.rs_slimit = (op->oq_search.rs_slimit > op->o_bd->be_sizelimit || op->oq_search.rs_slimit < 1) ? op->o_bd->be_sizelimit
-           : op->oq_search.rs_slimit;
+       if (op->ors_tlimit != SLAP_NO_LIMIT ) {
+               stoptime = op->o_time + op->ors_tlimit;
+       }
 
        /* Handle a query for the base of this backend */
        if ( be_issuffix( op->o_bd, &op->o_req_ndn ) ) {
@@ -54,7 +80,7 @@ passwd_back_search(
 
                rs->sr_matched = op->o_req_dn.bv_val;
 
-               if( op->oq_search.rs_scope != LDAP_SCOPE_ONELEVEL ) {
+               if( op->ors_scope != LDAP_SCOPE_ONELEVEL ) {
                        AttributeDescription *desc = NULL;
 
                        /* Create an entry corresponding to the base DN */
@@ -76,13 +102,13 @@ passwd_back_search(
                                goto done;
                        }
 
-                       if( slap_bv2ad( &rdn[0][0]->la_attr, &desc, &rs->sr_text )) {
+                       if( slap_bv2ad( &rdn[0]->la_attr, &desc, &rs->sr_text )) {
                                rs->sr_err = LDAP_NO_SUCH_OBJECT;
                                ldap_rdnfree(rdn);
                                goto done;
                        }
 
-                       vals[0] = rdn[0][0]->la_value;
+                       vals[0] = rdn[0]->la_value;
                        attr_mergeit( e, desc, vals );
 
                        ldap_rdnfree(rdn);
@@ -99,15 +125,15 @@ passwd_back_search(
                        vals[0].bv_len = sizeof("organizationalUnit")-1;
                        attr_mergeit( e, ad_objectClass, vals );
        
-                       if ( test_filter( op, e, op->oq_search.rs_filter ) == LDAP_COMPARE_TRUE ) {
+                       if ( test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE ) {
                                rs->sr_entry = e;
-                               rs->sr_attrs = op->oq_search.rs_attrs;
+                               rs->sr_attrs = op->ors_attrs;
+                               rs->sr_flags = REP_ENTRY_MODIFIABLE;
                                send_search_entry( op, rs );
-                               sent++;
                        }
                }
 
-               if ( op->oq_search.rs_scope != LDAP_SCOPE_BASE ) {
+               if ( op->ors_scope != LDAP_SCOPE_BASE ) {
                        /* check all our "children" */
 
                        ldap_pvt_thread_mutex_lock( &passwd_mutex );
@@ -117,11 +143,13 @@ passwd_back_search(
                                if ( op->o_abandon ) {
                                        endpwent();
                                        ldap_pvt_thread_mutex_unlock( &passwd_mutex );
-                                       return( -1 );
+                                       return( SLAPD_ABANDON );
                                }
 
                                /* check time limit */
-                               if ( slap_get_time() > stoptime ) {
+                               if ( op->ors_tlimit != SLAP_NO_LIMIT
+                                               && slap_get_time() > stoptime )
+                               {
                                        send_ldap_error( op, rs, LDAP_TIMELIMIT_EXCEEDED, NULL );
                                        endpwent();
                                        ldap_pvt_thread_mutex_unlock( &passwd_mutex );
@@ -135,9 +163,9 @@ passwd_back_search(
                                        goto done;
                                }
 
-                               if ( test_filter( op, e, op->oq_search.rs_filter ) == LDAP_COMPARE_TRUE ) {
+                               if ( test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE ) {
                                        /* check size limit */
-                                       if ( --op->oq_search.rs_slimit == -1 ) {
+                                       if ( --op->ors_slimit == -1 ) {
                                                send_ldap_error( op, rs, LDAP_SIZELIMIT_EXCEEDED, NULL );
                                                endpwent();
                                                ldap_pvt_thread_mutex_unlock( &passwd_mutex );
@@ -145,9 +173,9 @@ passwd_back_search(
                                        }
 
                                        rs->sr_entry = e;
-                                       rs->sr_attrs = op->oq_search.rs_attrs;
+                                       rs->sr_attrs = op->ors_attrs;
+                                       rs->sr_flags = REP_ENTRY_MODIFIABLE;
                                        send_search_entry( op, rs );
-                                       sent++;
                                }
 
                                entry_free( e );
@@ -176,7 +204,7 @@ passwd_back_search(
                        goto done;
                }
 
-               if( op->oq_search.rs_scope == LDAP_SCOPE_ONELEVEL ) {
+               if( op->ors_scope == LDAP_SCOPE_ONELEVEL ) {
                        goto done;
                }
 
@@ -189,7 +217,7 @@ passwd_back_search(
 
                ldap_pvt_thread_mutex_lock( &passwd_mutex );
                pw_start( op->o_bd );
-               if ( (pw = getpwnam( rdn[0][0]->la_value.bv_val )) == NULL ) {
+               if ( (pw = getpwnam( rdn[0]->la_value.bv_val )) == NULL ) {
                        rs->sr_matched = parent.bv_val;
                        rs->sr_err = LDAP_NO_SUCH_OBJECT;
                        ldap_pvt_thread_mutex_unlock( &passwd_mutex );
@@ -203,11 +231,11 @@ passwd_back_search(
                        goto done;
                }
 
-               if ( test_filter( op, e, op->oq_search.rs_filter ) == LDAP_COMPARE_TRUE ) {
+               if ( test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE ) {
                        rs->sr_entry = e;
-                       rs->sr_attrs = op->oq_search.rs_attrs;
+                       rs->sr_attrs = op->ors_attrs;
+                       rs->sr_flags = REP_ENTRY_MODIFIABLE;
                        send_search_entry( op, rs );
-                       sent++;
                }
 
                entry_free( e );
@@ -215,8 +243,7 @@ passwd_back_search(
 
 done:
        if( rs->sr_err != LDAP_NO_SUCH_OBJECT ) rs->sr_matched = NULL;
-       rs->sr_nentries = sent;
-       send_search_result( op, rs );
+       send_ldap_result( op, rs );
 
        if( rdn != NULL ) ldap_rdnfree( rdn );
 
@@ -275,7 +302,7 @@ pw2entry( Backend *be, struct passwd *pw, const char **text )
        sprintf( vals[0].bv_val, "uid=%s,%s",
                pw->pw_name, be->be_suffix[0].bv_val );
 
-       rc = dnNormalize2( NULL, vals, &bv );
+       rc = dnNormalize( 0, NULL, NULL, vals, &bv, NULL );
        if( rc != LDAP_SUCCESS ) {
                free( vals[0].bv_val );
                return NULL;