1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1998-12-29 04:38:04 +08:00
|
|
|
/*
|
2000-05-13 10:36:07 +08:00
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
1998-12-29 04:38:04 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
1998-12-22 09:34:01 +08:00
|
|
|
#include <ac/stdarg.h>
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include <ac/string.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
#include "lber-int.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-05-11 17:39:33 +08:00
|
|
|
/*
|
|
|
|
* We don't just set ber_pvt_err_file to stderr here, because in NT,
|
|
|
|
* stderr is a symbol imported from a DLL. As such, the compiler
|
|
|
|
* doesn't recognize the symbol as having a constant address. Thus
|
|
|
|
* we set ber_pvt_err_file to stderr later, when it first gets
|
|
|
|
* referenced.
|
|
|
|
*/
|
|
|
|
FILE *ber_pvt_err_file;
|
|
|
|
|
1999-11-08 23:38:59 +08:00
|
|
|
/*
|
|
|
|
* ber errno
|
|
|
|
*/
|
|
|
|
BER_ERRNO_FN ber_int_errno_fn;
|
|
|
|
|
|
|
|
int * ber_errno_addr(void)
|
|
|
|
{
|
|
|
|
static int ber_int_errno = LBER_ERROR_NONE;
|
|
|
|
|
|
|
|
if( ber_int_errno_fn ) {
|
|
|
|
return (*ber_int_errno_fn)();
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ber_int_errno;
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
1998-10-27 15:50:07 +08:00
|
|
|
* Print stuff
|
1998-08-09 08:43:13 +08:00
|
|
|
*/
|
2000-06-11 07:06:08 +08:00
|
|
|
void ber_error_print( LDAP_CONST char *data )
|
1998-10-27 15:50:07 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( data != NULL );
|
|
|
|
|
2000-06-11 07:13:01 +08:00
|
|
|
if (!ber_pvt_err_file) ber_pvt_err_file = stderr;
|
2000-05-11 17:39:33 +08:00
|
|
|
|
|
|
|
fputs( data, ber_pvt_err_file );
|
|
|
|
|
|
|
|
/* Print to both streams */
|
2000-06-11 07:13:01 +08:00
|
|
|
if (ber_pvt_err_file != stderr) {
|
|
|
|
fputs( data, stderr );
|
|
|
|
fflush( stderr );
|
2000-05-11 17:39:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fflush( ber_pvt_err_file );
|
1998-10-27 15:50:07 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print;
|
1999-01-26 06:55:00 +08:00
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
/*
|
|
|
|
* lber log
|
|
|
|
*/
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
static int ber_log_check( int errlvl, int loglvl )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
|
|
|
return errlvl & loglvl ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
1999-08-24 08:27:53 +08:00
|
|
|
int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
|
|
|
char buf[ 1024 ];
|
|
|
|
va_list ap;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( fmt != NULL );
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-22 09:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-08-24 08:27:53 +08:00
|
|
|
va_start( ap, fmt );
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
#ifdef HAVE_VSNPRINTF
|
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
vsnprintf( buf, sizeof(buf)-1, fmt, ap );
|
1998-12-24 09:31:40 +08:00
|
|
|
#elif HAVE_VSPRINTF
|
1998-12-22 09:34:01 +08:00
|
|
|
vsprintf( buf, fmt, ap ); /* hope it's not too long */
|
|
|
|
#else
|
|
|
|
/* use doprnt() */
|
1999-05-19 09:12:33 +08:00
|
|
|
#error "vsprintf() required."
|
1998-12-22 09:34:01 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
static int ber_log_puts(int errlvl, int loglvl, char *buf)
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( buf != NULL );
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-22 09:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-10-27 15:50:07 +08:00
|
|
|
/*
|
|
|
|
* Print arbitrary stuff, for debugging.
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_log_bprint(int errlvl,
|
|
|
|
int loglvl,
|
|
|
|
const char *data,
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_len_t len )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( data != NULL );
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-22 09:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
ber_bprint(data, len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_bprint(
|
|
|
|
LDAP_CONST char *data,
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_len_t len )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
1999-03-09 16:40:36 +08:00
|
|
|
static const char hexdig[] = "0123456789abcdef";
|
1998-12-22 09:34:01 +08:00
|
|
|
#define BPLEN 48
|
1998-08-09 08:43:13 +08:00
|
|
|
char out[ BPLEN ];
|
1998-12-22 09:34:01 +08:00
|
|
|
char buf[ BPLEN + sizeof("\t%s\n") ];
|
1998-08-09 08:43:13 +08:00
|
|
|
int i = 0;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( data != NULL );
|
|
|
|
|
2000-06-11 06:39:30 +08:00
|
|
|
memset( out, '\0', BPLEN );
|
1998-08-09 08:43:13 +08:00
|
|
|
for ( ;; ) {
|
|
|
|
if ( len < 1 ) {
|
1998-12-22 09:34:01 +08:00
|
|
|
sprintf( buf, "\t%s\n", ( i == 0 ) ? "(end)" : out );
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
#ifndef LDAP_HEX
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( isgraph( (unsigned char)*data )) {
|
|
|
|
out[ i ] = ' ';
|
|
|
|
out[ i+1 ] = *data;
|
|
|
|
} else {
|
|
|
|
#endif
|
1999-05-19 14:13:44 +08:00
|
|
|
out[ i ] = hexdig[ ( *data & 0xf0U ) >> 4 ];
|
|
|
|
out[ i+1 ] = hexdig[ *data & 0x0fU ];
|
1998-12-22 09:34:01 +08:00
|
|
|
#ifndef LDAP_HEX
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
i += 2;
|
|
|
|
len--;
|
|
|
|
data++;
|
|
|
|
|
|
|
|
if ( i > BPLEN - 2 ) {
|
1998-10-27 15:50:07 +08:00
|
|
|
char data[128 + BPLEN];
|
|
|
|
sprintf( data, "\t%s\n", out );
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)(data);
|
2000-06-11 06:39:30 +08:00
|
|
|
memset( out, '\0', BPLEN );
|
1998-08-09 08:43:13 +08:00
|
|
|
i = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
out[ i++ ] = ' ';
|
|
|
|
}
|
1998-12-22 09:34:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_log_dump(
|
|
|
|
int errlvl,
|
|
|
|
int loglvl,
|
1999-10-20 02:57:38 +08:00
|
|
|
BerElement *ber,
|
1999-05-19 09:12:33 +08:00
|
|
|
int inout )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( ber != NULL );
|
1999-05-29 03:33:05 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-22 09:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ber_dump(ber, inout);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_dump(
|
1999-10-20 02:57:38 +08:00
|
|
|
BerElement *ber,
|
1999-05-19 09:12:33 +08:00
|
|
|
int inout )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
|
|
|
char buf[132];
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( ber != NULL );
|
1999-05-29 03:33:05 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
sprintf( buf, "ber_dump: buf 0x%lx, ptr 0x%lx, end 0x%lx\n",
|
|
|
|
(long) ber->ber_buf,
|
|
|
|
(long) ber->ber_ptr,
|
|
|
|
(long) ber->ber_end );
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
if ( inout == 1 ) {
|
|
|
|
sprintf( buf, " current len %ld, contents:\n",
|
|
|
|
(long) (ber->ber_end - ber->ber_ptr) );
|
|
|
|
ber_bprint( ber->ber_ptr, ber->ber_end - ber->ber_ptr );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
sprintf( buf, " current len %ld, contents:\n",
|
|
|
|
(long) (ber->ber_ptr - ber->ber_buf) );
|
|
|
|
|
|
|
|
ber_bprint( ber->ber_buf, ber->ber_ptr - ber->ber_buf );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-09-06 12:33:41 +08:00
|
|
|
ber_log_sos_dump(
|
1999-05-19 09:12:33 +08:00
|
|
|
int errlvl,
|
|
|
|
int loglvl,
|
1999-10-20 02:57:38 +08:00
|
|
|
Seqorset *sos )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( sos != NULL );
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-22 09:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ber_sos_dump( sos );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_sos_dump(
|
1999-10-20 02:57:38 +08:00
|
|
|
Seqorset *sos )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
|
|
|
char buf[132];
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( sos != NULL );
|
|
|
|
|
|
|
|
(*ber_pvt_log_print)( "*** sos dump ***\n" );
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
while ( sos != NULL ) {
|
1998-12-22 09:34:01 +08:00
|
|
|
sprintf( buf, "ber_sos_dump: clen %ld first 0x%lx ptr 0x%lx\n",
|
1999-06-19 07:53:05 +08:00
|
|
|
(long) sos->sos_clen,
|
|
|
|
(long) sos->sos_first,
|
|
|
|
(long) sos->sos_ptr );
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
sprintf( buf, " current len %ld contents:\n",
|
|
|
|
(long) (sos->sos_ptr - sos->sos_first) );
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
|
|
|
|
|
|
|
|
sos = sos->sos_next;
|
|
|
|
}
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( "*** end dump ***\n" );
|
1999-05-19 14:13:44 +08:00
|
|
|
}
|