Start of client-side LDAP tranactions (non-working)

and lots of cleanup (hence the commit)
(ldapmodify will need much more work for transactions)
This commit is contained in:
Kurt Zeilenga 2004-03-14 23:32:00 +00:00
parent f1f1b0f69b
commit 647df2b9cb
10 changed files with 794 additions and 544 deletions

File diff suppressed because it is too large Load Diff

View File

@ -102,7 +102,7 @@ usage( void )
fprintf( stderr, _(" -a deref one of never (default), always, search, or find\n")); fprintf( stderr, _(" -a deref one of never (default), always, search, or find\n"));
fprintf( stderr, _(" -A retrieve attribute names only (no values)\n")); fprintf( stderr, _(" -A retrieve attribute names only (no values)\n"));
fprintf( stderr, _(" -b basedn base dn for search\n")); fprintf( stderr, _(" -b basedn base dn for search\n"));
fprintf( stderr, _(" -E [!]<ctrl>[=<ctrlparam>] search extensions (! indicates criticality)\n")); fprintf( stderr, _(" -E [!]<ext>[=<extparam>] search extensions (! indicates criticality)\n"));
#ifdef LDAP_CONTROL_X_DOMAIN_SCOPE #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
fprintf( stderr, _(" [!]domainScope (domain scope)\n")); fprintf( stderr, _(" [!]domainScope (domain scope)\n"));
#endif #endif
@ -237,23 +237,24 @@ handle_private_option( int i )
switch ( i ) { switch ( i ) {
case 'a': /* set alias deref option */ case 'a': /* set alias deref option */
if ( strcasecmp( optarg, "never" ) == 0 ) { if ( strcasecmp( optarg, "never" ) == 0 ) {
deref = LDAP_DEREF_NEVER; deref = LDAP_DEREF_NEVER;
} else if ( strncasecmp( optarg, "search", sizeof("search")-1 ) == 0 ) { } else if ( strncasecmp( optarg, "search", sizeof("search")-1 ) == 0 ) {
deref = LDAP_DEREF_SEARCHING; deref = LDAP_DEREF_SEARCHING;
} else if ( strncasecmp( optarg, "find", sizeof("find")-1 ) == 0 ) { } else if ( strncasecmp( optarg, "find", sizeof("find")-1 ) == 0 ) {
deref = LDAP_DEREF_FINDING; deref = LDAP_DEREF_FINDING;
} else if ( strcasecmp( optarg, "always" ) == 0 ) { } else if ( strcasecmp( optarg, "always" ) == 0 ) {
deref = LDAP_DEREF_ALWAYS; deref = LDAP_DEREF_ALWAYS;
} else { } else {
fprintf( stderr, _("alias deref should be never, search, find, or always\n") ); fprintf( stderr,
usage(); _("alias deref should be never, search, find, or always\n") );
usage();
} }
break; break;
case 'A': /* retrieve attribute names only -- no values */ case 'A': /* retrieve attribute names only -- no values */
++attrsonly; ++attrsonly;
break; break;
case 'b': /* search base */ case 'b': /* search base */
base = strdup( optarg ); base = ber_strdup( optarg );
break; break;
case 'E': /* search extensions */ case 'E': /* search extensions */
if( protocol == LDAP_VERSION2 ) { if( protocol == LDAP_VERSION2 ) {
@ -273,7 +274,7 @@ handle_private_option( int i )
optarg++; optarg++;
} }
control = strdup( optarg ); control = ber_strdup( optarg );
if ( (cvalue = strchr( control, '=' )) != NULL ) { if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0'; *cvalue++ = '\0';
} }
@ -281,7 +282,8 @@ handle_private_option( int i )
if ( strcasecmp( control, "mv" ) == 0 ) { if ( strcasecmp( control, "mv" ) == 0 ) {
/* ValuesReturnFilter control */ /* ValuesReturnFilter control */
if( valuesReturnFilter ) { if( valuesReturnFilter ) {
fprintf( stderr, _("ValuesReturnFilter previously specified\n")); fprintf( stderr,
_("ValuesReturnFilter previously specified\n"));
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
valuesReturnFilter= 1 + crit; valuesReturnFilter= 1 + crit;
@ -300,7 +302,8 @@ handle_private_option( int i )
int num, tmp; int num, tmp;
/* PagedResults control */ /* PagedResults control */
if ( pagedResults != 0 ) { if ( pagedResults != 0 ) {
fprintf( stderr, _("PagedResultsControl previously specified\n") ); fprintf( stderr,
_("PagedResultsControl previously specified\n") );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
@ -315,17 +318,22 @@ handle_private_option( int i )
} else if ( strcasecmp( promptp, "noprompt" ) == 0) { } else if ( strcasecmp( promptp, "noprompt" ) == 0) {
pagePrompt = 0; pagePrompt = 0;
} else { } else {
fprintf( stderr, _("Invalid value for PagedResultsControl, %s/%s.\n"), cvalue, promptp); fprintf( stderr,
_("Invalid value for PagedResultsControl,"
" %s/%s.\n"), cvalue, promptp );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
} }
num = sscanf( cvalue, "%d", &tmp ); num = sscanf( cvalue, "%d", &tmp );
if ( num != 1 ) { if ( num != 1 ) {
fprintf( stderr, _("Invalid value for PagedResultsControl, %s.\n"), cvalue); fprintf( stderr,
_("Invalid value for PagedResultsControl, %s.\n"),
cvalue );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
} else { } else {
fprintf( stderr, _("Invalid value for PagedResultsControl.\n"), cvalue); fprintf( stderr, _("Invalid value for PagedResultsControl.\n"),
cvalue);
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
pageSize = (ber_int_t) tmp; pageSize = (ber_int_t) tmp;
@ -350,7 +358,8 @@ handle_private_option( int i )
#ifdef LDAP_CONTROL_SUBENTRIES #ifdef LDAP_CONTROL_SUBENTRIES
} else if ( strcasecmp( control, "subentries" ) == 0 ) { } else if ( strcasecmp( control, "subentries" ) == 0 ) {
if( subentries ) { if( subentries ) {
fprintf( stderr, _("subentries control previously specified\n")); fprintf( stderr,
_("subentries control previously specified\n"));
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if( cvalue == NULL || strcasecmp( cvalue, "true") == 0 ) { if( cvalue == NULL || strcasecmp( cvalue, "true") == 0 ) {
@ -370,12 +379,11 @@ handle_private_option( int i )
char *cookiep; char *cookiep;
char *slimitp; char *slimitp;
if ( ldapsync ) { if ( ldapsync ) {
fprintf( stderr, _("ldap sync control previously specified\n") ); fprintf( stderr, _("sync control previously specified\n") );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if ( cvalue == NULL ) { if ( cvalue == NULL ) {
fprintf( stderr, fprintf( stderr, _("missing specification of sync control\n"));
_("missing specification of ldap sync control\n"));
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if ( strncasecmp( cvalue, "ro", 2 ) == 0 ) { if ( strncasecmp( cvalue, "ro", 2 ) == 0 ) {
@ -403,15 +411,15 @@ handle_private_option( int i )
if ( slimitp != NULL && *slimitp != '\0' ) if ( slimitp != NULL && *slimitp != '\0' )
sync_slimit = atoi( slimitp ); sync_slimit = atoi( slimitp );
} else { } else {
fprintf( stderr, fprintf( stderr, _("sync control value \"%s\" invalid\n"),
_("ldap sync control value \"%s\" invalid\n"),
cvalue ); cvalue );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if ( crit ) ldapsync *= -1; if ( crit ) ldapsync *= -1;
} else { } else {
fprintf( stderr, _("Invalid search extension name: %s\n"), control ); fprintf( stderr, _("Invalid search extension name: %s\n"),
control );
usage(); usage();
} }
break; break;
@ -442,8 +450,8 @@ handle_private_option( int i )
} else if ( strncasecmp( optarg, "sub", sizeof("sub")-1 ) == 0 ) { } else if ( strncasecmp( optarg, "sub", sizeof("sub")-1 ) == 0 ) {
scope = LDAP_SCOPE_SUBTREE; scope = LDAP_SCOPE_SUBTREE;
} else { } else {
fprintf( stderr, _("scope should be base, one, or sub\n") ); fprintf( stderr, _("scope should be base, one, or sub\n") );
usage(); usage();
} }
break; break;
case 'S': /* sort attribute */ case 'S': /* sort attribute */
@ -473,21 +481,25 @@ static void
private_conn_setup( LDAP *ld ) private_conn_setup( LDAP *ld )
{ {
if (deref != -1 && if (deref != -1 &&
ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref )
!= LDAP_OPT_SUCCESS )
{ {
fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref ); fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if (timelimit != -1 && if (timelimit != -1 &&
ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit ) != LDAP_OPT_SUCCESS ) ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit )
!= LDAP_OPT_SUCCESS )
{ {
fprintf( stderr, _("Could not set LDAP_OPT_TIMELIMIT %d\n"), timelimit ); fprintf( stderr, _("Could not set LDAP_OPT_TIMELIMIT %d\n"), timelimit );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if (sizelimit != -1 && if (sizelimit != -1 &&
ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit ) != LDAP_OPT_SUCCESS ) ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit )
!= LDAP_OPT_SUCCESS )
{ {
fprintf( stderr, _("Could not set LDAP_OPT_SIZELIMIT %d\n"), sizelimit ); fprintf( stderr,
_("Could not set LDAP_OPT_SIZELIMIT %d\n"), sizelimit );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
} }
@ -715,9 +727,13 @@ getNextPage:
tool_server_controls( ld, c, i ); tool_server_controls( ld, c, i );
#ifdef LDAP_CONTROL_SUBENTRIES
ber_free( seber, 1 ); ber_free( seber, 1 );
#endif
ber_free( vrber, 1 ); ber_free( vrber, 1 );
#ifdef LDAP_CONTROL_PAGEDRESULTS
ber_free( prber, 1 ); ber_free( prber, 1 );
#endif
} }
if ( verbose ) { if ( verbose ) {
@ -1121,8 +1137,8 @@ print_entry(
} else if ( bvals ) { } else if ( bvals ) {
for ( i = 0; bvals[i].bv_val != NULL; i++ ) { for ( i = 0; bvals[i].bv_val != NULL; i++ ) {
if ( vals2tmp > 1 || ( vals2tmp if ( vals2tmp > 1 || ( vals2tmp &&
&& ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len ) )) ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len )))
{ {
int tmpfd; int tmpfd;
/* write value to file */ /* write value to file */

View File

@ -1835,6 +1835,47 @@ ldap_parse_vlv_control LDAP_P((
struct berval **contextp, struct berval **contextp,
int *errcodep )); int *errcodep ));
/*
* LDAP Transactions
* in txn.c
*/
LDAP_F( int )
ldap_parse_txn_create LDAP_P((
LDAP *ld,
LDAPMessage *res,
struct berval **cookie ));
LDAP_F( int )
ldap_txn_create LDAP_P((
LDAP *ld,
LDAPControl **sctrls,
LDAPControl **cctrls,
int *msgidp ));
LDAP_F( int )
ldap_txn_create_s LDAP_P((
LDAP *ld,
struct berval **cookie,
LDAPControl **sctrls,
LDAPControl **cctrls ));
LDAP_F( int )
ldap_txn_end LDAP_P((
LDAP *ld,
struct berval *cookie,
int commit,
LDAPControl **sctrls,
LDAPControl **cctrls,
int *msgidp ));
LDAP_F( int )
ldap_txn_end_s LDAP_P((
LDAP *ld,
struct berval *cookie,
int commit,
LDAPControl **sctrls,
LDAPControl **cctrls ));
/* /*
* LDAP Who Am I? * LDAP Who Am I?
* in whoami.c * in whoami.c

View File

@ -26,7 +26,7 @@ SRCS = bind.c open.c result.c error.c compare.c search.c \
request.c os-ip.c url.c sortctrl.c vlvctrl.c \ request.c os-ip.c url.c sortctrl.c vlvctrl.c \
init.c options.c print.c string.c util-int.c schema.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 \ charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \
pcontrol.c groupings.c txn.c ppcontrol.c
OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \ OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \
controls.lo messages.lo references.lo extended.lo cyrus.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 sortctrl.lo vlvctrl.lo \ request.lo os-ip.lo url.lo sortctrl.lo vlvctrl.lo \
init.lo options.lo print.lo string.lo util-int.lo schema.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 \ charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \
ppcontrol.lo groupings.lo txn.lo ppcontrol.lo
LDAP_INCDIR= ../../include LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries LDAP_LIBDIR= ../../libraries

View File

@ -12,6 +12,10 @@
* top-level directory of the distribution or, alternatively, at * top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>. * <http://www.OpenLDAP.org/license.html>.
*/ */
/* ACKNOWLEDGEMENTS:
* This program was orignally developed by Kurt D. Zeilenga for inclusion in
* OpenLDAP Software.
*/
/* /*
* LDAPv3 Cancel Operation Request * LDAPv3 Cancel Operation Request

View File

@ -0,0 +1,30 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2004 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.
*/
#include "portable.h"
#include <ac/stdlib.h>
#include <ac/time.h>
#include <ac/string.h>
#include "ldap-int.h"

View File

@ -12,6 +12,10 @@
* top-level directory of the distribution or, alternatively, at * top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>. * <http://www.OpenLDAP.org/license.html>.
*/ */
/* ACKNOWLEDGEMENTS:
* This program was orignally developed by Kurt D. Zeilenga for inclusion in
* OpenLDAP Software.
*/
#include "portable.h" #include "portable.h"

48
libraries/libldap/txn.c Normal file
View File

@ -0,0 +1,48 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2004 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.
*/
#include "portable.h"
#include <ac/stdlib.h>
#include <ac/time.h>
#include <ac/string.h>
#include "ldap-int.h"
int
ldap_txn_create_s(
LDAP *ld,
struct berval **cookie,
LDAPControl **sctrls,
LDAPControl **cctrls )
{
return LDAP_NOT_SUPPORTED;
}
int
ldap_txn_end_s(
LDAP *ld,
struct berval *cookie,
int commit,
LDAPControl **sctrls,
LDAPControl **cctrls )
{
return LDAP_NOT_SUPPORTED;
}

View File

@ -12,6 +12,10 @@
* top-level directory of the distribution or, alternatively, at * top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>. * <http://www.OpenLDAP.org/license.html>.
*/ */
/* ACKNOWLEDGEMENTS:
* This program was orignally developed by Kurt D. Zeilenga for inclusion in
* OpenLDAP Software.
*/
#include "portable.h" #include "portable.h"

View File

@ -28,7 +28,7 @@ XXSRCS = apitest.c test.c \
request.c os-ip.c url.c sortctrl.c vlvctrl.c \ request.c os-ip.c url.c sortctrl.c vlvctrl.c \
init.c options.c print.c string.c util-int.c schema.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 \ charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \
ppcontrol.c groupings.c txn.c ppcontrol.c
SRCS = threads.c rdwr.c tpool.c rq.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_posix.c thr_cthreads.c thr_thr.c thr_lwp.c thr_nt.c \
thr_pth.c thr_stub.c thr_pth.c thr_stub.c
@ -44,7 +44,7 @@ OBJS = threads.lo rdwr.lo tpool.lo rq.lo \
request.lo os-ip.lo url.lo sortctrl.lo vlvctrl.lo \ request.lo os-ip.lo url.lo sortctrl.lo vlvctrl.lo \
init.lo options.lo print.lo string.lo util-int.lo schema.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 \ charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \
ppcontrol.lo groupings.lo txn.lo ppcontrol.lo
LDAP_INCDIR= ../../include LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries LDAP_LIBDIR= ../../libraries