]> git.sur5r.net Git - openldap/blobdiff - clients/tools/ldapexop.c
logging cleanup
[openldap] / clients / tools / ldapexop.c
index 3647604aea36aed5fb7c7eb7b0bc8f9037c616c3..59632de3c2693a773e6132ef848e49a36f4f2712 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * 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
 #include <ac/unistd.h>
 
 #include <ldap.h>
+#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] <oid|oid:data|oid::b64data>\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 )
@@ -182,14 +182,52 @@ main( int argc, char *argv[] )
                        goto skip;
                }
 
-       } else if ( tool_is_oid( argv[ 0 ] ) ) {
-               /* TODO */
-               fprintf( stderr, "exop \"%s\" not implemented yet.\n\n", argv[ 0 ] );
-               usage();
-               
        } 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 ( ; ; ) {
@@ -270,7 +308,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 ) {