1998-12-29 04:38:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-12-29 04:46:13 +08:00
|
|
|
/* Portions
|
1998-10-26 09:18:41 +08:00
|
|
|
* Copyright (c) 1990 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LBER_INT_H
|
|
|
|
#define _LBER_INT_H
|
|
|
|
|
|
|
|
#include "lber.h"
|
1998-12-22 09:34:01 +08:00
|
|
|
#include "ldap_log.h"
|
1999-01-26 09:21:35 +08:00
|
|
|
#include "lber_pvt.h"
|
1998-10-26 09:18:41 +08:00
|
|
|
|
|
|
|
LDAP_BEGIN_DECL
|
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
/* these have to match lber types settings */
|
|
|
|
#define LBER_INT_HTON(i) AC_HTONL(i)
|
|
|
|
#define LBER_INT_NTOH(i) AC_NTOHL(i)
|
|
|
|
#define LBER_LEN_HTON(l) AC_HTONL(l)
|
|
|
|
#define LBER_LEN_NTOH(l) AC_NTOHL(l)
|
|
|
|
#define LBER_TAG_HTON(t) AC_HTONL(t)
|
|
|
|
#define LBER_TAG_NTOH(t) AC_NTOHL(t)
|
|
|
|
|
|
|
|
|
1999-03-06 10:36:21 +08:00
|
|
|
struct lber_options {
|
1999-05-29 03:33:05 +08:00
|
|
|
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;
|
1999-03-06 10:36:21 +08:00
|
|
|
};
|
|
|
|
|
1999-05-29 03:33:05 +08:00
|
|
|
extern struct lber_options ber_int_options;
|
|
|
|
#define ber_int_debug ber_int_options.lbo_debug
|
|
|
|
|
1998-10-26 09:49:56 +08:00
|
|
|
struct berelement {
|
1999-03-06 10:36:21 +08:00
|
|
|
struct lber_options ber_opts;
|
1999-05-29 03:33:05 +08:00
|
|
|
#define ber_valid ber_opts.lbo_valid
|
1999-03-06 10:36:21 +08:00
|
|
|
#define ber_options ber_opts.lbo_options
|
|
|
|
#define ber_debug ber_opts.lbo_debug
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_tag_t ber_usertag;
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_tag_t ber_tag;
|
|
|
|
ber_len_t ber_len;
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
char *ber_buf;
|
|
|
|
char *ber_ptr;
|
|
|
|
char *ber_end;
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
struct seqorset *ber_sos;
|
|
|
|
char *ber_rwptr;
|
|
|
|
BERTranslateProc ber_encode_translate_proc;
|
|
|
|
BERTranslateProc ber_decode_translate_proc;
|
1998-10-26 09:49:56 +08:00
|
|
|
};
|
1999-05-29 03:33:05 +08:00
|
|
|
#define BER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
|
1999-06-19 07:53:05 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
|
1999-05-29 03:33:05 +08:00
|
|
|
#define ber_pvt_ber_bytes(ber) ((ber)->ber_ptr - (ber)->ber_buf)
|
|
|
|
#define ber_pvt_ber_remaining(ber) ((ber)->ber_end - (ber)->ber_ptr)
|
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
struct sockbuf;
|
|
|
|
|
|
|
|
struct sockbuf_io {
|
|
|
|
int (*sbi_setup)( struct sockbuf * sb, void *arg );
|
|
|
|
int (*sbi_remove)( struct sockbuf *sb );
|
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_slen_t (*sbi_read)( struct sockbuf *sb, void *buf, ber_len_t len );
|
|
|
|
ber_slen_t (*sbi_write)( struct sockbuf *sb, void *buf, ber_len_t len );
|
1999-03-03 04:23:14 +08:00
|
|
|
int (*sbi_close)( struct sockbuf *sb );
|
|
|
|
};
|
|
|
|
|
1999-03-06 10:36:21 +08:00
|
|
|
struct sockbuf_sec {
|
1999-03-03 04:23:14 +08:00
|
|
|
int (*sbs_setup)( struct sockbuf * sb, void *arg );
|
|
|
|
int (*sbs_remove)( struct sockbuf *sb );
|
|
|
|
|
|
|
|
long (*sbs_protect)( struct sockbuf *sb, char *in, long *ilen,
|
|
|
|
char *out, long olen );
|
|
|
|
long (*sbs_release)( struct sockbuf *sb, char *in, long ilen,
|
|
|
|
char *out0, long olen0, char *out1, long olen1 );
|
|
|
|
};
|
|
|
|
|
1999-03-06 10:36:21 +08:00
|
|
|
struct sockbuf_buf {
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_len_t buf_size;
|
|
|
|
ber_len_t buf_ptr;
|
|
|
|
ber_len_t buf_end;
|
1999-03-03 04:23:14 +08:00
|
|
|
char *buf_base;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct sockbuf_io Sockbuf_IO;
|
|
|
|
typedef struct sockbuf_sec Sockbuf_Sec;
|
|
|
|
typedef struct sockbuf_buf Sockbuf_Buf;
|
|
|
|
|
1999-05-29 03:33:05 +08:00
|
|
|
extern Sockbuf_IO ber_pvt_sb_io_tcp;
|
|
|
|
extern Sockbuf_IO ber_pvt_sb_io_udp;
|
1999-03-03 04:23:14 +08:00
|
|
|
|
|
|
|
|
1998-10-26 09:49:56 +08:00
|
|
|
struct sockbuf {
|
1999-03-06 10:36:21 +08:00
|
|
|
struct lber_options sb_opts;
|
1999-05-29 03:33:05 +08:00
|
|
|
#define sb_valid sb_opts.lbo_valid
|
1999-03-06 10:36:21 +08:00
|
|
|
#define sb_options sb_opts.lbo_options
|
|
|
|
#define sb_debug sb_opts.lbo_debug
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
int sb_non_block:1;
|
|
|
|
int sb_read_ahead:1;
|
|
|
|
|
|
|
|
int sb_buf_ready:1;
|
|
|
|
int sb_trans_ready:1;
|
|
|
|
int sb_sec_ready:1;
|
|
|
|
|
1999-07-14 03:38:01 +08:00
|
|
|
/* these bits indicate if the transport layer
|
|
|
|
* needs to read or write
|
|
|
|
*/
|
|
|
|
int sb_trans_needs_read:1;
|
|
|
|
int sb_trans_needs_write:1;
|
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
int sb_fd;
|
|
|
|
|
|
|
|
void *sb_iodata; /* transport-layer data pointer */
|
|
|
|
Sockbuf_IO *sb_io; /* I/O functions */
|
|
|
|
|
|
|
|
#ifdef LDAP_SASL
|
|
|
|
void *sb_sdata; /* security-layer data pointer */
|
|
|
|
Sockbuf_Sec *sb_sec;
|
|
|
|
#endif
|
1999-06-19 07:53:05 +08:00
|
|
|
|
|
|
|
ber_socket_t sb_sd;
|
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
#ifdef DEADWOOD
|
1998-12-22 09:34:01 +08:00
|
|
|
long sb_max_incoming;
|
1999-03-03 04:23:14 +08:00
|
|
|
#endif
|
|
|
|
Sockbuf_Buf sb_buf;
|
|
|
|
#ifdef LDAP_SASL
|
|
|
|
Sockbuf_Buf sb_sec_buf_in;
|
|
|
|
Sockbuf_Buf sb_sec_buf_out;
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_len_t sb_sec_prev_len;
|
1999-03-03 04:23:14 +08:00
|
|
|
#endif
|
1998-10-26 09:49:56 +08:00
|
|
|
};
|
1999-05-29 03:33:05 +08:00
|
|
|
#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))
|
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
#define ber_pvt_sb_in_use( sb ) ((sb)->sb_sd != AC_SOCKET_INVALID)
|
1999-05-29 03:33:05 +08:00
|
|
|
|
|
|
|
#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
|
1999-07-14 03:38:01 +08:00
|
|
|
#define ber_pvt_sb_needs_read( sb ) \
|
|
|
|
((sb)->sb_trans_needs_read)
|
|
|
|
#define ber_pvt_sb_needs_write( sb ) \
|
|
|
|
((sb)->sb_trans_needs_write)
|
1999-03-03 04:23:14 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
#define READBUFSIZ 8192
|
|
|
|
|
1998-10-26 09:49:56 +08:00
|
|
|
struct seqorset {
|
1998-10-26 09:18:41 +08:00
|
|
|
BerElement *sos_ber;
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_len_t sos_clen;
|
|
|
|
ber_tag_t sos_tag;
|
1998-10-26 09:18:41 +08:00
|
|
|
char *sos_first;
|
|
|
|
char *sos_ptr;
|
|
|
|
struct seqorset *sos_next;
|
1998-10-26 09:49:56 +08:00
|
|
|
};
|
1999-06-19 07:53:05 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
/*
|
|
|
|
* bprint.c
|
|
|
|
*/
|
1999-05-29 03:33:05 +08:00
|
|
|
#define ber_log_printf ber_pvt_log_printf
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAP_F( int )
|
|
|
|
ber_log_bprint LDAP_P((
|
1998-12-22 09:34:01 +08:00
|
|
|
int errlvl,
|
|
|
|
int loglvl,
|
1999-05-19 09:12:33 +08:00
|
|
|
const char *data,
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_len_t len ));
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAP_F( int )
|
|
|
|
ber_log_dump LDAP_P((
|
1998-12-22 09:34:01 +08:00
|
|
|
int errlvl,
|
|
|
|
int loglvl,
|
1999-05-19 09:12:33 +08:00
|
|
|
const BerElement *ber,
|
1998-12-22 09:34:01 +08:00
|
|
|
int inout ));
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAP_F( int )
|
|
|
|
ber_log_sos_dump LDAP_P((
|
1998-12-22 09:34:01 +08:00
|
|
|
int errlvl,
|
|
|
|
int loglvl,
|
1999-05-19 09:12:33 +08:00
|
|
|
const Seqorset *sos ));
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1999-05-29 13:16:31 +08:00
|
|
|
|
1999-05-29 09:19:14 +08:00
|
|
|
/* memory.c */
|
|
|
|
/* simple macros to realloc for now */
|
1999-05-31 07:00:52 +08:00
|
|
|
extern BerMemoryFunctions* ber_int_memory_fns;
|
1999-05-29 13:16:31 +08:00
|
|
|
|
1999-05-31 07:00:52 +08:00
|
|
|
#define LBER_INT_MALLOC(s) ber_memalloc((s))
|
|
|
|
#define LBER_INT_CALLOC(n,s) ber_memcalloc((n),(s))
|
|
|
|
#define LBER_INT_REALLOC(p,s) ber_memrealloc((p),(s))
|
|
|
|
#define LBER_INT_FREE(p) ber_memfree((p))
|
1999-06-02 03:25:17 +08:00
|
|
|
#define LBER_INT_VFREE(v) ber_memvfree((void**)(v))
|
1999-06-03 06:28:22 +08:00
|
|
|
#define LBER_INT_STRDUP(s) ber_strdup((s))
|
1999-06-08 02:48:22 +08:00
|
|
|
|
1999-05-31 07:00:52 +08:00
|
|
|
#define LBER_MALLOC(s) ber_memalloc((s))
|
|
|
|
#define LBER_CALLOC(n,s) ber_memcalloc((n),(s))
|
|
|
|
#define LBER_REALLOC(p,s) ber_memrealloc((p),(s))
|
|
|
|
#define LBER_FREE(p) ber_memfree((p))
|
1999-06-02 03:25:17 +08:00
|
|
|
#define LBER_VFREE(v) ber_memvfree((void**)(v))
|
1999-06-03 06:28:22 +08:00
|
|
|
#define LBER_STRDUP(s) ber_strdup((s))
|
1999-05-29 09:19:14 +08:00
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
/* sockbuf.c */
|
|
|
|
|
1999-05-29 03:33:05 +08:00
|
|
|
/* these should be ber_int*() functions */
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_sb_init LDAP_P(( Sockbuf *sb ));
|
|
|
|
|
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_sb_destroy LDAP_P(( Sockbuf *sb ));
|
|
|
|
|
1999-06-03 05:38:48 +08:00
|
|
|
#ifdef USE_SASL
|
1999-05-19 09:12:33 +08:00
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_sb_set_sec LDAP_P(( Sockbuf *sb, Sockbuf_Sec *sec, void *arg ));
|
|
|
|
|
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_sb_clear_sec LDAP_P(( Sockbuf *sb ));
|
1999-03-03 04:23:14 +08:00
|
|
|
#endif
|
1999-05-19 09:12:33 +08:00
|
|
|
|
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_sb_set_io LDAP_P(( Sockbuf *sb, Sockbuf_IO *layer, void *arg ));
|
|
|
|
|
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_sb_clear_io LDAP_P(( Sockbuf *sb ));
|
|
|
|
|
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_sb_close LDAP_P((Sockbuf *sb ));
|
|
|
|
|
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_sb_set_nonblock LDAP_P(( Sockbuf *sb, int nb ));
|
|
|
|
|
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_sb_set_readahead LDAP_P(( Sockbuf *sb, int rh ));
|
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
LDAP_F( ber_slen_t )
|
|
|
|
ber_pvt_sb_read LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
|
1999-05-19 09:12:33 +08:00
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
LDAP_F( ber_slen_t )
|
|
|
|
ber_pvt_sb_write LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
|
1999-05-19 09:12:33 +08:00
|
|
|
|
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_sb_udp_set_dst LDAP_P((Sockbuf *sb, void *addr ));
|
|
|
|
|
|
|
|
LDAP_F( void * )
|
|
|
|
ber_pvt_sb_udp_get_src LDAP_P((Sockbuf *sb ));
|
|
|
|
|
1999-08-05 02:29:59 +08:00
|
|
|
LDAP_F( int )
|
|
|
|
ber_pvt_socket_set_nonblock LDAP_P(( ber_socket_t sd, int nb ));
|
1999-03-03 04:23:14 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
#endif /* _LBER_INT_H */
|