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/>.
|
|
|
|
*
|
2006-01-04 07:11:52 +08:00
|
|
|
* Copyright 1998-2006 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-26 07:17:08 +08:00
|
|
|
|
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"
|
|
|
|
|
2003-06-06 21:50:01 +08:00
|
|
|
char ber_pvt_opt_on; /* used to get a non-NULL address for *_OPT_ON */
|
|
|
|
|
1999-05-29 03:33:05 +08:00
|
|
|
struct lber_options ber_int_options = {
|
2005-11-13 02:26:17 +08:00
|
|
|
LBER_UNINITIALIZED, 0, 0 };
|
1998-12-22 09:34:01 +08:00
|
|
|
|
2005-07-22 03:10:16 +08:00
|
|
|
static BerMemoryFunctions ber_int_memory_fns_datum;
|
|
|
|
|
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)
|
|
|
|
{
|
2001-07-22 07:13:04 +08:00
|
|
|
const BerElement *ber;
|
|
|
|
const Sockbuf *sb;
|
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) {
|
2005-07-21 03:07:04 +08:00
|
|
|
switch ( option ) {
|
|
|
|
case 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;
|
2005-07-21 03:07:04 +08:00
|
|
|
|
|
|
|
case LBER_OPT_MEMORY_INUSE:
|
2000-07-05 02:47:06 +08:00
|
|
|
/* 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
|
2005-11-13 02:26:17 +08:00
|
|
|
* (int *) outvalue = ber_int_meminuse;
|
2000-07-05 02:47:06 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
#else
|
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
#endif
|
2005-07-21 03:26:46 +08:00
|
|
|
|
2005-07-21 03:07:04 +08:00
|
|
|
case LBER_OPT_LOG_PRINT_FILE:
|
2000-10-13 04:01:12 +08:00
|
|
|
*((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:
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_VALID( ber ) );
|
1998-12-22 09:34:01 +08:00
|
|
|
* (int *) outvalue = ber->ber_options;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_DEBUG:
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_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:
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_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:
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_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:
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_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;
|
|
|
|
|
2003-04-09 21:25:11 +08:00
|
|
|
case LBER_OPT_BER_MEMCTX:
|
|
|
|
assert( LBER_VALID( ber ) );
|
|
|
|
*((void **) outvalue) = ber->ber_memctx;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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) {
|
2005-07-21 03:07:04 +08:00
|
|
|
switch ( option ) {
|
|
|
|
case 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
|
|
|
|
2005-07-21 03:07:04 +08:00
|
|
|
case 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;
|
2005-07-21 03:07:04 +08:00
|
|
|
|
|
|
|
case LBER_OPT_LOG_PRINT_FILE:
|
2000-05-11 17:39:33 +08:00
|
|
|
ber_pvt_err_file = (void *) invalue;
|
|
|
|
return LBER_OPT_SUCCESS;
|
2005-07-21 03:07:04 +08:00
|
|
|
|
|
|
|
case LBER_OPT_MEMORY_INUSE:
|
2000-07-05 02:47:06 +08:00
|
|
|
/* 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
|
2005-11-13 02:26:17 +08:00
|
|
|
ber_int_meminuse = * (int *) invalue;
|
2000-07-05 02:47:06 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
#else
|
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
#endif
|
2005-11-13 02:26:17 +08:00
|
|
|
case LBER_OPT_MEMORY_FNS:
|
|
|
|
if ( ber_int_memory_fns == NULL )
|
|
|
|
{
|
|
|
|
const BerMemoryFunctions *f =
|
|
|
|
(const BerMemoryFunctions *) invalue;
|
|
|
|
/* make sure all functions are provided */
|
|
|
|
if(!( f->bmf_malloc && f->bmf_calloc
|
|
|
|
&& f->bmf_realloc && f->bmf_free ))
|
|
|
|
{
|
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ber_int_memory_fns = &ber_int_memory_fns_datum;
|
|
|
|
|
|
|
|
AC_MEMCPY(ber_int_memory_fns, f,
|
|
|
|
sizeof(BerMemoryFunctions));
|
|
|
|
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-07-21 03:07:04 +08:00
|
|
|
case LBER_OPT_LOG_PROC:
|
2000-10-13 04:01:12 +08:00
|
|
|
ber_int_log_proc = (BER_LOG_FN)invalue;
|
2005-07-21 03:07:04 +08:00
|
|
|
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:
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_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:
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_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:
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_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:
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_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:
|
2001-07-22 07:13:04 +08:00
|
|
|
assert( LBER_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;
|
|
|
|
|
2003-04-09 21:25:11 +08:00
|
|
|
case LBER_OPT_BER_MEMCTX:
|
|
|
|
assert( LBER_VALID( ber ) );
|
2003-05-29 06:17:08 +08:00
|
|
|
ber->ber_memctx = *(void **)invalue;
|
2003-04-09 21:25:11 +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;
|
|
|
|
}
|