openldap/libraries/liblber/decode.c

805 lines
16 KiB
C
Raw Normal View History

1998-08-09 08:43:13 +08:00
/* decode.c - ber input decoding routines */
/* $OpenLDAP$ */
1998-08-09 08:43:13 +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
*/
/* Portions
1998-08-09 08:43:13 +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.
*/
1998-10-25 09:41:42 +08:00
#include "portable.h"
1998-08-09 08:43:13 +08:00
#include <stdio.h>
1999-06-03 08:37:44 +08:00
#include <ac/stdlib.h>
1998-10-25 09:41:42 +08:00
1999-06-03 08:37:44 +08:00
#include <ac/stdarg.h>
1998-10-25 09:41:42 +08:00
#include <ac/string.h>
#include <ac/socket.h>
#include "lber-int.h"
1998-08-09 08:43:13 +08:00
static ber_len_t ber_getnint LDAP_P((
BerElement *ber,
ber_int_t *num,
ber_len_t len ));
1998-08-09 08:43:13 +08:00
/* return the tag - LBER_DEFAULT returned means trouble */
ber_tag_t
1998-08-09 08:43:13 +08:00
ber_get_tag( BerElement *ber )
{
unsigned char xbyte;
ber_tag_t tag;
1998-11-04 21:15:18 +08:00
unsigned int i;
1998-08-09 08:43:13 +08:00
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
assert( ber != NULL );
assert( LBER_VALID( ber ) );
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
2000-04-25 18:42:32 +08:00
tag = xbyte;
if ( (xbyte & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK ) {
2000-04-25 18:42:32 +08:00
return tag;
}
1998-08-09 08:43:13 +08:00
for ( i = 1; i < sizeof(ber_tag_t); i++ ) {
if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
tag <<= 8;
2000-04-26 17:17:05 +08:00
tag |= 0x00ffUL & (ber_tag_t) xbyte;
1998-08-09 08:43:13 +08:00
if ( ! (xbyte & LBER_MORE_TAG_MASK) ) {
1998-08-09 08:43:13 +08:00
break;
}
1998-08-09 08:43:13 +08:00
}
/* tag too big! */
if ( i == sizeof(ber_tag_t) ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
2000-04-25 18:42:32 +08:00
return tag;
1998-08-09 08:43:13 +08:00
}
ber_tag_t
ber_skip_tag( BerElement *ber, ber_len_t *len )
1998-08-09 08:43:13 +08:00
{
ber_tag_t tag;
1998-08-09 08:43:13 +08:00
unsigned char lc;
ber_len_t i, noctets;
unsigned char netlen[sizeof(ber_len_t)];
1998-08-09 08:43:13 +08:00
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
assert( ber != NULL );
assert( len != NULL );
assert( LBER_VALID( ber ) );
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
1998-08-09 08:43:13 +08:00
/*
* Any ber element looks like this: tag length contents.
* Assuming everything's ok, we return the tag byte (we
* can assume a single byte), and return the length in len.
*
* Assumptions:
* 1) definite lengths
* 2) primitive encodings used whenever possible
*/
*len = 0;
1998-08-09 08:43:13 +08:00
/*
* First, we read the tag.
*/
if ( (tag = ber_get_tag( ber )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
/*
* Next, read the length. The first byte contains the length of
2001-01-18 01:08:44 +08:00
* the length. If bit 8 is set, the length is the long form,
1998-08-09 08:43:13 +08:00
* otherwise it's the short form. We don't allow a length that's
* greater than what we can hold in a ber_len_t.
1998-08-09 08:43:13 +08:00
*/
if ( ber_read( ber, (char *) &lc, 1 ) != 1 )
return LBER_DEFAULT;
1999-05-19 14:13:44 +08:00
if ( lc & 0x80U ) {
noctets = (lc & 0x7fU);
if ( noctets > sizeof(ber_len_t) ) {
return LBER_DEFAULT;
}
if( (unsigned) ber_read( ber, netlen, noctets ) != noctets ) {
return LBER_DEFAULT;
}
for( i = 0; i < noctets; i++ ) {
*len <<= 8;
*len |= netlen[i];
}
1998-08-09 08:43:13 +08:00
} else {
*len = lc;
}
2001-12-09 10:34:45 +08:00
/* BER length should be non-negative */
if( *len < 0 ) {
return LBER_DEFAULT;
}
2001-05-07 03:07:24 +08:00
/* BER element should have enough data left */
if( *len > (ber_len_t) ber_pvt_ber_remaining( ber ) ) {
2001-05-07 03:07:24 +08:00
return LBER_DEFAULT;
}
return tag;
1998-08-09 08:43:13 +08:00
}
ber_tag_t
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
ber_peek_tag(
BerElement *ber,
ber_len_t *len )
1998-08-09 08:43:13 +08:00
{
/*
* This implementation assumes ber_skip_tag() only
* modifies ber_ptr field of the BerElement.
*/
1998-08-09 08:43:13 +08:00
char *save;
ber_tag_t tag;
1999-11-08 23:38:59 +08:00
save = ber->ber_ptr;
1999-11-09 03:36:30 +08:00
tag = ber_skip_tag( ber, len );
ber->ber_ptr = save;
1999-11-09 03:36:30 +08:00
return tag;
1998-08-09 08:43:13 +08:00
}
static ber_len_t
ber_getnint(
BerElement *ber,
ber_int_t *num,
ber_len_t len )
1998-08-09 08:43:13 +08:00
{
unsigned char buf[sizeof(ber_int_t)];
1998-08-09 08:43:13 +08:00
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
assert( ber != NULL );
assert( num != NULL );
assert( LBER_VALID( ber ) );
1998-08-09 08:43:13 +08:00
/*
* The tag and length have already been stripped off. We should
* be sitting right before len bytes of 2's complement integer,
* ready to be read straight into an int. We may have to sign
* extend after we read it in.
*/
if ( len > sizeof(ber_int_t) ) {
return -1;
}
1998-08-09 08:43:13 +08:00
/* read into the low-order bytes of our buffer */
1999-08-02 04:27:03 +08:00
if ( (ber_len_t) ber_read( ber, (char *) buf, len ) != len ) {
return -1;
}
if( len ) {
/* sign extend if necessary */
ber_len_t i;
ber_int_t netnum = 0x80 & buf[0] ? -1 : 0;
1998-08-09 08:43:13 +08:00
/* shift in the bytes */
for( i=0 ; i<len; i++ ) {
netnum = (netnum << 8 ) | buf[i];
1998-08-09 08:43:13 +08:00
}
*num = netnum;
} else {
*num = 0;
1998-08-09 08:43:13 +08:00
}
return len;
1998-08-09 08:43:13 +08:00
}
ber_tag_t
ber_get_int(
BerElement *ber,
ber_int_t *num )
1998-08-09 08:43:13 +08:00
{
ber_tag_t tag;
ber_len_t len;
1998-08-09 08:43:13 +08:00
assert( ber != NULL );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
if ( ber_getnint( ber, num, len ) != len ) {
return LBER_DEFAULT;
}
return tag;
1998-08-09 08:43:13 +08:00
}
ber_tag_t
ber_get_enum(
BerElement *ber,
ber_int_t *num )
{
2000-05-14 11:38:27 +08:00
return ber_get_int( ber, num );
}
ber_tag_t
ber_get_stringb(
BerElement *ber,
char *buf,
ber_len_t *len )
1998-08-09 08:43:13 +08:00
{
ber_len_t datalen;
ber_tag_t tag;
assert( ber != NULL );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
}
2001-05-07 03:07:24 +08:00
/* must fit within allocated space with termination */
if ( datalen >= *len ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
if ( (ber_len_t) ber_read( ber, buf, datalen ) != datalen ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
buf[datalen] = '\0';
*len = datalen;
return tag;
1998-08-09 08:43:13 +08:00
}
ber_tag_t
2001-12-31 22:43:54 +08:00
ber_get_stringbv( BerElement *ber, struct berval *bv )
1998-08-09 08:43:13 +08:00
{
ber_tag_t tag;
1998-08-09 08:43:13 +08:00
assert( ber != NULL );
2001-12-31 22:43:54 +08:00
assert( bv != NULL );
assert( LBER_VALID( ber ) );
2001-12-31 22:43:54 +08:00
if ( (tag = ber_skip_tag( ber, &bv->bv_len )) == LBER_DEFAULT ) {
bv->bv_val = NULL;
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
2001-12-31 22:43:54 +08:00
if ( (bv->bv_val = (char *) LBER_MALLOC( bv->bv_len + 1 )) == NULL ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
2001-12-31 22:43:54 +08:00
if ( bv->bv_len > 0 && (ber_len_t) ber_read( ber, bv->bv_val,
bv->bv_len ) != bv->bv_len ) {
LBER_FREE( bv->bv_val );
bv->bv_val = NULL;
return LBER_DEFAULT;
}
2001-12-31 22:43:54 +08:00
bv->bv_val[bv->bv_len] = '\0';
return tag;
}
ber_tag_t
ber_get_stringa( BerElement *ber, char **buf )
{
BerValue bv;
ber_tag_t tag;
assert( buf != NULL );
tag = ber_get_stringbv( ber, &bv );
*buf = bv.bv_val;
1998-08-09 08:43:13 +08:00
return tag;
1998-08-09 08:43:13 +08:00
}
ber_tag_t
1998-08-09 08:43:13 +08:00
ber_get_stringal( BerElement *ber, struct berval **bv )
{
ber_tag_t tag;
1998-08-09 08:43:13 +08:00
assert( ber != NULL );
assert( bv != NULL );
*bv = (struct berval *) LBER_MALLOC( sizeof(struct berval) );
if ( *bv == NULL ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
2001-12-31 22:43:54 +08:00
tag = ber_get_stringbv( ber, *bv );
if ( tag == LBER_DEFAULT ) {
LBER_FREE( *bv );
*bv = NULL;
}
return tag;
1998-08-09 08:43:13 +08:00
}
ber_tag_t
ber_get_bitstringa(
BerElement *ber,
char **buf,
ber_len_t *blen )
1998-08-09 08:43:13 +08:00
{
ber_len_t datalen;
ber_tag_t tag;
1998-08-09 08:43:13 +08:00
unsigned char unusedbits;
assert( ber != NULL );
assert( buf != NULL );
assert( blen != NULL );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) {
*buf = NULL;
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
--datalen;
if ( (*buf = (char *) LBER_MALLOC( datalen )) == NULL ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
if ( ber_read( ber, (char *)&unusedbits, 1 ) != 1 ) {
LBER_FREE( buf );
*buf = NULL;
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
if ( (ber_len_t) ber_read( ber, *buf, datalen ) != datalen ) {
LBER_FREE( buf );
*buf = NULL;
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
*blen = datalen * 8 - unusedbits;
return tag;
1998-08-09 08:43:13 +08:00
}
ber_tag_t
1998-08-09 08:43:13 +08:00
ber_get_null( BerElement *ber )
{
ber_len_t len;
ber_tag_t tag;
1998-08-09 08:43:13 +08:00
assert( ber != NULL );
assert( LBER_VALID( ber ) );
if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
if ( len != 0 ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
return( tag );
}
ber_tag_t
ber_get_boolean(
BerElement *ber,
ber_int_t *boolval )
1998-08-09 08:43:13 +08:00
{
ber_int_t longbool;
ber_tag_t rc;
1998-08-09 08:43:13 +08:00
assert( ber != NULL );
assert( boolval != NULL );
assert( LBER_VALID( ber ) );
1998-08-09 08:43:13 +08:00
rc = ber_get_int( ber, &longbool );
*boolval = longbool;
return rc;
1998-08-09 08:43:13 +08:00
}
ber_tag_t
ber_first_element(
BerElement *ber,
ber_len_t *len,
char **last )
1998-08-09 08:43:13 +08:00
{
assert( ber != NULL );
assert( len != NULL );
assert( last != NULL );
1998-08-09 08:43:13 +08:00
/* skip the sequence header, use the len to mark where to stop */
if ( ber_skip_tag( ber, len ) == LBER_DEFAULT ) {
1999-11-09 03:36:30 +08:00
*last = NULL;
return LBER_DEFAULT;
1998-08-09 08:43:13 +08:00
}
*last = ber->ber_ptr + *len;
if ( *last == ber->ber_ptr ) {
return LBER_DEFAULT;
1998-08-09 08:43:13 +08:00
}
return ber_peek_tag( ber, len );
1998-08-09 08:43:13 +08:00
}
ber_tag_t
ber_next_element(
BerElement *ber,
ber_len_t *len,
1999-11-08 23:38:59 +08:00
LDAP_CONST char *last )
1998-08-09 08:43:13 +08:00
{
assert( ber != NULL );
assert( len != NULL );
assert( last != NULL );
assert( LBER_VALID( ber ) );
1998-08-09 08:43:13 +08:00
if ( ber->ber_ptr == last ) {
return LBER_DEFAULT;
1998-08-09 08:43:13 +08:00
}
return ber_peek_tag( ber, len );
1998-08-09 08:43:13 +08:00
}
2001-12-31 22:43:54 +08:00
/* Hopefully no one sends vectors with more elements than this */
#define TMP_SLOTS 1024
1998-08-09 08:43:13 +08:00
/* VARARGS */
ber_tag_t
ber_scanf ( BerElement *ber,
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
LDAP_CONST char *fmt,
... )
1998-08-09 08:43:13 +08:00
{
va_list ap;
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
LDAP_CONST char *fmt_reset;
1998-08-09 08:43:13 +08:00
char *last;
char *s, **ss, ***sss;
2001-01-18 01:08:44 +08:00
struct berval ***bv, **bvp, *bval;
ber_int_t *i;
int j;
ber_len_t *l;
ber_tag_t *t;
ber_tag_t rc, tag;
ber_len_t len;
1998-08-09 08:43:13 +08:00
va_start( ap, fmt );
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
assert( ber != NULL );
assert( fmt != NULL );
assert( LBER_VALID( ber ) );
fmt_reset = fmt;
1998-08-09 08:43:13 +08:00
#ifdef NEW_LOGGING
2001-01-18 01:08:44 +08:00
LDAP_LOG(( "liblber", LDAP_LEVEL_ENTRY, "ber_scanf fmt (%s) ber:\n", fmt ));
BER_DUMP(( "liblber", LDAP_LEVEL_DETAIL2, ber, 1 ));
#else
ber_log_printf( LDAP_DEBUG_TRACE, ber->ber_debug,
"ber_scanf fmt (%s) ber:\n", fmt );
ber_log_dump( LDAP_DEBUG_BER, ber->ber_debug, ber, 1 );
#endif
1998-08-09 08:43:13 +08:00
for ( rc = 0; *fmt && rc != LBER_DEFAULT; fmt++ ) {
/* When this is modified, remember to update
* the error-cleanup code below accordingly. */
1998-08-09 08:43:13 +08:00
switch ( *fmt ) {
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
case '!': { /* Hook */
BERDecodeCallback *f;
void *p;
f = va_arg( ap, BERDecodeCallback * );
p = va_arg( ap, void * );
rc = (*f)( ber, p, 0 );
} break;
1998-08-09 08:43:13 +08:00
case 'a': /* octet string - allocate storage as needed */
ss = va_arg( ap, char ** );
rc = ber_get_stringa( ber, ss );
break;
case 'b': /* boolean */
i = va_arg( ap, ber_int_t * );
1998-08-09 08:43:13 +08:00
rc = ber_get_boolean( ber, i );
break;
case 'e': /* enumerated */
case 'i': /* int */
i = va_arg( ap, ber_int_t * );
rc = ber_get_int( ber, i );
1998-08-09 08:43:13 +08:00
break;
case 'l': /* length of next item */
l = va_arg( ap, ber_len_t * );
rc = ber_peek_tag( ber, l );
1998-08-09 08:43:13 +08:00
break;
case 'n': /* null */
rc = ber_get_null( ber );
break;
case 's': /* octet string - in a buffer */
s = va_arg( ap, char * );
l = va_arg( ap, ber_len_t * );
rc = ber_get_stringb( ber, s, l );
1998-08-09 08:43:13 +08:00
break;
case 'o': /* octet string in a supplied berval */
bval = va_arg( ap, struct berval * );
2001-12-31 22:43:54 +08:00
rc = ber_get_stringbv( ber, bval );
1998-08-09 08:43:13 +08:00
break;
case 'O': /* octet string - allocate & include length */
bvp = va_arg( ap, struct berval ** );
rc = ber_get_stringal( ber, bvp );
break;
case 'B': /* bit string - allocate storage as needed */
ss = va_arg( ap, char ** );
l = va_arg( ap, ber_len_t * ); /* for length, in bits */
rc = ber_get_bitstringa( ber, ss, l );
1998-08-09 08:43:13 +08:00
break;
case 't': /* tag of next item */
t = va_arg( ap, ber_tag_t * );
*t = rc = ber_peek_tag( ber, &len );
1998-08-09 08:43:13 +08:00
break;
case 'T': /* skip tag of next item */
t = va_arg( ap, ber_tag_t * );
*t = rc = ber_skip_tag( ber, &len );
1998-08-09 08:43:13 +08:00
break;
case 'v': /* sequence of strings */
2001-12-31 22:43:54 +08:00
{
char *tmp[TMP_SLOTS];
1998-08-09 08:43:13 +08:00
sss = va_arg( ap, char *** );
*sss = NULL;
j = 0;
for ( tag = ber_first_element( ber, &len, &last );
1999-05-28 11:24:41 +08:00
tag != LBER_DEFAULT && rc != LBER_DEFAULT;
tag = ber_next_element( ber, &len, last ) )
{
2001-12-31 22:43:54 +08:00
rc = ber_get_stringa( ber, &tmp[j] );
j++;
assert(j < TMP_SLOTS);
}
if (j > 0 && rc != LBER_DEFAULT ) {
*sss = (char **)LBER_MALLOC( (j+1) * sizeof(char *));
if (*sss == NULL) {
2001-11-04 06:07:41 +08:00
rc = LBER_DEFAULT;
2001-12-31 22:43:54 +08:00
} else {
(*sss)[j] = NULL;
for (j--; j>=0; j--)
(*sss)[j] = tmp[j];
2001-11-04 06:07:41 +08:00
}
1998-08-09 08:43:13 +08:00
}
2001-12-31 22:43:54 +08:00
if ( rc == LBER_DEFAULT ) {
for (j--; j>=0; j--)
LBER_FREE(tmp[j]);
}
1998-08-09 08:43:13 +08:00
break;
2001-12-31 22:43:54 +08:00
}
1998-08-09 08:43:13 +08:00
case 'V': /* sequence of strings + lengths */
2001-12-31 22:43:54 +08:00
{
struct berval *tmp[TMP_SLOTS];
1998-08-09 08:43:13 +08:00
bv = va_arg( ap, struct berval *** );
*bv = NULL;
j = 0;
for ( tag = ber_first_element( ber, &len, &last );
1999-05-28 11:24:41 +08:00
tag != LBER_DEFAULT && rc != LBER_DEFAULT;
tag = ber_next_element( ber, &len, last ) )
{
2001-12-31 22:43:54 +08:00
rc = ber_get_stringal( ber, &tmp[j] );
j++;
assert( j < TMP_SLOTS);
}
if (j > 0 && rc != LBER_DEFAULT ) {
*bv = (struct berval **)LBER_MALLOC( (j+1) * sizeof(struct berval *));
if (*bv == NULL) {
2001-11-04 06:07:41 +08:00
rc = LBER_DEFAULT;
2001-12-31 22:43:54 +08:00
} else {
(*bv)[j] = NULL;
for (j--; j>=0; j--)
(*bv)[j] = tmp[j];
2001-11-04 06:07:41 +08:00
}
2001-12-31 22:43:54 +08:00
}
if ( rc == LBER_DEFAULT ) {
for (j--; j>=0; j--)
ber_bvfree(tmp[j]);
}
break;
}
2001-11-04 06:07:41 +08:00
2001-12-31 22:43:54 +08:00
case 'W': /* bvarray */
{
struct berval tmp[TMP_SLOTS];
bvp = va_arg( ap, struct berval ** );
*bvp = NULL;
j = 0;
for ( tag = ber_first_element( ber, &len, &last );
tag != LBER_DEFAULT && rc != LBER_DEFAULT;
tag = ber_next_element( ber, &len, last ) )
{
rc = ber_get_stringbv( ber, &tmp[j] );
1998-08-09 08:43:13 +08:00
j++;
2001-12-31 22:43:54 +08:00
assert( j < TMP_SLOTS);
}
if (j > 0 && rc != LBER_DEFAULT ) {
*bvp = (struct berval *)LBER_MALLOC( (j+1) * sizeof(struct berval));
if (*bvp == NULL) {
rc = LBER_DEFAULT;
} else {
(*bvp)[j].bv_val = NULL;
(*bvp)[j].bv_len = 0;
for (j--; j>=0; j--)
(*bvp)[j] = tmp[j];
}
}
if ( rc == LBER_DEFAULT ) {
for (j--; j>=0; j--)
LBER_FREE(tmp[j].bv_val);
1998-08-09 08:43:13 +08:00
}
break;
2001-12-31 22:43:54 +08:00
}
1998-08-09 08:43:13 +08:00
case 'x': /* skip the next element - whatever it is */
if ( (rc = ber_skip_tag( ber, &len )) == LBER_DEFAULT )
break;
ber->ber_ptr += len;
break;
case '{': /* begin sequence */
case '[': /* begin set */
2002-01-02 16:50:07 +08:00
if ( *(fmt + 1) != 'v' && *(fmt + 1) != 'V'
&& *(fmt + 1) != 'W' )
1998-08-09 08:43:13 +08:00
rc = ber_skip_tag( ber, &len );
break;
case '}': /* end sequence */
case ']': /* end set */
break;
default:
if( ber->ber_debug ) {
2001-01-18 01:08:44 +08:00
#ifdef NEW_LOGGING
LDAP_LOG(( "liblber", LDAP_LEVEL_ERR,
"ber_scanf: unknown fmt %c\n", *fmt ));
#else
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
ber_log_printf( LDAP_DEBUG_ANY, ber->ber_debug,
"ber_scanf: unknown fmt %c\n", *fmt );
2001-01-18 01:08:44 +08:00
#endif
}
1998-08-09 08:43:13 +08:00
rc = LBER_DEFAULT;
break;
}
}
2001-11-04 06:07:41 +08:00
breakout:
1998-08-09 08:43:13 +08:00
va_end( ap );
if ( rc == LBER_DEFAULT ) {
/*
* Error. Reclaim malloced memory that was given to the caller.
* Set allocated pointers to NULL, "data length" outvalues to 0.
*/
va_start( ap, fmt );
for ( ; fmt_reset < fmt; fmt_reset++ ) {
switch ( *fmt_reset ) {
Vienna Bulk Commit This commit includes many changes. All changes compile under NT but have not been tested under UNIX. A Summary of changes (likely incomplete): NT changes: Removed lint. Clean up configuration support for "Debug", "Release", "SDebug", and "SRelease" configurations. Share output directories for clients, libraries, and slapd. (maybe they should be combined further and moved to build/{,S}{Debug,Release}). Enable threading when _MT is defined. Enable debuging when _DEBUG is defined. Disable setting of NDEBUG under Release/SRelease. Asserts are disabled in <ac/assert.h> when LDAP_DEBUG is not defined. Added 'build/main.dsp' Master project. Removed non-slapd projects from slapd.dsp (see main.dsp). Removed replaced many uses of _WIN32 macro with feature based macros. ldap_cdefs.h changes #define LDAP_CONST const (see below) #define LDAP_F(type) LDAP_F_PRE type LDAP_F_POST To allow specifiers to be added before and after the type declaration. (For DLL handling) LBER/LDAP changes Namespace changes: s/lber_/ber_/ for here and there. s/NAME_ERROR/LDAP_NAME_ERROR/g Deleted NULLMSG and other NULL* macros for namespace reasons. "const" libraries. Installed headers (ie: lber.h, ldap.h) use LDAP_CONST macro. Normally set to 'const' when __STDC__. Can be set externally to enable/disable 'constification' of external interface. Internal interface always uses 'const'. Did not fix warnings in -lldif (in lieu of new LDIF parser). Added _ext API implementations (excepting search and bind). Need to implement ldap_int_get_controls() for reponses with controls. Added numberous assert() checks. LDAP_R _MT defines HAVE_NT_THREADS Added numberous assert() checks. Changed ldap_pthread_t back to unsigned long. Used cast to HANDLE in _join(). LDBM Replaced _WIN32 with HAVE_SYSLOG ud Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). slapd Made connection sockbuf field a pointer to a sockbuf. This removed slap.h dependency on lber-int.h. lber-int.h now only included by those files needing to mess with the sockbuf. Used ber_* functions/macros to access sockbuf internals whenever possible. Added version string if MKVERSION is not defined. (MKVERSION needs to be set under UNIX). Removed FD_SET unsigned lint slapd/tools Used EXEEXT to added ".exe" to routines. Need to define EXEEXT under UNIX. ldappasswd Added ldappasswd.dsp. Ported to NT. Used getpid() to seed rand(). nt_debug Minor cleanup. Added "portable.h" include and used <ac/*.h> where appropriate. Added const to char* format argument.
1999-05-19 09:12:33 +08:00
case '!': { /* Hook */
BERDecodeCallback *f;
void *p;
f = va_arg( ap, BERDecodeCallback * );
p = va_arg( ap, void * );
(void) (*f)( ber, p, 1 );
} break;
case 'a': /* octet string - allocate storage as needed */
ss = va_arg( ap, char ** );
if ( *ss ) {
LBER_FREE( *ss );
*ss = NULL;
}
break;
case 'b': /* boolean */
case 'e': /* enumerated */
case 'i': /* int */
(void) va_arg( ap, int * );
break;
case 's': /* octet string - in a buffer */
(void) va_arg( ap, char * );
(void) va_arg( ap, ber_len_t * );
break;
case 'l': /* length of next item */
(void) va_arg( ap, ber_len_t * );
break;
case 't': /* tag of next item */
case 'T': /* skip tag of next item */
(void) va_arg( ap, ber_tag_t * );
break;
case 'o': /* octet string in a supplied berval */
bval = va_arg( ap, struct berval * );
if ( bval->bv_val != NULL ) {
LBER_FREE( bval->bv_val );
bval->bv_val = NULL;
}
bval->bv_len = 0;
break;
case 'O': /* octet string - allocate & include length */
bvp = va_arg( ap, struct berval ** );
if ( *bvp ) {
ber_bvfree( *bvp );
*bvp = NULL;
}
break;
case 'B': /* bit string - allocate storage as needed */
ss = va_arg( ap, char ** );
if ( *ss ) {
LBER_FREE( *ss );
*ss = NULL;
}
*(va_arg( ap, ber_len_t * )) = 0; /* for length, in bits */
break;
case 'v': /* sequence of strings */
case 'V': /* sequence of strings + lengths */
2001-12-31 22:43:54 +08:00
case 'W': /* BVarray */
case 'n': /* null */
case 'x': /* skip the next element - whatever it is */
case '{': /* begin sequence */
case '[': /* begin set */
case '}': /* end sequence */
case ']': /* end set */
break;
default:
/* format should be good */
assert( 0 );
}
}
va_end( ap );
}
return rc;
1998-08-09 08:43:13 +08:00
}