Commit a6de3251 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

sync with HEAD

parent c71bafbf
/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, Redwood City, California, USA
* Copyright 1998-2003 The OpenLDAP Foundation, Redwood City, California, USA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -434,8 +434,9 @@ typedef struct ldapcontrol {
#define LDAP_IS_LEAF 0x23 /* not LDAPv3 */
#define LDAP_ALIAS_DEREF_PROBLEM 0x24
#define LDAP_SECURITY_ERROR(n) LDAP_RANGE((n),0x30,0x32) /* 48-50 */
#define LDAP_SECURITY_ERROR(n) LDAP_RANGE((n),0x2F,0x32) /* 47-50 */
#define LDAP_PROXY_AUTHZ_FAILURE 0x2F /* LDAPv3 proxy authorization */
#define LDAP_INAPPROPRIATE_AUTH 0x30
#define LDAP_INVALID_CREDENTIALS 0x31
#define LDAP_INSUFFICIENT_ACCESS 0x32
......@@ -712,6 +713,14 @@ ldap_parse_extended_partial LDAP_P((
LDAPControl ***serverctrls,
int freeit ));
LDAP_F( int )
ldap_parse_intermediate_resp_result LDAP_P((
LDAP *ld,
LDAPMessage *res,
char **retoidp,
struct berval **retdatap,
int freeit ));
/*
* in abandon.c:
*/
......@@ -910,6 +919,24 @@ LDAP_F( void )
ldap_uncache_request LDAP_P(( LDAP *ld, int msgid ));
/*
* LDAP Cancel Extended Operation <draft-zeilenga-ldap-cancel-xx.txt>
*/
LDAP_F( int )
ldap_cancel LDAP_P(( LDAP *ld,
int cancelid,
LDAPControl **sctrls,
LDAPControl **cctrls,
int *msgidp ));
LDAP_F( int )
ldap_cancel_s LDAP_P((
LDAP *ld,
int cancelid,
LDAPControl **sctrl,
LDAPControl **cctrl ));
/*
* in compare.c:
*/
......@@ -1686,6 +1713,28 @@ ldap_parse_vlv_control LDAP_P((
struct berval **contextp,
int *errcodep ));
/*
* LDAP Who Am I? (whoami.c)
*/
LDAP_F( int )
ldap_parse_whoami LDAP_P((
LDAP *ld,
LDAPMessage *res,
struct berval **authzid ));
LDAP_F( int )
ldap_whoami LDAP_P(( LDAP *ld,
LDAPControl **sctrls,
LDAPControl **cctrls,
int *msgidp ));
LDAP_F( int )
ldap_whoami_s LDAP_P((
LDAP *ld,
struct berval **authzid,
LDAPControl **sctrls,
LDAPControl **cctrls ));
LDAP_END_DECL
#endif /* _LDAP_H */
# $OpenLDAP$
## Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
## Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
## COPYING RESTRICTIONS APPLY, see COPYRIGHT file
##
## LIBAVL
......
/* avl.c - routines to implement an avl tree */
/* $OpenLDAP$ */
/*
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright (c) 1993 Regents of the University of Michigan.
* All rights reserved.
......@@ -11,34 +16,41 @@
* is provided ``as is'' without express or implied warranty.
*/
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n";
static char avl_version[] = "AVL library version 1.0\n";
#endif
#include "portable.h"
#include <sys/types.h>
#include <stdio.h>
#include <ac/stdlib.h>
#ifdef CSRIMALLOC
#define ber_memalloc malloc
#define ber_memrealloc realloc
#define ber_memfree free
#else
#include "lber.h"
#endif
#define AVL_INTERNAL
#include "avl.h"
#define ROTATERIGHT(x) { \
Avlnode *tmp;\
if ( *x == NULL || (*x)->avl_left == NULL ) {\
(void) printf("RR error\n"); exit(1); \
if ( *(x) == NULL || (*(x))->avl_left == NULL ) {\
(void) fputs("RR error\n", stderr); exit( EXIT_FAILURE ); \
}\
tmp = (*x)->avl_left;\
(*x)->avl_left = tmp->avl_right;\
tmp->avl_right = *x;\
*x = tmp;\
tmp = (*(x))->avl_left;\
(*(x))->avl_left = tmp->avl_right;\
tmp->avl_right = *(x);\
*(x) = tmp;\
}
#define ROTATELEFT(x) { \
Avlnode *tmp;\
if ( *x == NULL || (*x)->avl_right == NULL ) {\
(void) printf("RL error\n"); exit(1); \
if ( *(x) == NULL || (*(x))->avl_right == NULL ) {\
(void) fputs("RL error\n", stderr); exit( EXIT_FAILURE ); \
}\
tmp = (*x)->avl_right;\
(*x)->avl_right = tmp->avl_left;\
tmp->avl_left = *x;\
*x = tmp;\
tmp = (*(x))->avl_right;\
(*(x))->avl_right = tmp->avl_left;\
tmp->avl_left = *(x);\
*(x) = tmp;\
}
/*
......@@ -46,20 +58,21 @@ static char avl_version[] = "AVL library version 1.0\n";
* and balance of an avl tree.
*/
static
ravl_insert( iroot, data, taller, fcmp, fdup, depth )
Avlnode **iroot;
caddr_t data;
int *taller;
IFP fcmp; /* comparison function */
IFP fdup; /* function to call for duplicates */
int depth;
static int
ravl_insert(
Avlnode **iroot,
void* data,
int *taller,
AVL_CMP fcmp, /* comparison function */
AVL_DUP fdup, /* function to call for duplicates */
int depth
)
{
int rc, cmp, tallersub;
Avlnode *l, *r;
if ( *iroot == 0 ) {
if ( (*iroot = (Avlnode *) malloc( sizeof( Avlnode ) ))
if ( (*iroot = (Avlnode *) ber_memalloc( sizeof( Avlnode ) ))
== NULL ) {
return( -1 );
}
......@@ -200,11 +213,8 @@ ravl_insert( iroot, data, taller, fcmp, fdup, depth )
* NOTE: this routine may malloc memory
*/
avl_insert( root, data, fcmp, fdup )
Avlnode **root;
caddr_t data;
IFP fcmp;
IFP fdup;
int
avl_insert( Avlnode **root, void* data, AVL_CMP fcmp, AVL_DUP fdup )
{
int taller;
......@@ -216,11 +226,10 @@ avl_insert( root, data, fcmp, fdup )
* been shortened because of a deletion.
*/
static
right_balance( root )
Avlnode **root;
static int
right_balance( Avlnode **root )
{
int shorter;
int shorter = -1;
Avlnode *r, *l;
switch( (*root)->avl_bf ) {
......@@ -281,11 +290,10 @@ right_balance( root )
* been shortened because of a deletion.
*/
static
left_balance( root )
Avlnode **root;
static int
left_balance( Avlnode **root )
{
int shorter;
int shorter = -1;
Avlnode *r, *l;
switch( (*root)->avl_bf ) {
......@@ -348,16 +356,12 @@ left_balance( root )
* rebalancing.
*/
static caddr_t
ravl_delete( root, data, fcmp, shorter )
Avlnode **root;
caddr_t data;
IFP fcmp;
int *shorter;
static void*
ravl_delete( Avlnode **root, void* data, AVL_CMP fcmp, int *shorter )
{
int shortersubtree = 0;
int cmp;
caddr_t savedata;
void* savedata;
Avlnode *minnode, *savenode;
if ( *root == NULLAVL )
......@@ -374,13 +378,13 @@ ravl_delete( root, data, fcmp, shorter )
if ( (*root)->avl_left == 0 ) {
*root = (*root)->avl_right;
*shorter = 1;
free( (char *) savenode );
ber_memfree( (char *) savenode );
return( savedata );
/* no right child */
} else if ( (*root)->avl_right == 0 ) {
*root = (*root)->avl_left;
*shorter = 1;
free( (char *) savenode );
ber_memfree( (char *) savenode );
return( savedata );
}
......@@ -441,23 +445,16 @@ ravl_delete( root, data, fcmp, shorter )
* the avl tree rooted at root.
*/
caddr_t
avl_delete( root, data, fcmp )
Avlnode **root;
caddr_t data;
IFP fcmp;
void*
avl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
{
int shorter;
return( ravl_delete( root, data, fcmp, &shorter ) );
}
static
avl_inapply( root, fn, arg, stopflag )
Avlnode *root;
IFP fn;
caddr_t arg;
int stopflag;
static int
avl_inapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
{
if ( root == 0 )
return( AVL_NOMORE );
......@@ -476,12 +473,8 @@ avl_inapply( root, fn, arg, stopflag )
return( avl_inapply( root->avl_right, fn, arg, stopflag ) );
}
static
avl_postapply( root, fn, arg, stopflag )
Avlnode *root;
IFP fn;
caddr_t arg;
int stopflag;
static int
avl_postapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
{
if ( root == 0 )
return( AVL_NOMORE );
......@@ -499,12 +492,8 @@ avl_postapply( root, fn, arg, stopflag )
return( (*fn)( root->avl_data, arg ) );
}
static
avl_preapply( root, fn, arg, stopflag )
Avlnode *root;
IFP fn;
caddr_t arg;
int stopflag;
static int
avl_preapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
{
if ( root == 0 )
return( AVL_NOMORE );
......@@ -531,12 +520,8 @@ avl_preapply( root, fn, arg, stopflag )
* of nodes.
*/
avl_apply( root, fn, arg, stopflag, type )
Avlnode *root;
IFP fn;
caddr_t arg;
int stopflag;
int type;
int
avl_apply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag, int type )
{
switch ( type ) {
case AVL_INORDER:
......@@ -564,21 +549,23 @@ avl_apply( root, fn, arg, stopflag, type )
* AVL_NOMORE is returned.
*/
avl_prefixapply( root, data, fmatch, marg, fcmp, carg, stopflag )
Avlnode *root;
caddr_t data;
IFP fmatch;
caddr_t marg;
IFP fcmp;
caddr_t carg;
int stopflag;
int
avl_prefixapply(
Avlnode *root,
void* data,
AVL_CMP fmatch,
void* marg,
AVL_CMP fcmp,
void* carg,
int stopflag
)
{
int cmp;
if ( root == 0 )
return( AVL_NOMORE );
cmp = (*fcmp)( data, root->avl_data, carg );
cmp = (*fcmp)( data, root->avl_data /* , carg */);
if ( cmp == 0 ) {
if ( (*fmatch)( root->avl_data, marg ) == stopflag )
return( stopflag );
......@@ -613,9 +600,8 @@ avl_prefixapply( root, data, fmatch, marg, fcmp, carg, stopflag )
* number of items actually freed is returned.
*/
avl_free( root, dfree )
Avlnode *root;
IFP dfree;
int
avl_free( Avlnode *root, AVL_FREE dfree )
{
int nleft, nright;
......@@ -631,6 +617,7 @@ avl_free( root, dfree )
if ( dfree )
(*dfree)( root->avl_data );
ber_memfree( root );
return( nleft + nright + 1 );
}
......@@ -642,11 +629,8 @@ avl_free( root, dfree )
* < 0 if arg1 is less than arg2 and > 0 if arg1 is greater than arg2.
*/
caddr_t
avl_find( root, data, fcmp )
Avlnode *root;
caddr_t data;
IFP fcmp;
void*
avl_find( Avlnode *root, const void* data, AVL_CMP fcmp )
{
int cmp;
......@@ -667,13 +651,10 @@ avl_find( root, data, fcmp )
* they match, non-zero otherwise.
*/
caddr_t
avl_find_lin( root, data, fcmp )
Avlnode *root;
caddr_t data;
IFP fcmp;
void*
avl_find_lin( Avlnode *root, const void* data, AVL_CMP fcmp )
{
caddr_t res;
void* res;
if ( root == 0 )
return( NULL );
......@@ -692,28 +673,28 @@ avl_find_lin( root, data, fcmp )
return( avl_find_lin( root->avl_right, data, fcmp ) );
}
static caddr_t *avl_list;
/* NON-REENTRANT INTERFACE */
static void* *avl_list;
static int avl_maxlist;
static int avl_nextlist;
#define AVL_GRABSIZE 100
/* ARGSUSED */
static
avl_buildlist( data, arg )
caddr_t data;
int arg;
static int
avl_buildlist( void* data, void* arg )
{
static int slots;
if ( avl_list == (caddr_t *) 0 ) {
avl_list = (caddr_t *) malloc(AVL_GRABSIZE * sizeof(caddr_t));
if ( avl_list == (void* *) 0 ) {
avl_list = (void* *) ber_memalloc(AVL_GRABSIZE * sizeof(void*));
slots = AVL_GRABSIZE;
avl_maxlist = 0;
} else if ( avl_maxlist == slots ) {
slots += AVL_GRABSIZE;
avl_list = (caddr_t *) realloc( (char *) avl_list,
(unsigned) slots * sizeof(caddr_t));
avl_list = (void* *) ber_memrealloc( (char *) avl_list,
(unsigned) slots * sizeof(void*));
}
avl_list[ avl_maxlist++ ] = data;
......@@ -733,13 +714,12 @@ avl_buildlist( data, arg )
* different trees) cannot be active at once.
*/
caddr_t
avl_getfirst( root )
Avlnode *root;
void*
avl_getfirst( Avlnode *root )
{
if ( avl_list ) {
free( (char *) avl_list);
avl_list = (caddr_t *) 0;
ber_memfree( (char *) avl_list);
avl_list = (void* *) 0;
}
avl_maxlist = 0;
avl_nextlist = 0;
......@@ -747,32 +727,37 @@ avl_getfirst( root )
if ( root == 0 )
return( 0 );
(void) avl_apply( root, avl_buildlist, (caddr_t) 0, -1, AVL_INORDER );
(void) avl_apply( root, avl_buildlist, (void*) 0, -1, AVL_INORDER );
return( avl_list[ avl_nextlist++ ] );
}
caddr_t
avl_getnext()
void*
avl_getnext( void )
{
if ( avl_list == 0 )
return( 0 );
if ( avl_nextlist == avl_maxlist ) {
free( (caddr_t) avl_list);
avl_list = (caddr_t *) 0;
ber_memfree( (void*) avl_list);
avl_list = (void* *) 0;
return( 0 );
}
return( avl_list[ avl_nextlist++ ] );
}
avl_dup_error()
/* end non-reentrant code */
int
avl_dup_error( void* left, void* right )
{
return( -1 );
}
avl_dup_ok()
int
avl_dup_ok( void* left, void* right )
{
return( 0 );
}
/* testavl.c - Test Tim Howes AVL code */
#include <sys/types.h>
#include <stdio.h>
#include "avl.h"
/* $OpenLDAP$ */
/*
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
char *strdup( s )
char *s;
{
char *new;
#include "portable.h"
if ( (new = (char *) malloc( strlen( s ) + 1 )) == NULL )
return( NULL );
#include <stdio.h>
strcpy( new, s );
#include <ac/stdlib.h>
#include <ac/string.h>
return( new );
}
#define AVL_INTERNAL
#define AVL_NONREENTRANT
#include "avl.h"
main( argc, argv )
int argc;
char **argv;
static void ravl_print LDAP_P(( Avlnode *root, int depth ));
static void myprint LDAP_P(( Avlnode *root ));
static int avl_strcmp LDAP_P(( const void *s, const void *t ));
int
main( int argc, char **argv )
{
Avlnode *tree = NULLAVL;
Avlnode *tree = NULL;
char command[ 10 ];
char name[ 80 ];
char *p;
int free(), strcmp();
printf( "> " );
while ( fgets( command, sizeof( command ), stdin ) != NULL ) {
switch( *command ) {
case 'n': /* new tree */
( void ) avl_free( tree, free );
tree = NULLAVL;
tree = NULL;
break;
case 'p': /* print */
( void ) myprint( tree );
break;
case 't': /* traverse with first, next */
#ifdef AVL_NONREENTRANT
printf( "***\n" );
for ( p = (char * ) avl_getfirst( tree );
p != NULL; p = (char *) avl_getnext( tree, p ) )
p != NULL;
p = (char *) avl_getnext())
printf( "%s\n", p );
printf( "***\n" );
#else
printf( "*** reentrant interface not implemented ***" );
#endif
break;
case 'f': /* find */
printf( "data? " );
if ( fgets( name, sizeof( name ), stdin ) == NULL )
exit( 0 );
exit( EXIT_SUCCESS );
name[ strlen( name ) - 1 ] = '\0';
if ( (p = (char *) avl_find( tree, name, strcmp ))
if ( (p = (char *) avl_find( tree, name, avl_strcmp ))
== NULL )
printf( "Not found.\n\n" );
else
......@@ -57,22 +64,22 @@ char **argv;
case 'i': /* insert */
printf( "data? " );
if ( fgets( name, sizeof( name ), stdin ) == NULL )
exit( 0 );
exit( EXIT_SUCCESS );
name[ strlen( name ) - 1 ] = '\0';
if ( avl_insert( &tree, strdup( name ), strcmp,
avl_dup_error ) != OK )
if ( avl_insert( &tree, strdup( name ), avl_strcmp,
avl_dup_error ) != 0 )
printf( "\nNot inserted!\n" );
break;
case 'd': /* delete */
printf( "data? " );
if ( fgets( name, sizeof( name ), stdin ) == NULL )
exit( 0 );
exit( EXIT_SUCCESS );
name[ strlen( name ) - 1 ] = '\0';
if ( avl_delete( &tree, name, strcmp ) == NULL )
if ( avl_delete( &tree, name, avl_strcmp ) == NULL )
printf( "\nNot found!\n" );
break;
case 'q': /* quit */
exit( 0 );
exit( EXIT_SUCCESS );
break;
case '\n':