Transactions specification. A work in progress! Comments welcomed.
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
(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=<commit|abort> (transaction)\n"));
#endif
fprintf( stderr, _(" -F force all changes records to be used\n"));
fprintf( stderr, _(" -S file write skipped modifications to `file'\n"));
*cvalue++ = '\0';
}
-#ifdef LDAP_GROUP_TRANSACTION
+#ifdef LDAP_X_TXN
if( strcasecmp( control, "txn" ) == 0 ) {
/* Transaction */
if( txn ) {
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;
int i = 0;
LDAPControl c[1];
-
prog = lutil_progname( "ldapmodify", argc, argv );
/* strncmp instead of strcmp since NT binaries carry .exe extension */
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++;
}
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;
}
}
#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 \
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 */
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 \
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
--- /dev/null
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * 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
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* 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 <stdio.h>
+#include <ac/stdlib.h>
+
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
+#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
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
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