1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
2000-05-13 10:36:07 +08:00
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
1998-12-29 04:53:15 +08:00
|
|
|
* 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 )
|
|
|
|
{
|
2001-07-06 11:13:42 +08:00
|
|
|
int rc;
|
1999-05-19 09:12:33 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldap_abandon_ext %d\n", msgid, 0, 0 );
|
|
|
|
|
2001-07-06 11:13:42 +08:00
|
|
|
/* check client controls */
|
|
|
|
rc = ldap_int_client_controls( ld, cctrls );
|
|
|
|
if( rc != LDAP_SUCCESS ) return rc;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
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 );
|
2001-07-06 11:13:42 +08:00
|
|
|
return ldap_abandon_ext( ld, msgid, NULL, NULL ) == LDAP_SUCCESS
|
1999-05-19 09:12:33 +08:00
|
|
|
? 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 ) {
|
2000-10-17 07:11:41 +08:00
|
|
|
if( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) {
|
|
|
|
/* not connected */
|
|
|
|
err = -1;
|
|
|
|
ld->ld_errno = LDAP_SERVER_DOWN;
|
|
|
|
|
|
|
|
} else if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
|
|
|
|
/* BER element alocation failed */
|
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 {
|
2001-09-28 08:18:40 +08:00
|
|
|
#ifdef LDAP_CONNECTIONLESS
|
|
|
|
if ( LDAP_IS_UDP(ld) ) {
|
|
|
|
err = ber_write( ber, ld->ld_options.ldo_peer,
|
|
|
|
sizeof(struct sockaddr), 0);
|
2001-10-02 09:02:23 +08:00
|
|
|
}
|
|
|
|
if ( LDAP_IS_UDP(ld) && ld->ld_options.ldo_version ==
|
|
|
|
LDAP_VERSION2) {
|
|
|
|
char *dn = ld->ld_options.ldo_cldapdn;
|
|
|
|
if (!dn) dn = "";
|
|
|
|
err = ber_printf( ber, "{isti", /* '}' */
|
|
|
|
++ld->ld_msgid, dn,
|
|
|
|
LDAP_REQ_ABANDON, msgid );
|
2001-09-28 08:18:40 +08:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* create a message to send */
|
|
|
|
err = ber_printf( ber, "{iti", /* '}' */
|
2000-08-18 12:25:00 +08:00
|
|
|
++ld->ld_msgid,
|
2001-09-28 08:18:40 +08:00
|
|
|
LDAP_REQ_ABANDON, msgid );
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
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 '{' */
|
2000-06-24 09:40:39 +08:00
|
|
|
err = ber_printf( ber, /*{*/ "N}" );
|
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 {
|
2000-06-02 04:59:21 +08:00
|
|
|
sb = ld->ld_sb;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
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
|
|
|
}
|