/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2005-2006 The OpenLDAP Foundation.
+ * Copyright 2005-2011 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
usage( void )
{
fprintf( stderr, _("Issue LDAP extended operations\n\n"));
- fprintf( stderr, _("usage: %s [options]\n"), prog);
+ fprintf( stderr, _("usage: %s [options] <oid|oid:data|oid::b64data>\n"), prog);
+ fprintf( stderr, _(" %s [options] whoami\n"), prog);
+ fprintf( stderr, _(" %s [options] cancel <id>\n"), prog);
+ fprintf( stderr, _(" %s [options] refresh <DN> [<ttl>]\n"), prog);
tool_common_usage();
exit( EXIT_FAILURE );
}
const char options[] = ""
- "d:D:e:h:H:InO:p:QR:U:vVw:WxX:y:Y:Z";
+ "d:D:e:h:H:InNO:o:p:QR:U:vVw:WxX:y:Y:Z";
int
handle_private_option( int i )
main( int argc, char *argv[] )
{
int rc;
- char *user = NULL;
LDAP *ld = NULL;
char *matcheddn = NULL, *text = NULL, **refs = NULL;
+ LDAPControl **ctrls = NULL;
int id, code;
- LDAPMessage *res;
+ LDAPMessage *res = NULL;
tool_init( TOOL_EXOP );
prog = lutil_progname( "ldapexop", argc, argv );
usage();
}
- if ( pw_file || want_bindpw ) {
- if ( pw_file ) {
- rc = lutil_get_filed_password( pw_file, &passwd );
- if( rc ) return EXIT_FAILURE;
- } else {
- passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
- passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
- }
- }
-
ld = tool_conn_setup( 0, 0 );
tool_bind( ld );
argc -= optind;
if ( strcasecmp( argv[ 0 ], "whoami" ) == 0 ) {
- switch ( argc ) {
- case 2:
- user = argv[ 1 ];
-
- case 1:
- break;
-
- default:
- fprintf( stderr, "need [user]\n\n" );
- usage();
- }
-
tool_server_controls( ld, NULL, 0 );
rc = ldap_whoami( ld, NULL, NULL, &id );
case 2:
dn.bv_val = argv[ 1 ];
dn.bv_len = strlen( dn.bv_val );
-
- case 1:
break;
default:
goto skip;
}
- } else if ( tool_is_oid( argv[ 0 ] ) ) {
- rc = ldap_extended_operation( ld, argv[ 0 ], NULL, NULL, NULL, &id );
- if ( rc != LDAP_SUCCESS ) {
- tool_perror( "ldap_extended_operation", rc, NULL, NULL, NULL, NULL );
- rc = EXIT_FAILURE;
- goto skip;
- }
} else {
- fprintf( stderr, "unknown exop \"%s\"\n\n", argv[ 0 ] );
- usage();
+ char *p;
+
+ if ( argc != 1 ) {
+ usage();
+ }
+
+ p = strchr( argv[ 0 ], ':' );
+ if ( p == argv[ 0 ] ) {
+ usage();
+ }
+
+ if ( p != NULL )
+ *p++ = '\0';
+
+ if ( tool_is_oid( argv[ 0 ] ) ) {
+ struct berval reqdata;
+ struct berval type;
+ struct berval value;
+ int freeval;
+
+ if ( p != NULL ) {
+ p[ -1 ] = ':';
+ ldif_parse_line2( argv[ 0 ], &type, &value, &freeval );
+ p[ -1 ] = '\0';
+
+ if ( freeval ) {
+ reqdata = value;
+ } else {
+ ber_dupbv( &reqdata, &value );
+ }
+ }
+
+
+ tool_server_controls( ld, NULL, 0 );
+
+ rc = ldap_extended_operation( ld, argv[ 0 ], p ? &reqdata : NULL, NULL, NULL, &id );
+ if ( rc != LDAP_SUCCESS ) {
+ tool_perror( "ldap_extended_operation", rc, NULL, NULL, NULL, NULL );
+ rc = EXIT_FAILURE;
+ goto skip;
+ }
+ } else {
+ fprintf( stderr, "unknown exop \"%s\"\n\n", argv[ 0 ] );
+ usage();
+ }
}
for ( ; ; ) {
}
rc = ldap_parse_result( ld, res,
- &code, &matcheddn, &text, &refs, NULL, 0 );
+ &code, &matcheddn, &text, &refs, &ctrls, 0 );
if ( rc == LDAP_SUCCESS ) {
rc = code;
}
char *retoid = NULL;
struct berval *retdata = NULL;
- rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 1 );
+ rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 0 );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
printf(_("# extended operation response\n"));
}
- rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 1 );
+ rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 0 );
if ( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
rc = EXIT_FAILURE;
goto skip;
}
- if ( ldif < 2 ) {
+ if ( ldif < 2 && retoid != NULL ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
- "oid", retoid, retoid ? strlen(retoid) : 0 );
+ "oid", retoid, strlen(retoid) );
}
ber_memfree( retoid );
- if( retdata ) {
+ if( retdata != NULL ) {
if ( ldif < 2 ) {
tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY,
"data", retdata->bv_val, retdata->bv_len );
}
}
- if( verbose || ( code != LDAP_SUCCESS ) || matcheddn || text || refs ) {
+ if( verbose || code != LDAP_SUCCESS ||
+ ( matcheddn && *matcheddn ) || ( text && *text ) || refs ) {
printf( _("Result: %s (%d)\n"), ldap_err2string( code ), code );
if( text && *text ) {
}
}
+ if (ctrls) {
+ tool_print_ctrls( ld, ctrls );
+ ldap_controls_free( ctrls );
+ }
+
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( (void **) refs );
skip:
/* disconnect from server */
+ if ( res )
+ ldap_msgfree( res );
tool_unbind( ld );
tool_destroy();