]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/search.c
ITS#5300
[openldap] / libraries / libldap / search.c
index 60cac86f305042bb7daf3b7b274fe7f654c92077..7c6f62b977d180d40824f2c2cedb9a0578087c6c 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -259,8 +259,9 @@ ldap_build_search_req(
        LDAP_NEXT_MSGID( ld, *idp );
 #ifdef LDAP_CONNECTIONLESS
        if ( LDAP_IS_UDP(ld) ) {
-           err = ber_write( ber, ld->ld_options.ldo_peer,
-                   sizeof(struct sockaddr), 0);
+               struct sockaddr sa = {0};
+               /* dummy, filled with ldo_peer in request.c */
+           err = ber_write( ber, &sa, sizeof( sa ), 0 );
        }
        if ( LDAP_IS_UDP(ld) && ld->ld_options.ldo_version == LDAP_VERSION2) {
            char *dn = ld->ld_options.ldo_cldapdn;
@@ -298,6 +299,32 @@ ldap_build_search_req(
                return( NULL );
        }
 
+#ifdef LDAP_DEBUG
+       if ( ldap_debug & LDAP_DEBUG_ARGS ) {
+               char    buf[ BUFSIZ ] = { ' ', '*', '\0' };
+
+               if ( attrs != NULL ) {
+                       char    *ptr;
+                       int     i;
+
+                       for ( ptr = buf, i = 0;
+                               attrs[ i ] != NULL && ptr < &buf[ sizeof( buf ) ];
+                               i++ )
+                       {
+                               ptr += snprintf( ptr, sizeof( buf ) - ( ptr - buf ),
+                                       " %s", attrs[ i ] );
+                       }
+
+                       if ( ptr >= &buf[ sizeof( buf ) ] ) {
+                               AC_MEMCPY( &buf[ sizeof( buf ) - STRLENOF( "...(truncated)" ) - 1 ],
+                                       "...(truncated)", STRLENOF( "...(truncated)" ) + 1 );
+                       } 
+               }
+
+               Debug( LDAP_DEBUG_ARGS, "ldap_build_search_req ATTRS:%s\n", buf, 0, 0 );
+       }
+#endif /* LDAP_DEBUG */
+
        if ( ber_printf( ber, /*{*/ "{v}N}", attrs ) == -1 ) {
                ld->ld_errno = LDAP_ENCODING_ERROR;
                ber_free( ber, 1 );
@@ -331,7 +358,7 @@ ldap_search_st(
            == -1 )
                return( ld->ld_errno );
 
-       if ( ldap_result( ld, msgid, LDAP_MSG_ALL, timeout, res ) == -1 )
+       if ( ldap_result( ld, msgid, LDAP_MSG_ALL, timeout, res ) == -1 || !*res )
                return( ld->ld_errno );
 
        if ( ld->ld_errno == LDAP_TIMEOUT ) {
@@ -359,7 +386,7 @@ ldap_search_s(
            == -1 )
                return( ld->ld_errno );
 
-       if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, res ) == -1 )
+       if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, res ) == -1 || !*res )
                return( ld->ld_errno );
 
        return( ldap_result2error( ld, *res, 0 ) );
@@ -389,8 +416,7 @@ static char escape[128] = {
 #define        NEEDFLTESCAPE(c)        ((c) & 0x80 || escape[ (unsigned)(c) ])
 
 /*
- * compute the length of the escaped value;
- * returns ((ber_len_t)(-1)) if no escaping is required.
+ * compute the length of the escaped value
  */
 ber_len_t
 ldap_bv2escaped_filter_value_len( struct berval *in )
@@ -403,7 +429,6 @@ ldap_bv2escaped_filter_value_len( struct berval *in )
                return 0;
        }
 
-       /* assume we'll escape everything */
        for( l = 0, i = 0; i < in->bv_len; l++, i++ ) {
                char c = in->bv_val[ i ];
                if ( NEEDFLTESCAPE( c ) ) {