1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 07:17:08 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2016-01-30 03:32:05 +08:00
|
|
|
* Copyright 1998-2016 The OpenLDAP Foundation.
|
2003-11-26 07:17:08 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
1998-12-29 04:38:04 +08:00
|
|
|
*/
|
2003-11-27 06:51:15 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1991 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that this notice is preserved and that due credit is given
|
|
|
|
* to the University of Michigan at Ann Arbor. The name of the University
|
|
|
|
* may not be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission. This software
|
|
|
|
* is provided ``as is'' without express or implied warranty.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was originally developed by the University of Michigan
|
|
|
|
* (as part of U-MICH LDAP).
|
|
|
|
*/
|
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
|
|
|
|
2001-12-20 05:22:04 +08:00
|
|
|
#define ber_log_check(errlvl, loglvl) ((errlvl) & (loglvl))
|
2000-10-13 22:10:41 +08:00
|
|
|
|
2000-10-13 04:01:12 +08:00
|
|
|
BER_LOG_FN ber_int_log_proc = NULL;
|
|
|
|
|
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.
|
|
|
|
*/
|
2000-10-03 01:53:50 +08:00
|
|
|
FILE *ber_pvt_err_file = NULL;
|
2000-05-11 17:39:33 +08:00
|
|
|
|
1999-11-08 23:38:59 +08:00
|
|
|
/*
|
|
|
|
* ber errno
|
|
|
|
*/
|
2000-10-03 01:53:50 +08:00
|
|
|
BER_ERRNO_FN ber_int_errno_fn = NULL;
|
1999-11-08 23:38:59 +08:00
|
|
|
|
|
|
|
int * ber_errno_addr(void)
|
|
|
|
{
|
2003-05-22 13:33:04 +08:00
|
|
|
static int ber_int_errno = LBER_ERROR_NONE;
|
1999-11-08 23:38:59 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2001-12-20 05:22:04 +08:00
|
|
|
int ber_pvt_log_output(
|
|
|
|
const char *subsystem,
|
|
|
|
int level,
|
|
|
|
const char *fmt,
|
|
|
|
... )
|
2000-10-13 04:01:12 +08:00
|
|
|
{
|
2003-07-08 11:46:20 +08:00
|
|
|
char buf[1024];
|
2000-10-13 04:01:12 +08:00
|
|
|
va_list vl;
|
|
|
|
va_start( vl, fmt );
|
|
|
|
|
2003-07-08 11:46:20 +08:00
|
|
|
if ( ber_int_log_proc != NULL ) {
|
2000-10-13 04:01:12 +08:00
|
|
|
ber_int_log_proc( ber_pvt_err_file, subsystem, level, fmt, vl );
|
2003-07-08 11:46:20 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
int level;
|
|
|
|
ber_get_option( NULL, LBER_OPT_BER_DEBUG, &level );
|
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
vsnprintf( buf, sizeof(buf)-1, fmt, vl );
|
|
|
|
if ( ber_log_check( LDAP_DEBUG_BER, level ) ) {
|
|
|
|
(*ber_pvt_log_print)( buf );
|
|
|
|
}
|
2000-10-13 04:01:12 +08:00
|
|
|
}
|
|
|
|
|
2003-07-08 11:46:20 +08:00
|
|
|
va_end(vl);
|
2000-10-13 04:01:12 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2003-07-08 11:46:20 +08:00
|
|
|
char buf[1024];
|
1998-12-22 09:34:01 +08:00
|
|
|
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
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
vsnprintf( buf, sizeof(buf)-1, fmt, ap );
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2000-09-16 02:10:52 +08:00
|
|
|
|
2000-09-15 10:51:34 +08:00
|
|
|
#if 0
|
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;
|
|
|
|
}
|
2000-09-15 10:51:34 +08:00
|
|
|
#endif
|
2000-09-16 02:10:52 +08:00
|
|
|
|
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
|
|
|
{
|
2003-07-08 11:46:20 +08:00
|
|
|
static const char hexdig[] = "0123456789abcdef";
|
2000-09-16 02:59:46 +08:00
|
|
|
#define BP_OFFSET 9
|
2000-09-15 06:28:45 +08:00
|
|
|
#define BP_GRAPH 60
|
|
|
|
#define BP_LEN 80
|
2003-07-08 11:46:20 +08:00
|
|
|
char line[BP_LEN];
|
2000-09-15 06:28:45 +08:00
|
|
|
ber_len_t i;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( data != NULL );
|
|
|
|
|
2000-09-15 06:28:45 +08:00
|
|
|
/* in case len is zero */
|
|
|
|
line[0] = '\n';
|
|
|
|
line[1] = '\0';
|
|
|
|
|
|
|
|
for ( i = 0 ; i < len ; i++ ) {
|
|
|
|
int n = i % 16;
|
2000-09-23 06:43:30 +08:00
|
|
|
unsigned off;
|
2000-09-15 06:28:45 +08: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;
|
|
|
|
|
2003-07-08 11:46:20 +08:00
|
|
|
line[2] = hexdig[0x0f & (off >> 12)];
|
|
|
|
line[3] = hexdig[0x0f & (off >> 8)];
|
|
|
|
line[4] = hexdig[0x0f & (off >> 4)];
|
|
|
|
line[5] = hexdig[0x0f & off];
|
|
|
|
line[6] = ':';
|
2000-09-15 06:28:45 +08:00
|
|
|
}
|
|
|
|
|
2000-09-16 02:10:52 +08:00
|
|
|
off = BP_OFFSET + n*3 + ((n >= 8)?1:0);
|
2003-07-08 11:46:20 +08:00
|
|
|
line[off] = hexdig[0x0f & ( data[i] >> 4 )];
|
|
|
|
line[off+1] = hexdig[0x0f & data[i]];
|
2000-09-15 06:28:45 +08:00
|
|
|
|
2000-10-11 10:43:14 +08:00
|
|
|
off = BP_GRAPH + n + ((n >= 8)?1:0);
|
2000-09-15 06:28:45 +08:00
|
|
|
|
2002-04-08 17:43:22 +08:00
|
|
|
if ( isprint( (unsigned char) data[i] )) {
|
2003-07-08 11:46:20 +08:00
|
|
|
line[BP_GRAPH + n] = data[i];
|
2000-09-15 06:28:45 +08:00
|
|
|
} else {
|
2003-07-08 11:46:20 +08:00
|
|
|
line[BP_GRAPH + n] = '.';
|
2000-09-15 06:28:45 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2000-09-15 06:28:45 +08:00
|
|
|
(*ber_pvt_log_print)( line );
|
1998-12-22 09:34:01 +08:00
|
|
|
}
|
|
|
|
|
2000-10-25 23:33:39 +08:00
|
|
|
|
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 );
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_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];
|
2000-09-15 13:56:37 +08:00
|
|
|
ber_len_t len;
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( ber != NULL );
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_VALID( ber ) );
|
1999-05-19 09:12:33 +08:00
|
|
|
|
2000-09-15 13:56:37 +08:00
|
|
|
if ( inout == 1 ) {
|
|
|
|
len = ber_pvt_ber_remaining(ber);
|
|
|
|
} else {
|
|
|
|
len = ber_pvt_ber_write(ber);
|
|
|
|
}
|
|
|
|
|
2007-08-25 05:58:20 +08:00
|
|
|
sprintf( buf, "ber_dump: buf=%p ptr=%p end=%p len=%ld\n",
|
|
|
|
ber->ber_buf,
|
|
|
|
ber->ber_ptr,
|
|
|
|
ber->ber_end,
|
2000-09-15 13:56:37 +08:00
|
|
|
(long) len );
|
1998-12-22 09:34:01 +08:00
|
|
|
|
2001-12-20 05:22:04 +08:00
|
|
|
(void) (*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
|
2000-09-15 13:56:37 +08:00
|
|
|
ber_bprint( ber->ber_ptr, len );
|
1998-12-22 09:34:01 +08:00
|
|
|
}
|
|
|
|
|
2009-07-30 01:07:52 +08:00
|
|
|
typedef struct seqorset Seqorset;
|
|
|
|
|
More ITS#6215 -
Speedup & less memory allocation:
Simplify the work to encode tag, length, integer/enum, sequence/set.
Drop struct seqorset and allocations of it. Replace BerElement.ber_sos.
Drop ber_write(,,,nonzero) support. Callers, if any, need to be rewritten.
Make ber_log_sos_dump() and ber_sos_dump() stubs, they could no longer work.
Fix ber_write() buffer overrun after ber_start_seqorset().
Check overflow and max sizes, e.g. for functions returning int size.
Some cleanup, and handwaves in the direction of supporting CHAR_BIT>8.
Add/fix comments and a few descriptive types/macros.
2009-07-30 00:49:42 +08:00
|
|
|
/* Exists for binary compatibility with OpenLDAP 2.4.17-- */
|
1998-12-22 09:34:01 +08:00
|
|
|
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
|
|
|
{
|
More ITS#6215 -
Speedup & less memory allocation:
Simplify the work to encode tag, length, integer/enum, sequence/set.
Drop struct seqorset and allocations of it. Replace BerElement.ber_sos.
Drop ber_write(,,,nonzero) support. Callers, if any, need to be rewritten.
Make ber_log_sos_dump() and ber_sos_dump() stubs, they could no longer work.
Fix ber_write() buffer overrun after ber_start_seqorset().
Check overflow and max sizes, e.g. for functions returning int size.
Some cleanup, and handwaves in the direction of supporting CHAR_BIT>8.
Add/fix comments and a few descriptive types/macros.
2009-07-30 00:49:42 +08:00
|
|
|
return 0;
|
1998-12-22 09:34:01 +08:00
|
|
|
}
|
|
|
|
|
More ITS#6215 -
Speedup & less memory allocation:
Simplify the work to encode tag, length, integer/enum, sequence/set.
Drop struct seqorset and allocations of it. Replace BerElement.ber_sos.
Drop ber_write(,,,nonzero) support. Callers, if any, need to be rewritten.
Make ber_log_sos_dump() and ber_sos_dump() stubs, they could no longer work.
Fix ber_write() buffer overrun after ber_start_seqorset().
Check overflow and max sizes, e.g. for functions returning int size.
Some cleanup, and handwaves in the direction of supporting CHAR_BIT>8.
Add/fix comments and a few descriptive types/macros.
2009-07-30 00:49:42 +08:00
|
|
|
/* Exists for binary compatibility with OpenLDAP 2.4.17-- */
|
1998-12-22 09:34:01 +08:00
|
|
|
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
|
|
|
{
|
1999-05-19 14:13:44 +08:00
|
|
|
}
|