]> git.sur5r.net Git - openldap/commitdiff
Some minor bugs for dntest ""
authorKurt Zeilenga <kurt@openldap.org>
Mon, 24 Dec 2001 07:22:25 +0000 (07:22 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 24 Dec 2001 07:22:25 +0000 (07:22 +0000)
libraries/libldap/dntest.c
libraries/libldap/getdn.c

index a1a65f5feb9b4d94def935f42d3ae1f7d920fd78..ffbc28b4cc4702b9a0ad938f03712dd5b9354fde 100644 (file)
@@ -120,22 +120,27 @@ main( int argc, char *argv[] )
 
        if ( rc == LDAP_SUCCESS ) {
                int i;
-               for ( i = 0; dn[ i ]; i++ ) {
-                       LDAPRDN         *rdn = dn[ i ][ 0 ];
-                       char            *rstr;
+               if( dn ) {
+                       for ( i = 0; dn[i]; i++ ) {
+                               LDAPRDN         *rdn = dn[ i ][ 0 ];
+                               char            *rstr;
 
-                       if ( ldap_rdn2str( rdn, &rstr, flags[ f2 ] ) ) {
-                               fprintf( stdout, "\tldap_rdn2str() failed\n" );
-                               continue;
-                       }
+                               if ( ldap_rdn2str( rdn, &rstr, flags[ f2 ] ) ) {
+                                       fprintf( stdout, "\tldap_rdn2str() failed\n" );
+                                       continue;
+                               }
 
-                       fprintf( stdout, "\tldap_rdn2str() = \"%s\"\n", rstr );
-                       ldap_memfree( rstr );
+                               fprintf( stdout, "\tldap_rdn2str() = \"%s\"\n", rstr );
+                               ldap_memfree( rstr );
+                       }
+               } else {
+                       fprintf( stdout, "\tempty DN\n" );
                }
        }
 
-       if ( rc == LDAP_SUCCESS && 
-                       ldap_dn2str( dn, &str, flags[ f2 ] ) == LDAP_SUCCESS ) {
+       if ( rc == LDAP_SUCCESS &&
+               ldap_dn2str( dn, &str, flags[ f2 ] ) == LDAP_SUCCESS )
+       {
                char    **values, *tmp, *tmp2;
                int     n;
                
@@ -216,7 +221,13 @@ main( int argc, char *argv[] )
                                str, str2, 
                                strcmp( str, str2 ) == 0 ? "yes" : "no" );
 
-                       for ( iRDN = 0; dn[ iRDN ] && dn2[ iRDN ]; iRDN++ ) {
+                       if(( dn != NULL && dn2 == NULL )
+                               || ( dn != NULL && dn2 == NULL ))
+                       {
+                               fprintf( stdout, "mismatch\n" );
+                       } else if (( dn != NULL ) && (dn2 != NULL))
+                               for ( iRDN = 0; dn[ iRDN ] && dn2[ iRDN ]; iRDN++ )
+                       {
                                LDAPRDN         *r = dn[ iRDN ][ 0 ];
                                LDAPRDN         *r2 = dn2[ iRDN ][ 0 ];
                                int             iAVA;
@@ -226,12 +237,14 @@ main( int argc, char *argv[] )
                                        LDAPAVA         *a2 = r2[ iAVA ][ 0 ];
 
                                        if ( a->la_attr->bv_len != a2->la_attr->bv_len
-                                                       || memcmp( a->la_attr->bv_val, a2->la_attr->bv_val, a->la_attr->bv_len )
-                                                       || a->la_flags != a2->la_flags
-                                                       || a->la_value->bv_len != a2->la_value->bv_len
-                                                       || memcmp( a->la_value->bv_val, a2->la_value->bv_val, a->la_value->bv_len ) ) {
+                                               || memcmp( a->la_attr->bv_val, a2->la_attr->bv_val,
+                                                       a->la_attr->bv_len )
+                                               || a->la_flags != a2->la_flags
+                                               || a->la_value->bv_len != a2->la_value->bv_len
+                                               || memcmp( a->la_value->bv_val, a2->la_value->bv_val,
+                                                       a->la_value->bv_len ) )
+                                       {
                                                fprintf( stdout, "mismatch\n" );
-                                               
                                        }
                                }
                        }
index 4d4b29133cf7d65a5b43f5c69e61891cdf5af3d3..21980226d1e54f24d836e47f01d2816b31bec7e9 100644 (file)
@@ -141,7 +141,15 @@ ldap_explode_dn( LDAP_CONST char *dn, int notypes )
 
        if ( ldap_str2dn( dn, &tmpDN, LDAP_DN_FORMAT_LDAP ) 
                        != LDAP_SUCCESS ) {
-               return( NULL );
+               return NULL;
+       }
+
+       if( tmpDN == NULL ) {
+               values = LDAP_MALLOC( sizeof( char * ) );
+               if( values == NULL ) return NULL;
+
+               values[0] = NULL;
+               return values;
        }
 
        for ( iRDN = 0; tmpDN[ iRDN ]; iRDN++ ) {
@@ -149,18 +157,18 @@ ldap_explode_dn( LDAP_CONST char *dn, int notypes )
                
                ldap_rdn2str( tmpDN[ iRDN ][ 0 ], &str, flag );
 
-               v = LDAP_REALLOC( values, sizeof( char * ) * ( 2 + iRDN ) );
+               v = LDAP_REALLOC( values, sizeof( char * ) * ( iRDN + 1 ) );
                if ( v == NULL ) {
                        LBER_VFREE( values );
                        ldap_dnfree( tmpDN );
-                       return( NULL );
+                       return NULL;
                }
                values = v;
                values[ iRDN ] = str;
        }
-       values[ iRDN ] = NULL;
 
-       return( values );
+       values[ iRDN ] = NULL;
+       return values;
 }
 
 char **