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
|
|
|
|
*/
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-08-21 03:42:38 +08:00
|
|
|
#include <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"
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
static int do_abandon LDAP_P(( LDAP *ld, int origid, int msgid ));
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
|
|
|
* ldap_abandon - perform an ldap (and X.500) abandon operation. Parameters:
|
|
|
|
*
|
|
|
|
* 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 );
|
|
|
|
return( do_abandon( ld, msgid, msgid ));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
do_abandon( LDAP *ld, int origid, int msgid )
|
|
|
|
{
|
|
|
|
BerElement *ber;
|
|
|
|
int i, err, sendabandon;
|
|
|
|
Sockbuf *sb;
|
1998-11-10 03:41:09 +08:00
|
|
|
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
|
1998-08-09 08:43:13 +08:00
|
|
|
LDAPRequest *lr;
|
1998-11-10 03:41:09 +08:00
|
|
|
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* An abandon request looks like this:
|
|
|
|
* AbandonRequest ::= MessageID
|
|
|
|
*/
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "do_abandon origid %d, msgid %d\n",
|
|
|
|
origid, msgid, 0 );
|
|
|
|
|
|
|
|
sendabandon = 1;
|
|
|
|
|
1998-11-10 03:41:09 +08:00
|
|
|
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
|
1998-08-09 08:43:13 +08:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
if ( lr->lr_origid == msgid ) { /* child: abandon it */
|
|
|
|
do_abandon( ld, msgid, lr->lr_msgid );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( lr != NULL ) {
|
|
|
|
if ( origid == msgid && lr->lr_parent != NULL ) {
|
|
|
|
/* don't let caller abandon child requests! */
|
|
|
|
ld->ld_errno = LDAP_PARAM_ERROR;
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
if ( lr->lr_status != LDAP_REQST_INPROGRESS ) {
|
|
|
|
/* no need to send abandon message */
|
|
|
|
sendabandon = 0;
|
|
|
|
}
|
|
|
|
}
|
1998-11-10 03:41:09 +08:00
|
|
|
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
if ( ldap_msgdelete( ld, msgid ) == 0 ) {
|
|
|
|
ld->ld_errno = LDAP_SUCCESS;
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
if ( sendabandon ) {
|
|
|
|
/* create a message to send */
|
1998-08-09 11:04:12 +08:00
|
|
|
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
err = -1;
|
|
|
|
ld->ld_errno = LDAP_NO_MEMORY;
|
|
|
|
} else {
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef LDAP_CONNECTIONLESS
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( ld->ld_sb.sb_naddr > 0 ) {
|
|
|
|
err = ber_printf( ber, "{isti}",
|
|
|
|
++ld->ld_msgid, ld->ld_cldapdn,
|
|
|
|
LDAP_REQ_ABANDON, msgid );
|
|
|
|
} else {
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif /* LDAP_CONNECTIONLESS */
|
1998-08-09 08:43:13 +08:00
|
|
|
err = ber_printf( ber, "{iti}", ++ld->ld_msgid,
|
|
|
|
LDAP_REQ_ABANDON, msgid );
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef LDAP_CONNECTIONLESS
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif /* LDAP_CONNECTIONLESS */
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
if ( err == -1 ) {
|
|
|
|
ld->ld_errno = LDAP_ENCODING_ERROR;
|
|
|
|
ber_free( ber, 1 );
|
|
|
|
} else {
|
|
|
|
/* send the message */
|
1998-11-10 03:41:09 +08:00
|
|
|
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( lr != NULL ) {
|
|
|
|
sb = lr->lr_conn->lconn_sb;
|
|
|
|
} else {
|
|
|
|
sb = &ld->ld_sb;
|
|
|
|
}
|
1998-11-10 03:41:09 +08:00
|
|
|
#else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
|
1998-08-09 08:43:13 +08:00
|
|
|
sb = &ld->ld_sb;
|
1998-11-10 03:41:09 +08:00
|
|
|
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-10 03:41:09 +08:00
|
|
|
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
|
1998-08-09 08:43:13 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
1998-11-10 03:41:09 +08:00
|
|
|
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
if ( ld->ld_abandoned == NULL ) {
|
|
|
|
if ( (ld->ld_abandoned = (int *) malloc( 2 * sizeof(int) ))
|
|
|
|
== NULL ) {
|
|
|
|
ld->ld_errno = LDAP_NO_MEMORY;
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
} else {
|
|
|
|
for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
|
|
|
|
; /* NULL */
|
|
|
|
if ( (ld->ld_abandoned = (int *) realloc( (char *)
|
|
|
|
ld->ld_abandoned, (i + 2) * sizeof(int) )) == NULL ) {
|
|
|
|
ld->ld_errno = LDAP_NO_MEMORY;
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ld->ld_abandoned[i] = msgid;
|
|
|
|
ld->ld_abandoned[i + 1] = -1;
|
|
|
|
|
|
|
|
if ( err != -1 ) {
|
|
|
|
ld->ld_errno = LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
return( err );
|
|
|
|
}
|