1998-08-09 08:43:13 +08:00
|
|
|
/*
|
1998-12-29 04:53:15 +08:00
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
/* Portions
|
1998-08-09 08:43:13 +08:00
|
|
|
* Copyright (c) 1990 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* abandon.c
|
|
|
|
*/
|
|
|
|
|
1999-06-04 03:22:33 +08:00
|
|
|
/*
|
|
|
|
* An abandon request looks like this:
|
|
|
|
* AbandonRequest ::= MessageID
|
|
|
|
*/
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
#include "ldap-int.h"
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
static int do_abandon LDAP_P((
|
|
|
|
LDAP *ld,
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_int_t origid,
|
|
|
|
ber_int_t msgid,
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAPControl **sctrls,
|
|
|
|
LDAPControl **cctrls));
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
1999-05-19 09:12:33 +08:00
|
|
|
* ldap_abandon_ext - perform an ldap extended abandon operation.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* ld LDAP descriptor
|
|
|
|
* msgid The message id of the operation to abandon
|
|
|
|
* scntrls Server Controls
|
|
|
|
* ccntrls Client Controls
|
|
|
|
*
|
|
|
|
* ldap_abandon_ext returns a LDAP error code.
|
|
|
|
* (LDAP_SUCCESS if everything went ok)
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* ldap_abandon_ext( ld, msgid, scntrls, ccntrls );
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ldap_abandon_ext(
|
|
|
|
LDAP *ld,
|
|
|
|
int msgid,
|
|
|
|
LDAPControl **sctrls,
|
|
|
|
LDAPControl **cctrls )
|
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0 );
|
|
|
|
|
|
|
|
return do_abandon( ld, msgid, msgid, sctrls, cctrls );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ldap_abandon - perform an ldap abandon operation. Parameters:
|
1998-08-09 08:43:13 +08:00
|
|
|
*
|
|
|
|
* ld LDAP descriptor
|
|
|
|
* msgid The message id of the operation to abandon
|
|
|
|
*
|
|
|
|
* ldap_abandon returns 0 if everything went ok, -1 otherwise.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* ldap_abandon( ld, msgid );
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ldap_abandon( LDAP *ld, int msgid )
|
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_abandon %d\n", msgid, 0, 0 );
|
1999-05-19 09:12:33 +08:00
|
|
|
return do_abandon( ld, msgid, msgid, NULL, NULL ) == LDAP_SUCCESS
|
|
|
|
? 0 : -1;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
1999-05-19 09:12:33 +08:00
|
|
|
do_abandon(
|
|
|
|
LDAP *ld,
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_int_t origid,
|
|
|
|
ber_int_t msgid,
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAPControl **sctrls,
|
|
|
|
LDAPControl **cctrls)
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
BerElement *ber;
|
|
|
|
int i, err, sendabandon;
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_int_t *old_abandon;
|
1998-08-09 08:43:13 +08:00
|
|
|
Sockbuf *sb;
|
|
|
|
LDAPRequest *lr;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
|
|
|
|
origid, msgid, 0 );
|
|
|
|
|
|
|
|
sendabandon = 1;
|
|
|
|
|
|
|
|
/* find the request that we are abandoning */
|
|
|
|
for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
|
|
|
|
if ( lr->lr_msgid == msgid ) { /* this message */
|
|
|
|
break;
|
|
|
|
}
|
1999-05-19 09:12:33 +08:00
|
|
|
if ( lr->lr_origid == msgid ) {/* child: abandon it */
|
|
|
|
(void) do_abandon( ld,
|
|
|
|
msgid, lr->lr_msgid, sctrls, cctrls );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( lr != NULL ) {
|
|
|
|
if ( origid == msgid && lr->lr_parent != NULL ) {
|
|
|
|
/* don't let caller abandon child requests! */
|
|
|
|
ld->ld_errno = LDAP_PARAM_ERROR;
|
1999-05-19 09:12:33 +08:00
|
|
|
return( LDAP_PARAM_ERROR );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
|
|
|
|
/* no need to send abandon message */
|
|
|
|
sendabandon = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ldap_msgdelete( ld, msgid ) == 0 ) {
|
|
|
|
ld->ld_errno = LDAP_SUCCESS;
|
1999-05-19 09:12:33 +08:00
|
|
|
return LDAP_SUCCESS;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
if ( sendabandon ) {
|
|
|
|
/* create a message to send */
|
1999-06-19 07:53:05 +08:00
|
|
|
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
err = -1;
|
|
|
|
ld->ld_errno = LDAP_NO_MEMORY;
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef LDAP_CONNECTIONLESS
|
1999-03-03 04:23:14 +08:00
|
|
|
if ( ld->ld_cldapnaddr > 0 ) {
|
1999-06-19 07:53:05 +08:00
|
|
|
err = ber_printf( ber, "{isti", /* '}' */
|
1998-08-09 08:43:13 +08:00
|
|
|
++ld->ld_msgid, ld->ld_cldapdn,
|
|
|
|
LDAP_REQ_ABANDON, msgid );
|
1999-05-19 09:12:33 +08:00
|
|
|
} else
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif /* LDAP_CONNECTIONLESS */
|
1999-05-19 09:12:33 +08:00
|
|
|
{
|
1999-06-19 07:53:05 +08:00
|
|
|
err = ber_printf( ber, "{iti", /* '}' */
|
1999-05-19 09:12:33 +08:00
|
|
|
++ld->ld_msgid,
|
1998-08-09 08:43:13 +08:00
|
|
|
LDAP_REQ_ABANDON, msgid );
|
|
|
|
}
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
if( err == -1 ) {
|
|
|
|
/* encoding error */
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
1999-05-19 09:12:33 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Put Server Controls */
|
|
|
|
if ( ldap_int_put_controls( ld, sctrls, ber )
|
|
|
|
!= LDAP_SUCCESS )
|
|
|
|
{
|
|
|
|
err = -1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* close '{' */
|
1999-06-19 07:53:05 +08:00
|
|
|
err = ber_printf( ber, /*{*/ "}" );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
|
|
|
if( err == -1 ) {
|
|
|
|
/* encoding error */
|
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( err == -1 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
ber_free( ber, 1 );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
|
|
|
/* send the message */
|
|
|
|
if ( lr != NULL ) {
|
|
|
|
sb = lr->lr_conn->lconn_sb;
|
1999-05-22 14:11:48 +08:00
|
|
|
} else {
|
1998-08-09 08:43:13 +08:00
|
|
|
sb = &ld->ld_sb;
|
|
|
|
}
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( ber_flush( sb, ber, 1 ) != 0 ) {
|
|
|
|
ld->ld_errno = LDAP_SERVER_DOWN;
|
|
|
|
err = -1;
|
|
|
|
} else {
|
|
|
|
err = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( lr != NULL ) {
|
|
|
|
if ( sendabandon ) {
|
1998-08-09 11:04:12 +08:00
|
|
|
ldap_free_connection( ld, lr->lr_conn, 0, 1 );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
if ( origid == msgid ) {
|
1998-08-09 11:04:12 +08:00
|
|
|
ldap_free_request( ld, lr );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-29 09:19:14 +08:00
|
|
|
i = 0;
|
|
|
|
if ( ld->ld_abandoned != NULL ) {
|
|
|
|
for ( ; ld->ld_abandoned[i] != -1; i++ )
|
1998-08-09 08:43:13 +08:00
|
|
|
; /* NULL */
|
|
|
|
}
|
1999-05-29 09:19:14 +08:00
|
|
|
|
|
|
|
old_abandon = ld->ld_abandoned;
|
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
ld->ld_abandoned = (ber_int_t *) LDAP_REALLOC( (char *)
|
|
|
|
ld->ld_abandoned, (i + 2) * sizeof(ber_int_t) );
|
1999-05-29 09:19:14 +08:00
|
|
|
|
|
|
|
if ( ld->ld_abandoned == NULL ) {
|
|
|
|
ld->ld_abandoned = old_abandon;
|
|
|
|
ld->ld_errno = LDAP_NO_MEMORY;
|
|
|
|
return( ld->ld_errno );
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
ld->ld_abandoned[i] = msgid;
|
|
|
|
ld->ld_abandoned[i + 1] = -1;
|
|
|
|
|
|
|
|
if ( err != -1 ) {
|
|
|
|
ld->ld_errno = LDAP_SUCCESS;
|
|
|
|
}
|
1999-05-19 09:12:33 +08:00
|
|
|
|
|
|
|
return( ld->ld_errno );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|