]> git.sur5r.net Git - openldap/commitdiff
improve control support thru -E switch
authorPierangelo Masarati <ando@openldap.org>
Thu, 29 Aug 2002 10:41:10 +0000 (10:41 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 29 Aug 2002 10:41:10 +0000 (10:41 +0000)
clients/tools/ldapmodify.c
clients/tools/ldapsearch.c

index 17ad97179a03282487289eb8483ddf5716331622..60bc559f6af30c14fcd776ee1c81b95559646433 100644 (file)
@@ -105,13 +105,16 @@ usage( const char *prog )
 "Add or modify options:\n"
 "  -a         add values (default%s)\n"
 "  -c         continuous operation mode (do not stop on errors)\n"
-"  -f file    read operations from `file'\n"
+"  -E <ctrl>[=<ctrlparam>] controls\n"
+"             manageDSAit[={no|yes|critical}]   (alternate form, see -M)\n"
+"             noop[={no|yes|critical}]          (no operation)\n"
 "  -F         force all changes records to be used\n"
 "  -S file    write skipped modifications to `file'\n"
 
 "Common options:\n"
 "  -d level   set LDAP debugging level to `level'\n"
 "  -D binddn  bind DN\n"
+"  -f file    read operations from `file'\n"
 "  -h host    LDAP server\n"
 "  -H URI     LDAP Uniform Resource Indentifier(s)\n"
 "  -I         use SASL Interactive mode\n"
@@ -145,9 +148,10 @@ main( int argc, char **argv )
     char               *infile, *rejfile, *rbuf, *start, *rejbuf = NULL;
     FILE               *fp, *rejfp;
        char            *matched_msg = NULL, *error_msg = NULL;
-       int             rc, i, authmethod, version, want_bindpw, debug, manageDSAit, referrals;
+       int             rc, i, authmethod, version, want_bindpw, debug, manageDSAit, noop, referrals;
        int count, len;
        char    *pw_file = NULL;
+       char    *control, *s;
 
     prog = lutil_progname( "ldapmodify", argc, argv );
 
@@ -159,11 +163,11 @@ main( int argc, char **argv )
 
     infile = NULL;
     rejfile = NULL;
-    not = verbose = want_bindpw = debug = manageDSAit = referrals = 0;
+    not = verbose = want_bindpw = debug = manageDSAit = noop = referrals = 0;
     authmethod = -1;
        version = -1;
 
-    while (( i = getopt( argc, argv, "acrf:F"
+    while (( i = getopt( argc, argv, "acrf:E:F"
                "Cd:D:h:H:IkKMnO:p:P:QR:S:U:vw:WxX:y:Y:Z" )) != EOF )
        {
        switch( i ) {
@@ -174,6 +178,75 @@ main( int argc, char **argv )
        case 'c':       /* continuous operation */
            contoper = 1;
            break;
+       case 'E': /* controls */
+               if( version == LDAP_VERSION2 ) {
+                       fprintf( stderr, "%s: -C incompatible with LDAPv%d\n",
+                               prog, version );
+                       return EXIT_FAILURE;
+               }
+
+               /* should be extended to support comma separated list of
+                *      key/value pairs:  -E foo=123,bar=567
+                */
+
+               control = strdup( optarg );
+               if ( (s = strchr( control, '=' )) != NULL ) {
+                       *s++ = '\0';
+               }
+
+               if ( strcasecmp( control, "manageDSAit" ) == 0 ) {
+                       if ( s == NULL ) {
+                               manageDSAit = 1;
+
+                       } else if ( strcasecmp( s, "no" ) == 0 ) {
+                               manageDSAit = 0;
+                               
+                       } else if ( strcasecmp( s, "yes" ) == 0 ) {
+                               manageDSAit = 1;
+                               
+                       } else if ( strcasecmp( s, "critical" ) == 0 ) {
+                               manageDSAit = 2;
+
+                       } else {
+                               fprintf( stderr, "unknown manageDSAit control "
+                                               "value: %s (accepts \"no\", "
+                                               "\"yes\", \"critical\")\n", 
+                                               s );
+                               usage(prog);
+                               return EXIT_FAILURE;
+                       }
+                       free( control );
+                       break;
+                       
+               } else if ( strcasecmp( control, "noop" ) == 0 ) {
+                       if ( s == NULL ) {
+                               noop = 1;
+
+                       } else if ( strcasecmp( s, "no" ) == 0 ) {
+                               noop = 0;
+                               
+                       } else if ( strcasecmp( s, "yes" ) == 0 ) {
+                               noop = 1;
+                               
+                       } else if ( strcasecmp( s, "critical" ) == 0 ) {
+                               noop = 2;
+
+                       } else {
+                               fprintf( stderr, "unknown noop control "
+                                               "value: %s (accepts \"no\", "
+                                               "\"yes\", \"critical\")\n", 
+                                               s );
+                               usage(prog);
+                               return EXIT_FAILURE;
+                       }
+                       free( control );
+                       break;
+
+               } else {
+                       fprintf( stderr, "Invalid control name: %s\n", control );
+                       usage(prog);
+                       return EXIT_FAILURE;
+               }
        case 'f':       /* read from file */
                if( infile != NULL ) {
                        fprintf( stderr, "%s: -f previously specified\n", prog );
@@ -701,25 +774,38 @@ main( int argc, char **argv )
 
     rc = 0;
 
-       if ( manageDSAit ) {
-               int err;
-               LDAPControl c;
-               LDAPControl *ctrls[2];
-               ctrls[0] = &c;
-               ctrls[1] = NULL;
+       if ( manageDSAit || noop ) {
+               int err, i = 0;
+               LDAPControl c1, c2;
+               LDAPControl *ctrls[3];
+
+               if ( manageDSAit ) {
+                       ctrls[i++] = &c1;
+                       ctrls[i] = NULL;
+                       c1.ldctl_oid = LDAP_CONTROL_MANAGEDSAIT;
+                       c1.ldctl_value.bv_val = NULL;
+                       c1.ldctl_value.bv_len = 0;
+                       c1.ldctl_iscritical = manageDSAit > 1;
+               }
 
-               c.ldctl_oid = LDAP_CONTROL_MANAGEDSAIT;
-               c.ldctl_value.bv_val = NULL;
-               c.ldctl_value.bv_len = 0;
-               c.ldctl_iscritical = manageDSAit > 1;
+               if ( noop ) {
+                       ctrls[i++] = &c2;
+                       ctrls[i] = NULL;
 
+                       c2.ldctl_oid = LDAP_CONTROL_NOOP;
+                       c2.ldctl_value.bv_val = NULL;
+                       c2.ldctl_value.bv_len = 0;
+                       c2.ldctl_iscritical = noop > 1;
+               }
+       
                err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
 
                if( err != LDAP_OPT_SUCCESS ) {
-                       fprintf( stderr, "Could not set ManageDSAit %scontrol\n",
-                               c.ldctl_iscritical ? "critical " : "" );
-                       if( c.ldctl_iscritical ) {
-                               exit( EXIT_FAILURE );
+                       fprintf( stderr, "Could not set %scontrols\n",
+                               (c1.ldctl_iscritical || c2.ldctl_iscritical)
+                               ? "critical " : "" );
+                       if ( c1.ldctl_iscritical && c2.ldctl_iscritical ) {
+                               return EXIT_FAILURE;
                        }
                }
        }
index 2dd5615eb7a96c1c78c5e196b6f5c0deeb65a76f..4db8a5d8a64b965b5967930d834de35748a13375 100644 (file)
@@ -54,6 +54,9 @@ usage( const char *s )
 "  -a deref   one of never (default), always, search, or find\n"
 "  -A         retrieve attribute names only (no values)\n"
 "  -b basedn  base dn for search\n"
+"  -E <ctrl>[=<ctrlparam>] controls\n"
+"             manageDSAit[={no|yes|critical}]   (alternate form, see -M)\n"
+"             mv=<filter>                       (matched values filter)\n"
 "  -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"
@@ -252,13 +255,6 @@ main( int argc, char **argv )
        case 'b': /* search base */
                base = strdup( optarg );
                break;
-       case 'f':       /* input file */
-               if( infile != NULL ) {
-                       fprintf( stderr, "%s: -f previously specified\n", prog );
-                       return EXIT_FAILURE;
-               }
-               infile = strdup( optarg );
-               break;
        case 'E': /* controls */
                if( version == LDAP_VERSION2 ) {
                        fprintf( stderr, "%s: -C incompatible with LDAPv%d\n",
@@ -271,18 +267,46 @@ main( int argc, char **argv )
                 */
 
                control = strdup( optarg );
-               if ( (s = strchr( control, '=' )) == NULL ) {
-                       return EXIT_FAILURE;
+               if ( (s = strchr( control, '=' )) != NULL ) {
+                       *s++ = '\0';
                }
 
-               *s++ = '\0';
-               if ( strcasecmp( control, "mv" ) == 0 ) {
+               if ( strcasecmp( control, "manageDSAit" ) == 0 ) {
+                       if ( s == NULL ) {
+                               manageDSAit = 1;
+
+                       } else if ( strcasecmp( s, "no" ) == 0 ) {
+                               manageDSAit = 0;
+                               
+                       } else if ( strcasecmp( s, "yes" ) == 0 ) {
+                               manageDSAit = 1;
+                               
+                       } else if ( strcasecmp( s, "critical" ) == 0 ) {
+                               manageDSAit = 2;
+
+                       } else {
+                               fprintf( stderr, "unknown manageDSAit control "
+                                               "value: %s (accepts \"no\", "
+                                               "\"yes\", \"critical\")\n", 
+                                               s );
+                               usage(prog);
+                               return EXIT_FAILURE;
+                       }
+                       free( control );
+                       break;
+                       
+               } else if ( strcasecmp( control, "mv" ) == 0 ) {
                        /* ValuesReturnFilter control */
                        if (valuesReturnFilter!=0) {
                                fprintf( stderr, "ValuesReturnFilter previously specified");
                                return EXIT_FAILURE;
                        }
 
+                       if ( s == NULL ) {
+                               fprintf( stderr, "missing filter in ValuesReturnFilter control\n");
+                               return EXIT_FAILURE;
+                       }
+
                        if ( *s == '!' ){
                                s++;
                                valuesReturnFilter=2;
@@ -299,7 +323,13 @@ main( int argc, char **argv )
                        usage(prog);
                        return EXIT_FAILURE;
                }
-
+       case 'f':       /* input file */
+               if( infile != NULL ) {
+                       fprintf( stderr, "%s: -f previously specified\n", prog );
+                       return EXIT_FAILURE;
+               }
+               infile = strdup( optarg );
+               break;
        case 'F':       /* uri prefix */
                if( urlpre ) free( urlpre );
                urlpre = strdup( optarg );
@@ -922,7 +952,7 @@ main( int argc, char **argv )
 
                        c2.ldctl_value=(*bvalp);
                }
-       
+
                err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
 
                ber_bvfree(bvalp);