"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"
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 );
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 ) {
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 );
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;
}
}
}
" -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"
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",
*/
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;
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 );
c2.ldctl_value=(*bvalp);
}
-
+
err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, ctrls );
ber_bvfree(bvalp);