]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/test.c
Cast char* argument to hh_to_c() to Byte*
[openldap] / libraries / libldap / test.c
index 34c1eb9250257d81fbb73302abc5627a328df72f..23088a116620cb41626733ebcf55085a7bc48a1b 100644 (file)
@@ -1,3 +1,8 @@
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+
 #include "portable.h"
 
 #include <stdio.h>
 
 #include <fcntl.h>
 
-#include "lber.h"
-#include "ldap.h"
-
 /* including the "internal" defs is legit and nec. since this test routine has 
  * a-priori knowledge of libldap internal workings.
  * hodges@stanford.edu 5-Feb-96
  */
 #include "ldap-int.h"
 
+/* local functions */
+#ifndef HAVE_GETLINE
+static char *getline LDAP_P(( char *line, int len, FILE *fp, char *prompt ));
+#endif
+static char **get_list LDAP_P(( char *prompt ));
+static int file_read LDAP_P(( char *path, struct berval *bv ));
+static LDAPMod **get_modlist LDAP_P(( char *prompt1, char *prompt2, char *prompt3 ));
 static void handle_result LDAP_P(( LDAP *ld, LDAPMessage *lm ));
 static void print_ldap_result LDAP_P(( LDAP *ld, LDAPMessage *lm, char *s ));
 static void print_search_entry LDAP_P(( LDAP *ld, LDAPMessage *res ));
@@ -36,7 +45,7 @@ static void free_list LDAP_P(( char **list ));
 
 #define NOCACHEERRMSG  "don't compile with -DLDAP_NOCACHE if you desire local caching"
 
-char *dnsuffix;
+static char *dnsuffix;
 
 #ifndef HAVE_GETLINE
 static char *
@@ -217,8 +226,8 @@ get_modlist( char *prompt1, char *prompt2, char *prompt3 )
 }
 
 
-#ifdef LDAP_REFERRALS
-int
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
+static int
 bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp,
        int freeit )
 {
@@ -252,7 +261,7 @@ bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp,
 
        return( LDAP_SUCCESS );
 }
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 
 
 int
@@ -273,9 +282,6 @@ main( int argc, char **argv )
        int             copyoptions = 0;
        LDAPURLDesc     *ludp;
 
-       extern char     *optarg;
-       extern int      optind;
-
        host = NULL;
        port = LDAP_PORT;
        dnsuffix = "";
@@ -294,9 +300,11 @@ main( int argc, char **argv )
                case 'd':
 #ifdef LDAP_DEBUG
                        ldap_debug = atoi( optarg );
+#ifdef LBER_DEBUG
                        if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
                                lber_debug = ldap_debug;
                        }
+#endif
 #else
                        printf( "Compile with -DLDAP_DEBUG for debugging\n" );
 #endif
@@ -476,9 +484,11 @@ main( int argc, char **argv )
 #ifdef LDAP_DEBUG
                        getline( line, sizeof(line), stdin, "debug level? " );
                        ldap_debug = atoi( line );
+#ifdef LBER_DEBUG
                        if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
                                lber_debug = ldap_debug;
                        }
+#endif
 #else
                        printf( "Compile with -DLDAP_DEBUG for debugging\n" );
 #endif
@@ -535,11 +545,11 @@ main( int argc, char **argv )
                        if ( cldapflg )
                                cldap_close( ld );
 #endif /* LDAP_CONNECTIONLESS */
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
                        if ( !cldapflg )
-#else /* LDAP_REFERRALS */
+#else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
                        if ( !cldapflg && bound )
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
                                ldap_unbind( ld );
                        exit( 0 );
                        break;
@@ -753,7 +763,7 @@ main( int argc, char **argv )
                        getline( line, sizeof(line), stdin, "sizelimit?" );
                        ld->ld_sizelimit = atoi( line );
 
-                       ld->ld_options = 0;
+                       LDAP_BOOL_ZERO(&ld->ld_options);
 
 #ifdef STR_TRANSLATION
                        getline( line, sizeof(line), stdin,
@@ -774,26 +784,26 @@ main( int argc, char **argv )
                        }
 #endif /* STR_TRANSLATION */
 
-#ifdef LDAP_DNS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
                        getline( line, sizeof(line), stdin,
                                "Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
                        if ( atoi( line ) != 0 ) {
-                               ld->ld_options |= LDAP_OPT_DNS;
+                               LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_DNS);
                        }
-#endif /* LDAP_DNS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
 
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
                        getline( line, sizeof(line), stdin,
                                "Recognize and chase referrals (0=no, 1=yes)?" );
                        if ( atoi( line ) != 0 ) {
-                               ld->ld_options |= LDAP_OPT_REFERRALS;
+                               LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
                                getline( line, sizeof(line), stdin,
                                        "Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
                                if ( atoi( line ) != 0 ) {
                                        ldap_set_rebind_proc( ld, bind_prompt );
                                }
                        }
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
                        break;
 
                case 'O':       /* set cache options */
@@ -904,14 +914,14 @@ print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s )
 static void
 print_search_entry( LDAP *ld, LDAPMessage *res )
 {
-       BerElement      *ber;
-       char            *a, *dn, *ufn;
-       struct berval   **vals;
-       int             i;
        LDAPMessage     *e;
 
        for ( e = ldap_first_entry( ld, res ); e != NULLMSG;
-           e = ldap_next_entry( ld, e ) ) {
+           e = ldap_next_entry( ld, e ) )
+       {
+               BerElement      *ber = NULL;
+               char *a, *dn, *ufn;
+
                if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT )
                        break;
 
@@ -925,12 +935,16 @@ print_search_entry( LDAP *ld, LDAPMessage *res )
                free( ufn );
 
                for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
-                   a = ldap_next_attribute( ld, e, ber ) ) {
+                   a = ldap_next_attribute( ld, e, ber ) )
+               {
+                       struct berval   **vals;
+
                        printf( "\t\tATTR: %s\n", a );
                        if ( (vals = ldap_get_values_len( ld, e, a ))
                            == NULL ) {
                                printf( "\t\t\t(no values)\n" );
                        } else {
+                               int i;
                                for ( i = 0; vals[i] != NULL; i++ ) {
                                        int     j, nonascii;
 
@@ -955,6 +969,10 @@ print_search_entry( LDAP *ld, LDAPMessage *res )
                                ber_bvecfree( vals );
                        }
                }
+
+               if(ber != NULL) {
+                       ber_free( ber, 0 );
+               }
        }
 
        if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT