From 8ac8d70a55fa6448d471f813219bc0ff870d57e8 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Tue, 7 Mar 2006 00:48:14 +0000 Subject: [PATCH] TXN protocol element parsers (without any backend support) Misc cleanup --- include/ldap.h | 2 + servers/slapd/Makefile.in | 4 +- servers/slapd/cancel.c | 2 + servers/slapd/controls.c | 7 +++ servers/slapd/extended.c | 15 ++--- servers/slapd/passwd.c | 2 + servers/slapd/proto-slap.h | 13 +++++ servers/slapd/slap.h | 7 +++ servers/slapd/starttls.c | 5 +- servers/slapd/txn.c | 110 +++++++++++++++++++++++++++++++++++++ 10 files changed, 157 insertions(+), 10 deletions(-) create mode 100644 servers/slapd/txn.c diff --git a/include/ldap.h b/include/ldap.h index e9a8ef12a0..ae4e9ae7f5 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -626,6 +626,8 @@ typedef struct ldapcontrol { #define LDAP_X_INVALIDREFERENCE 0x4112 #endif +#define LDAP_X_TXN_ID_INVALID 0x4120 + /* API Error Codes * * Based on draft-ietf-ldap-c-api-xx diff --git a/servers/slapd/Makefile.in b/servers/slapd/Makefile.in index 00ce0e515f..e6dc34ed90 100644 --- a/servers/slapd/Makefile.in +++ b/servers/slapd/Makefile.in @@ -38,7 +38,7 @@ SRCS = main.c globals.c bconfig.c config.c daemon.c \ backglue.c backover.c ctxcsn.c ldapsync.c frontend.c \ slapadd.c slapcat.c slapcommon.c slapdn.c slapindex.c \ slappasswd.c slaptest.c slapauth.c slapacl.c component.c \ - aci.c alock.c \ + aci.c alock.c txn.c \ $(@PLAT@_SRCS) OBJS = main.o globals.o bconfig.o config.o daemon.o \ @@ -56,7 +56,7 @@ OBJS = main.o globals.o bconfig.o config.o daemon.o \ backglue.o backover.o ctxcsn.o ldapsync.o frontend.o \ slapadd.o slapcat.o slapcommon.o slapdn.o slapindex.o \ slappasswd.o slaptest.o slapauth.o slapacl.o component.o \ - aci.o alock.o \ + aci.o alock.o txn.o \ $(@PLAT@_OBJS) LDAP_INCDIR= ../../include -I$(srcdir) -I$(srcdir)/slapi -I. diff --git a/servers/slapd/cancel.c b/servers/slapd/cancel.c index 1c209729e9..bc94616010 100644 --- a/servers/slapd/cancel.c +++ b/servers/slapd/cancel.c @@ -28,6 +28,8 @@ #include #include +const struct berval slap_EXOP_CANCEL = BER_BVC(LDAP_EXOP_CANCEL); + int cancel_extop( Operation *op, SlapReply *rs ) { Operation *o; diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index a0ed023722..cf4cfa930f 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -183,6 +183,13 @@ static struct slap_control control_defs[] = { SLAP_CTRL_GLOBAL|SLAP_CTRL_UPDATE|SLAP_CTRL_HIDE, NULL, NULL, parseManageDIT, LDAP_SLIST_ENTRY_INITIALIZER(next) }, +#endif +#ifdef LDAP_X_TXN + { LDAP_CONTROL_X_TXN_SPEC, + (int)offsetof(struct slap_control_ids, sc_txnSpec), + SLAP_CTRL_UPDATE|SLAP_CTRL_HIDE, + NULL, NULL, + txn_spec_ctrl, LDAP_SLIST_ENTRY_INITIALIZER(next) }, #endif { LDAP_CONTROL_MANAGEDSAIT, (int)offsetof(struct slap_control_ids, sc_manageDSAit), diff --git a/servers/slapd/extended.c b/servers/slapd/extended.c index fc2dd748a3..27e7ffd1ab 100644 --- a/servers/slapd/extended.c +++ b/servers/slapd/extended.c @@ -41,7 +41,6 @@ #define UNSUPPORTED_EXOP "unsupported extended operation" - static struct extop_list { struct extop_list *next; struct berval oid; @@ -56,16 +55,15 @@ static SLAP_EXTOP_MAIN_FN whoami_extop; * just a way to get built-in extops onto the extop list without * having a separate init routine for each built-in extop. */ -const struct berval slap_EXOP_CANCEL = BER_BVC(LDAP_EXOP_CANCEL); -const struct berval slap_EXOP_WHOAMI = BER_BVC(LDAP_EXOP_WHO_AM_I); -const struct berval slap_EXOP_MODIFY_PASSWD = BER_BVC(LDAP_EXOP_MODIFY_PASSWD); -const struct berval slap_EXOP_START_TLS = BER_BVC(LDAP_EXOP_START_TLS); - static struct { const struct berval *oid; slap_mask_t flags; SLAP_EXTOP_MAIN_FN *ext_main; } builtin_extops[] = { +#ifdef LDAP_X_TXN + { &slap_EXOP_TXN_START, 0, txn_start_extop }, + { &slap_EXOP_TXN_END, 0, txn_end_extop }, +#endif { &slap_EXOP_CANCEL, 0, cancel_extop }, { &slap_EXOP_WHOAMI, 0, whoami_extop }, { &slap_EXOP_MODIFY_PASSWD, SLAP_EXOP_WRITES, passwd_extop }, @@ -349,6 +347,8 @@ find_extop( struct extop_list *list, struct berval *oid ) } +const struct berval slap_EXOP_WHOAMI = BER_BVC(LDAP_EXOP_WHO_AM_I); + static int whoami_extop ( Operation *op, @@ -367,7 +367,8 @@ whoami_extop ( op->o_bd = op->o_conn->c_authz_backend; if( backend_check_restrictions( op, rs, - (struct berval *)&slap_EXOP_WHOAMI ) != LDAP_SUCCESS ) { + (struct berval *)&slap_EXOP_WHOAMI ) != LDAP_SUCCESS ) + { return rs->sr_err; } diff --git a/servers/slapd/passwd.c b/servers/slapd/passwd.c index fef49ef8b7..90d666dd8f 100644 --- a/servers/slapd/passwd.c +++ b/servers/slapd/passwd.c @@ -33,6 +33,8 @@ #include #include +const struct berval slap_EXOP_MODIFY_PASSWD = BER_BVC(LDAP_EXOP_MODIFY_PASSWD); + static const char *defhash[] = { #ifdef LUTIL_SHA1_BYTES "{SSHA}", diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index f3917f0386..c79c434f8c 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -860,6 +860,10 @@ LDAP_SLAPD_V( const struct berval ) slap_EXOP_CANCEL; LDAP_SLAPD_V( const struct berval ) slap_EXOP_WHOAMI; LDAP_SLAPD_V( const struct berval ) slap_EXOP_MODIFY_PASSWD; LDAP_SLAPD_V( const struct berval ) slap_EXOP_START_TLS; +#ifdef LDAP_X_TXN +LDAP_SLAPD_V( const struct berval ) slap_EXOP_TXN_START; +LDAP_SLAPD_V( const struct berval ) slap_EXOP_TXN_END; +#endif typedef int (SLAP_EXTOP_MAIN_FN) LDAP_P(( Operation *op, SlapReply *rs )); @@ -880,6 +884,15 @@ LDAP_SLAPD_F (int) extops_kill LDAP_P(( void )); LDAP_SLAPD_F (struct berval *) get_supported_extop LDAP_P((int index)); +/* + * txn.c + */ +#ifdef LDAP_X_TXN +LDAP_SLAPD_F ( SLAP_CTRL_PARSE_FN ) txn_spec_ctrl; +LDAP_SLAPD_F ( SLAP_EXTOP_MAIN_FN ) txn_start_extop; +LDAP_SLAPD_F ( SLAP_EXTOP_MAIN_FN ) txn_end_extop; +#endif + /* * cancel.c */ diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index f46d69e69d..46f5b9104c 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -2303,6 +2303,9 @@ struct slap_control_ids { #endif int sc_subentries; int sc_treeDelete; +#ifdef LDAP_X_TXN + int sc_txnSpec; +#endif int sc_valuesReturnFilter; }; @@ -2502,6 +2505,10 @@ typedef struct slap_op { #define o_sortedresults o_ctrlflag[slap_cids.sc_sortedResults] #endif +#ifdef LDAP_X_TXN +#define o_txnSpec o_ctrlflag[slap_cids.sc_txnSpec] +#endif + #define o_sync o_ctrlflag[slap_cids.sc_LDAPsync] AuthorizationInformation o_authz; diff --git a/servers/slapd/starttls.c b/servers/slapd/starttls.c index 0a626367ac..f2593e7474 100644 --- a/servers/slapd/starttls.c +++ b/servers/slapd/starttls.c @@ -17,11 +17,14 @@ #include #include +#include #include "slap.h" +#include "lber_pvt.h" -#ifdef HAVE_TLS +const struct berval slap_EXOP_START_TLS = BER_BVC(LDAP_EXOP_START_TLS); +#ifdef HAVE_TLS int starttls_extop ( Operation *op, SlapReply *rs ) { diff --git a/servers/slapd/txn.c b/servers/slapd/txn.c new file mode 100644 index 0000000000..e0d46670f0 --- /dev/null +++ b/servers/slapd/txn.c @@ -0,0 +1,110 @@ +/* txn.c - LDAP Transactions */ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-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 + * . + */ + +#include "portable.h" + +#include + +#include +#include +#include +#include + +#include "slap.h" + +#include +#include + +#ifdef LDAP_X_TXN +const struct berval slap_EXOP_TXN_START = BER_BVC(LDAP_EXOP_X_TXN_START); +const struct berval slap_EXOP_TXN_END = BER_BVC(LDAP_EXOP_X_TXN_END); + +int txn_start_extop( + Operation *op, SlapReply *rs ) +{ + struct berval *bv; + + if( op->ore_reqdata != NULL ) { + rs->sr_text = "no request data expected"; + return LDAP_PROTOCOL_ERROR; + } + + Statslog( LDAP_DEBUG_STATS, "%s TXN START\n", + op->o_log_prefix, 0, 0, 0, 0 ); + + op->o_bd = op->o_conn->c_authz_backend; + if( backend_check_restrictions( op, rs, + (struct berval *)&slap_EXOP_TXN_START ) != LDAP_SUCCESS ) + { + return rs->sr_err; + } + + bv = (struct berval *) ch_malloc( sizeof (struct berval) ); + bv->bv_len = 0; + bv->bv_val = NULL; + + rs->sr_rspdata = bv; + return LDAP_SUCCESS; +} + +int txn_spec_ctrl( + Operation *op, SlapReply *rs, LDAPControl *ctrl ) +{ + if ( !ctrl->ldctl_iscritical ) { + rs->sr_text = "txnSpec control must be marked critical"; + return LDAP_PROTOCOL_ERROR; + } + if( op->o_txnSpec ) { + rs->sr_text = "txnSpec control provided multiple times"; + return LDAP_PROTOCOL_ERROR; + } + + if ( ctrl->ldctl_value.bv_val == NULL ) { + rs->sr_text = "no transaction identifier provided"; + return LDAP_PROTOCOL_ERROR; + } + if ( ctrl->ldctl_value.bv_len != 0 ) { + rs->sr_text = "invalid transaction identifier"; + return LDAP_X_TXN_ID_INVALID; + } + + op->o_txnSpec = SLAP_CONTROL_CRITICAL; + return LDAP_SUCCESS; +} + +int txn_end_extop( + Operation *op, SlapReply *rs ) +{ + if( op->ore_reqdata == NULL ) { + rs->sr_text = "request data expected"; + return LDAP_PROTOCOL_ERROR; + } + + Statslog( LDAP_DEBUG_STATS, "%s TXN END\n", + op->o_log_prefix, 0, 0, 0, 0 ); + + op->o_bd = op->o_conn->c_authz_backend; + if( backend_check_restrictions( op, rs, + (struct berval *)&slap_EXOP_TXN_END ) != LDAP_SUCCESS ) + { + return rs->sr_err; + } + + rs->sr_text = "not yet implemented"; + return LDAP_UNWILLING_TO_PERFORM; +} + +#endif /* LDAP_X_TXN */ -- 2.39.5