1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 15:16:36 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2012-01-01 23:07:45 +08:00
|
|
|
* Copyright 1998-2012 The OpenLDAP Foundation.
|
2003-11-26 15:16:36 +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 15:16:36 +08:00
|
|
|
/* Portions Copyright (c) 1990 Regents of the University of Michigan.
|
1998-10-26 09:18:41 +08:00
|
|
|
* 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"
|
2002-01-03 08:49:52 +08:00
|
|
|
#include "ldap_queue.h"
|
1998-10-26 09:18:41 +08:00
|
|
|
|
|
|
|
LDAP_BEGIN_DECL
|
|
|
|
|
2001-12-20 05:22:04 +08:00
|
|
|
typedef void (*BER_LOG_FN)(FILE *file,
|
2001-12-20 05:46:34 +08:00
|
|
|
const char *subsys, int level, const char *fmt, ... );
|
2001-12-20 05:22:04 +08:00
|
|
|
|
2001-12-07 12:03:25 +08:00
|
|
|
LBER_V (BER_ERRNO_FN) ber_int_errno_fn;
|
1999-11-08 23:38:59 +08:00
|
|
|
|
2005-11-13 02:26:17 +08:00
|
|
|
#ifdef LDAP_MEMORY_TRACE
|
|
|
|
# ifndef LDAP_MEMORY_DEBUG
|
|
|
|
# define LDAP_MEMORY_DEBUG 1
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LDAP_MEMORY_DEBUG
|
|
|
|
LBER_V (long) ber_int_meminuse;
|
|
|
|
#endif
|
2007-07-25 04:53:23 +08:00
|
|
|
#if defined(LDAP_MEMORY_DEBUG) && ((LDAP_MEMORY_DEBUG +0) & 2)
|
|
|
|
# define LDAP_MEMORY_DEBUG_ASSERT assert
|
|
|
|
#else
|
|
|
|
# define LDAP_MEMORY_DEBUG_ASSERT(expr) ((void) 0)
|
|
|
|
#endif
|
2005-11-13 02:26:17 +08:00
|
|
|
|
1999-03-06 10:36:21 +08:00
|
|
|
struct lber_options {
|
1999-05-29 03:33:05 +08:00
|
|
|
short lbo_valid;
|
2000-06-02 04:59:21 +08:00
|
|
|
unsigned short lbo_options;
|
|
|
|
int lbo_debug;
|
|
|
|
};
|
|
|
|
|
2001-12-20 05:22:04 +08:00
|
|
|
LBER_F( int ) ber_pvt_log_output(
|
|
|
|
const char *subsystem,
|
|
|
|
int level,
|
|
|
|
const char *fmt, ... );
|
|
|
|
|
1999-05-29 03:33:05 +08:00
|
|
|
#define LBER_UNINITIALIZED 0x0
|
|
|
|
#define LBER_INITIALIZED 0x1
|
|
|
|
#define LBER_VALID_BERELEMENT 0x2
|
|
|
|
#define LBER_VALID_SOCKBUF 0x3
|
|
|
|
|
2001-12-07 12:03:25 +08:00
|
|
|
LBER_V (struct lber_options) ber_int_options;
|
1999-05-29 03:33:05 +08:00
|
|
|
#define ber_int_debug ber_int_options.lbo_debug
|
|
|
|
|
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
|
|
|
/* Data encoded in ASN.1 BER format */
|
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
|
|
|
|
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
|
|
|
/*
|
|
|
|
* The members below, when not NULL/LBER_DEFAULT/etc, are:
|
|
|
|
* ber_buf Data buffer. Other pointers normally point into it.
|
|
|
|
* ber_rwptr Read/write cursor for Sockbuf I/O.
|
|
|
|
* ber_memctx Context passed to ber_memalloc() & co.
|
|
|
|
* When decoding data (reading it from the BerElement):
|
|
|
|
* ber_end End of BER data.
|
|
|
|
* ber_ptr Read cursor, except for 1st octet of tags.
|
|
|
|
* ber_tag 1st octet of next tag, saved from *ber_ptr when
|
|
|
|
* ber_ptr may be pointing at a tag and is >ber_buf.
|
|
|
|
* The octet *ber_ptr itself may get overwritten with
|
|
|
|
* a \0, to terminate the preceding element.
|
|
|
|
* When encoding data (writing it to the BerElement):
|
|
|
|
* ber_end End of allocated buffer - 1 (allowing a final \0).
|
|
|
|
* ber_ptr Last complete BER element (normally write cursor).
|
|
|
|
* ber_sos_ptr NULL or write cursor for incomplete sequence or set.
|
|
|
|
* ber_sos_inner offset(seq/set length octets) if ber_sos_ptr!=NULL.
|
|
|
|
* ber_tag Default tag for next ber_printf() element.
|
2009-10-21 19:41:44 +08:00
|
|
|
* ber_usertag Boolean set by ber_printf "!" if it sets ber_tag.
|
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
|
|
|
* ber_len Reused for ber_sos_inner.
|
|
|
|
* When output to a Sockbuf:
|
|
|
|
* ber_ptr End of encoded data to write.
|
|
|
|
* When input from a Sockbuf:
|
|
|
|
* See ber_get_next().
|
|
|
|
*/
|
|
|
|
|
2002-01-13 11:00:45 +08:00
|
|
|
/* Do not change the order of these 3 fields! see ber_get_next */
|
1999-06-19 07:53:05 +08:00
|
|
|
ber_tag_t ber_tag;
|
|
|
|
ber_len_t ber_len;
|
2002-01-13 11:00:45 +08:00
|
|
|
ber_tag_t ber_usertag;
|
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
|
|
|
|
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
|
|
|
char *ber_sos_ptr;
|
|
|
|
# define ber_sos_inner ber_len /* reused for binary compat */
|
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
char *ber_rwptr;
|
2003-04-09 21:25:11 +08:00
|
|
|
void *ber_memctx;
|
1998-10-26 09:49:56 +08:00
|
|
|
};
|
2001-07-22 07:13:04 +08:00
|
|
|
#define LBER_VALID(ber) ((ber)->ber_valid==LBER_VALID_BERELEMENT)
|
1999-06-19 07:53:05 +08:00
|
|
|
|
1999-05-29 03:33:05 +08:00
|
|
|
#define ber_pvt_ber_remaining(ber) ((ber)->ber_end - (ber)->ber_ptr)
|
2000-09-15 13:56:37 +08:00
|
|
|
#define ber_pvt_ber_total(ber) ((ber)->ber_end - (ber)->ber_buf)
|
|
|
|
#define ber_pvt_ber_write(ber) ((ber)->ber_ptr - (ber)->ber_buf)
|
1999-05-29 03:33:05 +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;
|
2000-06-02 04:59:21 +08:00
|
|
|
Sockbuf_IO_Desc *sb_iod; /* I/O functions */
|
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
|
2000-06-02 04:59:21 +08:00
|
|
|
ber_socket_t sb_fd;
|
2007-03-25 12:40:22 +08:00
|
|
|
ber_len_t sb_max_incoming;
|
2000-07-21 03:50:40 +08:00
|
|
|
unsigned int sb_trans_needs_read:1;
|
|
|
|
unsigned int sb_trans_needs_write:1;
|
2007-03-25 12:40:22 +08:00
|
|
|
#ifdef LDAP_PF_LOCAL_SENDMSG
|
|
|
|
char sb_ungetlen;
|
|
|
|
char sb_ungetbuf[8];
|
|
|
|
#endif
|
1998-10-26 09:49:56 +08:00
|
|
|
};
|
1999-05-29 03:33:05 +08:00
|
|
|
|
2000-06-02 04:59:21 +08:00
|
|
|
#define SOCKBUF_VALID( sb ) ( (sb)->sb_valid == LBER_VALID_SOCKBUF )
|
1999-03-03 04:23:14 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
|
2007-07-23 20:57:23 +08:00
|
|
|
/*
|
|
|
|
* decode.c, encode.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Simplest OID max-DER-component to implement in both decode and encode */
|
|
|
|
#define LBER_OID_COMPONENT_MAX ((unsigned long)-1 - 128)
|
|
|
|
|
|
|
|
|
2000-03-16 03:47:22 +08:00
|
|
|
/*
|
|
|
|
* io.c
|
|
|
|
*/
|
2001-12-07 12:03:25 +08:00
|
|
|
LBER_F( int )
|
|
|
|
ber_realloc LDAP_P((
|
2000-03-16 03:47:22 +08:00
|
|
|
BerElement *ber,
|
|
|
|
ber_len_t len ));
|
|
|
|
|
2003-04-09 17:41:02 +08:00
|
|
|
LBER_F (char *) ber_start LDAP_P(( BerElement * ));
|
|
|
|
LBER_F (int) ber_len LDAP_P(( BerElement * ));
|
|
|
|
LBER_F (int) ber_ptrlen LDAP_P(( BerElement * ));
|
|
|
|
LBER_F (void) ber_rewind LDAP_P(( BerElement * ));
|
|
|
|
|
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
|
|
|
|
|
2000-06-19 03:48:07 +08:00
|
|
|
LBER_F( int )
|
1999-05-19 09:12:33 +08:00
|
|
|
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
|
|
|
|
2000-06-19 03:48:07 +08:00
|
|
|
LBER_F( int )
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_log_dump LDAP_P((
|
1998-12-22 09:34:01 +08:00
|
|
|
int errlvl,
|
|
|
|
int loglvl,
|
1999-10-20 02:57:38 +08:00
|
|
|
BerElement *ber,
|
1998-12-22 09:34:01 +08:00
|
|
|
int inout ));
|
|
|
|
|
2002-01-03 05:19:45 +08:00
|
|
|
LBER_V (BER_LOG_FN) ber_int_log_proc;
|
|
|
|
LBER_V (FILE *) ber_pvt_err_file;
|
1999-05-29 13:16:31 +08:00
|
|
|
|
1999-05-29 09:19:14 +08:00
|
|
|
/* memory.c */
|
|
|
|
/* simple macros to realloc for now */
|
2001-12-07 12:03:25 +08:00
|
|
|
LBER_V (BerMemoryFunctions *) ber_int_memory_fns;
|
2001-10-19 03:00:07 +08:00
|
|
|
LBER_F (char *) ber_strndup( LDAP_CONST char *, ber_len_t );
|
2003-04-09 21:25:11 +08:00
|
|
|
LBER_F (char *) ber_strndup_x( LDAP_CONST char *, ber_len_t, void *ctx );
|
|
|
|
|
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))
|
2001-10-19 03:00:07 +08:00
|
|
|
#define LBER_STRNDUP(s,l) ber_strndup((s),(l))
|
1999-05-29 09:19:14 +08:00
|
|
|
|
1999-03-03 04:23:14 +08:00
|
|
|
/* sockbuf.c */
|
|
|
|
|
2000-06-19 03:48:07 +08:00
|
|
|
LBER_F( int )
|
2000-06-02 04:59:21 +08:00
|
|
|
ber_int_sb_init LDAP_P(( Sockbuf *sb ));
|
1999-05-19 09:12:33 +08:00
|
|
|
|
2000-06-19 03:48:07 +08:00
|
|
|
LBER_F( int )
|
2000-06-02 04:59:21 +08:00
|
|
|
ber_int_sb_close LDAP_P(( Sockbuf *sb ));
|
1999-05-19 09:12:33 +08:00
|
|
|
|
2000-06-19 03:48:07 +08:00
|
|
|
LBER_F( int )
|
2000-06-02 04:59:21 +08:00
|
|
|
ber_int_sb_destroy LDAP_P(( Sockbuf *sb ));
|
1999-05-19 09:12:33 +08:00
|
|
|
|
2000-06-19 03:48:07 +08:00
|
|
|
LBER_F( ber_slen_t )
|
2000-06-02 04:59:21 +08:00
|
|
|
ber_int_sb_read LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
|
1999-05-19 09:12:33 +08:00
|
|
|
|
2000-06-19 03:48:07 +08:00
|
|
|
LBER_F( ber_slen_t )
|
2000-06-02 04:59:21 +08:00
|
|
|
ber_int_sb_write LDAP_P(( Sockbuf *sb, void *buf, ber_len_t len ));
|
1999-03-03 04:23:14 +08:00
|
|
|
|
1999-12-22 08:42:05 +08:00
|
|
|
LDAP_END_DECL
|
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
#endif /* _LBER_INT_H */
|