From: Kurt Zeilenga Date: Mon, 6 Mar 2006 21:20:36 +0000 (+0000) Subject: Initial and rough client-side implementation of the revised LDAP X-Git-Tag: OPENLDAP_REL_ENG_2_4_BP~145 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=825ce796114ef194c70918e5b75b5ac416ff2b36;p=openldap Initial and rough client-side implementation of the revised LDAP Transactions specification. A work in progress! Comments welcomed. --- diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index 0a6ccb14b9..17589fe0bd 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -122,9 +122,10 @@ static int process_response( const char *dn ); static char *read_one_record LDAP_P(( FILE *fp )); -#ifdef LDAP_GROUP_TRANSACTION +#ifdef LDAP_X_TXN static int txn = 0; static int txnabort = 0; +struct berval *txn_id = NULL; #endif void @@ -140,9 +141,9 @@ usage( void ) (ldapadd ? _("default") : _("default is to replace"))); fprintf( stderr, _(" -E [!]ext=extparam modify extensions" " (! indicate s criticality)\n")); -#ifdef LDAP_GROUP_TRANSACTION +#ifdef LDAP_X_TXN fprintf( stderr, - _(" [!]txn (transaction)\n")); + _(" [!]txn= (transaction)\n")); #endif fprintf( stderr, _(" -F force all changes records to be used\n")); fprintf( stderr, _(" -S file write skipped modifications to `file'\n")); @@ -185,7 +186,7 @@ handle_private_option( int i ) *cvalue++ = '\0'; } -#ifdef LDAP_GROUP_TRANSACTION +#ifdef LDAP_X_TXN if( strcasecmp( control, "txn" ) == 0 ) { /* Transaction */ if( txn ) { @@ -241,10 +242,6 @@ handle_private_option( int i ) int main( int argc, char **argv ) { -#ifdef LDAP_GROUP_TRANSACTION - BerElement *txnber; - struct berval txnCookie = { 0, NULL }; -#endif char *rbuf, *start, *rejbuf = NULL; FILE *fp, *rejfp; char *matched_msg, *error_msg; @@ -253,7 +250,6 @@ main( int argc, char **argv ) int i = 0; LDAPControl c[1]; - prog = lutil_progname( "ldapmodify", argc, argv ); /* strncmp instead of strcmp since NT binaries carry .exe extension */ @@ -300,43 +296,28 @@ main( int argc, char **argv ) tool_bind( ld ); } -#ifdef LDAP_GROUP_TRANSACTION +#ifdef LDAP_X_TXN if( txn ) { - struct berval *txnCookiep = &txnCookie; - - /* create transaction */ - rc = ldap_txn_create_s( ld, &txnCookiep, NULL, NULL ); + /* start transaction */ + rc = ldap_txn_start_s( ld, NULL, NULL, &txn_id ); if( rc != LDAP_SUCCESS ) { - tool_perror( "ldap_txn_create_s", rc, NULL, NULL, NULL, NULL ); - if( txn > 2 ) return EXIT_FAILURE; + tool_perror( "ldap_txn_start_s", rc, NULL, NULL, NULL, NULL ); + if( txn > 1 ) return EXIT_FAILURE; txn = 0; } } #endif if ( 0 -#ifdef LDAP_GROUP_TRANSACTION +#ifdef LDAP_X_TXN || txn #endif ) { -#ifdef LDAP_GROUP_TRANSACTION +#ifdef LDAP_X_TXN if( txn ) { - int err; - txnber = ber_alloc_t( LBER_USE_DER ); - if( txnber == NULL ) return EXIT_FAILURE; - - err = ber_printf( txnber, "{o}", &txnCookie ); - if( err == -1 ) { - ber_free( txnber, 1 ); - fprintf( stderr, _("txn grouping control encoding error!\n") ); - return EXIT_FAILURE; - } - - err = ber_flatten2( txnber, &c[i].ldctl_value, 0 ); - if( err == -1 ) return EXIT_FAILURE; - - c[i].ldctl_oid = LDAP_CONTROL_GROUPING; + c[i].ldctl_oid = LDAP_CONTROL_X_TXN_SPEC; + c[i].ldctl_value = *txn_id; c[i].ldctl_iscritical = 1; i++; } @@ -394,13 +375,13 @@ main( int argc, char **argv ) free( rbuf ); } -#ifdef LDAP_GROUP_TRANSACTION +#ifdef LDAP_X_TXN if( txn ) { /* create transaction */ - rc = ldap_txn_end_s( ld, &txnCookie, !txnabort, NULL, NULL ); + rc = ldap_txn_end_s( ld, !txnabort, txn_id, NULL, NULL, NULL ); if( rc != LDAP_SUCCESS ) { - tool_perror( "ldap_txn_create_s", rc, NULL, NULL, NULL, NULL ); - if( txn > 2 ) return EXIT_FAILURE; + tool_perror( "ldap_txn_end_s", rc, NULL, NULL, NULL, NULL ); + if( txn > 1 ) return EXIT_FAILURE; txn = 0; } } diff --git a/include/ldap.h b/include/ldap.h index 0d65ea29e4..e9a8ef12a0 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -357,6 +357,14 @@ typedef struct ldapcontrol { #define LDAP_URLEXT_X_FAILEDNAME "x-failedName" #endif +#ifdef LDAP_DEVEL +#define LDAP_X_TXN "1.3.6.1.4.1.4203.666.11.7" /* temp */ +#define LDAP_EXOP_X_TXN_START LDAP_X_TXN ".1" +#define LDAP_CONTROL_X_TXN_SPEC LDAP_X_TXN ".2" +#define LDAP_EXOP_X_TXN_END LDAP_X_TXN ".3" +#define LDAP_EXOP_X_TXN_ABORTED_NOTICE LDAP_X_TXN ".4" +#endif + /* LDAP Features */ #define LDAP_FEATURE_ALL_OP_ATTRS "1.3.6.1.4.1.4203.1.5.1" /* RFC 3673 */ #define LDAP_FEATURE_OBJECTCLASS_ATTRS \ @@ -2060,5 +2068,38 @@ ldap_refresh_s LDAP_P(( LDAPControl **sctrls, LDAPControl **cctrls )); +/* + * LDAP Transactions + */ +#ifdef LDAP_X_TXN +LDAP_F( int ) +ldap_txn_start LDAP_P(( LDAP *ld, + LDAPControl **sctrls, + LDAPControl **cctrls, + int *msgidp )); + +LDAP_F( int ) +ldap_txn_start_s LDAP_P(( LDAP *ld, + LDAPControl **sctrl, + LDAPControl **cctrl, + struct berval **rettxnid )); + +LDAP_F( int ) +ldap_txn_end LDAP_P(( LDAP *ld, + int commit, + struct berval *txnid, + LDAPControl **sctrls, + LDAPControl **cctrls, + int *msgidp )); + +LDAP_F( int ) +ldap_txn_end_s LDAP_P(( LDAP *ld, + int commit, + struct berval *txnid, + LDAPControl **sctrl, + LDAPControl **cctrl, + int *retidp )); +#endif + LDAP_END_DECL #endif /* _LDAP_H */ diff --git a/libraries/libldap/Makefile.in b/libraries/libldap/Makefile.in index 89e00e432a..25d48cf7db 100644 --- a/libraries/libldap/Makefile.in +++ b/libraries/libldap/Makefile.in @@ -26,7 +26,7 @@ SRCS = bind.c open.c result.c error.c compare.c search.c \ request.c os-ip.c url.c pagectrl.c sortctrl.c vlvctrl.c \ init.c options.c print.c string.c util-int.c schema.c \ charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \ - turn.c ppolicy.c dds.c + turn.c ppolicy.c dds.c txn.c OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \ controls.lo messages.lo references.lo extended.lo cyrus.lo \ @@ -37,7 +37,7 @@ OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \ request.lo os-ip.lo url.lo pagectrl.lo sortctrl.lo vlvctrl.lo \ init.lo options.lo print.lo string.lo util-int.lo schema.lo \ charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \ - turn.lo ppolicy.lo dds.lo + turn.lo ppolicy.lo dds.lo txn.lo LDAP_INCDIR= ../../include LDAP_LIBDIR= ../../libraries diff --git a/libraries/libldap/txn.c b/libraries/libldap/txn.c new file mode 100644 index 0000000000..c25460a8e7 --- /dev/null +++ b/libraries/libldap/txn.c @@ -0,0 +1,122 @@ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 2006 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* ACKNOWLEDGEMENTS: + * This program was orignally developed by Kurt D. Zeilenga for inclusion + * in OpenLDAP Software. + */ + +/* + * LDAPv3 Transactions (draft-zeilenga-ldap-txn) + */ + +#include "portable.h" + +#include +#include + +#include +#include +#include + +#include "ldap-int.h" +#include "ldap_log.h" + +#ifdef LDAP_X_TXN +int +ldap_txn_start( + LDAP *ld, + LDAPControl **sctrls, + LDAPControl **cctrls, + int *msgidp ) +{ + return ldap_extended_operation( ld, LDAP_EXOP_X_TXN_START, + NULL, sctrls, cctrls, msgidp ); +} + +int +ldap_txn_start_s( + LDAP *ld, + LDAPControl **sctrls, + LDAPControl **cctrls, + struct berval **txnid ) +{ + assert( txnid != NULL ); + + return ldap_extended_operation_s( ld, LDAP_EXOP_X_TXN_START, + NULL, sctrls, cctrls, NULL, txnid ); +} + +int +ldap_txn_end( + LDAP *ld, + int commit, + struct berval *txnid, + LDAPControl **sctrls, + LDAPControl **cctrls, + int *msgidp ) +{ + int rc; + BerElement *txnber = NULL; + struct berval *txnval = NULL; + + assert( txnid != NULL ); + + txnber = ber_alloc_t( LBER_USE_DER ); + ber_printf( txnber, "{io}", commit, txnid ); + ber_flatten( txnber, &txnval ); + + rc = ldap_extended_operation( ld, LDAP_EXOP_X_TXN_END, + txnval, sctrls, cctrls, msgidp ); + + ber_free( txnber, 1 ); + return rc; +} + +int +ldap_txn_end_s( + LDAP *ld, + int commit, + struct berval *txnid, + LDAPControl **sctrls, + LDAPControl **cctrls, + int *retidp ) +{ + int rc, msgid; + struct berval *retdata = NULL; + LDAPMessage *res; + + rc = ldap_txn_end( ld, commit, txnid, sctrls, cctrls, &msgid ); + if( rc != LDAP_SUCCESS ) return rc; + + if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, &res ) + == -1 ) + { + return ld->ld_errno; + } + + rc = ldap_parse_extended_result( ld, res, NULL, &retdata, 0 ); + if( rc != LDAP_SUCCESS ) { + ldap_msgfree( res ); + return rc; + } + + /* don't bother parsing the retdata (yet) */ + if( retidp != NULL ) { + *retidp = 0; + } + + return ldap_result2error( ld, res, 1 ); +} +#endif diff --git a/libraries/libldap_r/Makefile.in b/libraries/libldap_r/Makefile.in index da77edb993..7ad2ceca35 100644 --- a/libraries/libldap_r/Makefile.in +++ b/libraries/libldap_r/Makefile.in @@ -28,7 +28,7 @@ XXSRCS = apitest.c test.c \ request.c os-ip.c url.c pagectrl.c sortctrl.c vlvctrl.c \ init.c options.c print.c string.c util-int.c schema.c \ charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \ - turn.c ppolicy.c dds.c + turn.c ppolicy.c dds.c txn.c SRCS = threads.c rdwr.c tpool.c rq.c \ thr_posix.c thr_cthreads.c thr_thr.c thr_lwp.c thr_nt.c \ thr_pth.c thr_stub.c thr_debug.c @@ -44,7 +44,7 @@ OBJS = threads.lo rdwr.lo tpool.lo rq.lo \ request.lo os-ip.lo url.lo pagectrl.lo sortctrl.lo vlvctrl.lo \ init.lo options.lo print.lo string.lo util-int.lo schema.lo \ charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \ - turn.lo ppolicy.lo dds.lo + turn.lo ppolicy.lo dds.lo txn.lo LDAP_INCDIR= ../../include LDAP_LIBDIR= ../../libraries