]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/search.c
Fix ldap_send_initial_request() to open connection if not already
[openldap] / libraries / libldap / search.c
index da6e7d37636c35d446e6fe7942056e36bb8b3b4b..4aa78fb4f2cbffc4d958f4108160e422ddbec98e 100644 (file)
@@ -1,4 +1,8 @@
 /*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/*  Portions
  *  Copyright (c) 1990 Regents of the University of Michigan.
  *  All rights reserved.
  *
 
 #include "portable.h"
 
-#ifndef lint 
-static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
-#endif
-
 #include <stdio.h>
-#include <ctype.h>
 #include <stdlib.h>
 
+#include <ac/ctype.h>
 #include <ac/socket.h>
 #include <ac/string.h>
 #include <ac/time.h>
 
-#include "lber.h"
-#include "ldap.h"
 #include "ldap-int.h"
 
 static char *find_right_paren LDAP_P(( char *s ));
@@ -61,7 +59,7 @@ ldap_search( LDAP *ld, char *base, int scope, char *filter,
                return( -1 );
        }
 
-#ifndef NO_CACHE
+#ifndef LDAP_NOCACHE
        if ( ld->ld_cache != NULL ) {
                if ( ldap_check_cache( ld, LDAP_REQ_SEARCH, ber ) == 0 ) {
                        ber_free( ber, 1 );
@@ -70,7 +68,7 @@ ldap_search( LDAP *ld, char *base, int scope, char *filter,
                }
                ldap_add_request_to_cache( ld, LDAP_REQ_SEARCH, ber );
        }
-#endif /* NO_CACHE */
+#endif /* LDAP_NOCACHE */
 
        /* send the message */
        return ( ldap_send_initial_request( ld, LDAP_REQ_SEARCH, base, ber ));
@@ -114,22 +112,28 @@ ldap_build_search_req( LDAP *ld, char *base, int scope, char *filter,
        }
 
        if ( base == NULL ) {
+               /* no base provided, use session default base */
+               base = ld->ld_options.ldo_defbase;
+       }
+
+       if ( base == NULL ) {
+               /* no session default base, use top */
            base = "";
        }
 
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
        if ( ld->ld_sb.sb_naddr > 0 ) {
            err = ber_printf( ber, "{ist{seeiib", ++ld->ld_msgid,
                ld->ld_cldapdn, LDAP_REQ_SEARCH, base, scope, ld->ld_deref,
                ld->ld_sizelimit, ld->ld_timelimit, attrsonly );
        } else {
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
                err = ber_printf( ber, "{it{seeiib", ++ld->ld_msgid,
                    LDAP_REQ_SEARCH, base, scope, ld->ld_deref,
                    ld->ld_sizelimit, ld->ld_timelimit, attrsonly );
-#ifdef CLDAP
+#ifdef LDAP_CONNECTIONLESS
        }
-#endif /* CLDAP */
+#endif /* LDAP_CONNECTIONLESS */
 
        if ( err == -1 ) {
                ld->ld_errno = LDAP_ENCODING_ERROR;