X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fdntest.c;h=e99a0570c61926216117be556f33a4c58160e76c;hb=2dfd312fa12a765a5ad311f6c9bf8dce76a63155;hp=72d3c52febb82f4e73f4c1564564ccfcef8a84eb;hpb=4a8ab5dbf2ba037b0824d64bb3217ca06671884a;p=openldap
diff --git a/libraries/libldap/dntest.c b/libraries/libldap/dntest.c
index 72d3c52feb..e99a0570c6 100644
--- a/libraries/libldap/dntest.c
+++ b/libraries/libldap/dntest.c
@@ -1,23 +1,35 @@
+/* dntest.c -- OpenLDAP DN API Test Program */
/* $OpenLDAP$ */
-/*
- * Copyright 1998-2002 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 DN 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 "ldap-int.h"
@@ -33,7 +45,7 @@ main( int argc, char *argv[] )
int rc, i, debug = 0, f2 = 0;
unsigned flags[ 2 ] = { 0U, 0 };
char *strin, *str = NULL, buf[ 1024 ];
- LDAPDN *dn, *dn2 = NULL;
+ LDAPDN dn, dn2 = NULL;
while ( 1 ) {
int opt = getopt( argc, argv, "d:" );
@@ -124,8 +136,8 @@ main( int argc, char *argv[] )
if ( rc == LDAP_SUCCESS ) {
int i;
if ( dn ) {
- for ( i = 0; dn[ 0 ][ i ]; i++ ) {
- LDAPRDN *rdn = dn[ 0 ][ i ];
+ for ( i = 0; dn[ i ]; i++ ) {
+ LDAPRDN rdn = dn[ i ];
char *rstr = NULL;
if ( ldap_rdn2str( rdn, &rstr, flags[ f2 ] ) ) {
@@ -158,23 +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 );
@@ -232,15 +254,15 @@ main( int argc, char *argv[] )
if( dn != NULL && dn2 == NULL ) {
fprintf( stdout, "dn mismatch\n" );
} else if (( dn != NULL ) && (dn2 != NULL))
- for ( iRDN = 0; dn[ 0 ][ iRDN ] && dn2[ 0 ][ iRDN ]; iRDN++ )
+ for ( iRDN = 0; dn[ iRDN ] && dn2[ iRDN ]; iRDN++ )
{
- LDAPRDN *r = dn[ 0 ][ iRDN ];
- LDAPRDN *r2 = dn2[ 0 ][ iRDN ];
+ LDAPRDN r = dn[ iRDN ];
+ LDAPRDN r2 = dn2[ iRDN ];
int iAVA;
- for ( iAVA = 0; r[ 0 ][ iAVA ] && r2[ 0 ][ iAVA ]; iAVA++ ) {
- LDAPAVA *a = r[ 0 ][ iAVA ];
- LDAPAVA *a2 = r2[ 0 ][ iAVA ];
+ 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",