From: Pierangelo Masarati Date: Mon, 9 Jan 2006 23:00:28 +0000 (+0000) Subject: streamline server control requests X-Git-Tag: OPENLDAP_REL_ENG_2_4_BP~368 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ade92725619054220ad8935c4bec89f74a2e8329;p=openldap streamline server control requests --- diff --git a/clients/tools/common.c b/clients/tools/common.c index 86bd7efda5..88f3430ebf 100644 --- a/clients/tools/common.c +++ b/clients/tools/common.c @@ -1119,6 +1119,21 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) int i = 0, j, crit = 0, err; LDAPControl c[10], **ctrls; + if ( ! ( assertctl + || authzid + || manageDIT + || manageDSAit + || noop + || preread + || postread +#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR + || chaining +#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */ + || count ) ) + { + return; + } + ctrls = (LDAPControl**) malloc(sizeof(c) + (count+1)*sizeof(LDAPControl*)); if ( ctrls == NULL ) { fprintf( stderr, "No memory\n" ); diff --git a/clients/tools/ldapcompare.c b/clients/tools/ldapcompare.c index ea7570b0b0..5c42585f48 100644 --- a/clients/tools/ldapcompare.c +++ b/clients/tools/ldapcompare.c @@ -181,11 +181,14 @@ handle_private_option( int i ) int main( int argc, char **argv ) { - char *compdn = NULL, *attrs = NULL; - char *sep; + char *compdn = NULL, *attrs = NULL; + char *sep; int rc; - LDAP *ld = NULL; - struct berval bvalue = { 0, NULL }; + LDAP *ld = NULL; + struct berval bvalue = { 0, NULL }; + int i = 0; + LDAPControl c[1]; + tool_init( TOOL_COMPARE ); prog = lutil_progname( "ldapcompare", argc, argv ); @@ -238,16 +241,12 @@ main( int argc, char **argv ) tool_bind( ld ); - if ( assertion || authzid || manageDSAit || noop + if ( 0 #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; @@ -257,10 +256,10 @@ main( int argc, char **argv ) i++; } #endif - - tool_server_controls( ld, c, i ); } + tool_server_controls( ld, c, i ); + if ( verbose ) { fprintf( stderr, _("DN:%s, attr:%s, value:%s\n"), compdn, attrs, sep ); diff --git a/clients/tools/ldapdelete.c b/clients/tools/ldapdelete.c index 0b91b0847e..8bbc1c4663 100644 --- a/clients/tools/ldapdelete.c +++ b/clients/tools/ldapdelete.c @@ -170,13 +170,11 @@ main( int argc, char **argv ) tool_bind( ld ); - if ( assertion || authzid || manageDIT || manageDSAit || noop ) { - tool_server_controls( ld, NULL, 0 ); - } + tool_server_controls( ld, NULL, 0 ); retval = rc = 0; - if ( fp == NULL ) { + if ( fp == NULL ) { for ( ; optind < argc; ++optind ) { rc = dodelete( ld, argv[ optind ] ); diff --git a/clients/tools/ldapexop.c b/clients/tools/ldapexop.c index 1e08881afa..3647604aea 100644 --- a/clients/tools/ldapexop.c +++ b/clients/tools/ldapexop.c @@ -116,14 +116,7 @@ main( int argc, char *argv[] ) usage(); } - if ( assertion || manageDSAit || noop ) { - fprintf( stderr, _("controls incompatible with WhoAmI exop\n\n") ); - usage(); - } - - if ( authzid ) { - tool_server_controls( ld, NULL, 0 ); - } + tool_server_controls( ld, NULL, 0 ); rc = ldap_whoami( ld, NULL, NULL, &id ); if ( rc != LDAP_SUCCESS ) { @@ -156,7 +149,9 @@ main( int argc, char *argv[] ) } } else if ( strcasecmp( argv[ 0 ], "passwd" ) == 0 ) { - /* do we need this? */ + fprintf( stderr, "use ldappasswd(1) instead.\n\n", argv[ 0 ] ); + usage(); + /* TODO? */ } else if ( strcasecmp( argv[ 0 ], "refresh" ) == 0 ) { int ttl = 3600; @@ -178,9 +173,7 @@ main( int argc, char *argv[] ) usage(); } - if ( assertion || manageDSAit || noop || authzid ) { - tool_server_controls( ld, NULL, 0 ); - } + tool_server_controls( ld, NULL, 0 ); rc = ldap_refresh( ld, &dn, ttl, NULL, NULL, &id ); if ( rc != LDAP_SUCCESS ) { @@ -190,6 +183,9 @@ main( int argc, char *argv[] ) } } else if ( tool_is_oid( argv[ 0 ] ) ) { + /* TODO */ + fprintf( stderr, "exop \"%s\" not implemented yet.\n\n", argv[ 0 ] ); + usage(); } else { fprintf( stderr, "unknown exop \"%s\"\n\n", argv[ 0 ] ); @@ -258,6 +254,7 @@ main( int argc, char *argv[] ) assert( 0 ); } else if ( strcasecmp( argv[ 0 ], "passwd" ) == 0 ) { + /* TODO */ } else if ( strcasecmp( argv[ 0 ], "refresh" ) == 0 ) { int newttl; diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index 8752ce2fea..0a6ccb14b9 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -242,14 +242,17 @@ int main( int argc, char **argv ) { #ifdef LDAP_GROUP_TRANSACTION - BerElement *txnber; - struct berval txnCookie = { 0, NULL }; + BerElement *txnber; + struct berval txnCookie = { 0, NULL }; #endif char *rbuf, *start, *rejbuf = NULL; FILE *fp, *rejfp; char *matched_msg, *error_msg; int rc, retval; - int count, len; + int count, len; + int i = 0; + LDAPControl c[1]; + prog = lutil_progname( "ldapmodify", argc, argv ); @@ -311,15 +314,12 @@ main( int argc, char **argv ) } #endif - if ( assertion || authzid || manageDIT || manageDSAit || noop + if ( 0 #ifdef LDAP_GROUP_TRANSACTION || txn #endif - || preread || postread ) + ) { - int i = 0; - LDAPControl c[1]; - #ifdef LDAP_GROUP_TRANSACTION if( txn ) { int err; @@ -341,10 +341,10 @@ main( int argc, char **argv ) i++; } #endif - - tool_server_controls( ld, c, i ); } + tool_server_controls( ld, c, i ); + rc = 0; count = 0; retval = 0; diff --git a/clients/tools/ldapmodrdn.c b/clients/tools/ldapmodrdn.c index f37eae86af..4c77b6fbed 100644 --- a/clients/tools/ldapmodrdn.c +++ b/clients/tools/ldapmodrdn.c @@ -198,9 +198,7 @@ main(int argc, char **argv) tool_bind( ld ); - if ( assertion || authzid || manageDSAit || noop ) { - tool_server_controls( ld, NULL, 0 ); - } + tool_server_controls( ld, NULL, 0 ); retval = rc = 0; if (havedn) diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index c49a48b7be..4e4f757f11 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -625,12 +625,13 @@ main( int argc, char **argv ) { char *filtpattern, **attrs = NULL, line[BUFSIZ]; FILE *fp = NULL; - int rc, i, first; + int rc, i, first; LDAP *ld = NULL; BerElement *seber = NULL, *vrber = NULL; BerElement *syncber = NULL; struct berval *syncbvalp = NULL; + int err; tool_init( TOOL_SEARCH ); @@ -724,20 +725,18 @@ main( int argc, char **argv ) tool_bind( ld ); getNextPage: - if ( nctrls > 0 || assertion || authzid || manageDSAit || noop + save_nctrls = nctrls; + i = nctrls; + if ( nctrls > 0 #ifdef LDAP_CONTROL_DONTUSECOPY || dontUseCopy #endif - || domainScope || pagedResults -#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR - || chaining -#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */ + || domainScope + || pagedResults || ldapsync - || subentries || valuesReturnFilter ) + || subentries + || valuesReturnFilter ) { - int err; - int i = nctrls; - save_nctrls = nctrls; #ifdef LDAP_CONTROL_DONTUSECOPY if ( dontUseCopy ) { @@ -867,17 +866,17 @@ getNextPage: c[i].ldctl_iscritical = pagedResults > 1; i++; } + } - tool_server_controls( ld, c, i ); + tool_server_controls( ld, c, i ); - /* step back to the original number of controls, so that - * those set while parsing args are preserved */ - nctrls = save_nctrls; + ber_free( seber, 1 ); + ber_free( vrber, 1 ); + + /* step back to the original number of controls, so that + * those set while parsing args are preserved */ + nctrls = save_nctrls; - ber_free( seber, 1 ); - ber_free( vrber, 1 ); - } - if ( verbose ) { fprintf( stderr, _("filter%s: %s\nrequesting: "), infile != NULL ? _(" pattern") : "", diff --git a/clients/tools/ldapwhoami.c b/clients/tools/ldapwhoami.c index a436c738e9..7f27817be3 100644 --- a/clients/tools/ldapwhoami.c +++ b/clients/tools/ldapwhoami.c @@ -154,9 +154,7 @@ main( int argc, char *argv[] ) goto skip; } - if ( assertion || authzid || manageDSAit || noop ) { - tool_server_controls( ld, NULL, 0 ); - } + tool_server_controls( ld, NULL, 0 ); rc = ldap_whoami( ld, NULL, NULL, &id );