]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/test.c
Add strdup.c from -llutil, renamed to ldap_strdup() and always used.
[openldap] / libraries / libldap / test.c
index 340fae9b965133c87c5e700309ef2b4bf64d288c..ad50e483ca3b1a19a7a8b47bfef8d84f597e4a3f 100644 (file)
 
 #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"
 
-#if !defined( PCNFS ) && !defined( WINSOCK ) && !defined( MACOS )
-#define MOD_USE_BVALS
-#endif /* !PCNFS && !WINSOCK && !MACOS */
-
+/* 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 ));
@@ -40,9 +40,9 @@ 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 WINSOCK
+#ifndef HAVE_GETLINE
 static char *
 getline( char *line, int len, FILE *fp, char *prompt )
 {
@@ -55,7 +55,7 @@ getline( char *line, int len, FILE *fp, char *prompt )
 
        return( line );
 }
-#endif /* WINSOCK */
+#endif
 
 static char **
 get_list( char *prompt )
@@ -78,7 +78,7 @@ get_list( char *prompt )
                        result = (char **) realloc( result,
                            sizeof(char *) * (num + 1) );
 
-               result[num++] = (char *) strdup( buf );
+               result[num++] = (char *) ldap_strdup( buf );
        }
        if ( result == (char **) 0 )
                return( NULL );
@@ -103,7 +103,6 @@ free_list( char **list )
 }
 
 
-#ifdef MOD_USE_BVALS
 static int
 file_read( char *path, struct berval *bv )
 {
@@ -148,7 +147,6 @@ file_read( char *path, struct berval *bv )
 
        return( bv->bv_len );
 }
-#endif /* MOD_USE_BVALS */
 
 
 static LDAPMod **
@@ -158,9 +156,7 @@ get_modlist( char *prompt1, char *prompt2, char *prompt3 )
        int             num;
        LDAPMod         tmp;
        LDAPMod         **result;
-#ifdef MOD_USE_BVALS
        struct berval   **bvals;
-#endif /* MOD_USE_BVALS */
 
        num = 0;
        result = NULL;
@@ -176,10 +172,10 @@ get_modlist( char *prompt1, char *prompt2, char *prompt3 )
                getline( buf, sizeof(buf), stdin, prompt2 );
                if ( buf[0] == '\0' )
                        break;
-               tmp.mod_type = strdup( buf );
+               tmp.mod_type = ldap_strdup( buf );
 
                tmp.mod_values = get_list( prompt3 );
-#ifdef MOD_USE_BVALS
+
                if ( tmp.mod_values != NULL ) {
                        int     i;
 
@@ -205,7 +201,6 @@ get_modlist( char *prompt1, char *prompt2, char *prompt3 )
                        tmp.mod_bvalues = bvals;
                        tmp.mod_op |= LDAP_MOD_BVALUES;
                }
-#endif /* MOD_USE_BVALS */
 
                if ( result == NULL )
                        result = (LDAPMod **) malloc( sizeof(LDAPMod *) );
@@ -226,8 +221,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 )
 {
@@ -261,16 +256,11 @@ 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
-#ifdef WINSOCK
-ldapmain(
-#else /* WINSOCK */
-main(
-#endif /* WINSOCK */
-       int argc, char **argv )
+main( int argc, char **argv )
 {
        LDAP            *ld = NULL;
        int             i, c, port, cldapflg, errflg, method, id, msgtype;
@@ -287,18 +277,6 @@ main(
        int             copyoptions = 0;
        LDAPURLDesc     *ludp;
 
-       extern char     *optarg;
-       extern int      optind;
-
-#ifdef MACOS
-       if (( argv = get_list( "cmd line arg?" )) == NULL ) {
-               exit( 1 );
-       }
-       for ( argc = 0; argv[ argc ] != NULL; ++argc ) {
-               ;
-       }
-#endif /* MACOS */
-
        host = NULL;
        port = LDAP_PORT;
        dnsuffix = "";
@@ -337,17 +315,15 @@ main(
                        port = atoi( optarg );
                        break;
 
-#if !defined(MACOS) && !defined(DOS)
                case 't':       /* copy ber's to given file */
-                       copyfname = strdup( optarg );
+                       copyfname = ldap_strdup( optarg );
                        copyoptions = LBER_TO_FILE;
                        break;
 
                case 'T':       /* only output ber's to given file */
-                       copyfname = strdup( optarg );
+                       copyfname = ldap_strdup( optarg );
                        copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY);
                        break;
-#endif
 
                default:
                    ++errflg;
@@ -380,7 +356,6 @@ main(
                exit(1);
        }
 
-#if !defined(MACOS) && !defined(DOS)
        if ( copyfname != NULL ) {
                if ( (ld->ld_sb.sb_fd = open( copyfname, O_WRONLY | O_CREAT,
                    0600 ))  == -1 ) {
@@ -389,7 +364,6 @@ main(
                }
                ld->ld_sb.sb_options = copyoptions;
        }
-#endif
 
        bound = 0;
        timeout.tv_sec = 0;
@@ -562,11 +536,11 @@ main(
                        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;
@@ -780,7 +754,7 @@ main(
                        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,
@@ -801,26 +775,26 @@ main(
                        }
 #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 */
@@ -947,13 +921,9 @@ print_search_entry( LDAP *ld, LDAPMessage *res )
 
                ufn = ldap_dn2ufn( dn );
                printf( "\tUFN: %s\n", ufn );
-#ifdef WINSOCK
-               ldap_memfree( dn );
-               ldap_memfree( ufn );
-#else /* WINSOCK */
+
                free( dn );
                free( ufn );
-#endif /* WINSOCK */
 
                for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL;
                    a = ldap_next_attribute( ld, e, ber ) ) {
@@ -992,23 +962,3 @@ print_search_entry( LDAP *ld, LDAPMessage *res )
            || res->lm_chain != NULLMSG )
                print_ldap_result( ld, res, "search" );
 }
-
-
-#ifdef WINSOCK
-void
-ldap_perror( LDAP *ld, char *s )
-{
-       char    *errs;
-
-       if ( ld == NULL ) {
-               perror( s );
-               return;
-       }
-
-       errs = ldap_err2string( ld->ld_errno );
-       printf( "%s: %s\n", s, errs == NULL ? "unknown error" : errs );
-       if ( ld->ld_error != NULL && *ld->ld_error != '\0' ) {
-               printf( "%s: additional info: %s\n", s, ld->ld_error );
-       }
-}
-#endif /* WINSOCK */