BER_BVSTR( &what, "postread" );
}
- tool_write_ldif( LDIF_PUT_COMMENT, "==> ", what.bv_val, what.bv_len );
+ tool_write_ldif( LDIF_PUT_COMMENT, "==> ",
+ what.bv_val, what.bv_len );
ber = ber_init( &ctrls[i]->ldctl_value );
if ( ber == NULL ) {
/* ... */
int i;
BerVarray vals = NULL;
- if ( ber_scanf( ber, "[W]", &vals ) == LBER_ERROR || vals == NULL ) {
+ if ( ber_scanf( ber, "[W]", &vals ) == LBER_ERROR ||
+ vals == NULL )
+ {
/* error? */
continue;
}
for ( i = 0; vals[ i ].bv_val != NULL; i++ ) {
- tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
+ tool_write_ldif(
+ ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
bv.bv_val, vals[ i ].bv_val, vals[ i ].bv_len );
}
ber_free( ber, 1 );
}
- tool_write_ldif( LDIF_PUT_COMMENT, "<== ", what.bv_val, what.bv_len );
+ tool_write_ldif( LDIF_PUT_COMMENT, "<== ",
+ what.bv_val, what.bv_len );
-#ifdef LDAP_CONTROL_PAGEDRESULTS
- } else if ( strcmp( ctrls[i]->ldctl_oid, LDAP_CONTROL_PAGEDRESULTS ) == 0 ) {
+ } else if ( strcmp( ctrls[i]->ldctl_oid,
+ LDAP_CONTROL_PAGEDRESULTS ) == 0 )
+ {
BerElement *ber;
struct berval cookie;
int size;
if ( ber != NULL ) {
ber_free( ber, 1 );
}
-#endif /* LDAP_CONTROL_PAGEDRESULTS */
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
- } else if ( strcmp( ctrls[i]->ldctl_oid, LDAP_CONTROL_PASSWORDPOLICYRESPONSE ) == 0 ) {
+ } else if ( strcmp( ctrls[i]->ldctl_oid,
+ LDAP_CONTROL_PASSWORDPOLICYRESPONSE ) == 0 )
+ {
int expire = 0, grace = 0, rc;
LDAPPasswordPolicyError pperr;
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
"ppolicy", buf, ptr - buf );
}
- }
#endif /* LDAP_CONTROL_PASSWORDPOLICYREQUEST */
-
+ }
}
}
fprintf( stderr, _(" b64value\tbase64 encoding of assertion value\n"));
fprintf( stderr, _("Compare options:\n"));
+#ifdef LDAP_CONTROL_DONTUSECOPY
+ fprintf( stderr, _(" -E [!]<ext>[=<extparam>] compare extensions (! indicates criticality)\n"));
+ fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n"));
+#endif
fprintf( stderr, _(" -z Quiet mode,"
" don't print anything, use return values\n"));
tool_common_usage();
const char options[] = "z"
"Cd:D:e:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
+#ifdef LDAP_CONTROL_DONTUSECOPY
+int dontUseCopy = 0;
+#endif
+
int
handle_private_option( int i )
{
+ char *control, *cvalue;
+ int crit;
+
switch ( i ) {
-#if 0
- char *control, *cvalue;
- int crit;
case 'E': /* compare extensions */
if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
optarg++;
}
- control = strdup( optarg );
+ control = ber_strdup( optarg );
if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0';
}
- fprintf( stderr, _("Invalid compare extension name: %s\n"), control );
- usage();
+
+#ifdef LDAP_CONTROL_DONTUSECOPY
+ if ( strcasecmp( control, "dontUseCopy" ) == 0 ) {
+ if( dontUseCopy ) {
+ fprintf( stderr,
+ _("dontUseCopy control previously specified\n"));
+ exit( EXIT_FAILURE );
+ }
+ if( cvalue != NULL ) {
+ fprintf( stderr,
+ _("dontUseCopy: no control value expected\n") );
+ usage();
+ }
+ if( !crit ) {
+ fprintf( stderr,
+ _("dontUseCopy: critical flag required\n") );
+ usage();
+ }
+
+ dontUseCopy = 1 + crit;
+ } else
#endif
+ {
+ fprintf( stderr,
+ _("Invalid compare extension name: %s\n"), control );
+ usage();
+ }
+ break;
case 'z':
quiet = 1;
tool_bind( ld );
- if ( assertion || authzid || manageDSAit || noop ) {
- tool_server_controls( ld, NULL, 0 );
+ if ( assertion || authzid || manageDSAit || noop
+#ifdef LDAP_CONTROL_DONTUSECOPY
+ || dontUseCopy
+#endif
+ )
+ {
+ int err;
+ int i = 0;
+ LDAPControl c[1];
+
+#ifdef LDAP_CONTROL_DONTUSECOPY
+ if ( dontUseCopy ) {
+ c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
+ c[i].ldctl_value.bv_val = NULL;
+ c[i].ldctl_value.bv_len = 0;
+ c[i].ldctl_iscritical = dontUseCopy > 1;
+ i++;
+ }
+#endif
+
+ tool_server_controls( ld, c, i );
}
if ( verbose ) {
fprintf( stderr, _(" -A retrieve attribute names only (no values)\n"));
fprintf( stderr, _(" -b basedn base dn for search\n"));
fprintf( stderr, _(" -E [!]<ext>[=<extparam>] search extensions (! indicates criticality)\n"));
-#ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
- fprintf( stderr, _(" [!]domainScope (domain scope)\n"));
+#ifdef LDAP_CONTROL_DONTUSECOPY
+ fprintf( stderr, _(" !dontUseCopy (Don't Use Copy)\n"));
#endif
+ fprintf( stderr, _(" [!]domainScope (domain scope)\n"));
fprintf( stderr, _(" [!]mv=<filter> (matched values filter)\n"));
-#ifdef LDAP_CONTROL_PAGEDRESULTS
fprintf( stderr, _(" [!]pr=<size>[/prompt|noprompt] (paged results/prompt)\n"));
-#endif
-#ifdef LDAP_CONTROL_SUBENTRIES
fprintf( stderr, _(" [!]subentries[=true|false] (subentries)\n"));
-#endif
fprintf( stderr, _(" [!]sync=ro[/<cookie>] (LDAP Sync refreshOnly)\n"));
fprintf( stderr, _(" rp[/<cookie>][/<slimit>] (LDAP Sync refreshAndPersist)\n"));
fprintf( stderr, _(" [!]<oid>=:<value> (generic control; no response handling)\n"));
fprintf( stderr, _(" -LL print responses in LDIF format without comments\n"));
fprintf( stderr, _(" -LLL print responses in LDIF format without comments\n"));
fprintf( stderr, _(" and version\n"));
-#ifdef LDAP_SCOPE_SUBORDINATE
fprintf( stderr, _(" -s scope one of base, one, sub or children (search scope)\n"));
-#else /* ! LDAP_SCOPE_SUBORDINATE */
- fprintf( stderr, _(" -s scope one of base, one, or sub (search scope)\n"));
-#endif /* ! LDAP_SCOPE_SUBORDINATE */
fprintf( stderr, _(" -S attr sort the results by attribute `attr'\n"));
fprintf( stderr, _(" -t write binary values to files in temporary directory\n"));
fprintf( stderr, _(" -tt write all values to files in temporary directory\n"));
static int subentries = 0, valuesReturnFilter = 0;
static char *vrFilter = NULL;
-#ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
-static int domainScope = 0;
+#ifdef LDAP_CONTROL_DONTUSECOPY
+static int dontUseCopy = 0;
#endif
+static int domainScope = 0;
+
static int ldapsync = 0;
static struct berval sync_cookie = { 0, NULL };
static int sync_slimit = -1;
-#ifdef LDAP_CONTROL_PAGEDRESULTS
static int pagedResults = 0;
static int pagePrompt = 1;
static ber_int_t pageSize = 0;
LDAP *ld,
LDAPMessage *result,
struct berval *cookie );
-#endif
static void
urlize(char *url)
vrFilter = cvalue;
protocol = LDAP_VERSION3;
-#ifdef LDAP_CONTROL_PAGEDRESULTS
} else if ( strcasecmp( control, "pr" ) == 0 ) {
int num, tmp;
/* PagedResults control */
pageSize = (ber_int_t) tmp;
pagedResults = 1 + crit;
+#ifdef LDAP_CONTROL_DONTUSECOPY
+ } else if ( strcasecmp( control, "dontUseCopy" ) == 0 ) {
+ if( dontUseCopy ) {
+ fprintf( stderr,
+ _("dontUseCopy control previously specified\n"));
+ exit( EXIT_FAILURE );
+ }
+ if( cvalue != NULL ) {
+ fprintf( stderr,
+ _("dontUseCopy: no control value expected\n") );
+ usage();
+ }
+ if( !crit ) {
+ fprintf( stderr,
+ _("dontUseCopy: critical flag required\n") );
+ usage();
+ }
+
+ dontUseCopy = 1 + crit;
#endif
-#ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
} else if ( strcasecmp( control, "domainScope" ) == 0 ) {
if( domainScope ) {
fprintf( stderr,
}
domainScope = 1 + crit;
-#endif
-#ifdef LDAP_CONTROL_SUBENTRIES
} else if ( strcasecmp( control, "subentries" ) == 0 ) {
if( subentries ) {
fprintf( stderr,
exit( EXIT_FAILURE );
}
if( crit ) subentries *= -1;
-#endif
} else if ( strcasecmp( control, "sync" ) == 0 ) {
char *cookiep;
scope = LDAP_SCOPE_BASE;
} else if ( strncasecmp( optarg, "one", sizeof("one")-1 ) == 0 ) {
scope = LDAP_SCOPE_ONELEVEL;
-#ifdef LDAP_SCOPE_SUBORDINATE
} else if (( strcasecmp( optarg, "subordinate" ) == 0 )
|| ( strcasecmp( optarg, "children" ) == 0 ))
{
scope = LDAP_SCOPE_SUBORDINATE;
-#endif
} else if ( strncasecmp( optarg, "sub", sizeof("sub")-1 ) == 0 ) {
scope = LDAP_SCOPE_SUBTREE;
} else {
tool_init();
-#ifdef LDAP_CONTROL_PAGEDRESULTS
npagedresponses = npagedentries = npagedreferences =
npagedextended = npagedpartial = 0;
-#endif
prog = lutil_progname( "ldapsearch", argc, argv );
getNextPage:
if ( nctrls > 0 || assertion || authzid || manageDSAit || noop
-#ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
- || domainScope
-#endif
-#ifdef LDAP_CONTROL_PAGEDRESULTS
- || pagedResults
+#ifdef LDAP_CONTROL_DONTUSECOPY
+ || dontUseCopy
#endif
+ || domainScope || pagedResults
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
|| chaining
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
int i = nctrls;
save_nctrls = nctrls;
-#ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
+#ifdef LDAP_CONTROL_DONTUSECOPY
+ if ( dontUseCopy ) {
+ if ( ctrl_add() ) {
+ return EXIT_FAILURE;
+ }
+
+ c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
+ c[i].ldctl_value.bv_val = NULL;
+ c[i].ldctl_value.bv_len = 0;
+ c[i].ldctl_iscritical = dontUseCopy > 1;
+ i++;
+ }
+#endif
+
if ( domainScope ) {
if ( ctrl_add() ) {
return EXIT_FAILURE;
c[i].ldctl_iscritical = domainScope > 1;
i++;
}
-#endif
-#ifdef LDAP_CONTROL_SUBENTRIES
if ( subentries ) {
if ( ctrl_add() ) {
return EXIT_FAILURE;
c[i].ldctl_iscritical = subentries < 1;
i++;
}
-#endif
if ( ldapsync ) {
if ( ctrl_add() ) {
i++;
}
-#ifdef LDAP_CONTROL_PAGEDRESULTS
if ( pagedResults ) {
if ( ctrl_add() ) {
return EXIT_FAILURE;
c[i].ldctl_iscritical = pagedResults > 1;
i++;
}
-#endif
tool_server_controls( ld, c, i );
* those set while parsing args are preserved */
nctrls = save_nctrls;
-#ifdef LDAP_CONTROL_SUBENTRIES
ber_free( seber, 1 );
-#endif
ber_free( vrber, 1 );
-#ifdef LDAP_CONTROL_PAGEDRESULTS
ber_free( prber, 1 );
-#endif
}
if ( verbose ) {
base ? base : "",
((scope == LDAP_SCOPE_BASE) ? "baseObject"
: ((scope == LDAP_SCOPE_ONELEVEL) ? "oneLevel"
-#ifdef LDAP_SCOPE_SUBORDINATE
: ((scope == LDAP_SCOPE_SUBORDINATE) ? "children"
-#endif
- : "subtree"
-#ifdef LDAP_SCOPE_SUBORDINATE
- )
-#endif
- )));
+ : "subtree" ))));
printf(_("# filter%s: %s\n"), infile != NULL ? _(" pattern") : "",
filtpattern);
printf(_("# requesting: "));
printf(_("\n# with valuesReturnFilter %scontrol: %s"),
valuesReturnFilter > 1 ? _("critical ") : "", vrFilter );
}
-#ifdef LDAP_CONTROL_PAGEDRESULTS
if ( pagedResults ) {
printf(_("\n# with pagedResults %scontrol: size=%d"),
(pagedResults > 1) ? _("critical ") : "",
pageSize );
}
-#endif
printf( _("\n#\n\n") );
}
}
}
-#ifdef LDAP_CONTROL_PAGEDRESULTS
- if ( ( rc == LDAP_SUCCESS ) && ( pageSize != 0 ) && ( morePagedResults != 0 ) ) {
+ if (( rc == LDAP_SUCCESS ) && pageSize && morePagedResults ) {
char buf[6];
int i, moreEntries, tmpSize;
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);
+ fprintf( stderr,
+ _("Invalid value for PagedResultsControl, %s.\n"), buf);
return EXIT_FAILURE;
}
goto getNextPage;
}
-#endif
tool_unbind( ld );
tool_destroy();
case LDAP_RES_SEARCH_RESULT:
rc = print_result( ld, msg, 1 );
-#ifdef LDAP_CONTROL_PAGEDRESULTS
if ( pageSize != 0 ) {
if ( rc == LDAP_SUCCESS ) {
rc = parse_page_control( ld, msg, &page_cookie );
} else {
morePagedResults = 0;
}
-#endif
if ( ldapsync == LDAP_SYNC_REFRESH_AND_PERSIST ) {
break;
}
ldap_msgfree( res );
-#ifdef LDAP_CONTROL_PAGEDRESULTS
+
if ( pagedResults ) {
npagedresponses += nresponses;
npagedentries += nentries;
npagedreferences += nreferences;
if ( ( morePagedResults == 0 ) && ( ldif < 2 ) ) {
printf( _("\n# numResponses: %d\n"), npagedresponses );
- if( npagedentries ) printf( _("# numEntries: %d\n"), npagedentries );
- if( npagedextended ) printf( _("# numExtended: %d\n"), npagedextended );
- if( npagedpartial ) printf( _("# numPartial: %d\n"), npagedpartial );
- if( npagedreferences ) printf( _("# numReferences: %d\n"), npagedreferences );
+ if( npagedentries ) {
+ printf( _("# numEntries: %d\n"), npagedentries );
+ }
+ if( npagedextended ) {
+ printf( _("# numExtended: %d\n"), npagedextended );
+ }
+ if( npagedpartial ) {
+ printf( _("# numPartial: %d\n"), npagedpartial );
+ }
+ if( npagedreferences ) {
+ printf( _("# numReferences: %d\n"), npagedreferences );
+ }
}
- } else
-#endif
- if ( ldif < 2 ) {
+ } else if ( ldif < 2 ) {
printf( _("\n# numResponses: %d\n"), nresponses );
if( nentries ) printf( _("# numEntries: %d\n"), nentries );
if( nextended ) printf( _("# numExtended: %d\n"), nextended );
return err;
}
-#ifdef LDAP_CONTROL_PAGEDRESULTS
static int
parse_page_control(
LDAP *ld,
return err;
}
-#endif