]> git.sur5r.net Git - openldap/commitdiff
streamline server control requests
authorPierangelo Masarati <ando@openldap.org>
Mon, 9 Jan 2006 23:00:28 +0000 (23:00 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 9 Jan 2006 23:00:28 +0000 (23:00 +0000)
clients/tools/common.c
clients/tools/ldapcompare.c
clients/tools/ldapdelete.c
clients/tools/ldapexop.c
clients/tools/ldapmodify.c
clients/tools/ldapmodrdn.c
clients/tools/ldapsearch.c
clients/tools/ldapwhoami.c

index 86bd7efda5109e75153bfcf77362546937632b69..88f3430ebf0d2e3aa56c01a43051615644d08cd1 100644 (file)
@@ -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" );
index ea7570b0b014ae3f60ff5037186d419dc68c26e5..5c42585f48eb3727640fd237c8b47ab32d322b9b 100644 (file)
@@ -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 );
index 0b91b0847ea106f3751cd40cd34a7ed7f1d6237b..8bbc1c46635ca5426e083295d8aab4e1fd7629b0 100644 (file)
@@ -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 ] );
 
index 1e08881afad9310f28aa3abd1f94a866e8b8f043..3647604aea36aed5fb7c7eb7b0bc8f9037c616c3 100644 (file)
@@ -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;
index 8752ce2fea01bc5ea163c8a0e3e95e3ca8ec6aa4..0a6ccb14b990179697d33f606215d44c970957a9 100644 (file)
@@ -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;
index f37eae86af05d7f01d09351086dad9bb70d6af24..4c77b6fbeded977bcf677ea7422867e531268501 100644 (file)
@@ -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)
index c49a48b7be5222efe634b4958406f7014eb43f79..4e4f757f1198ba5e01bde4288cf93b9451758bcf 100644 (file)
@@ -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") : "",
index a436c738e9d77286e56d983a625512d4c5f9040d..7f27817be31e981c257492e51474f5a670c45771 100644 (file)
@@ -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 );