X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=clients%2Ftools%2Fldapexop.c;h=6de7ec2bd02a4f78eb91553005a9eb9ae56b4790;hb=6e63bac9ebf7f6480e422f9f34c58cb36063fe7b;hp=1e08881afad9310f28aa3abd1f94a866e8b8f043;hpb=57ca537d0c1059c881be5f1fb5fd9ff2600bd7bc;p=openldap diff --git a/clients/tools/ldapexop.c b/clients/tools/ldapexop.c index 1e08881afa..6de7ec2bd0 100644 --- a/clients/tools/ldapexop.c +++ b/clients/tools/ldapexop.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2005-2006 The OpenLDAP Foundation. + * Copyright 2005-2007 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,25 +31,25 @@ #include #include +#include "ldif.h" #include "lutil.h" #include "lutil_ldap.h" #include "ldap_defaults.h" #include "common.h" - void usage( void ) { fprintf( stderr, _("Issue LDAP extended operations\n\n")); - fprintf( stderr, _("usage: %s [options]\n"), prog); + fprintf( stderr, _("usage: %s [options] \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:InO:o:p:QR:U:vVw:WxX:y:Y:Z"; int handle_private_option( int i ) @@ -66,11 +66,11 @@ int 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; @@ -104,26 +104,7 @@ main( int argc, char *argv[] ) 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(); - } - - if ( assertion || manageDSAit || noop ) { - fprintf( stderr, _("controls incompatible with WhoAmI exop\n\n") ); - usage(); - } - - if ( authzid ) { - tool_server_controls( ld, NULL, 0 ); - } + tool_server_controls( ld, NULL, 0 ); rc = ldap_whoami( ld, NULL, NULL, &id ); if ( rc != LDAP_SUCCESS ) { @@ -156,7 +137,9 @@ main( int argc, char *argv[] ) } } else if ( strcasecmp( argv[ 0 ], "passwd" ) == 0 ) { - /* do we need this? */ + fprintf( stderr, "use ldappasswd(1) instead.\n\n", argv[ 0 ] ); + usage(); + /* TODO? */ } else if ( strcasecmp( argv[ 0 ], "refresh" ) == 0 ) { int ttl = 3600; @@ -178,9 +161,7 @@ main( int argc, char *argv[] ) usage(); } - if ( assertion || manageDSAit || noop || authzid ) { - tool_server_controls( ld, NULL, 0 ); - } + tool_server_controls( ld, NULL, 0 ); rc = ldap_refresh( ld, &dn, ttl, NULL, NULL, &id ); if ( rc != LDAP_SUCCESS ) { @@ -189,11 +170,52 @@ main( int argc, char *argv[] ) goto skip; } - } else if ( tool_is_oid( argv[ 0 ] ) ) { - } 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 ( ; ; ) { @@ -219,7 +241,7 @@ main( int argc, char *argv[] ) } rc = ldap_parse_result( ld, res, - &code, &matcheddn, &text, &refs, NULL, 0 ); + &code, &matcheddn, &text, &refs, &ctrls, 0 ); if ( rc == LDAP_SUCCESS ) { rc = code; } @@ -258,6 +280,7 @@ main( int argc, char *argv[] ) assert( 0 ); } else if ( strcasecmp( argv[ 0 ], "passwd" ) == 0 ) { + /* TODO */ } else if ( strcasecmp( argv[ 0 ], "refresh" ) == 0 ) { int newttl; @@ -273,7 +296,35 @@ main( int argc, char *argv[] ) printf( "newttl=%d\n", newttl ); } else if ( tool_is_oid( argv[ 0 ] ) ) { - /* ... */ + char *retoid = NULL; + struct berval *retdata = NULL; + + if( ldif < 2 ) { + printf(_("# extended operation response\n")); + } + + rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 1 ); + if ( rc != LDAP_SUCCESS ) { + tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL ); + rc = EXIT_FAILURE; + goto skip; + } + + if ( ldif < 2 && retoid != NULL ) { + tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE, + "oid", retoid, strlen(retoid) ); + } + + ber_memfree( retoid ); + + if( retdata != NULL ) { + if ( ldif < 2 ) { + tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_BINARY, + "data", retdata->bv_val, retdata->bv_len ); + } + + ber_bvfree( retdata ); + } } if( verbose || ( code != LDAP_SUCCESS ) || matcheddn || text || refs ) { @@ -295,6 +346,11 @@ main( int argc, char *argv[] ) } } + if (ctrls) { + tool_print_ctrls( ld, ctrls ); + ldap_controls_free( ctrls ); + } + ber_memfree( text ); ber_memfree( matcheddn ); ber_memvfree( (void **) refs );