]> git.sur5r.net Git - openldap/blobdiff - clients/tools/ldapcompare.c
Parse server controls on each response, and print them.
[openldap] / clients / tools / ldapcompare.c
index 1bdd4c0ff5750e940bccd4d84f5dd45776bfa236..18f9179476238c6fc881fc03ffc45679dd90afef 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2006 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
  * Portions Copyright 1998-2003 Kurt D. Zeilenga.
  * Portions Copyright 1998-2001 Net Boolean Incorporated.
  * All rights reserved.
@@ -46,6 +46,7 @@
 #include <ac/string.h>
 #include <ac/unistd.h>
 #include <ac/errno.h>
+#include <ac/socket.h>
 #include <ac/time.h>
 #include <sys/stat.h>
 
@@ -82,10 +83,8 @@ usage( void )
        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();
@@ -103,7 +102,7 @@ static int docompare LDAP_P((
 
 
 const char options[] = "z"
-       "Cd:D:e:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
+       "Cd:D:e:h:H:IMnO:o:p:P:QR:U:vVw:WxX:y:Y:Z";
 
 #ifdef LDAP_CONTROL_DONTUSECOPY
 int dontUseCopy = 0;
@@ -181,13 +180,16 @@ 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_init( TOOL_COMPARE );
        prog = lutil_progname( "ldapcompare", argc, argv );
 
        tool_args( argc, argv );
@@ -238,16 +240,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 +255,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 );
@@ -290,8 +288,9 @@ static int docompare(
        char            *matcheddn;
        char            *text;
        char            **refs;
+       LDAPControl **ctrls = NULL;
 
-       if ( not ) {
+       if ( dont ) {
                return LDAP_SUCCESS;
        }
 
@@ -322,7 +321,7 @@ static int docompare(
                }
        }
 
-       rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, NULL, 1 );
+       rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, &ctrls, 1 );
 
        if( rc != LDAP_SUCCESS ) {
                fprintf( stderr, "%s: ldap_parse_result: %s (%d)\n",
@@ -352,10 +351,6 @@ static int docompare(
                }
        }
 
-       ber_memfree( text );
-       ber_memfree( matcheddn );
-       ber_memvfree( (void **) refs );
-
        /* if we were told to be quiet, use the return value. */
        if ( !quiet ) {
                if ( code == LDAP_COMPARE_TRUE ) {
@@ -367,6 +362,15 @@ static int docompare(
                }
        }
 
+       if ( ctrls ) {
+               tool_print_ctrls( ld, ctrls );
+               ldap_controls_free( ctrls );
+       }
+
+       ber_memfree( text );
+       ber_memfree( matcheddn );
+       ber_memvfree( (void **) refs );
+
        return( code );
 }