diff --git a/mozilla/directory/c-sdk/ldap/clients/tools/ldapcompare.c b/mozilla/directory/c-sdk/ldap/clients/tools/ldapcompare.c index 2fca92b4ef7..0eed2a00a83 100644 --- a/mozilla/directory/c-sdk/ldap/clients/tools/ldapcompare.c +++ b/mozilla/directory/c-sdk/ldap/clients/tools/ldapcompare.c @@ -114,7 +114,7 @@ main( int argc, char **argv ) } } } else { - while ( contoper || !LDAPTOOL_RESULT_IS_AN_ERROR( rc ) && + while (( contoper || !LDAPTOOL_RESULT_IS_AN_ERROR( rc )) && fgets(buf, sizeof(buf), ldaptool_fp) != NULL) { buf[ strlen( buf ) - 1 ] = '\0'; /* remove trailing newline */ if ( *buf != '\0' ) { diff --git a/mozilla/directory/c-sdk/ldap/clients/tools/ldapsearch.c b/mozilla/directory/c-sdk/ldap/clients/tools/ldapsearch.c index 68b4dfd17b0..608cefa5a77 100644 --- a/mozilla/directory/c-sdk/ldap/clients/tools/ldapsearch.c +++ b/mozilla/directory/c-sdk/ldap/clients/tools/ldapsearch.c @@ -296,8 +296,7 @@ static void options_callback( int option, char *optarg ) { char *s, *temp_arg, *ps_ptr, *ps_arg; - int i=0; - + switch( option ) { case 'u': /* include UFN */ ++includeufn; @@ -444,7 +443,7 @@ options_callback( int option, char *optarg ) fprintf (stderr, "Invalid argument for -C\n"); usage(); } - if (ps_ptr=strtok(NULL, ":")) { + if (NULL != (ps_ptr=strtok(NULL, ":"))) { if ( (temp_arg = strdup( ps_ptr )) == NULL ) { perror ("strdup"); exit (LDAP_NO_MEMORY); @@ -453,13 +452,13 @@ options_callback( int option, char *optarg ) fprintf (stderr, "Invalid argument for -C\n"); usage(); } - if (ps_ptr=strtok(NULL, ":")) { + if (NULL != (ps_ptr=strtok(NULL, ":"))) { if ( (changesonly = ldaptool_boolean_str2value(ps_ptr, 0)) == -1) { fprintf(stderr, "Invalid option value: %s\n", ps_ptr); usage(); } } - if (ps_ptr=strtok(NULL, ":")) { + if (NULL != (ps_ptr=strtok(NULL, ":"))) { if ( (return_echg_ctls = ldaptool_boolean_str2value(ps_ptr, 0)) == -1) { fprintf(stderr, "Invalid option value: %s\n", ps_ptr); usage(); @@ -516,29 +515,39 @@ dosearch( ld, base, scope, attrs, attrsonly, filtpatt, value ) LDAPVirtualList vlv_data; int msgid = 0; int length = 0; + int mallocd_filter = 0; - length = strlen( filtpatt ) + strlen ( value ) +1; - if ( length > BUFSIZ ) { - if ((filterp = (char *) - malloc ( length )) == NULL) { - perror( "filter and/or pattern too long?" ); - exit (LDAP_PARAM_ERROR); - } + if ( strstr( filtpatt, "%s" ) == NULL ) { /* no need to sprintf() */ + filterp = filtpatt; } else { - filterp = filter; - } - + length = strlen( filtpatt ) + strlen ( value ) +1; + if ( length > BUFSIZ ) { + if ((filterp = (char *) + malloc ( length )) == NULL) { + perror( "filter and/or pattern too long?" ); + exit (LDAP_PARAM_ERROR); + } + mallocd_filter = 1; + } else { + filterp = filter; + } + #ifdef HAVE_SNPRINTF - if ( snprintf( filterp, length, filtpatt, value ) < 0 ) { - perror( "snprintf filter (filter and/or pattern too long?)" ); - exit( LDAP_PARAM_ERROR ); - } + if ( snprintf( filterp, length, filtpatt, value ) < 0 ) { + perror( "snprintf filter (filter and/or pattern too long?)" ); + exit( LDAP_PARAM_ERROR ); + } #else - sprintf( filterp, filtpatt, value ); + sprintf( filterp, filtpatt, value ); #endif + } if ( *filterp == '\0' ) { /* treat empty filter is a shortcut for oc=* */ - strcpy( filterp, "(objectclass=*)" ); + if (mallocd_filter) { + free(filterp); + mallocd_filter = 0; + } + filterp = "(objectclass=*)"; } if ( ldaptool_verbose ) { @@ -554,8 +563,7 @@ dosearch( ld, base, scope, attrs, attrsonly, filtpatt, value ) } if ( ldaptool_not ) { - if (filterp != filter) - free (filterp); + if (mallocd_filter) free(filterp); return( LDAP_SUCCESS ); } @@ -615,8 +623,7 @@ dosearch( ld, base, scope, attrs, attrsonly, filtpatt, value ) rc = ldap_create_sort_control(ld,keylist,0,&ldctrl); ldap_free_sort_keylist(keylist); if ( rc != LDAP_SUCCESS ) { - if (filterp != filter) - free (filterp); + if (mallocd_filter) free(filterp); return( ldaptool_print_lderror( ld, "ldap_create_sort_control", LDAPTOOL_CHECK4SSL_IF_APPROP )); } @@ -656,16 +663,14 @@ dosearch( ld, base, scope, attrs, attrsonly, filtpatt, value ) } if ( rc != LDAP_SUCCESS ) { - if (filterp != filter) - free (filterp); + if (mallocd_filter) free(filterp); return( ldaptool_print_lderror( ld, "ldap_create_sort_control", LDAPTOOL_CHECK4SSL_IF_APPROP )); } if (LDAP_SUCCESS != (rc = ldap_create_virtuallist_control(ld, &vlv_data, &ldctrl))) { - if (filterp != filter) - free (filterp); + if (mallocd_filter) free(filterp); return( ldaptool_print_lderror( ld, "ldap_create_virtuallist_control", LDAPTOOL_CHECK4SSL_IF_APPROP )); @@ -678,8 +683,7 @@ dosearch( ld, base, scope, attrs, attrsonly, filtpatt, value ) if ( ldap_search_ext( ld, base, scope, filterp, attrs, attrsonly, ldaptool_request_ctrls, NULL, NULL, -1, &msgid ) != LDAP_SUCCESS ) { - if (filterp != filter) - free (filterp); + if (mallocd_filter) free(filterp); return( ldaptool_print_lderror( ld, "ldap_search", LDAPTOOL_CHECK4SSL_IF_APPROP )); } @@ -719,8 +723,7 @@ dosearch( ld, base, scope, attrs, attrsonly, filtpatt, value ) } } if ( rc == -1 ) { - if (filterp != filter) - free (filterp); + if (mallocd_filter) free(filterp); return( ldaptool_print_lderror( ld, "ldap_result", LDAPTOOL_CHECK4SSL_IF_APPROP )); } @@ -743,8 +746,7 @@ dosearch( ld, base, scope, attrs, attrsonly, filtpatt, value ) LDAPTOOL_CHECK4SSL_IF_APPROP ); ldap_controls_free(ctrl_response_array); ldap_msgfree(res); - if (filterp != filter) - free (filterp); + if (mallocd_filter) free(filterp); return ( ldap_get_lderrno( ld, NULL, NULL ) ); } @@ -771,8 +773,7 @@ dosearch( ld, base, scope, attrs, attrsonly, filtpatt, value ) LDAPTOOL_CHECK4SSL_IF_APPROP ); ldap_controls_free(ctrl_response_array); ldap_msgfree(res); - if (filterp != filter) - free (filterp); + if (mallocd_filter) free(filterp); return ( ldap_get_lderrno( ld, NULL, NULL ) ); } @@ -819,8 +820,7 @@ dosearch( ld, base, scope, attrs, attrsonly, filtpatt, value ) ldap_value_free( refs ); } - if (filterp != filter) - free (filterp); + if (mallocd_filter) free(filterp); ldap_msgfree( res ); return( rc ); @@ -858,7 +858,7 @@ print_entry( ld, entry, attrsonly ) LDAPControl **ectrls; int chgtype, chgnumpresent; long chgnum; - char *prevdn, intbuf[ 128 ]; + char *prevdn, longbuf[ 128 ]; if ( ldap_get_entry_controls( ld, entry, &ectrls ) == LDAP_SUCCESS ) { if ( ldap_parse_entrychange_control( ld, ectrls, &chgtype, @@ -867,10 +867,10 @@ print_entry( ld, entry, attrsonly ) LDAPTOOL_PSEARCH_ATTR_PREFIX "changeType", changetype_num2string( chgtype ), 0 ); if ( chgnumpresent ) { - sprintf( intbuf, "%d", chgnum ); + sprintf( longbuf, "%ld", chgnum ); write_string_attr_value( LDAPTOOL_PSEARCH_ATTR_PREFIX "changeNumber", - intbuf, 0 ); + longbuf, 0 ); } if ( NULL != prevdn ) { write_string_attr_value( diff --git a/mozilla/directory/c-sdk/ldap/clients/tools/ldaptool.h b/mozilla/directory/c-sdk/ldap/clients/tools/ldaptool.h index b5500f7e3d9..941c3144c6e 100644 --- a/mozilla/directory/c-sdk/ldap/clients/tools/ldaptool.h +++ b/mozilla/directory/c-sdk/ldap/clients/tools/ldaptool.h @@ -63,6 +63,10 @@ extern int getopt (int argc, char *const *argv, const char *optstring); #define LDAPTOOL_MKTEMP( p ) mktemp( p ) #endif +#ifdef LINUX +#include /* not always included from unistd.h */ +#endif + #include #ifndef SCOOS