From b88720091597780b6919b7020a0d2a4fae27101e Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 17 Mar 2004 20:54:53 +0000 Subject: [PATCH] Sync with HEAD --- clients/tools/common.c | 8 +- clients/tools/ldapcompare.c | 4 +- clients/tools/ldapdelete.c | 4 +- clients/tools/ldapmodrdn.c | 4 +- clients/tools/ldappasswd.c | 4 +- clients/tools/ldapsearch.c | 258 +++++++------------- clients/tools/ldapwhoami.c | 5 +- contrib/slapd-modules/dsaschema/dsaschema.c | 22 +- 8 files changed, 122 insertions(+), 187 deletions(-) diff --git a/clients/tools/common.c b/clients/tools/common.c index 83167d3bb2..c44092493a 100644 --- a/clients/tools/common.c +++ b/clients/tools/common.c @@ -98,12 +98,12 @@ N_(" -c continuous operation mode (do not stop on errors)\n"), N_(" -C chase referrals (anonymously)\n"), N_(" -d level set LDAP debugging level to `level'\n"), N_(" -D binddn bind DN\n"), -N_(" -e [!][=] general controls (! indicates criticality)\n") +N_(" -e [!][=] general extensions (! indicates criticality)\n") N_(" [!]assert= (an RFC 2254 Filter)\n") N_(" [!]authzid= (\"dn:\" or \"u:\")\n") N_(" [!]manageDSAit\n") -N_(" [!]noop\n"), -N_(" [!]postread[=] (a comma-separated attribute list)\n"), +N_(" [!]noop\n") +N_(" [!]postread[=] (a comma-separated attribute list)\n") N_(" [!]preread[=] (a comma-separated attribute list)\n"), N_(" -f file read operations from `file'\n"), N_(" -h host LDAP server\n"), @@ -166,7 +166,7 @@ tool_args( int argc, char **argv ) } binddn = ber_strdup( optarg ); break; - case 'e': /* general controls */ + case 'e': /* general extensions (controls and such) */ /* should be extended to support comma separated list of * [!]key[=value] parameters, e.g. -e !foo,bar=567 */ diff --git a/clients/tools/ldapcompare.c b/clients/tools/ldapcompare.c index 22f2852cac..056b47ac77 100644 --- a/clients/tools/ldapcompare.c +++ b/clients/tools/ldapcompare.c @@ -107,7 +107,7 @@ handle_private_option( int i ) #if 0 char *control, *cvalue; int crit; - case 'E': /* compare controls */ + case 'E': /* compare extensions */ if( protocol == LDAP_VERSION2 ) { fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"), prog, protocol ); @@ -129,7 +129,7 @@ handle_private_option( int i ) if ( (cvalue = strchr( control, '=' )) != NULL ) { *cvalue++ = '\0'; } - fprintf( stderr, _("Invalid compare control name: %s\n"), control ); + fprintf( stderr, _("Invalid compare extension name: %s\n"), control ); usage(); #endif diff --git a/clients/tools/ldapdelete.c b/clients/tools/ldapdelete.c index 420949f7a1..1c19abbe96 100644 --- a/clients/tools/ldapdelete.c +++ b/clients/tools/ldapdelete.c @@ -83,7 +83,7 @@ handle_private_option( int i ) #if 0 int crit; char *control, *cvalue; - case 'E': /* delete controls */ + case 'E': /* delete extensions */ if( protocol == LDAP_VERSION2 ) { fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"), prog, protocol ); @@ -105,7 +105,7 @@ handle_private_option( int i ) if ( (cvalue = strchr( control, '=' )) != NULL ) { *cvalue++ = '\0'; } - fprintf( stderr, _("Invalid delete control name: %s\n"), control ); + fprintf( stderr, _("Invalid delete extension name: %s\n"), control ); usage(); #endif diff --git a/clients/tools/ldapmodrdn.c b/clients/tools/ldapmodrdn.c index 6bc82fc716..75dc7a0019 100644 --- a/clients/tools/ldapmodrdn.c +++ b/clients/tools/ldapmodrdn.c @@ -98,7 +98,7 @@ handle_private_option( int i ) #if 0 int crit; char *control, *cvalue; - case 'E': /* modrdn controls */ + case 'E': /* modrdn extensions */ if( protocol == LDAP_VERSION2 ) { fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"), prog, version ); @@ -120,7 +120,7 @@ handle_private_option( int i ) if ( (cvalue = strchr( control, '=' )) != NULL ) { *cvalue++ = '\0'; } - fprintf( stderr, _("Invalid modrdn control name: %s\n"), control ); + fprintf( stderr, _("Invalid modrdn extension name: %s\n"), control ); usage(); #endif diff --git a/clients/tools/ldappasswd.c b/clients/tools/ldappasswd.c index 3f7af44dbe..d20daf9d65 100644 --- a/clients/tools/ldappasswd.c +++ b/clients/tools/ldappasswd.c @@ -88,7 +88,7 @@ handle_private_option( int i ) { switch ( i ) { #if 0 - case 'E': /* passwd controls */ { + case 'E': /* passwd extensions */ { int crit; char *control, *cvalue; if( protocol == LDAP_VERSION2 ) { @@ -112,7 +112,7 @@ handle_private_option( int i ) if ( (cvalue = strchr( control, '=' )) != NULL ) { *cvalue++ = '\0'; } - fprintf( stderr, _("Invalid passwd control name: %s\n"), control ); + fprintf( stderr, _("Invalid passwd extension name: %s\n"), control ); usage(); } #endif diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 0b602067ee..0875c6de50 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -102,13 +102,13 @@ usage( void ) fprintf( stderr, _(" -a deref one of never (default), always, search, or find\n")); fprintf( stderr, _(" -A retrieve attribute names only (no values)\n")); fprintf( stderr, _(" -b basedn base dn for search\n")); - fprintf( stderr, _(" -E [!][=] search controls (! indicates criticality)\n")); + fprintf( stderr, _(" -E [!][=] search extensions (! indicates criticality)\n")); #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE fprintf( stderr, _(" [!]domainScope (domain scope)\n")); #endif fprintf( stderr, _(" [!]mv= (matched values filter)\n")); #ifdef LDAP_CONTROL_PAGEDRESULTS - fprintf( stderr, _(" [!]pr= (paged results)\n")); + fprintf( stderr, _(" [!]pr=[/prompt|noprompt] (paged results/prompt)\n")); #endif #ifdef LDAP_CONTROL_SUBENTRIES fprintf( stderr, _(" [!]subentries[=true|false] (subentries)\n")); @@ -195,6 +195,7 @@ static int sync_slimit = -1; #ifdef LDAP_CONTROL_PAGEDRESULTS static int pagedResults = 0; +static int pagePrompt = 1; static ber_int_t pageSize = 0; static ber_int_t entriesLeft = 0; static ber_int_t morePagedResults = 1; @@ -236,25 +237,26 @@ handle_private_option( int i ) switch ( i ) { case 'a': /* set alias deref option */ if ( strcasecmp( optarg, "never" ) == 0 ) { - deref = LDAP_DEREF_NEVER; + deref = LDAP_DEREF_NEVER; } else if ( strncasecmp( optarg, "search", sizeof("search")-1 ) == 0 ) { - deref = LDAP_DEREF_SEARCHING; + deref = LDAP_DEREF_SEARCHING; } else if ( strncasecmp( optarg, "find", sizeof("find")-1 ) == 0 ) { - deref = LDAP_DEREF_FINDING; + deref = LDAP_DEREF_FINDING; } else if ( strcasecmp( optarg, "always" ) == 0 ) { - deref = LDAP_DEREF_ALWAYS; + deref = LDAP_DEREF_ALWAYS; } else { - fprintf( stderr, _("alias deref should be never, search, find, or always\n") ); - usage(); + fprintf( stderr, + _("alias deref should be never, search, find, or always\n") ); + usage(); } break; case 'A': /* retrieve attribute names only -- no values */ ++attrsonly; break; case 'b': /* search base */ - base = strdup( optarg ); + base = ber_strdup( optarg ); break; - case 'E': /* search controls */ + case 'E': /* search extensions */ if( protocol == LDAP_VERSION2 ) { fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"), prog, protocol ); @@ -272,7 +274,7 @@ handle_private_option( int i ) optarg++; } - control = strdup( optarg ); + control = ber_strdup( optarg ); if ( (cvalue = strchr( control, '=' )) != NULL ) { *cvalue++ = '\0'; } @@ -280,7 +282,8 @@ handle_private_option( int i ) if ( strcasecmp( control, "mv" ) == 0 ) { /* ValuesReturnFilter control */ if( valuesReturnFilter ) { - fprintf( stderr, _("ValuesReturnFilter previously specified\n")); + fprintf( stderr, + _("ValuesReturnFilter previously specified\n")); exit( EXIT_FAILURE ); } valuesReturnFilter= 1 + crit; @@ -299,15 +302,39 @@ handle_private_option( int i ) int num, tmp; /* PagedResults control */ if ( pagedResults != 0 ) { - fprintf( stderr, _("PagedResultsControl previously specified\n") ); + fprintf( stderr, + _("PagedResultsControl previously specified\n") ); exit( EXIT_FAILURE ); } - - num = sscanf( cvalue, "%d", &tmp ); - if ( num != 1 ) { - fprintf( stderr, _("Invalid value for PagedResultsControl, %s.\n"), cvalue); - exit( EXIT_FAILURE ); + if( cvalue != NULL ) { + char *promptp; + + promptp = strchr( cvalue, '/' ); + if ( promptp != NULL ) { + *promptp++ = '\0'; + if ( strcasecmp( promptp, "prompt" ) == 0 ) { + pagePrompt = 1; + } else if ( strcasecmp( promptp, "noprompt" ) == 0) { + pagePrompt = 0; + } else { + fprintf( stderr, + _("Invalid value for PagedResultsControl," + " %s/%s.\n"), cvalue, promptp ); + exit( EXIT_FAILURE ); + } + } + num = sscanf( cvalue, "%d", &tmp ); + if ( num != 1 ) { + fprintf( stderr, + _("Invalid value for PagedResultsControl, %s.\n"), + cvalue ); + exit( EXIT_FAILURE ); + } + } else { + fprintf( stderr, _("Invalid value for PagedResultsControl.\n"), + cvalue); + exit( EXIT_FAILURE ); } pageSize = (ber_int_t) tmp; pagedResults = 1 + crit; @@ -331,7 +358,8 @@ handle_private_option( int i ) #ifdef LDAP_CONTROL_SUBENTRIES } else if ( strcasecmp( control, "subentries" ) == 0 ) { if( subentries ) { - fprintf( stderr, _("subentries control previously specified\n")); + fprintf( stderr, + _("subentries control previously specified\n")); exit( EXIT_FAILURE ); } if( cvalue == NULL || strcasecmp( cvalue, "true") == 0 ) { @@ -351,12 +379,11 @@ handle_private_option( int i ) char *cookiep; char *slimitp; if ( ldapsync ) { - fprintf( stderr, _("ldap sync control previously specified\n") ); + fprintf( stderr, _("sync control previously specified\n") ); exit( EXIT_FAILURE ); } if ( cvalue == NULL ) { - fprintf( stderr, - _("missing specification of ldap sync control\n")); + fprintf( stderr, _("missing specification of sync control\n")); exit( EXIT_FAILURE ); } if ( strncasecmp( cvalue, "ro", 2 ) == 0 ) { @@ -384,15 +411,15 @@ handle_private_option( int i ) if ( slimitp != NULL && *slimitp != '\0' ) sync_slimit = atoi( slimitp ); } else { - fprintf( stderr, - _("ldap sync control value \"%s\" invalid\n"), + fprintf( stderr, _("sync control value \"%s\" invalid\n"), cvalue ); exit( EXIT_FAILURE ); } if ( crit ) ldapsync *= -1; } else { - fprintf( stderr, _("Invalid control name: %s\n"), control ); + fprintf( stderr, _("Invalid search extension name: %s\n"), + control ); usage(); } break; @@ -419,8 +446,8 @@ handle_private_option( int i ) } else if ( strncasecmp( optarg, "sub", sizeof("sub")-1 ) == 0 ) { scope = LDAP_SCOPE_SUBTREE; } else { - fprintf( stderr, _("scope should be base, one, or sub\n") ); - usage(); + fprintf( stderr, _("scope should be base, one, or sub\n") ); + usage(); } break; case 'S': /* sort attribute */ @@ -450,21 +477,25 @@ static void private_conn_setup( LDAP *ld ) { if (deref != -1 && - ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) + ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref ) + != LDAP_OPT_SUCCESS ) { fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref ); exit( EXIT_FAILURE ); } if (timelimit != -1 && - ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit ) != LDAP_OPT_SUCCESS ) + ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit ) + != LDAP_OPT_SUCCESS ) { fprintf( stderr, _("Could not set LDAP_OPT_TIMELIMIT %d\n"), timelimit ); exit( EXIT_FAILURE ); } if (sizelimit != -1 && - ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit ) != LDAP_OPT_SUCCESS ) + ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit ) + != LDAP_OPT_SUCCESS ) { - fprintf( stderr, _("Could not set LDAP_OPT_SIZELIMIT %d\n"), sizelimit ); + fprintf( stderr, + _("Could not set LDAP_OPT_SIZELIMIT %d\n"), sizelimit ); exit( EXIT_FAILURE ); } } @@ -692,9 +723,13 @@ getNextPage: tool_server_controls( ld, c, i ); +#ifdef LDAP_CONTROL_SUBENTRIES ber_free( seber, 1 ); +#endif ber_free( vrber, 1 ); +#ifdef LDAP_CONTROL_PAGEDRESULTS ber_free( prber, 1 ); +#endif } if ( verbose ) { @@ -794,30 +829,32 @@ getNextPage: /* Loop to get the next pages when * enter is pressed on the terminal. */ - if ( entriesLeft > 0 ) { - printf( _("Estimate entries: %d\n"), entriesLeft ); - } - printf( _("Press [size] Enter for the next {%d|size} entries.\n"), - (int)pageSize ); - i = 0; - moreEntries = getchar(); - while ( moreEntries != EOF && moreEntries != '\n' ) { - if ( i < (int)sizeof(buf) - 1 ) { - buf[i] = moreEntries; - i++; + if ( pagePrompt != 0 ) { + if ( entriesLeft > 0 ) { + printf( _("Estimate entries: %d\n"), entriesLeft ); } + printf( _("Press [size] Enter for the next {%d|size} entries.\n"), + (int)pageSize ); + i = 0; moreEntries = getchar(); - } - buf[i] = '\0'; - - if ( i > 0 && isdigit( (unsigned char)buf[0] ) ) { - int num = sscanf( buf, "%d", &tmpSize ); - if ( num != 1 ) { - fprintf( stderr, _("Invalid value for PagedResultsControl, %s.\n"), buf); - return EXIT_FAILURE; + while ( moreEntries != EOF && moreEntries != '\n' ) { + if ( i < (int)sizeof(buf) - 1 ) { + buf[i] = moreEntries; + i++; + } + moreEntries = getchar(); + } + buf[i] = '\0'; + if ( i > 0 && isdigit( (unsigned char)buf[0] ) ) { + int num = sscanf( buf, "%d", &tmpSize ); + if ( num != 1 ) { + fprintf( stderr, _("Invalid value for PagedResultsControl, %s.\n"), buf); + return EXIT_FAILURE; + + } + pageSize = (ber_int_t)tmpSize; } - pageSize = (ber_int_t)tmpSize; } goto getNextPage; @@ -1033,116 +1070,6 @@ done: return( rc ); } -#ifdef OLD_WAY -/* This is the original version, the old way of doing things. */ -static void -print_entry( - LDAP *ld, - LDAPMessage *entry, - int attrsonly) -{ - char *a, *dn, *ufn; - char tmpfname[ 256 ]; - char url[ 256 ]; - int i, rc; - BerElement *ber = NULL; - struct berval **bvals; - LDAPControl **ctrls = NULL; - FILE *tmpfp; - - dn = ldap_get_dn( ld, entry ); - ufn = NULL; - - if ( ldif < 2 ) { - ufn = ldap_dn2ufn( dn ); - write_ldif( LDIF_PUT_COMMENT, NULL, ufn, ufn ? strlen( ufn ) : 0 ); - } - write_ldif( LDIF_PUT_VALUE, "dn", dn, dn ? strlen( dn ) : 0); - - rc = ldap_get_entry_controls( ld, entry, &ctrls ); - - if( rc != LDAP_SUCCESS ) { - fprintf(stderr, _("print_entry: %d\n"), rc ); - ldap_perror( ld, "ldap_get_entry_controls" ); - exit( EXIT_FAILURE ); - } - - if( ctrls ) { - print_ctrls( ctrls ); - ldap_controls_free( ctrls ); - } - - if ( includeufn ) { - if( ufn == NULL ) { - ufn = ldap_dn2ufn( dn ); - } - write_ldif( LDIF_PUT_VALUE, "ufn", ufn, ufn ? strlen( ufn ) : 0 ); - } - - if( ufn != NULL ) ldap_memfree( ufn ); - ldap_memfree( dn ); - - for ( a = ldap_first_attribute( ld, entry, &ber ); a != NULL; - a = ldap_next_attribute( ld, entry, ber ) ) - { - if ( attrsonly ) { - write_ldif( LDIF_PUT_NOVALUE, a, NULL, 0 ); - - } else if (( bvals = ldap_get_values_len( ld, entry, a )) != NULL ) { - for ( i = 0; bvals[i] != NULL; i++ ) { - if ( vals2tmp > 1 || ( vals2tmp && ldif_is_not_printable( - bvals[i]->bv_val, bvals[i]->bv_len ) )) - { - int tmpfd; - /* write value to file */ - snprintf( tmpfname, sizeof tmpfname, - "%s" LDAP_DIRSEP "ldapsearch-%s-XXXXXX", - tmpdir, a ); - tmpfp = NULL; - - tmpfd = mkstemp( tmpfname ); - - if ( tmpfd < 0 ) { - perror( tmpfname ); - continue; - } - - if (( tmpfp = fdopen( tmpfd, "w")) == NULL ) { - perror( tmpfname ); - continue; - } - - if ( fwrite( bvals[ i ]->bv_val, - bvals[ i ]->bv_len, 1, tmpfp ) == 0 ) - { - perror( tmpfname ); - fclose( tmpfp ); - continue; - } - - fclose( tmpfp ); - - snprintf( url, sizeof url, "%s%s", urlpre, - &tmpfname[strlen(tmpdir) + sizeof(LDAP_DIRSEP) - 1] ); - - urlize( url ); - write_ldif( LDIF_PUT_URL, a, url, strlen( url )); - - } else { - write_ldif( LDIF_PUT_VALUE, a, - bvals[ i ]->bv_val, bvals[ i ]->bv_len ); - } - } - ber_bvecfree( bvals ); - } - ldap_memfree( a ); - } - - if( ber != NULL ) { - ber_free( ber, 0 ); - } -} -#else /* This is the proposed new way of doing things. * It is more efficient, but the API is non-standard. */ @@ -1203,8 +1130,8 @@ print_entry( } else if ( bvals ) { for ( i = 0; bvals[i].bv_val != NULL; i++ ) { - if ( vals2tmp > 1 || ( vals2tmp - && ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len ) )) + if ( vals2tmp > 1 || ( vals2tmp && + ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len ))) { int tmpfd; /* write value to file */ @@ -1254,7 +1181,6 @@ print_entry( ber_free( ber, 0 ); } } -#endif static void print_reference( LDAP *ld, @@ -1587,6 +1513,10 @@ parse_page_control( return EXIT_FAILURE; } + if ( servercookie.bv_len == 0 ) { + morePagedResults = 0; + } + ldap_controls_free( ctrl ); } else { diff --git a/clients/tools/ldapwhoami.c b/clients/tools/ldapwhoami.c index bb731be1d2..1eba2b60a6 100644 --- a/clients/tools/ldapwhoami.c +++ b/clients/tools/ldapwhoami.c @@ -71,7 +71,7 @@ handle_private_option( int i ) #if 0 char *control, *cvalue; int crit; - case 'E': /* whoami controls */ + case 'E': /* whoami extension */ if( protocol == LDAP_VERSION2 ) { fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"), prog, protocol ); @@ -93,7 +93,8 @@ handle_private_option( int i ) if ( (cvalue = strchr( control, '=' )) != NULL ) { *cvalue++ = '\0'; } - fprintf( stderr, _("Invalid whoami control name: %s\n"), control ); + + fprintf( stderr, _("Invalid whoami extension name: %s\n"), control ); usage(); #endif diff --git a/contrib/slapd-modules/dsaschema/dsaschema.c b/contrib/slapd-modules/dsaschema/dsaschema.c index 229830090f..906cbee34c 100644 --- a/contrib/slapd-modules/dsaschema/dsaschema.c +++ b/contrib/slapd-modules/dsaschema/dsaschema.c @@ -12,14 +12,18 @@ * . */ +#include + +#include +#include +#include +#include +#include +#include +#include +#include + #include -#include -#include -#include -#include -#include -#include -#include /* * Schema reader that allows us to define DSA schema (including @@ -336,12 +340,12 @@ strtok_quote( char *line, char *sep ) } else { inquote = 1; } - memcpy( next, next + 1, strlen( next + 1 ) + 1 ); + AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 ); break; case '\\': if ( next[1] ) - memcpy( next, + AC_MEMCPY( next, next + 1, strlen( next + 1 ) + 1 ); next++; /* dont parse the escaped character */ break; -- 2.39.5