1999-09-08 15:06:24 -04:00
|
|
|
/* $OpenLDAP$ */
|
1998-12-28 15:38:04 -05:00
|
|
|
/*
|
2000-05-12 22:36:07 -04:00
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
1998-12-28 15:38:04 -05:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
|
*/
|
1998-10-24 21:41:42 -04:00
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
#include <stdio.h>
|
1998-10-24 21:41:42 -04:00
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
1998-12-21 20:34:01 -05: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-15 17:40:11 -05:00
|
|
|
#include <ac/string.h>
|
1998-10-24 21:41:42 -04:00
|
|
|
|
1998-10-25 20:18:41 -05:00
|
|
|
#include "lber-int.h"
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2000-05-11 05:39:33 -04: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.
|
|
|
|
|
*/
|
2000-10-02 13:53:50 -04:00
|
|
|
FILE *ber_pvt_err_file = NULL;
|
2000-05-11 05:39:33 -04:00
|
|
|
|
1999-11-08 10:38:59 -05:00
|
|
|
/*
|
|
|
|
|
* ber errno
|
|
|
|
|
*/
|
2000-10-02 13:53:50 -04:00
|
|
|
BER_ERRNO_FN ber_int_errno_fn = NULL;
|
1999-11-08 10:38:59 -05:00
|
|
|
|
|
|
|
|
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-08 20:43:13 -04:00
|
|
|
/*
|
1998-10-27 02:50:07 -05:00
|
|
|
* Print stuff
|
1998-08-08 20:43:13 -04:00
|
|
|
*/
|
2000-06-10 19:06:08 -04:00
|
|
|
void ber_error_print( LDAP_CONST char *data )
|
1998-10-27 02:50:07 -05:00
|
|
|
{
|
1999-05-18 21:12:33 -04:00
|
|
|
assert( data != NULL );
|
|
|
|
|
|
2000-06-10 19:13:01 -04:00
|
|
|
if (!ber_pvt_err_file) ber_pvt_err_file = stderr;
|
2000-05-11 05:39:33 -04:00
|
|
|
|
|
|
|
|
fputs( data, ber_pvt_err_file );
|
|
|
|
|
|
|
|
|
|
/* Print to both streams */
|
2000-06-10 19:13:01 -04:00
|
|
|
if (ber_pvt_err_file != stderr) {
|
|
|
|
|
fputs( data, stderr );
|
|
|
|
|
fflush( stderr );
|
2000-05-11 05:39:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fflush( ber_pvt_err_file );
|
1998-10-27 02:50:07 -05:00
|
|
|
}
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print;
|
1999-01-25 17:55:00 -05:00
|
|
|
|
1998-12-21 20:34:01 -05:00
|
|
|
/*
|
|
|
|
|
* lber log
|
|
|
|
|
*/
|
|
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
static int ber_log_check( int errlvl, int loglvl )
|
1998-12-21 20:34:01 -05:00
|
|
|
{
|
|
|
|
|
return errlvl & loglvl ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-23 20:27:53 -04:00
|
|
|
int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
|
1998-12-21 20:34:01 -05:00
|
|
|
{
|
|
|
|
|
char buf[ 1024 ];
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
assert( fmt != NULL );
|
|
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-21 20:34:01 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-23 20:27:53 -04:00
|
|
|
va_start( ap, fmt );
|
|
|
|
|
|
1998-12-21 20:34:01 -05:00
|
|
|
#ifdef HAVE_VSNPRINTF
|
|
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
|
vsnprintf( buf, sizeof(buf)-1, fmt, ap );
|
1998-12-23 20:31:40 -05:00
|
|
|
#elif HAVE_VSPRINTF
|
1998-12-21 20:34:01 -05:00
|
|
|
vsprintf( buf, fmt, ap ); /* hope it's not too long */
|
|
|
|
|
#else
|
|
|
|
|
/* use doprnt() */
|
1999-05-18 21:12:33 -04:00
|
|
|
#error "vsprintf() required."
|
1998-12-21 20:34:01 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-21 20:34:01 -05:00
|
|
|
return 1;
|
|
|
|
|
}
|
2000-09-15 14:10:52 -04:00
|
|
|
|
2000-09-14 22:51:34 -04:00
|
|
|
#if 0
|
1999-05-18 21:12:33 -04:00
|
|
|
static int ber_log_puts(int errlvl, int loglvl, char *buf)
|
1998-12-21 20:34:01 -05:00
|
|
|
{
|
1999-05-18 21:12:33 -04:00
|
|
|
assert( buf != NULL );
|
|
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-21 20:34:01 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-21 20:34:01 -05:00
|
|
|
return 1;
|
|
|
|
|
}
|
2000-09-14 22:51:34 -04:00
|
|
|
#endif
|
2000-09-15 14:10:52 -04:00
|
|
|
|
1998-10-27 02:50:07 -05:00
|
|
|
/*
|
|
|
|
|
* Print arbitrary stuff, for debugging.
|
|
|
|
|
*/
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1998-12-21 20:34:01 -05:00
|
|
|
int
|
1999-05-18 21:12:33 -04:00
|
|
|
ber_log_bprint(int errlvl,
|
|
|
|
|
int loglvl,
|
|
|
|
|
const char *data,
|
1999-06-18 19:53:05 -04:00
|
|
|
ber_len_t len )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
1999-05-18 21:12:33 -04:00
|
|
|
assert( data != NULL );
|
|
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-21 20:34:01 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
1998-10-24 21:41:42 -04:00
|
|
|
|
1998-12-21 20:34:01 -05:00
|
|
|
ber_bprint(data, len);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
1999-05-18 21:12:33 -04:00
|
|
|
ber_bprint(
|
|
|
|
|
LDAP_CONST char *data,
|
1999-06-18 19:53:05 -04:00
|
|
|
ber_len_t len )
|
1998-12-21 20:34:01 -05:00
|
|
|
{
|
2000-09-14 18:28:45 -04:00
|
|
|
static const char hexdig[] = "0123456789abcdef";
|
2000-09-15 14:59:46 -04:00
|
|
|
#define BP_OFFSET 9
|
2000-09-14 18:28:45 -04:00
|
|
|
#define BP_GRAPH 60
|
|
|
|
|
#define BP_LEN 80
|
|
|
|
|
char line[ BP_LEN ];
|
|
|
|
|
ber_len_t i;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
assert( data != NULL );
|
|
|
|
|
|
2000-09-14 18:28:45 -04:00
|
|
|
/* in case len is zero */
|
|
|
|
|
line[0] = '\n';
|
|
|
|
|
line[1] = '\0';
|
|
|
|
|
|
|
|
|
|
for ( i = 0 ; i < len ; i++ ) {
|
|
|
|
|
int n = i % 16;
|
2000-09-22 18:43:30 -04:00
|
|
|
unsigned off;
|
2000-09-14 18:28:45 -04:00
|
|
|
|
|
|
|
|
if( !n ) {
|
|
|
|
|
if( i ) (*ber_pvt_log_print)( line );
|
|
|
|
|
memset( line, ' ', sizeof(line)-2 );
|
|
|
|
|
line[sizeof(line)-2] = '\n';
|
|
|
|
|
line[sizeof(line)-1] = '\0';
|
|
|
|
|
|
|
|
|
|
off = i % 0x0ffffU;
|
|
|
|
|
|
2000-09-22 18:43:30 -04:00
|
|
|
line[ 2 ] = hexdig[ 0x0f & (off >> 12) ];
|
|
|
|
|
line[ 3 ] = hexdig[ 0x0f & (off >> 8) ];
|
|
|
|
|
line[ 4 ] = hexdig[ 0x0f & (off >> 4) ];
|
|
|
|
|
line[ 5 ] = hexdig[ 0x0f & off ];
|
2000-09-14 18:28:45 -04:00
|
|
|
line[ 6 ] = ':';
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-15 14:10:52 -04:00
|
|
|
off = BP_OFFSET + n*3 + ((n >= 8)?1:0);
|
2000-09-22 18:43:30 -04:00
|
|
|
line[ off ] = hexdig[ 0x0f & ( data[i] >> 4 ) ];
|
|
|
|
|
line[ off+1 ] = hexdig[ 0x0f & data[i] ];
|
2000-09-14 18:28:45 -04:00
|
|
|
|
2000-10-10 22:43:14 -04:00
|
|
|
off = BP_GRAPH + n + ((n >= 8)?1:0);
|
2000-09-14 18:28:45 -04:00
|
|
|
|
|
|
|
|
if ( isprint( data[i] )) {
|
|
|
|
|
line[ BP_GRAPH + n ] = data[i];
|
|
|
|
|
} else {
|
|
|
|
|
line[ BP_GRAPH + n ] = '.';
|
|
|
|
|
}
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
2000-09-14 18:28:45 -04:00
|
|
|
(*ber_pvt_log_print)( line );
|
1998-12-21 20:34:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
1999-05-18 21:12:33 -04:00
|
|
|
ber_log_dump(
|
|
|
|
|
int errlvl,
|
|
|
|
|
int loglvl,
|
1999-10-19 14:57:38 -04:00
|
|
|
BerElement *ber,
|
1999-05-18 21:12:33 -04:00
|
|
|
int inout )
|
1998-12-21 20:34:01 -05:00
|
|
|
{
|
1999-05-18 21:12:33 -04:00
|
|
|
assert( ber != NULL );
|
1999-05-28 15:33:05 -04:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-05-18 21:12:33 -04:00
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-21 20:34:01 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ber_dump(ber, inout);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
1999-05-18 21:12:33 -04:00
|
|
|
ber_dump(
|
1999-10-19 14:57:38 -04:00
|
|
|
BerElement *ber,
|
1999-05-18 21:12:33 -04:00
|
|
|
int inout )
|
1998-12-21 20:34:01 -05:00
|
|
|
{
|
|
|
|
|
char buf[132];
|
2000-09-15 01:56:37 -04:00
|
|
|
ber_len_t len;
|
1998-12-21 20:34:01 -05:00
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
assert( ber != NULL );
|
1999-05-28 15:33:05 -04:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-05-18 21:12:33 -04:00
|
|
|
|
2000-09-15 01:56:37 -04:00
|
|
|
if ( inout == 1 ) {
|
|
|
|
|
len = ber_pvt_ber_remaining(ber);
|
|
|
|
|
} else {
|
|
|
|
|
len = ber_pvt_ber_write(ber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sprintf( buf, "ber_dump: buf=0x%08lx ptr=0x%08lx end=0x%08lx len=%ld\n",
|
1998-12-21 20:34:01 -05:00
|
|
|
(long) ber->ber_buf,
|
|
|
|
|
(long) ber->ber_ptr,
|
2000-09-15 01:56:37 -04:00
|
|
|
(long) ber->ber_end,
|
|
|
|
|
(long) len );
|
1998-12-21 20:34:01 -05:00
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-21 20:34:01 -05:00
|
|
|
|
2000-09-15 01:56:37 -04:00
|
|
|
ber_bprint( ber->ber_ptr, len );
|
1998-12-21 20:34:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
1999-09-06 00:33:41 -04:00
|
|
|
ber_log_sos_dump(
|
1999-05-18 21:12:33 -04:00
|
|
|
int errlvl,
|
|
|
|
|
int loglvl,
|
1999-10-19 14:57:38 -04:00
|
|
|
Seqorset *sos )
|
1998-12-21 20:34:01 -05:00
|
|
|
{
|
1999-05-18 21:12:33 -04:00
|
|
|
assert( sos != NULL );
|
|
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-21 20:34:01 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ber_sos_dump( sos );
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
1999-05-18 21:12:33 -04:00
|
|
|
ber_sos_dump(
|
1999-10-19 14:57:38 -04:00
|
|
|
Seqorset *sos )
|
1998-12-21 20:34:01 -05:00
|
|
|
{
|
|
|
|
|
char buf[132];
|
|
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
assert( sos != NULL );
|
|
|
|
|
|
|
|
|
|
(*ber_pvt_log_print)( "*** sos dump ***\n" );
|
1998-12-21 20:34:01 -05:00
|
|
|
|
1999-06-18 19:53:05 -04:00
|
|
|
while ( sos != NULL ) {
|
1998-12-21 20:34:01 -05:00
|
|
|
sprintf( buf, "ber_sos_dump: clen %ld first 0x%lx ptr 0x%lx\n",
|
1999-06-18 19:53:05 -04:00
|
|
|
(long) sos->sos_clen,
|
|
|
|
|
(long) sos->sos_first,
|
|
|
|
|
(long) sos->sos_ptr );
|
1999-05-18 21:12:33 -04:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-21 20:34:01 -05:00
|
|
|
|
|
|
|
|
sprintf( buf, " current len %ld contents:\n",
|
|
|
|
|
(long) (sos->sos_ptr - sos->sos_first) );
|
1999-05-18 21:12:33 -04:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-21 20:34:01 -05:00
|
|
|
|
|
|
|
|
ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
|
|
|
|
|
|
|
|
|
|
sos = sos->sos_next;
|
|
|
|
|
}
|
1998-10-24 21:41:42 -04:00
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
(*ber_pvt_log_print)( "*** end dump ***\n" );
|
1999-05-19 02:13:44 -04:00
|
|
|
}
|