]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/getvalues.c
blind fix of value_match when SLAP_NVALUES is set
[openldap] / libraries / libldap / getvalues.c
index d886ab0689a30ceebfa81f57191720af0e8de529..82e36299baa20f6932f86e1bb42eb6033264f0bd 100644 (file)
@@ -1,5 +1,6 @@
+/* $OpenLDAP$ */
 /*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /*  Portions
@@ -12,7 +13,8 @@
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/ctype.h>
 #include <ac/socket.h>
@@ -29,12 +31,21 @@ ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
        int             found = 0;
        char            **vals;
 
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+       assert( entry != NULL );
+       assert( target != NULL );
+
+#ifdef NEW_LOGGING
+       LDAP_LOG ( OPERATION, ENTRY, "ldap_get_values\n", 0, 0, 0 );
+#else
        Debug( LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0 );
+#endif
 
        ber = *entry->lm_ber;
 
        /* skip sequence, dn, sequence of, and snag the first attr */
-       if ( ber_scanf( &ber, "{x{{a", &attr ) == LBER_ERROR ) {
+       if ( ber_scanf( &ber, "{x{{a" /*}}}*/, &attr ) == LBER_ERROR ) {
                ld->ld_errno = LDAP_DECODING_ERROR;
                return( NULL );
        }
@@ -47,7 +58,7 @@ ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
                LDAP_FREE(attr);
                attr = NULL;
 
-               if ( ber_scanf( &ber, "x}{a", &attr ) == LBER_ERROR ) {
+               if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
                        ld->ld_errno = LDAP_DECODING_ERROR;
                        return( NULL );
                }
@@ -81,12 +92,21 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
        int             found = 0;
        struct berval   **vals;
 
+       assert( ld != NULL );
+       assert( LDAP_VALID( ld ) );
+       assert( entry != NULL );
+       assert( target != NULL );
+
+#ifdef NEW_LOGGING
+       LDAP_LOG ( OPERATION, ENTRY, "ldap_get_values_len\n", 0, 0, 0 );
+#else
        Debug( LDAP_DEBUG_TRACE, "ldap_get_values_len\n", 0, 0, 0 );
+#endif
 
        ber = *entry->lm_ber;
 
        /* skip sequence, dn, sequence of, and snag the first attr */
-       if ( ber_scanf( &ber, "{x{{a", &attr ) == LBER_ERROR ) {
+       if ( ber_scanf( &ber, "{x{{a" /* }}} */, &attr ) == LBER_ERROR ) {
                ld->ld_errno = LDAP_DECODING_ERROR;
                return( NULL );
        }
@@ -99,7 +119,7 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
                LDAP_FREE( attr );
                attr = NULL;
 
-               if ( ber_scanf( &ber, "x}{a", &attr ) == LBER_ERROR ) {
+               if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
                        ld->ld_errno = LDAP_DECODING_ERROR;
                        return( NULL );
                }
@@ -155,3 +175,39 @@ ldap_value_free_len( struct berval **vals )
 {
        ber_bvecfree( vals );
 }
+
+char **
+ldap_value_dup( char *const *vals )
+{
+       char **new;
+       int i;
+
+       if( vals == NULL ) {
+               return NULL;
+       }
+
+       for( i=0; vals[i]; i++ ) {
+               ;   /* Count the number of values */
+       }
+
+       if( i == 0 ) {
+               return NULL;
+       }
+
+       new = LDAP_MALLOC( (i+1)*sizeof(char *) );  /* Alloc array of pointers */
+       if( new == NULL ) {
+               return NULL;
+       }
+
+       for( i=0; vals[i]; i++ ) {
+               new[i] = LDAP_STRDUP( vals[i] );   /* Dup each value */
+               if( new[i] == NULL ) {
+                       LDAP_VFREE( new );
+                       return NULL;
+               }
+       }
+       new[i] = NULL;
+
+       return new;
+}
+