int inout )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( !ber_log_check( errlvl, loglvl )) {
return 0;
char buf[132];
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
sprintf( buf, "ber_dump: buf 0x%lx, ptr 0x%lx, end 0x%lx\n",
(long) ber->ber_buf,
unsigned int i;
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 )
return( LBER_DEFAULT );
assert( ber != NULL );
assert( len != NULL );
+ assert( BER_VALID( ber ) );
/*
* Any ber element looks like this: tag length contents.
BerElement *ber;
assert( ber_in != NULL );
+ assert( BER_VALID( ber_in ) );
ber = ber_dup( ber_in );
return LBER_ERROR;
}
+ assert( BER_VALID( ber ) );
+
tag = ber_skip_tag( ber, len );
ber_free( ber, 0 );
assert( ber != NULL );
assert( num != NULL );
+ assert( BER_VALID( ber ) );
+
/*
* The tag and length have already been stripped off. We should
* be sitting right before len bytes of 2's complement integer,
unsigned long tag, len;
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT )
return( LBER_DEFAULT );
#endif /* STR_TRANSLATION */
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT )
return( LBER_DEFAULT );
assert( ber != NULL );
assert( buf != NULL );
+ assert( BER_VALID( ber ) );
+
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
*buf = NULL;
return( LBER_DEFAULT );
assert( ber != NULL );
assert( bv != NULL );
+ assert( BER_VALID( ber ) );
+
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
*bv = NULL;
return( LBER_DEFAULT );
assert( buf != NULL );
assert( blen != NULL );
+ assert( BER_VALID( ber ) );
+
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
*buf = NULL;
return( LBER_DEFAULT );
unsigned long len, tag;
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT )
return( LBER_DEFAULT );
assert( ber != NULL );
assert( boolval != NULL );
+ assert( BER_VALID( ber ) );
+
rc = ber_get_int( ber, &longbool );
*boolval = longbool;
assert( len != NULL );
assert( last != NULL );
+ assert( BER_VALID( ber ) );
+
if ( ber->ber_ptr == last ) {
return( LBER_DEFAULT );
}
assert( ber != NULL );
assert( fmt != NULL );
+ assert( BER_VALID( ber ) );
+
fmt_reset = fmt;
ber_log_printf( LDAP_DEBUG_TRACE, ber->ber_debug,
BERTranslateProc decode_proc )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
ber->ber_encode_translate_proc = encode_proc;
ber->ber_decode_translate_proc = decode_proc;
int taglen;
unsigned long ntag;
+ assert( ber != NULL );
+ assert( BER_VALID( ber ) );
+
taglen = ber_calc_taglen( tag );
ntag = AC_HTONL( tag );
unsigned long netlen;
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
/*
* short len if it's less than 128 - one byte giving the len,
long netnum, mask;
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
sign = (num < 0);
ber_put_enum( BerElement *ber, long num, unsigned long tag )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( tag == LBER_DEFAULT )
tag = LBER_ENUMERATED;
ber_put_int( BerElement *ber, long num, unsigned long tag )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( tag == LBER_DEFAULT )
tag = LBER_INTEGER;
assert( ber != NULL );
assert( str != NULL );
+ assert( BER_VALID( ber ) );
+
if ( tag == LBER_DEFAULT )
tag = LBER_OCTETSTRING;
assert( ber != NULL );
assert( bv != NULL );
+ assert( BER_VALID( ber ) );
+
if( bv == NULL ) {
return -1;
}
assert( ber != NULL );
assert( str != NULL );
+ assert( BER_VALID( ber ) );
+
return( ber_put_ostring( ber, str, strlen( str ), tag ));
}
assert( ber != NULL );
assert( str != NULL );
+ assert( BER_VALID( ber ) );
+
if ( tag == LBER_DEFAULT )
tag = LBER_BITSTRING;
{
int taglen;
+ assert( ber != NULL );
+ assert( BER_VALID( ber ) );
+
if ( tag == LBER_DEFAULT )
tag = LBER_NULL;
unsigned char falseval = 0x00U;
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( tag == LBER_DEFAULT )
tag = LBER_BOOLEAN;
Seqorset *new;
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( (new = (Seqorset *) calloc( sizeof(Seqorset), 1 ))
== NULLSEQORSET )
ber_start_seq( BerElement *ber, unsigned long tag )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( tag == LBER_DEFAULT )
tag = LBER_SEQUENCE;
ber_start_set( BerElement *ber, unsigned long tag )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( tag == LBER_DEFAULT )
tag = LBER_SET;
Seqorset **sos = &ber->ber_sos;
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
/*
* If this is the toplevel sequence or set, we need to actually
ber_put_seq( BerElement *ber )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
+
return( ber_put_seqorset( ber ) );
}
ber_put_set( BerElement *ber )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
+
return( ber_put_seqorset( ber ) );
}
assert( ber != NULL );
assert( fmt != NULL );
+ assert( BER_VALID( ber ) );
+
for ( rc = 0; *fmt && rc != -1; fmt++ ) {
switch ( *fmt ) {
case '!': { /* hook */
assert( sb != NULL );
assert( buf != NULL );
+ assert( SOCKBUF_VALID( sb ) );
+
while ( len > 0 ) {
if ( (c = ber_pvt_sb_read( sb, buf, len )) <= 0 ) {
if ( nread > 0 )
assert( ber != NULL );
assert( buf != NULL );
+ assert( BER_VALID( ber ) );
+
nleft = ber->ber_end - ber->ber_ptr;
actuallen = nleft < len ? nleft : len;
assert( ber != NULL );
assert( buf != NULL );
+ assert( BER_VALID( ber ) );
+
if ( nosos || ber->ber_sos == NULL ) {
if ( ber->ber_ptr + len > ber->ber_end ) {
if ( ber_realloc( ber, len ) != 0 )
assert( ber != NULL );
assert( len > 0 );
+ assert( BER_VALID( ber ) );
+
have = (ber->ber_end - ber->ber_buf) / EXBUFSIZ;
need = (len < EXBUFSIZ ? 1 : (len + (EXBUFSIZ - 1)) / EXBUFSIZ);
total = have * EXBUFSIZ + need * EXBUFSIZ;
ber_free( BerElement *ber, int freebuf )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( freebuf && ber->ber_buf != NULL )
free( ber->ber_buf );
ber->ber_buf = NULL;
+ ber->ber_valid = LBER_UNINITIALIZED;
free( (char *) ber );
}
assert( sb != NULL );
assert( ber != NULL );
+ assert( SOCKBUF_VALID( ber ) );
+ assert( BER_VALID( ber ) );
+
if ( ber->ber_rwptr == NULL ) {
ber->ber_rwptr = ber->ber_buf;
}
if ( ber == NULLBER )
return( NULLBER );
+ ber->ber_valid = LBER_VALID_BERELEMENT;
ber->ber_tag = LBER_DEFAULT;
ber->ber_options = options;
ber->ber_debug = ber_int_debug;
+ assert( BER_VALID( ber ) );
return( ber );
}
BerElement *new;
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( (new = ber_alloc_t( ber->ber_options )) == NULL ) {
return( NULL );
*new = *ber;
+ assert( BER_VALID( new ) );
return( new );
}
assert( ber != NULL );
(void) memset( (char *)ber, '\0', sizeof( BerElement ));
+ ber->ber_valid = LBER_VALID_BERELEMENT;
ber->ber_tag = LBER_DEFAULT;
ber->ber_options = (char) options;
ber->ber_debug = ber_int_debug;
+
+ assert( BER_VALID( ber ) );
}
/* New C-API ber_init() */
ber_reset( BerElement *ber, int was_writing )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ( was_writing ) {
ber->ber_end = ber->ber_ptr;
unsigned int i;
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
if ( ber_pvt_sb_read( sb, (char *) &xbyte, 1 ) != 1 )
return( LBER_DEFAULT );
assert( len != NULL );
assert( ber != NULL );
- if ( ber->ber_debug ) {
- ber_log_printf( LDAP_DEBUG_TRACE, ber->ber_debug,
- "ber_get_next\n" );
- }
-
+ assert( SOCKBUF_VALID( sb ) );
+ assert( BER_VALID( ber ) );
+
+ ber_log_printf( LDAP_DEBUG_TRACE, ber->ber_debug,
+ "ber_get_next\n" );
+
/*
* Any ber element looks like this: tag length contents.
* Assuming everything's ok, we return the tag byte (we
void ber_clear( BerElement *ber, int freebuf )
{
assert( ber != NULL );
+ assert( BER_VALID( ber ) );
if ((freebuf) && (ber->ber_buf))
free( ber->ber_buf );
ber->ber_buf = NULL;
ber->ber_rwptr = NULL;
ber->ber_end = NULL;
+
+ ber->ber_valid = LBER_UNINITIALIZED;
}
LDAP_BEGIN_DECL
-extern int ber_int_debug;
-#define ber_log_printf ber_pvt_log_printf
-
struct lber_options {
- short lbo_item_type;
-#define LBER_ITEM_BERELEMENT 1
-#define LBER_ITEM_SOCKBUF 2
- short lbo_options;
- int lbo_debug;
+ short lbo_valid;
+#define LBER_UNINITIALIZED 0x0
+#define LBER_INITIALIZED 0x1
+#define LBER_VALID_BERELEMENT 0x2
+#define LBER_VALID_SOCKBUF 0x3
+
+ unsigned short lbo_options;
+ int lbo_debug;
};
+extern struct lber_options ber_int_options;
+#define ber_int_debug ber_int_options.lbo_debug
+
struct berelement {
struct lber_options ber_opts;
-#define ber_item_type ber_opts.lbo_item_type
+#define ber_valid ber_opts.lbo_valid
#define ber_options ber_opts.lbo_options
#define ber_debug ber_opts.lbo_debug
BERTranslateProc ber_encode_translate_proc;
BERTranslateProc ber_decode_translate_proc;
};
+#define BER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
#define NULLBER ((BerElement *) 0)
+#define ber_pvt_ber_bytes(ber) ((ber)->ber_ptr - (ber)->ber_buf)
+#define ber_pvt_ber_remaining(ber) ((ber)->ber_end - (ber)->ber_ptr)
+
struct sockbuf;
struct sockbuf_io {
typedef struct sockbuf_sec Sockbuf_Sec;
typedef struct sockbuf_buf Sockbuf_Buf;
-#define ber_pvt_sb_get_desc( sb ) ((sb)->sb_sd)
-#define ber_pvt_sb_set_desc( sb, val ) ((sb)->sb_sd =(val))
-#define ber_pvt_sb_in_use( sb ) ((sb)->sb_sd!=-1)
+extern Sockbuf_IO ber_pvt_sb_io_tcp;
+extern Sockbuf_IO ber_pvt_sb_io_udp;
-#ifdef USE_SASL
-#define ber_pvt_sb_data_ready( sb ) \
-(((sb)->sb_buf_ready) || ((sb)->sb_trans_ready) || ((sb)->sb_sec_ready))
-#else
-#define ber_pvt_sb_data_ready( sb ) \
-(((sb)->sb_buf_ready) || ((sb)->sb_trans_ready))
-#endif
struct sockbuf {
struct lber_options sb_opts;
-#define sb_item_type sb_opts.lbo_item_type
+#define sb_valid sb_opts.lbo_valid
#define sb_options sb_opts.lbo_options
#define sb_debug sb_opts.lbo_debug
long sb_sec_prev_len;
#endif
};
+#define SOCKBUF_VALID(ber) ((sb)->sb_valid==LBER_VALID_SOCKBUF)
+
+/* these should be internal ie: ber_int_* */
+#define ber_pvt_sb_get_desc( sb ) ((sb)->sb_sd)
+#define ber_pvt_sb_set_desc( sb, val ) ((sb)->sb_sd =(val))
+
+#define ber_pvt_sb_in_use( sb ) ((sb)->sb_sd!=-1)
+
+#ifdef USE_SASL
+#define ber_pvt_sb_data_ready( sb ) \
+(((sb)->sb_buf_ready) || ((sb)->sb_trans_ready) || ((sb)->sb_sec_ready))
+#else
+#define ber_pvt_sb_data_ready( sb ) \
+(((sb)->sb_buf_ready) || ((sb)->sb_trans_ready))
+#endif
#define READBUFSIZ 8192
/*
* bprint.c
*/
+#define ber_log_printf ber_pvt_log_printf
+
LDAP_F( int )
ber_log_bprint LDAP_P((
int errlvl,
/* sockbuf.c */
+/* these should be ber_int*() functions */
+
LDAP_F( int )
ber_pvt_sb_init LDAP_P(( Sockbuf *sb ));
LDAP_F( void * )
ber_pvt_sb_udp_get_src LDAP_P((Sockbuf *sb ));
-extern Sockbuf_IO ber_pvt_sb_io_tcp;
-extern Sockbuf_IO ber_pvt_sb_io_udp;
#endif /* _LBER_INT_H */
#include "lber-int.h"
-int ber_int_debug = 0;
+struct lber_options ber_int_options = {
+ LBER_UNINITIALIZED, 0, 0 };
int
ber_get_option(
switch(option) {
case LBER_OPT_BER_OPTIONS:
+ assert( BER_VALID( ber ) );
* (int *) outvalue = ber->ber_options;
return LBER_OPT_SUCCESS;
case LBER_OPT_BER_DEBUG:
+ assert( BER_VALID( ber ) );
* (int *) outvalue = ber->ber_debug;
return LBER_OPT_SUCCESS;
switch(option) {
case LBER_OPT_BER_OPTIONS:
+ assert( BER_VALID( ber ) );
ber->ber_options = * (int *) invalue;
return LBER_OPT_SUCCESS;
case LBER_OPT_BER_DEBUG:
+ assert( BER_VALID( ber ) );
ber->ber_debug = * (int *) invalue;
return LBER_OPT_SUCCESS;
update_status( Sockbuf *sb )
{
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
sb->sb_buf_ready = (sb->sb_buf.buf_ptr < sb->sb_buf.buf_end);
#ifdef USE_SASL
#endif
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
obr = sb->sb_buf_ready;
#ifdef USE_SASL
assert( buf != NULL );
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( sb->sb_sec );
assert( sb->sb_sec->sbs_release );
assert( buf != NULL );
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
+
assert( sb->sb_sec_out.buf_end == 0 );
assert( sb->sb_sec_out.buf_ptr == 0 );
assert( buf != NULL );
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( status_is_ok(sb) );
if (blen) {
void ber_sockbuf_free( Sockbuf *sb )
{
assert(sb != NULL);
+ assert( SOCKBUF_VALID( sb ) );
ber_pvt_sb_destroy( sb );
free(sb);
}
assert( buf_arg != NULL );
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( status_is_ok(sb) );
#if 0
/* breaks slapd :-< */
long to_go;
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
to_go = sb->sb_sec_out.buf_end - sb->sb_sec_out.buf_ptr;
assert( to_go > 0 );
{
long ret;
long len = len_arg;
+
+ assert( buf != NULL );
+ assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( status_is_ok(sb) );
#if 0
/* unfortunately breaks slapd */
int ret;
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( sb->sb_io );
assert( sb->sb_io->sbi_close );
assert( status_is_ok(sb) );
int ber_pvt_sb_set_readahead( Sockbuf *sb, int rh )
{
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( status_is_ok(sb) );
sb->sb_read_ahead = (rh!=0);
return 0;
int ber_pvt_sb_set_nonblock( Sockbuf *sb, int nb )
{
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( status_is_ok(sb) );
if (nb) {
sb->sb_non_block = 1;
{
assert( sb != NULL);
- sb->sb_item_type=LBER_ITEM_SOCKBUF;
+ sb->sb_valid=LBER_VALID_SOCKBUF;
sb->sb_options = 0;
sb->sb_debug = 0;
sb->sb_trans_ready = 0;
sb->sb_sdata = NULL;
sb->sb_sec = NULL;
sb->sb_sec_prev_len = 0;
-#endif
+#endif
+
+ assert( SOCKBUF_VALID( sb ) );
return 0;
}
int ber_pvt_sb_destroy( Sockbuf *sb )
{
assert( sb != NULL);
+ assert( SOCKBUF_VALID(sb) );
#ifdef USE_SASL
ber_pvt_sb_clear_sec(sb);
sockbuf_buf_destroy( &(sb->sb_sec_buf_in) );
{
int len;
assert( sb != NULL);
+ assert( SOCKBUF_VALID( *sb ) );
if ((sb->sb_sec) || (sec==NULL))
return -1;
int ber_pvt_sb_clear_sec( Sockbuf *sb )
{
assert( sb != NULL);
+ assert( SOCKBUF_VALID( sb ) );
if (sb->sb_buf.buf_ptr!=0)
return -1;
int ber_pvt_sb_set_io( Sockbuf *sb, Sockbuf_IO *trans, void *arg )
{
assert( sb != NULL);
+ assert( SOCKBUF_VALID( sb ) );
assert( sb->sb_io == &sb_IO_None );
if (trans==NULL)
int ber_pvt_sb_clear_io( Sockbuf *sb )
{
assert( sb != NULL);
+ assert( SOCKBUF_VALID( sb ) );
+
if (sb->sb_io==&sb_IO_None)
return -1;
stream_read( Sockbuf *sb, void *buf, long len )
{
assert( sb != NULL);
+ assert( SOCKBUF_VALID( sb ) );
#if defined(MACOS)
/*
stream_write( Sockbuf *sb, void *buf, long len )
{
assert( sb != NULL);
+ assert( SOCKBUF_VALID( sb ) );
#if defined(MACOS)
/*
stream_close( Sockbuf *sb )
{
assert( sb != NULL);
+ assert( SOCKBUF_VALID( sb ) );
tcp_close( ber_pvt_sb_get_desc( sb ) );
return 0;
}
dgram_setup( Sockbuf *sb, void *arg )
{
assert( sb != NULL);
+ assert( SOCKBUF_VALID( sb ) );
+
sb->sb_iodata = malloc( sizeof( struct dgram_data ) );
if (sb->sb_iodata==NULL)
return -1;
dgram_release( Sockbuf *sb )
{
assert( sb != NULL);
+ assert( SOCKBUF_VALID( sb ) );
+
free( sb->sb_iodata );
return 0;
}
struct dgram_data *dd;
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( buf != NULL );
dd = (struct dgram_data *)(sb->sb_iodata);
struct dgram_data *dd;
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( buf != NULL );
dd = (struct dgram_data *)(sb->sb_iodata);
dgram_close( Sockbuf *sb )
{
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
tcp_close( ber_pvt_sb_get_desc(sb) );
return 0;
{
struct dgram_data *dd;
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( sb->sb_io == &ber_pvt_sb_io_udp );
dd = (struct dgram_data *) (sb->sb_iodata);
memcpy( &(dd->dst), addr, sizeof( struct sockaddr ) );
void *ber_pvt_sb_udp_get_src( Sockbuf *sb )
{
struct dgram_data *dd;
+
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
assert( sb->sb_io == &ber_pvt_sb_io_udp );
dd = (struct dgram_data *) (sb->sb_iodata);
return &(dd->src);
have_no_read( Sockbuf *sb, void *buf, long len )
{
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
+
ber_log_printf( LDAP_DEBUG_ANY, ber_int_debug,
"warning: reading from uninitialized sockbuf\n");
errno = EBADF;
have_no_write( Sockbuf *sb, void *buf, long len )
{
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
+
ber_log_printf( LDAP_DEBUG_ANY, ber_int_debug,
"warning: writing to uninitialized sockbuf\n");
errno = EBADF;
have_no_close( Sockbuf *sb )
{
assert( sb != NULL );
+ assert( SOCKBUF_VALID( sb ) );
+
assert( 0 );
return -1;
}
*ctrls = NULL;
- len = ber->ber_end - ber->ber_ptr;
+ len = ber_pvt_ber_remaining(ber);
if( len == 0) {
/* no controls */
#include "ldap-int.h"
#include "ldapconfig.h"
-struct ldapoptions openldap_ldap_global_options = { LDAP_DEBUG_NONE };
+struct ldapoptions ldap_int_global_options =
+ { LDAP_UNINITIALIZED, LDAP_DEBUG_NONE };
#undef gopts
-#define gopts openldap_ldap_global_options
-
-int openldap_ldap_initialized = 0;
+#define gopts ldap_int_global_options
#define ATTR_NONE 0
#define ATTR_BOOL 1
}
}
-void openldap_ldap_initialize( void )
+void ldap_int_initialize( void )
{
- if ( openldap_ldap_initialized ) {
+ if ( gopts.ldo_valid == LDAP_INITIALIZED ) {
return;
}
LDAP_BOOL_SET(&gopts, LDAP_BOOL_REFERRALS);
- openldap_ldap_initialized = 1;
+ gopts.ldo_valid = LDAP_INITIALIZED;
if( getenv("LDAPNOINIT") != NULL ) {
return;
#include "../liblber/lber-int.h"
-#define ldap_debug (openldap_ldap_global_options.ldo_debug)
+#define ldap_debug (ldap_int_global_options.ldo_debug)
#undef Debug
#define Debug( level, fmt, arg1, arg2, arg3 ) \
ldap_log_printf( NULL, (level), (fmt), (arg1), (arg2), (arg3) )
* which have global defaults.
*/
struct ldapoptions {
+ short ldo_valid;
+#define LDAP_UNINITIALIZED 0x0
+#define LDAP_INITIALIZED 0x1
+#define LDAP_VALID_SESSION 0x2
+
int ldo_debug;
int ldo_version; /* version to connect at */
char* ldo_defbase;
char* ldo_defhost;
+#ifdef LDAP_CONNECTIONLESS
int ldo_cldaptries; /* connectionless search retry count */
int ldo_cldaptimeout;/* time between retries */
+#endif
+
int ldo_refhoplimit; /* limit on referral nesting */
/* LDAPv3 server and client controls */
LDAPServer *lconn_server;
char *lconn_krbinstance;
struct ldap_conn *lconn_next;
- BerElement lconn_ber;/* ber receiving on this conn. */
+ BerElement *lconn_ber;/* ber receiving on this conn. */
} LDAPConn;
struct ldapoptions ld_options;
+#define ld_valid ld_options.ldo_valid
+#define ld_debug ld_options.ldo_debug
+
#define ld_deref ld_options.ldo_deref
#define ld_timelimit ld_options.ldo_timelimit
#define ld_sizelimit ld_options.ldo_sizelimit
LDAPCache *ld_cache; /* non-null if cache is initialized */
/* stuff used by connectionless searches. */
+
char *ld_cldapdn; /* DN used in connectionless search */
int ld_cldapnaddr; /* number of addresses */
void **ld_cldapaddrs;/* addresses to send request to */
char **passwdp, int *authmethodp, int freeit );
/* routine to get info needed for re-bind */
};
+#define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
/*
* in init.c
*/
-extern int openldap_ldap_initialized;
-extern struct ldapoptions openldap_ldap_global_options;
-void openldap_ldap_initialize LDAP_P((void));
+
+extern struct ldapoptions ldap_int_global_options;
+void ldap_int_initialize LDAP_P((void));
/*
# End Source File
# Begin Source File
+SOURCE=..\..\include\ldap_schema.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\include\ldapconfig.h
# End Source File
# Begin Source File
# End Source File
# Begin Source File
+SOURCE=.\schema.c
+# End Source File
+# Begin Source File
+
SOURCE=.\search.c
# End Source File
# Begin Source File
{
LDAP *ld;
- if(!openldap_ldap_initialized) {
- openldap_ldap_initialize();
+ if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) {
+ ldap_int_initialize();
}
Debug( LDAP_DEBUG_TRACE, "ldap_init\n", 0, 0, 0 );
}
/* copy the global options */
- memcpy(&ld->ld_options, &openldap_ldap_global_options,
+ memcpy(&ld->ld_options, &ldap_int_global_options,
sizeof(ld->ld_options));
+ ld->ld_valid = LDAP_VALID_SESSION;
+
/* but not pointers to malloc'ed items */
ld->ld_options.ldo_defbase = NULL;
ld->ld_options.ldo_defhost = NULL;
ld->ld_options.ldo_defhost = strdup( defhost );
} else {
ld->ld_options.ldo_defhost = strdup(
- openldap_ldap_global_options.ldo_defhost);
+ ldap_int_global_options.ldo_defhost);
}
if ( ld->ld_options.ldo_defhost == NULL ) {
return( NULL );
}
- if ( openldap_ldap_global_options.ldo_defbase != NULL ) {
+ if ( ldap_int_global_options.ldo_defbase != NULL ) {
ld->ld_options.ldo_defbase = strdup(
- openldap_ldap_global_options.ldo_defbase);
+ ldap_int_global_options.ldo_defbase);
}
if (( ld->ld_selectinfo = ldap_new_select_info()) == NULL ) {
{
struct ldapoptions *lo;
- if(!openldap_ldap_initialized) {
- openldap_ldap_initialize();
+ if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) {
+ ldap_int_initialize();
}
if(outvalue == NULL) {
/* no place to get to */
- return -1;
+ return LDAP_OPT_ERROR;
}
if(ld == NULL) {
- lo = &openldap_ldap_global_options;
+ lo = &ldap_int_global_options;
+
} else {
+ assert( LDAP_VALID( ld ) );
+
+ if( !LDAP_VALID( ld ) ) {
+ return LDAP_OPT_ERROR;
+ }
+
lo = &ld->ld_options;
}
if(info == NULL) {
/* outvalue must point to an apiinfo structure */
- return -1;
+ return LDAP_OPT_ERROR;
}
if(info->ldapai_info_version != LDAP_API_INFO_VERSION) {
/* api info version mismatch */
info->ldapai_info_version = LDAP_API_INFO_VERSION;
- return -1;
+ return LDAP_OPT_ERROR;
}
info->ldapai_api_version = LDAP_API_VERSION;
info->ldapai_vendor_name = strdup(LDAP_VENDOR_NAME);
info->ldapai_vendor_version = LDAP_VENDOR_VERSION;
- return 0;
+ return LDAP_OPT_SUCCESS;
} break;
case LDAP_OPT_DESC:
}
* (int *) outvalue = ber_pvt_sb_get_desc( &(ld->ld_sb) );
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_DEREF:
* (int *) outvalue = lo->ldo_deref;
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_SIZELIMIT:
* (int *) outvalue = lo->ldo_sizelimit;
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_TIMELIMIT:
* (int *) outvalue = lo->ldo_timelimit;
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_REFERRALS:
* (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS) ==
LDAP_OPT_ON);
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_RESTART:
* (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART) ==
LDAP_OPT_ON);
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_DNS: /* LDAPv2 */
* (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_DNS) ==
LDAP_OPT_ON);
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_PROTOCOL_VERSION:
if ((ld != NULL) && ld->ld_version) {
} else {
* (int *) outvalue = lo->ldo_version;
}
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_SERVER_CONTROLS:
* (LDAPControl ***) outvalue =
ldap_controls_dup( lo->ldo_sctrls );
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_CLIENT_CONTROLS:
* (LDAPControl ***) outvalue =
ldap_controls_dup( lo->ldo_cctrls );
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_HOST_NAME:
/*
*/
* (char **) outvalue = strdup(lo->ldo_defhost);
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_ERROR_NUMBER:
if(ld == NULL) {
break;
}
* (int *) outvalue = ld->ld_errno;
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_ERROR_STRING:
if(ld == NULL) {
* (char **) outvalue = strdup(ld->ld_error);
}
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_MATCH_STRING:
if(ld == NULL) {
LDAPAPIFeatureInfo *info = (LDAPAPIFeatureInfo *) outvalue;
int i;
- if(info == NULL) return -1;
+ if(info == NULL) return LDAP_OPT_ERROR;
if(info->ldapaif_info_version != LDAP_FEATURE_INFO_VERSION) {
/* api info version mismatch */
info->ldapaif_info_version = LDAP_FEATURE_INFO_VERSION;
- return -1;
+ return LDAP_OPT_ERROR;
}
- if(info->ldapaif_name == NULL) return -1;
+ if(info->ldapaif_name == NULL) return LDAP_OPT_ERROR;
for(i=0; features[i].ldapaif_name != NULL; i++) {
if(!strcmp(info->ldapaif_name, features[i].ldapaif_name)) {
info->ldapaif_version =
features[i].ldapaif_version;
- return 0;
+ return LDAP_OPT_SUCCESS;
}
}
}
case LDAP_OPT_DEBUG_LEVEL:
* (int *) outvalue = lo->ldo_debug;
- return 0;
+ return LDAP_OPT_SUCCESS;
default:
/* bad param */
break;
}
- return -1;
+ return LDAP_OPT_ERROR;
}
int
{
struct ldapoptions *lo;
- if(!openldap_ldap_initialized) {
- openldap_ldap_initialize();
+ if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) {
+ ldap_int_initialize();
}
if(ld == NULL) {
- lo = &openldap_ldap_global_options;
+ lo = &ldap_int_global_options;
+
} else {
+ assert( LDAP_VALID( ld ) );
+
+ if( !LDAP_VALID( ld ) ) {
+ return LDAP_OPT_ERROR;
+ }
+
lo = &ld->ld_options;
}
} else {
LDAP_BOOL_CLR(lo, LDAP_BOOL_REFERRALS);
}
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_RESTART:
if(invalue == LDAP_OPT_ON) {
} else {
LDAP_BOOL_CLR(lo, LDAP_BOOL_RESTART);
}
- return 0;
+ return LDAP_OPT_SUCCESS;
}
if(invalue == NULL) {
/* no place to set from */
- return -1;
+ return LDAP_OPT_ERROR;
}
switch(option) {
case LDAP_OPT_DEREF:
lo->ldo_deref = * (int *) invalue;
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_SIZELIMIT:
lo->ldo_sizelimit = * (int *) invalue;
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_TIMELIMIT:
lo->ldo_timelimit = * (int *) invalue;
- return 0;
+ return LDAP_OPT_SUCCESS;
case LDAP_OPT_PROTOCOL_VERSION: {
int vers = * (int *) invalue;
break;
}
ld->ld_version = vers;
- } return 0;
+ } return LDAP_OPT_SUCCESS;
case LDAP_OPT_SERVER_CONTROLS: {
LDAPControl **controls = (LDAPControl **) invalue;
if( controls == NULL || *controls == NULL ) {
lo->ldo_sctrls = NULL;
- return 0;
+ return LDAP_OPT_SUCCESS;
}
lo->ldo_sctrls =
/* memory allocation error ? */
break;
}
- } return 0;
+ } return LDAP_OPT_SUCCESS;
case LDAP_OPT_CLIENT_CONTROLS: {
LDAPControl **controls = (LDAPControl **) invalue;
if( controls == NULL || *controls == NULL ) {
lo->ldo_cctrls = NULL;
- return 0;
+ return LDAP_OPT_SUCCESS;
}
lo->ldo_cctrls =
/* memory allocation error ? */
break;
}
- } return 0;
+ } return LDAP_OPT_SUCCESS;
case LDAP_OPT_HOST_NAME: {
char* host = (char *) invalue;
if(host != NULL) {
lo->ldo_defhost = strdup(host);
- return 0;
+ return LDAP_OPT_SUCCESS;
}
if(ld == NULL) {
* updated to the current global default
*/
lo->ldo_defhost = strdup(
- openldap_ldap_global_options.ldo_defhost);
+ ldap_int_global_options.ldo_defhost);
}
- } return 0;
+ } return LDAP_OPT_SUCCESS;
case LDAP_OPT_ERROR_NUMBER: {
int err = * (int *) invalue;
}
ld->ld_errno = err;
- } return 0;
+ } return LDAP_OPT_SUCCESS;
case LDAP_OPT_ERROR_STRING: {
char* err = (char *) invalue;
}
ld->ld_error = strdup(err);
- } return 0;
+ } return LDAP_OPT_SUCCESS;
case LDAP_OPT_API_FEATURE_INFO:
/* read-only */
case LDAP_OPT_DEBUG_LEVEL:
lo->ldo_debug = * (int *) invalue;
- return 0;
+ return LDAP_OPT_SUCCESS;
default:
/* bad param */
break;
}
- return -1;
+ return LDAP_OPT_ERROR;
}
}
ldap_close_connection( lc->lconn_sb );
ber_pvt_sb_destroy( lc->lconn_sb );
- ber_clear( &lc->lconn_ber, 1 );
+ if( lc->lconn_ber != NULL ) {
+ ber_free( lc->lconn_ber, 1 );
+ }
}
prevlc = NULL;
for ( tmplc = ld->ld_conns; tmplc != NULL;
*ports++ = '\0';
srv->lsrv_port = atoi( ports );
} else {
- srv->lsrv_port = openldap_ldap_global_options.ldo_defport;
+ srv->lsrv_port = ldap_int_global_options.ldo_defport;
}
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
} else {
assert( ld != NULL );
assert( lc != NULL );
- ber = &lc->lconn_ber;
-
Debug( LDAP_DEBUG_TRACE, "read1msg\n", 0, 0, 0 );
-#if 0
- ber_init_w_nullc( &ber, 0 );
- ldap_set_ber_options( ld, &ber );
-#endif
+ if ( lc->lconn_ber == NULLBER ) {
+ lc->lconn_ber = ldap_alloc_ber_with_options(ld);
+
+ if( lc->lconn_ber == NULL ) {
+ return -1;
+ }
+ }
+
+ ber = lc->lconn_ber;
+ assert( BER_VALID (ber) );
/* get the next message */
errno = 0;
return -1;
}
+ /*
+ * We read a complete message.
+ * The connection should no longer need this ber.
+ */
+ lc->lconn_ber = NULLBER;
+
/* message id */
if ( ber_get_int( ber, &id ) == LBER_ERROR ) {
+ ber_free( ber, 1 );
ld->ld_errno = LDAP_DECODING_ERROR;
return( -1 );
}
/* if it's been abandoned, toss it */
if ( ldap_abandoned( ld, (int)id ) ) {
- ber_clear( ber, 1 ); /* gack! */
+ ber_free( ber, 1 );
return( -2 ); /* continue looking */
}
Debug( LDAP_DEBUG_ANY,
"no request for response with msgid %ld (tossing)\n",
id, 0, 0 );
- ber_clear( ber, 1 ); /* gack! */
+ ber_free( ber, 1 );
return( -2 ); /* continue looking */
}
- Debug( LDAP_DEBUG_TRACE, "ldap_read: %s msgid %ld, original id %d\n",
- ( tag == LDAP_RES_SEARCH_ENTRY ) ? "entry" :
- ( tag == LDAP_RES_SEARCH_REFERENCE ) ? "reference" : "result",
- id, lr->lr_origid );
- id = lr->lr_origid;
/* the message type */
if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
+ ber_free( ber, 1 );
return( -1 );
}
+ Debug( LDAP_DEBUG_TRACE, "ldap_read: %s msgid %ld, original id %d\n",
+ ( tag == LDAP_RES_SEARCH_ENTRY ) ? "entry" :
+ ( tag == LDAP_RES_SEARCH_REFERENCE ) ? "reference" : "result",
+ id, lr->lr_origid );
+
+ id = lr->lr_origid;
refer_cnt = 0;
hadref = simple_request = 0;
rc = -2; /* default is to keep looking (no response found) */
"read1msg: %d new referrals\n", refer_cnt, 0, 0 );
if ( refer_cnt != 0 ) { /* chasing referrals */
- ber_clear( ber, 1 ); /* gack! */
+ ber_free( ber, 1 );
+ ber = NULL;
if ( refer_cnt < 0 ) {
return( -1 ); /* fatal error */
}
simple_request = ( hadref ? 0 : 1 );
} else {
/* request with referrals or child request */
- ber_clear( ber, 1 ); /* gack! */
+ ber_free( ber, 1 );
+ ber = NULL;
}
while ( lr->lr_parent != NULL ) {
lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
lr->lr_res_matched ? lr->lr_res_matched : "" );
if ( !simple_request ) {
- ber_clear( ber, 1 ); /* gack! */
+ ber_free( ber, 1 );
+ ber = NULL;
if ( build_result_ber( ld, ber, lr )
== LBER_ERROR ) {
ld->ld_errno = LDAP_NO_MEMORY;
}
}
- if ( ber->ber_buf == NULL ) {
+ if ( ber == NULL ) {
return( rc );
}
}
new->lm_msgid = (int)id;
new->lm_msgtype = tag;
- new->lm_ber = ber_dup( ber );
- ber_clear( ber, 0 ); /* don't kill buffer */
+ new->lm_ber = ber;
#ifndef LDAP_NOCACHE
if ( ld->ld_cache != NULL ) {
return( -1 );
}
+ assert( BER_VALID( ber ) );
+
/* fill it in */
if ( ber_printf( ber, "{it{ists}}", ++ld->ld_msgid, LDAP_REQ_BIND,
ld->ld_version, dn, LDAP_AUTH_SIMPLE, passwd ) == -1 ) {
#include "portable.h"
+#include <stdio.h>
+#include <stdlib.h>
+
#include <ac/ctype.h>
#include <ac/string.h>
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
+
#include <lber.h>
#include <ldap.h>
#include <ldap_schema.h>
-#include <stdio.h>
/*
* When pretty printing the entities we will be appending to a buffer.
err = -1;
} else {
if ( ludp->lud_port == 0 ) {
- srv->lsrv_port = openldap_ldap_global_options.ldo_defport;
+ srv->lsrv_port = ldap_int_global_options.ldo_defport;
} else {
srv->lsrv_port = ludp->lud_port;
}
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
char *matched;
Entry *e;
- int err;
Debug(LDAP_DEBUG_ARGS, "ldbm_back_modify:\n", 0, 0, 0);
}
-
-
/* change the entry itself */
if ( id2entry_add( be, e ) != 0 ) {
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
ldap_pvt_thread_mutex_lock( &conn->c_mutex );
/* write the pdu */
- bytes = ber->ber_ptr - ber->ber_buf;
+ bytes = ber_pvt_ber_bytes( ber );
while ( 1 ) {
int err;
return( 1 );
}
- bytes = ber->ber_ptr - ber->ber_buf;
+ bytes = ber_pvt_ber_bytes( ber );
/* write only one pdu at a time - wait til it's our turn */
ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );