X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fdntest.c;h=e99a0570c61926216117be556f33a4c58160e76c;hb=2dfd312fa12a765a5ad311f6c9bf8dce76a63155;hp=74b0e9ada1d1c04879769c82e8252ba233a9721d;hpb=a2eec74fc1d535fa9092f4d7b82a669b39eef539;p=openldap
diff --git a/libraries/libldap/dntest.c b/libraries/libldap/dntest.c
index 74b0e9ada1..e99a0570c6 100644
--- a/libraries/libldap/dntest.c
+++ b/libraries/libldap/dntest.c
@@ -1,25 +1,35 @@
+/* dntest.c -- OpenLDAP DN API Test Program */
/* $OpenLDAP$ */
-/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software .
+ *
+ * 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
+ * .
+ */
+/* ACKNOWLEDGEMENT:
+ * This program was initially developed by Pierangelo Masarati
+ * for inclusion in OpenLDAP Software.
*/
+
/*
- * OpenLDAP API Test
- * Written by: Pierangelo Masarati
- *
* This program is designed to test the ldap_str2dn/ldap_dn2str
* functions
*/
#include "portable.h"
-#include
+#include
#include
#include
#include
-#include
-
#include
#include "ldap-int.h"
@@ -33,9 +43,9 @@ int
main( int argc, char *argv[] )
{
int rc, i, debug = 0, f2 = 0;
- unsigned flags[ 2 ] = { 0U, 0U };
- char *strin, *str, *str2, buf[ 1024 ];
- LDAPDN *dn, *dn2 = NULL;
+ unsigned flags[ 2 ] = { 0U, 0 };
+ char *strin, *str = NULL, buf[ 1024 ];
+ LDAPDN dn, dn2 = NULL;
while ( 1 ) {
int opt = getopt( argc, argv, "d:" );
@@ -57,9 +67,9 @@ main( int argc, char *argv[] )
if ( argc < 2 ) {
fprintf( stderr, "usage: dntest [flags-in[,...]] [flags-out[,...]]\n\n" );
- fprintf( stderr, "\tflags-in: V3,V2,DCE,\n" );
- fprintf( stderr, "\tflags-out: V3,V2,UFN,DCE,AD,\n\n" );
- fprintf( stderr, "\t: PEDANTIC,NOSPACES,NOONESPACE\n\n" );
+ fprintf( stderr, "\tflags-in: V3,V2,DCE,\n" );
+ fprintf( stderr, "\tflags-out: V3,V2,UFN,DCE,AD,\n\n" );
+ fprintf( stderr, "\t: PRETTY,PEDANTIC,NOSPACES,NOONESPACE\n\n" );
return( 0 );
}
@@ -74,8 +84,8 @@ main( int argc, char *argv[] )
size_t len;
fgets( buf, sizeof( buf ), stdin );
- len = strlen( buf ) - 1;
- if ( len >= 0 && buf[ len ] == '\n' ) {
+ len = strlen( buf );
+ if ( len > 0 && buf[ --len ] == '\n' ) {
buf[ len ] = '\0';
}
strin = buf;
@@ -103,6 +113,8 @@ main( int argc, char *argv[] )
flags[ i ] |= LDAP_DN_FORMAT_UFN;
} else if ( !strcasecmp( s, "AD" ) ) {
flags[ i ] |= LDAP_DN_FORMAT_AD_CANONICAL;
+ } else if ( !strcasecmp( s, "PRETTY" ) ) {
+ flags[ i ] |= LDAP_DN_PRETTY;
} else if ( !strcasecmp( s, "PEDANTIC" ) ) {
flags[ i ] |= LDAP_DN_PEDANTIC;
} else if ( !strcasecmp( s, "NOSPACES" ) ) {
@@ -114,29 +126,38 @@ main( int argc, char *argv[] )
}
}
- f2 = argc > 3 ? 1 : 0;
+ if ( flags[ 1 ] == 0 )
+ flags[ 1 ] = LDAP_DN_FORMAT_LDAPV3;
+
+ f2 = 1;
rc = ldap_str2dn( strin, &dn, flags[ 0 ] );
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 ];
+ char *rstr = NULL;
+
+ 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 ) {
- char **values, *tmp, *tmp2;
+ str = NULL;
+ if ( rc == LDAP_SUCCESS &&
+ ldap_dn2str( dn, &str, flags[ f2 ] ) == LDAP_SUCCESS )
+ {
+ char **values, *tmp, *tmp2, *str2 = NULL;
int n;
fprintf( stdout, "\nldap_dn2str(ldap_str2dn(\"%s\"))\n"
@@ -149,21 +170,33 @@ main( int argc, char *argv[] )
case LDAP_DN_FORMAT_LDAPV3:
case LDAP_DN_FORMAT_LDAPV2:
+ n = ldap_dn2domain( strin, &tmp );
+ if ( n ) {
+ fprintf( stdout, "\nldap_dn2domain(\"%s\") FAILED\n", strin );
+ } else {
+ fprintf( stdout, "\nldap_dn2domain(\"%s\")\n"
+ "\t= \"%s\"\n", strin, tmp ? tmp : "" );
+ }
+ ldap_memfree( tmp );
+
tmp = ldap_dn2ufn( strin );
fprintf( stdout, "\nldap_dn2ufn(\"%s\")\n"
- "\t= \"%s\"\n", strin, tmp );
+ "\t= \"%s\"\n", strin, tmp ? tmp : "" );
ldap_memfree( tmp );
+
tmp = ldap_dn2dcedn( strin );
fprintf( stdout, "\nldap_dn2dcedn(\"%s\")\n"
- "\t= \"%s\"\n", strin, tmp );
+ "\t= \"%s\"\n", strin, tmp ? tmp : "" );
tmp2 = ldap_dcedn2dn( tmp );
fprintf( stdout, "\nldap_dcedn2dn(\"%s\")\n"
- "\t= \"%s\"\n", tmp, tmp2 );
+ "\t= \"%s\"\n",
+ tmp ? tmp : "", tmp2 ? tmp2 : "" );
ldap_memfree( tmp );
ldap_memfree( tmp2 );
+
tmp = ldap_dn2ad_canonical( strin );
fprintf( stdout, "\nldap_dn2ad_canonical(\"%s\")\n"
- "\t= \"%s\"\n", strin, tmp );
+ "\t= \"%s\"\n", strin, tmp ? tmp : "" );
ldap_memfree( tmp );
fprintf( stdout, "\nldap_explode_dn(\"%s\"):\n", str );
@@ -205,8 +238,10 @@ main( int argc, char *argv[] )
break;
}
-
+
+ dn2 = NULL;
rc = ldap_str2dn( str, &dn2, flags[ f2 ] );
+ str2 = NULL;
if ( rc == LDAP_SUCCESS &&
ldap_dn2str( dn2, &str2, flags[ f2 ] )
== LDAP_SUCCESS ) {
@@ -216,31 +251,46 @@ main( int argc, char *argv[] )
str, str2,
strcmp( str, str2 ) == 0 ? "yes" : "no" );
- for ( iRDN = 0; dn[ iRDN ] && dn2[ iRDN ]; iRDN++ ) {
- LDAPRDN *r = dn[ iRDN ][ 0 ];
- LDAPRDN *r2 = dn2[ iRDN ][ 0 ];
+ if( dn != NULL && dn2 == NULL ) {
+ fprintf( stdout, "dn mismatch\n" );
+ } else if (( dn != NULL ) && (dn2 != NULL))
+ for ( iRDN = 0; dn[ iRDN ] && dn2[ iRDN ]; iRDN++ )
+ {
+ LDAPRDN r = dn[ iRDN ];
+ LDAPRDN r2 = dn2[ iRDN ];
int iAVA;
- for ( iAVA = 0; r[ iAVA ] && r[ iAVA ]; iAVA++ ) {
- LDAPAVA *a = r[ iAVA ][ 0 ];
- LDAPAVA *a2 = r2[ iAVA ][ 0 ];
-
- if ( strcmp( a->la_attr, a2->la_attr )
- || 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" );
-
+ for ( iAVA = 0; r[ iAVA ] && r2[ iAVA ]; iAVA++ ) {
+ LDAPAVA *a = r[ iAVA ];
+ LDAPAVA *a2 = r2[ iAVA ];
+
+ if ( a->la_attr.bv_len != a2->la_attr.bv_len ) {
+ fprintf( stdout, "ava(%d), rdn(%d) attr len mismatch (%ld->%ld)\n",
+ iAVA + 1, iRDN + 1,
+ a->la_attr.bv_len, a2->la_attr.bv_len );
+ } else if ( memcmp( a->la_attr.bv_val, a2->la_attr.bv_val, a->la_attr.bv_len ) ) {
+ fprintf( stdout, "ava(%d), rdn(%d) attr mismatch\n",
+ iAVA + 1, iRDN + 1 );
+ } else if ( a->la_flags != a2->la_flags ) {
+ fprintf( stdout, "ava(%d), rdn(%d) flag mismatch (%x->%x)\n",
+ iAVA + 1, iRDN + 1, a->la_flags, a2->la_flags );
+ } else if ( a->la_value.bv_len != a2->la_value.bv_len ) {
+ fprintf( stdout, "ava(%d), rdn(%d) value len mismatch (%ld->%ld)\n",
+ iAVA + 1, iRDN + 1,
+ a->la_value.bv_len, a2->la_value.bv_len );
+ } else if ( memcmp( a->la_value.bv_val, a2->la_value.bv_val, a->la_value.bv_len ) ) {
+ fprintf( stdout, "ava(%d), rdn(%d) value mismatch\n",
+ iAVA + 1, iRDN + 1 );
}
}
}
- ldapava_free_dn( dn2 );
+ ldap_dnfree( dn2 );
ldap_memfree( str2 );
}
ldap_memfree( str );
}
- ldapava_free_dn( dn );
+ ldap_dnfree( dn );
/* note: dn is not freed */