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-12-22 09:34:01 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/stdlib.h>
|
1999-05-31 07:00:52 +08:00
|
|
|
#include <ac/string.h>
|
2000-10-13 22:10:41 +08:00
|
|
|
#include <ac/stdarg.h>
|
1998-12-22 09:34:01 +08:00
|
|
|
#include "lber-int.h"
|
|
|
|
|
2000-10-13 22:10:41 +08:00
|
|
|
/* bprint.c */
|
|
|
|
typedef void (*BER_LOG_FN) LDAP_P((FILE *file, char *subsys, int level, const char *fmt, va_list vl));
|
|
|
|
extern void * ber_pvt_err_file;
|
2000-10-13 04:01:12 +08:00
|
|
|
extern BER_LOG_FN ber_int_log_proc;
|
2000-05-11 17:39:33 +08:00
|
|
|
|
1999-05-29 03:33:05 +08:00
|
|
|
struct lber_options ber_int_options = {
|
|
|
|
LBER_UNINITIALIZED, 0, 0 };
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_get_option(
|
1999-10-20 08:19:47 +08:00
|
|
|
void *item,
|
1998-12-22 09:34:01 +08:00
|
|
|
int option,
|
|
|
|
void *outvalue)
|
|
|
|
{
|
1999-06-03 05:38:48 +08:00
|
|
|
LDAP_CONST BerElement *ber;
|
|
|
|
LDAP_CONST Sockbuf *sb;
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1999-05-29 13:16:31 +08:00
|
|
|
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
if(outvalue == NULL) {
|
|
|
|
/* no place to get to */
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item == NULL) {
|
|
|
|
if(option == LBER_OPT_BER_DEBUG) {
|
1999-05-19 09:12:33 +08:00
|
|
|
* (int *) outvalue = ber_int_debug;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
2000-07-05 02:47:06 +08:00
|
|
|
} else if(option == LBER_OPT_MEMORY_INUSE) {
|
|
|
|
/* The memory inuse is a global variable on kernal implementations.
|
|
|
|
* This means that memory debug is shared by all LDAP processes
|
|
|
|
* so for this variable to have much meaning, only one LDAP process
|
|
|
|
* should be running and memory inuse should be initialized to zero
|
|
|
|
* using the lber_set_option() function during startup.
|
|
|
|
* The counter is not accurate for multithreaded ldap applications.
|
|
|
|
*/
|
|
|
|
#ifdef LDAP_MEMORY_DEBUG
|
|
|
|
* (int *) outvalue = ber_int_options.lbo_meminuse;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
#else
|
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
#endif
|
2000-10-13 04:01:12 +08:00
|
|
|
} else if(option == LBER_OPT_LOG_PRINT_FILE) {
|
|
|
|
*((FILE**)outvalue) = (FILE*)ber_pvt_err_file;
|
|
|
|
return LBER_OPT_SUCCESS;
|
1998-12-22 09:34:01 +08:00
|
|
|
}
|
|
|
|
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
1999-06-03 05:38:48 +08:00
|
|
|
ber = item;
|
|
|
|
sb = item;
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
switch(option) {
|
|
|
|
case LBER_OPT_BER_OPTIONS:
|
1999-05-29 03:33:05 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1998-12-22 09:34:01 +08:00
|
|
|
* (int *) outvalue = ber->ber_options;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_DEBUG:
|
1999-05-29 03:33:05 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1998-12-22 09:34:01 +08:00
|
|
|
* (int *) outvalue = ber->ber_debug;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
1999-11-08 23:38:59 +08:00
|
|
|
case LBER_OPT_BER_REMAINING_BYTES:
|
2000-09-16 09:28:20 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
2000-09-15 13:56:37 +08:00
|
|
|
*((ber_len_t *) outvalue) = ber_pvt_ber_remaining(ber);
|
1999-11-08 23:38:59 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_TOTAL_BYTES:
|
2000-09-16 09:28:20 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
2000-09-15 13:56:37 +08:00
|
|
|
*((ber_len_t *) outvalue) = ber_pvt_ber_total(ber);
|
1999-11-08 23:38:59 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_BYTES_TO_WRITE:
|
2000-09-16 09:28:20 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
2000-09-15 13:56:37 +08:00
|
|
|
*((ber_len_t *) outvalue) = ber_pvt_ber_write(ber);
|
1999-11-08 23:38:59 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
default:
|
|
|
|
/* bad param */
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_set_option(
|
1998-12-22 09:34:01 +08:00
|
|
|
void *item,
|
|
|
|
int option,
|
1999-05-19 09:42:29 +08:00
|
|
|
LDAP_CONST void *invalue)
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
|
|
|
BerElement *ber;
|
|
|
|
Sockbuf *sb;
|
|
|
|
|
1999-05-29 13:16:31 +08:00
|
|
|
if( (ber_int_options.lbo_valid == LBER_UNINITIALIZED)
|
1999-05-31 07:00:52 +08:00
|
|
|
&& ( ber_int_memory_fns == NULL )
|
|
|
|
&& ( option == LBER_OPT_MEMORY_FNS )
|
1999-05-29 13:16:31 +08:00
|
|
|
&& ( invalue != NULL ))
|
|
|
|
{
|
1999-07-13 13:17:50 +08:00
|
|
|
const BerMemoryFunctions *f =
|
|
|
|
(const BerMemoryFunctions *) invalue;
|
1999-05-31 07:00:52 +08:00
|
|
|
|
|
|
|
/* make sure all functions are provided */
|
|
|
|
if(!( f->bmf_malloc && f->bmf_calloc
|
|
|
|
&& f->bmf_realloc && f->bmf_free ))
|
|
|
|
{
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1999-05-31 07:00:52 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ber_int_memory_fns = (BerMemoryFunctions *)
|
|
|
|
(*(f->bmf_malloc))(sizeof(BerMemoryFunctions));
|
|
|
|
|
|
|
|
if ( ber_int_memory_fns == NULL ) {
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_MEMORY;
|
1999-05-31 07:00:52 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
2000-07-28 09:07:07 +08:00
|
|
|
AC_MEMCPY(ber_int_memory_fns, f, sizeof(BerMemoryFunctions));
|
1999-05-31 07:00:52 +08:00
|
|
|
|
1999-05-29 13:16:31 +08:00
|
|
|
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
if(invalue == NULL) {
|
|
|
|
/* no place to set from */
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item == NULL) {
|
|
|
|
if(option == LBER_OPT_BER_DEBUG) {
|
1999-07-13 13:17:50 +08:00
|
|
|
ber_int_debug = * (const int *) invalue;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
1999-01-26 06:55:00 +08:00
|
|
|
|
|
|
|
} else if(option == LBER_OPT_LOG_PRINT_FN) {
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_pvt_log_print = (BER_LOG_PRINT_FN) invalue;
|
1999-01-26 06:55:00 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
2000-05-11 17:39:33 +08:00
|
|
|
} else if(option == LBER_OPT_LOG_PRINT_FILE) {
|
|
|
|
ber_pvt_err_file = (void *) invalue;
|
|
|
|
return LBER_OPT_SUCCESS;
|
2000-07-05 02:47:06 +08:00
|
|
|
} else if(option == LBER_OPT_MEMORY_INUSE) {
|
|
|
|
/* The memory inuse is a global variable on kernal implementations.
|
|
|
|
* This means that memory debug is shared by all LDAP processes
|
|
|
|
* so for this variable to have much meaning, only one LDAP process
|
|
|
|
* should be running and memory inuse should be initialized to zero
|
|
|
|
* using the lber_set_option() function during startup.
|
|
|
|
* The counter is not accurate for multithreaded applications.
|
|
|
|
*/
|
|
|
|
#ifdef LDAP_MEMORY_DEBUG
|
|
|
|
ber_int_options.lbo_meminuse = * (int *) invalue;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
#else
|
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
#endif
|
2000-10-13 04:01:12 +08:00
|
|
|
} else if(option == LBER_OPT_LOG_PROC) {
|
|
|
|
ber_int_log_proc = (BER_LOG_FN)invalue;
|
1998-12-22 09:34:01 +08:00
|
|
|
}
|
|
|
|
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
1999-06-03 05:38:48 +08:00
|
|
|
ber = item;
|
|
|
|
sb = item;
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
switch(option) {
|
|
|
|
case LBER_OPT_BER_OPTIONS:
|
1999-05-29 03:33:05 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-07-13 13:17:50 +08:00
|
|
|
ber->ber_options = * (const int *) invalue;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_DEBUG:
|
1999-05-29 03:33:05 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-07-13 13:17:50 +08:00
|
|
|
ber->ber_debug = * (const int *) invalue;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
1999-11-08 23:38:59 +08:00
|
|
|
case LBER_OPT_BER_REMAINING_BYTES:
|
2000-09-16 09:28:20 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-11-08 23:38:59 +08:00
|
|
|
ber->ber_end = &ber->ber_ptr[* (const ber_len_t *) invalue];
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_TOTAL_BYTES:
|
2000-09-16 09:28:20 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-11-08 23:38:59 +08:00
|
|
|
ber->ber_end = &ber->ber_buf[* (const ber_len_t *) invalue];
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_BYTES_TO_WRITE:
|
2000-09-16 09:28:20 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-11-08 23:38:59 +08:00
|
|
|
ber->ber_ptr = &ber->ber_buf[* (const ber_len_t *) invalue];
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
default:
|
|
|
|
/* bad param */
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|