Make sure client controls are not specified multiple times.
NT port updates.
     Begin Project Dependency
     Project_Dep_Name ldapwhoami
     End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name ldapcompare
+    End Project Dependency
 }}}
 
 ###############################################################################
 
 Package=<4>
 {{{
+    Begin Project Dependency
+    Project_Dep_Name liblber
+    End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name libldap
+    End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name liblutil
+    End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name libldif
+    End Project Dependency
 }}}
 
 ###############################################################################
 
                "Cd:D:e:h:H:IkKMnO:p:P:qQR:U:vw:WxX:y:Y:zZ")) != EOF )
        {
                switch( i ) {
+#if 0
        case 'E': /* compare controls */
                if( version == LDAP_VERSION2 ) {
                        fprintf( stderr, "%s: -E incompatible with LDAPv%d\n",
                fprintf( stderr, "Invalid compare control name: %s\n", control );
                usage(prog);
                return EXIT_FAILURE;
+#endif
 
                /* Common Options */
                case 'C':
                }
 
                if ( strcasecmp( control, "manageDSAit" ) == 0 ) {
+                       if( manageDSAit ) {
+                               fprintf( stderr, "manageDSAit control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "manageDSAit: no control value expected" );
                                usage(prog);
                        break;
                        
                } else if ( strcasecmp( control, "noop" ) == 0 ) {
+                       if( noop ) {
+                               fprintf( stderr, "noop control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "noop: no control value expected" );
                                usage(prog);
 
                }
 
                if ( strcasecmp( control, "manageDSAit" ) == 0 ) {
+                       if( manageDSAit ) {
+                               fprintf( stderr, "manageDSAit control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "manageDSAit: no control value expected" );
                                usage(prog);
                        break;
                        
                } else if ( strcasecmp( control, "noop" ) == 0 ) {
+                       if( noop ) {
+                               fprintf( stderr, "noop control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "noop: no control value expected" );
                                usage(prog);
 
                }
 
                if ( strcasecmp( control, "manageDSAit" ) == 0 ) {
+                       if( manageDSAit ) {
+                               fprintf( stderr, "manageDSAit control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "manageDSAit: no control value expected" );
                                usage(prog);
                        break;
                        
                } else if ( strcasecmp( control, "noop" ) == 0 ) {
+                       if( noop ) {
+                               fprintf( stderr, "noop control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "noop: no control value expected" );
                                usage(prog);
 
                }
 
                if ( strcasecmp( control, "manageDSAit" ) == 0 ) {
+                       if( manageDSAit ) {
+                               fprintf( stderr, "manageDSAit control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "manageDSAit: no control value expected" );
                                usage(prog);
                        break;
                        
                } else if ( strcasecmp( control, "noop" ) == 0 ) {
+                       if( noop ) {
+                               fprintf( stderr, "noop control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "noop: no control value expected" );
                                usage(prog);
 
                }
 
                if ( strcasecmp( control, "manageDSAit" ) == 0 ) {
+                       if( manageDSAit ) {
+                               fprintf( stderr, "manageDSAit control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "manageDSAit: no control value expected" );
                                usage(prog);
 
 "  -A         retrieve attribute names only (no values)\n"
 "  -b basedn  base dn for search\n"
 "  -E [!]<ctrl>[=<ctrlparam>] search controls (! indicates criticality)\n"
-"             [!]mv=<filter>   (matched values filter)\n"
+"             [!]mv=<filter>              (matched values filter)\n"
+#ifdef LDAP_CONTROL_SUBENTRIES
+"             [!]subentries[=true|false]  (subentries)\n"
+#endif
 "  -F prefix  URL prefix for files (default: %s)\n"
 "  -l limit   time limit (in seconds) for search\n"
 "  -L         print responses in LDIFv1 format\n"
        int                     referrals, timelimit, sizelimit, debug;
        int             authmethod, version, want_bindpw;
        LDAP            *ld = NULL;
-       int             valuesReturnFilter;
+       int             subentries, valuesReturnFilter;
        BerElement      *ber = NULL;
        struct berval   *bvalp = NULL;
        char    *vrFilter  = NULL, *control = NULL, *cvalue;
 
 
        infile = NULL;
-       debug = verbose = not = vals2tmp = referrals = valuesReturnFilter =
+       debug = verbose = not = vals2tmp = referrals =
+               subentries = valuesReturnFilter =
                attrsonly = manageDSAit = noop = ldif = want_bindpw = 0;
 
        prog = lutil_progname( "ldapsearch", argc, argv );
 
                if ( strcasecmp( control, "mv" ) == 0 ) {
                        /* ValuesReturnFilter control */
-                       if (valuesReturnFilter!=0) {
+                       if( valuesReturnFilter ) {
                                fprintf( stderr, "ValuesReturnFilter previously specified");
                                return EXIT_FAILURE;
                        }
                        version = LDAP_VERSION3;
                        break;
 
+#ifdef LDAP_CONTROL_SUBENTRIES
+               } else if ( strcasecmp( control, "subentries" ) == 0 ) {
+                       if( subentries ) {
+                               fprintf( stderr, "subentries control previously specified");
+                               return EXIT_FAILURE;
+                       }
+                       if( cvalue == NULL || strcasecmp( cvalue, "true") == 0 ) {
+                               subentries = 2;
+                       } else if ( strcasecmp( cvalue, "false") == 0 ) {
+                               subentries = 1;
+                       } else {
+                               fprintf( stderr,
+                                       "subentries control value \"%s\" invalid\n");
+                               return EXIT_FAILURE;
+                       }
+                       if( crit ) subentries *= -1;
+#endif
+
                } else {
                        fprintf( stderr, "Invalid control name: %s\n", control );
                        usage(prog);
                }
 
                if ( strcasecmp( control, "manageDSAit" ) == 0 ) {
+                       if( manageDSAit ) {
+                               fprintf( stderr, "manageDSAit control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "manageDSAit: no control value expected" );
                                usage(prog);
                        break;
                        
                } else if ( strcasecmp( control, "noop" ) == 0 ) {
+                       if( noop ) {
+                               fprintf( stderr, "noop control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "noop: no control value expected" );
                                usage(prog);
                        printf("\n# with noop %scontrol",
                                noop > 1 ? "critical " : "" );
                }
+               if ( subentries ) {
+                       printf("\n# with subentries %scontrol: %s",
+                               subentries < 0 ? "critical " : "",
+                               abs(subentries) == 1 ? "false" : "true" );
+               }
                if ( valuesReturnFilter ) {
                        printf("\n# with valuesReturnFilter %scontrol: %s",
                                valuesReturnFilter > 1 ? "critical " : "", vrFilter );
 
                }
 
                if ( strcasecmp( control, "manageDSAit" ) == 0 ) {
+                       if( manageDSAit ) {
+                               fprintf( stderr, "manageDSAit control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "manageDSAit: no control value expected" );
                                usage(prog);
                        break;
                        
                } else if ( strcasecmp( control, "noop" ) == 0 ) {
+                       if( noop ) {
+                               fprintf( stderr, "noop control previously specified");
+                               return EXIT_FAILURE;
+                       }
                        if( cvalue != NULL ) {
                                fprintf( stderr, "noop: no control value expected" );
                                usage(prog);