Commit 04391a9e authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Initial round of changes for 2.3 beta

parent 2ace030c
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2005 The OpenLDAP Foundation.
## All rights reserved.
##
......
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2005 The OpenLDAP Foundation.
## All rights reserved.
##
......
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2005 The OpenLDAP Foundation.
## All rights reserved.
##
......
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2005 The OpenLDAP Foundation.
## All rights reserved.
##
......
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2005 The OpenLDAP Foundation.
## All rights reserved.
##
......
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2005 The OpenLDAP Foundation.
## All rights reserved.
##
......
......@@ -64,6 +64,7 @@ echo "Rolling up $OL_STRING ..."
tar cf $RELNAME.tar $RELNAME
gzip -9 -c $RELNAME.tar > $RELNAME.tgz
md5 $RELNAME.tgz > $RELNAME.md5
sha1 $RELNAME.tgz > $RELNAME.sha1
rm -f $RELNAME.tar
ls -l $RELNAME.*
......
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2005 The OpenLDAP Foundation.
## All rights reserved.
##
......
......@@ -247,6 +247,75 @@ fi
])
dnl
dnl ====================================================================
dnl DNS resolver macros
AC_DEFUN([OL_RESOLVER_TRY],
[if test $ol_cv_lib_resolver = no ; then
AC_CACHE_CHECK([for resolver link (]ifelse($2,,default,$2)[)],[$1],
[
ol_RESOLVER_LIB=ifelse($2,,,$2)
ol_LIBS=$LIBS
LIBS="$ol_RESOLVER_LIB $LIBS"
AC_TRY_LINK([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <netinet/in.h>
#ifdef HAVE_ARPA_NAMESER_H
# include <arpa/nameser.h>
#endif
#ifdef HAVE_RESOLV_H
# include <resolv.h>
#endif
],[{
int len, status;
char *request = NULL;
unsigned char reply[64*1024];
unsigned char host[64*1024];
unsigned char *p;
#ifdef NS_HFIXEDSZ
/* Bind 8/9 interface */
len = res_query(request, ns_c_in, ns_t_srv, reply, sizeof(reply));
#else
/* Bind 4 interface */
# ifndef T_SRV
# define T_SRV 33
# endif
len = res_query(request, C_IN, T_SRV, reply, sizeof(reply));
#endif
p = reply;
#ifdef NS_HFIXEDSZ
/* Bind 8/9 interface */
p += NS_HFIXEDSZ;
#elif defined(HFIXEDSZ)
/* Bind 4 interface w/ HFIXEDSZ */
p += HFIXEDSZ;
#else
/* Bind 4 interface w/o HFIXEDSZ */
p += sizeof(HEADER);
#endif
status = dn_expand( reply, reply+len, p, host, sizeof(host));
}],[$1=yes],[$1=no])
LIBS="$ol_LIBS"
])
if test $$1 = yes ; then
ol_cv_lib_resolver=ifelse($2,,yes,$2)
fi
fi
])
dnl --------------------------------------------------------------------
dnl Try to locate appropriate library
AC_DEFUN([OL_RESOLVER_LINK],
[ol_cv_lib_resolver=no
OL_RESOLVER_TRY(ol_cv_resolver_none)
OL_RESOLVER_TRY(ol_cv_resolver_resolv,[-lresolv])
OL_RESOLVER_TRY(ol_cv_resolver_bind,[-lbind])
])
dnl
dnl ====================================================================
dnl Berkeley DB macros
dnl
dnl --------------------------------------------------------------------
......
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2005 The OpenLDAP Foundation.
## All rights reserved.
##
......
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2005 The OpenLDAP Foundation.
## All rights reserved.
##
......
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 1998-2005 The OpenLDAP Foundation.
## All rights reserved.
##
......
......@@ -15,7 +15,7 @@
ol_package=OpenLDAP
ol_major=2
ol_minor=3
ol_patch=2beta
ol_patch=X
ol_api_inc=20302
ol_api_current=0
ol_api_revision=2
......
......@@ -86,6 +86,15 @@ static int chainingResolve = -1;
static int chainingContinuation = -1;
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
static int gotintr;
static int abcan;
RETSIGTYPE
do_sig( int sig )
{
gotintr = abcan;
}
/* Set in main() */
char *prog = NULL;
......@@ -97,6 +106,17 @@ tool_init( void )
ldap_pvt_textdomain(OPENLDAP_PACKAGE);
}
void
tool_destroy( void )
{
#ifdef HAVE_CYRUS_SASL
sasl_done();
#endif
#ifdef HAVE_TLS
ldap_pvt_tls_destroy();
#endif
}
void
tool_common_usage( void )
{
......@@ -108,18 +128,19 @@ N_(" -D binddn bind DN\n"),
N_(" -e [!]<ext>[=<extparam>] general extensions (! indicates criticality)\n")
N_(" [!]assert=<filter> (an RFC 2254 Filter)\n")
N_(" [!]authzid=<authzid> (\"dn:<dn>\" or \"u:<user>\")\n")
N_(" [!]manageDSAit\n")
N_(" [!]noop\n")
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
N_(" ppolicy\n")
#endif
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
N_(" [!]chaining[=<resolveBehavior>[/<continuationBehavior>]]\n")
N_(" one of \"chainingPreferred\", \"chainingRequired\",\n")
N_(" \"referralsPreferred\", \"referralsRequired\"\n")
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
N_(" [!]manageDSAit\n")
N_(" [!]noop\n")
#ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
N_(" ppolicy\n")
#endif
N_(" [!]postread[=<attrs>] (a comma-separated attribute list)\n")
N_(" [!]preread[=<attrs>] (a comma-separated attribute list)\n"),
N_(" abandon, cancel (SIGINT sends abandon/cancel (not really controls)\n")
N_(" -f file read operations from `file'\n"),
N_(" -h host LDAP server\n"),
N_(" -H URI LDAP Uniform Resource Indentifier(s)\n"),
......@@ -343,6 +364,13 @@ tool_args( int argc, char **argv )
}
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
/* this shouldn't go here, really; but it's a feature... */
} else if ( strcasecmp( control, "abandon" ) == 0 ) {
abcan = LDAP_REQ_ABANDON;
} else if ( strcasecmp( control, "cancel" ) == 0 ) {
abcan = LDAP_REQ_EXTENDED;
} else {
fprintf( stderr, "Invalid general control name: %s\n",
control );
......@@ -631,28 +659,28 @@ tool_args( int argc, char **argv )
if (api.ldapai_info_version != LDAP_API_INFO_VERSION) {
fprintf( stderr, "LDAP APIInfo version mismatch: "
"got %d, expected %d\n",
"library %d, header %d\n",
api.ldapai_info_version, LDAP_API_INFO_VERSION );
exit( EXIT_FAILURE );
}
if( api.ldapai_api_version != LDAP_API_VERSION ) {
fprintf( stderr, "LDAP API version mismatch: "
"got %d, expected %d\n",
"library %d, header %d\n",
api.ldapai_api_version, LDAP_API_VERSION );
exit( EXIT_FAILURE );
}
if( strcmp(api.ldapai_vendor_name, LDAP_VENDOR_NAME ) != 0 ) {
fprintf( stderr, "LDAP vendor name mismatch: "
"got %s, expected %s\n",
"library %s, header %s\n",
api.ldapai_vendor_name, LDAP_VENDOR_NAME );
exit( EXIT_FAILURE );
}
if( api.ldapai_vendor_version != LDAP_VENDOR_VERSION ) {
fprintf( stderr, "LDAP vendor version mismatch: "
"got %d, expected %d\n",
"library %d, header %d\n",
api.ldapai_vendor_version, LDAP_VENDOR_VERSION );
exit( EXIT_FAILURE );
}
......@@ -745,6 +773,10 @@ tool_conn_setup( int not, void (*private_setup)( LDAP * ) )
(void) SIGNAL( SIGPIPE, SIG_IGN );
#endif
if ( abcan ) {
SIGNAL( SIGINT, do_sig );
}
if ( !not ) {
int rc;
......@@ -918,6 +950,18 @@ tool_bind( LDAP *ld )
}
}
void
tool_unbind( LDAP *ld )
{
int err = ldap_set_option( ld, LDAP_OPT_SERVER_CONTROLS, NULL );
if ( err != LDAP_OPT_SUCCESS ) {
fprintf( stderr, "Could not unset controls\n");
}
(void) ldap_unbind_ext( ld, NULL, NULL );
}
/* Set server controls. Add controls extra_c[0..count-1], if set. */
void
......@@ -1112,3 +1156,26 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
exit( EXIT_FAILURE );
}
}
int
tool_check_abandon( LDAP *ld, int msgid )
{
int rc;
switch ( gotintr ) {
case LDAP_REQ_EXTENDED:
rc = ldap_cancel_s( ld, msgid, NULL, NULL );
fprintf( stderr, "got interrupt, cancel got %d: %s\n",
rc, ldap_err2string( rc ) );
return -1;
case LDAP_REQ_ABANDON:
rc = ldap_abandon( ld, msgid );
fprintf( stderr, "got interrupt, abandon got %d: %s\n",
rc, ldap_err2string( rc ) );
return -1;
}
return 0;
}
......@@ -77,7 +77,10 @@ void tool_common_usage LDAP_P(( void ));
void tool_args LDAP_P(( int, char ** ));
LDAP *tool_conn_setup LDAP_P(( int dont, void (*private_setup)( LDAP * ) ));
void tool_bind LDAP_P(( LDAP * ));
void tool_unbind LDAP_P(( LDAP * ));
void tool_destroy LDAP_P(( void ));
void tool_server_controls LDAP_P(( LDAP *, LDAPControl *, int ));
int tool_check_abandon LDAP_P(( LDAP *ld, int msgid ));
LDAP_END_DECL
......
......@@ -217,8 +217,8 @@ main( int argc, char **argv )
free( bvalue.bv_val );
ldap_unbind_ext( ld, NULL, NULL );
tool_unbind( ld );
tool_destroy();
return rc;
}
......@@ -232,27 +232,88 @@ static int docompare(
LDAPControl **sctrls,
LDAPControl **cctrls )
{
int rc;
int rc, msgid, code;
LDAPMessage *res;
char *matcheddn;
char *text;
char **refs;
if ( not ) {
return LDAP_SUCCESS;
}
rc = ldap_compare_ext_s( ld, dn, attr, bvalue,
sctrls, cctrls );
rc = ldap_compare_ext( ld, dn, attr, bvalue,
sctrls, cctrls, &msgid );
if ( rc == -1 ) {
return( rc );
}
for ( ; ; ) {
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 100000;
if ( tool_check_abandon( ld, msgid ) ) {
return LDAP_CANCELLED;
}
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
ldap_perror( ld, "ldapcompare: ldap_result" );
return rc;
}
if ( rc != 0 ) {
break;
}
}
rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, NULL, 1 );
if( rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: ldap_parse_result: %s (%d)\n",
prog, ldap_err2string( rc ), rc );
return rc;
}
if ( !quiet && ( verbose || ( code != LDAP_SUCCESS && code != LDAP_COMPARE_TRUE && code != LDAP_COMPARE_FALSE )||
(matcheddn && *matcheddn) || (text && *text) || (refs && *refs) ) )
{
printf( _("Compare Result: %s (%d)\n"),
ldap_err2string( code ), code );
if( text && *text ) {
printf( _("Additional info: %s\n"), text );
}
if( matcheddn && *matcheddn ) {
printf( _("Matched DN: %s\n"), matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf(_("Referral: %s\n"), refs[i] );
}
}
}
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( (void **) refs );
/* if we were told to be quiet, use the return value. */
if ( !quiet ) {
if ( rc == LDAP_COMPARE_TRUE ) {
if ( code == LDAP_COMPARE_TRUE ) {
printf(_("TRUE\n"));
} else if ( rc == LDAP_COMPARE_FALSE ) {
} else if ( code == LDAP_COMPARE_FALSE ) {
printf(_("FALSE\n"));
} else {
printf(_("UNDEFINED\n"));
ldap_perror( ld, "ldap_compare" );
}
}
return( rc );
return( code );
}
......@@ -39,6 +39,7 @@
#include <ac/ctype.h>
#include <ac/string.h>
#include <ac/unistd.h>
#include <ac/time.h>
#include <ldap.h>
#include "lutil.h"
......@@ -197,9 +198,9 @@ main( int argc, char **argv )
}
}
ldap_unbind_ext( ld, NULL, NULL );
return( retval );
tool_unbind( ld );
tool_destroy();
return retval;
}
......@@ -233,10 +234,25 @@ static int dodelete(
return rc;
}
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, NULL, &res );
if ( rc < 0 ) {
ldap_perror( ld, "ldapdelete: ldap_result" );
return rc;
for ( ; ; ) {
struct timeval tv;
if ( tool_check_abandon( ld, id ) ) {
return LDAP_CANCELLED;
}
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
ldap_perror( ld, "ldapdelete: ldap_result" );
return rc;
}
if ( rc != 0 ) {
break;
}
}
rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, NULL, 1 );
......@@ -250,7 +266,8 @@ static int dodelete(
if( verbose || code != LDAP_SUCCESS ||
(matcheddn && *matcheddn) || (text && *text) || (refs && *refs) )
{
printf( _("Delete Result: %s (%d)\n"), ldap_err2string( code ), code );
printf( _("Delete Result: %s (%d)\n"),
ldap_err2string( code ), code );
if( text && *text ) {
printf( _("Additional info: %s\n"), text );
......
......@@ -405,13 +405,14 @@ main( int argc, char **argv )
#endif
if ( !not ) {
ldap_unbind_ext( ld, NULL, NULL );
tool_unbind( ld );
}
if ( rejfp != NULL ) {
fclose( rejfp );
}
tool_destroy();
return( retval );
}
......@@ -1009,7 +1010,7 @@ domodify(
}
if ( !not ) {
int msgid;
int msgid;
if ( newentry ) {
rc = ldap_add_ext( ld, dn, pmods, pctrls, NULL, &msgid );
} else {
......@@ -1113,21 +1114,37 @@ static int process_response(
const char *opstr,
const char *dn )
{
LDAPMessage *res;
int rc = LDAP_OTHER;
LDAPMessage *res;
int rc = LDAP_OTHER;
struct timeval tv = { 0 };
if( ldap_result( ld, msgid,
for ( ; ; ) {
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = ldap_result( ld, msgid,
#ifdef LDAP_GROUP_TRANSACTION
txn ? 0 : 1,
txn ? 0 : 1,
#else
1,
1,
#endif
NULL, &res ) == -1 ) {
ldap_get_option( ld, LDAP_OPT_ERROR_NUMBER, &rc );
return rc;
&tv, &res );
if ( tool_check_abandon( ld, msgid ) ) {
return LDAP_CANCELLED;
}
if ( rc == -1 ) {
ldap_get_option( ld, LDAP_OPT_ERROR_NUMBER, &rc );
return rc;
}
if ( rc != 0 ) {
break;
}
}
if( ldap_msgtype( res ) != LDAP_RES_INTERMEDIATE ) {
done:;
if ( ldap_msgtype( res ) != LDAP_RES_INTERMEDIATE ) {
rc = ldap_result2error( ld, res, 1 );
if( rc != LDAP_SUCCESS ) ldap_perror( ld, opstr );
return rc;
......
......@@ -52,6 +52,7 @@
#include <ac/ctype.h>
#include <ac/string.h>
#include <ac/unistd.h>
#include <ac/time.h>
#include <ldap.h>
#include "lutil.h"
......@@ -227,8 +228,8 @@ main(int argc, char **argv)
}
}
ldap_unbind_ext( ld, NULL, NULL );
tool_unbind( ld );
tool_destroy();
return( retval );
}
......@@ -263,10 +264,25 @@ static int domodrdn(
return rc;
}
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, NULL, &res );
if ( rc < 0 ) {
ldap_perror( ld, "ldapmodrdn: ldap_result" );
return rc;
for ( ; ; ) {
struct timeval tv = { 0 };
if ( tool_check_abandon( ld, id ) ) {
return LDAP_CANCELLED;
}
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
if ( rc < 0 ) {
ldap_perror( ld, "ldapmodrdn: ldap_result" );
return rc;
}
if ( rc != 0 ) {