openldap/libraries/liblber/decode.c

987 lines
20 KiB
C
Raw Normal View History

1998-08-09 08:43:13 +08:00
/* decode.c - ber input decoding routines */
/* $OpenLDAP$ */
2003-11-26 07:17:08 +08:00
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
2009-01-22 08:40:04 +08:00
* Copyright 1998-2009 The OpenLDAP Foundation.
2003-11-26 07:17:08 +08:00
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
1998-12-29 04:38:04 +08:00
*/
2003-11-26 07:17:08 +08:00
/* Portions Copyright (c) 1990 Regents of the University of Michigan.
1998-08-09 08:43:13 +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.
*/
2003-11-27 06:51:15 +08:00
/* ACKNOWLEDGEMENTS:
* This work was originally developed by the University of Michigan
* (as part of U-MICH LDAP).
*/
1998-08-09 08:43:13 +08:00
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>
#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
2007-03-20 23:10:16 +08:00
/* out->bv_len should be the buffer size on input */
int
ber_decode_oid( BerValue *in, BerValue *out )
{
const unsigned char *der;
unsigned long val;
unsigned val1;
ber_len_t i;
2007-03-20 23:10:16 +08:00
char *ptr;
assert( in != NULL );
assert( out != NULL );
/* need 4 chars/inbyte + \0 for input={7f 7f 7f...} */
if ( !out->bv_val || (out->bv_len+3)/4 <= in->bv_len )
2007-03-20 23:10:16 +08:00
return -1;
ptr = NULL;
der = (unsigned char *) in->bv_val;
2007-03-20 23:10:16 +08:00
val = 0;
for ( i=0; i < in->bv_len; i++ ) {
2007-03-20 23:10:16 +08:00
val |= der[i] & 0x7f;
if ( !( der[i] & 0x80 )) {
if ( ptr == NULL ) {
2008-08-06 21:36:53 +08:00
/* Initial "x.y": val=x*40+y, x<=2, y<40 if x<2 */
ptr = out->bv_val;
val1 = (val < 80 ? val/40 : 2);
val -= val1*40;
ptr += sprintf( ptr, "%u", val1 );
}
ptr += sprintf( ptr, ".%lu", val );
2007-03-20 23:10:16 +08:00
val = 0;
} else if ( val - 1UL < LBER_OID_COMPONENT_MAX >> 7 ) {
val <<= 7;
} else {
/* val would overflow, or is 0 from invalid initial 0x80 octet */
return -1;
2007-03-20 23:10:16 +08:00
}
}
if ( ptr == NULL || val != 0 )
return -1;
2007-03-20 23:10:16 +08:00
out->bv_len = ptr - out->bv_val;
return 0;
}
/* Return tag, with *bv = rest of element (starting at length octets) */
static ber_tag_t
ber_tag_and_rest( const BerElement *ber, struct berval *bv )
1998-08-09 08:43:13 +08:00
{
ber_tag_t tag;
ptrdiff_t rest;
unsigned char *ptr;
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
ptr = (unsigned char *) ber->ber_ptr;
rest = (unsigned char *) ber->ber_end - ptr;
if ( rest <= 0 ) {
goto fail;
}
1998-08-09 08:43:13 +08:00
tag = ber->ber_tag;
if ( (char *) ptr == ber->ber_buf ) {
tag = *ptr;
2003-07-08 11:46:20 +08:00
}
ptr++;
rest--;
2002-01-06 11:05:02 +08:00
if ( (tag & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK ) {
goto done;
}
1998-08-09 08:43:13 +08:00
do {
if ( rest <= 0 ) {
break;
}
tag <<= 8;
tag |= *ptr++ & 0xffU;
rest--;
1998-08-09 08:43:13 +08:00
if ( ! (tag & LBER_MORE_TAG_MASK) ) {
goto done;
}
} while ( tag <= (ber_tag_t)-1 / 256 );
1998-08-09 08:43:13 +08:00
fail:
/* Error or unsupported tag size */
tag = LBER_DEFAULT;
done:
bv->bv_len = rest;
bv->bv_val = (char *) ptr;
return tag;
1998-08-09 08:43:13 +08:00
}
/* Return the tag - LBER_DEFAULT returned means trouble */
ber_tag_t
ber_get_tag( BerElement *ber )
{
struct berval bv;
ber_tag_t tag = ber_tag_and_rest( ber, &bv );
ber->ber_ptr = bv.bv_val;
return tag;
}
/* Return next element's tag and point *bv at its contents in-place */
ber_tag_t
ber_peek_element( const BerElement *ber, struct berval *bv )
1998-08-09 08:43:13 +08:00
{
ber_tag_t tag;
ber_len_t len, rest;
unsigned i;
unsigned char *ptr;
1998-08-09 08:43:13 +08:00
assert( bv != NULL );
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, and point
* bv at the contents.
1998-08-09 08:43:13 +08:00
*
* 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.
*/
tag = ber_tag_and_rest( ber, bv );
1998-08-09 08:43:13 +08:00
rest = bv->bv_len;
ptr = (unsigned char *) bv->bv_val;
if ( tag == LBER_DEFAULT || rest == 0 ) {
goto fail;
}
1998-08-09 08:43:13 +08:00
/*
* Next, read the length. The first octet determines the length
* of the length. If bit 8 is 0, the length is the short form,
* otherwise if the octet != 0x80 it's the long form, otherwise
* the ber element has the unsupported indefinite-length format.
* Lengths that do not fit in a ber_len_t are not accepted.
1998-08-09 08:43:13 +08:00
*/
len = *ptr++;
rest--;
if ( len & 0x80U ) {
len &= 0x7fU;
if ( len - 1U > sizeof(ber_len_t) - 1U || rest < len ) {
/* Indefinite-length/too long length/not enough data */
goto fail;
}
rest -= len;
i = len;
for( len = *ptr++ & 0xffU; --i; len |= *ptr++ & 0xffU ) {
len <<= 8;
}
1998-08-09 08:43:13 +08:00
}
2001-05-07 03:07:24 +08:00
/* BER element should have enough data left */
if( len > rest ) {
fail:
tag = LBER_DEFAULT;
}
bv->bv_len = len;
bv->bv_val = (char *) ptr;
return tag;
}
/* Move past next element, point *bv at it in-place, and return its tag.
* The caller may \0-terminate *bv, as next octet is saved in ber->ber_tag.
* Similar to ber_get_stringbv(ber, bv, LBER_BV_NOTERM) except on error.
*/
ber_tag_t
ber_skip_element( BerElement *ber, struct berval *bv )
{
ber_tag_t tag = ber_peek_element( ber, bv );
if ( tag != LBER_DEFAULT ) {
ber->ber_ptr = bv->bv_val + bv->bv_len;
ber->ber_tag = *(unsigned char *) ber->ber_ptr;
2001-05-07 03:07:24 +08:00
}
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
{
struct berval bv;
ber_tag_t tag = ber_peek_element( ber, &bv );
1998-08-09 08:43:13 +08:00
*len = bv.bv_len;
return tag;
}
ber_tag_t
ber_skip_tag( BerElement *ber, ber_len_t *lenp )
{
struct berval bv;
ber_tag_t tag = ber_peek_element( ber, &bv );
1999-11-08 23:38:59 +08:00
ber->ber_ptr = bv.bv_val;
ber->ber_tag = *(unsigned char *) ber->ber_ptr;
1999-11-09 03:36:30 +08:00
*lenp = bv.bv_len;
return tag;
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;
struct berval bv;
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( num != NULL );
tag = ber_skip_element( ber, &bv );
len = bv.bv_len;
if ( tag == LBER_DEFAULT || len > sizeof(ber_int_t) ) {
return LBER_DEFAULT;
}
/* parse two's complement integer */
if( len ) {
unsigned char *buf = (unsigned char *) bv.bv_val;
ber_len_t i;
ber_int_t netnum = buf[0] & 0xff;
/* sign extend */
netnum = (netnum ^ 0x80) - 0x80;
1998-08-09 08:43:13 +08:00
/* shift in the bytes */
for( i = 1; 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 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
{
struct berval bv;
ber_tag_t tag;
if ( (tag = ber_skip_element( ber, &bv )) == LBER_DEFAULT ) {
return LBER_DEFAULT;
}
2001-05-07 03:07:24 +08:00
/* must fit within allocated space with termination */
if ( bv.bv_len >= *len ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
memcpy( buf, bv.bv_val, bv.bv_len );
buf[bv.bv_len] = '\0';
1998-08-09 08:43:13 +08:00
*len = bv.bv_len;
return tag;
1998-08-09 08:43:13 +08:00
}
/* Definitions for get_string vector
*
* ChArray, BvArray, and BvVec are self-explanatory.
* BvOff is a struct berval embedded in an array of larger structures
* of siz bytes at off bytes from the beginning of the struct.
*/
enum bgbvc { ChArray, BvArray, BvVec, BvOff };
/* Use this single cookie for state, to keep actual
* stack use to the absolute minimum.
*/
typedef struct bgbvr {
const enum bgbvc choice;
const int alloc; /* choice == BvOff ? 0 : LBER_ALLOC */
ber_len_t siz; /* input array element size, output count */
ber_len_t off; /* BvOff offset to the struct berval */
void *result;
} bgbvr;
static ber_tag_t
ber_get_stringbvl( BerElement *ber, bgbvr *b )
{
int i = 0, n;
ber_tag_t tag;
ber_len_t tot_size = 0, siz = b->siz;
char *last, *orig;
struct berval bv, *bvp = NULL;
union stringbvl_u {
char **ca; /* ChArray */
BerVarray ba; /* BvArray */
struct berval **bv; /* BvVec */
char *bo; /* BvOff */
} res;
tag = ber_skip_tag( ber, &bv.bv_len );
if ( tag != LBER_DEFAULT ) {
tag = 0;
orig = ber->ber_ptr;
last = orig + bv.bv_len;
for ( ; ber->ber_ptr < last; i++, tot_size += siz ) {
if ( ber_skip_element( ber, &bv ) == LBER_DEFAULT )
break;
}
if ( ber->ber_ptr != last ) {
i = 0;
tag = LBER_DEFAULT;
}
ber->ber_ptr = orig;
ber->ber_tag = *(unsigned char *) orig;
}
b->siz = i;
2003-07-08 11:46:20 +08:00
if ( i == 0 ) {
return tag;
}
/* Allocate and NULL-terminate the result vector */
b->result = ber_memalloc_x( tot_size + siz, ber->ber_memctx );
if ( b->result == NULL ) {
return LBER_DEFAULT;
}
switch (b->choice) {
case ChArray:
res.ca = b->result;
res.ca[i] = NULL;
break;
case BvArray:
res.ba = b->result;
res.ba[i].bv_val = NULL;
break;
case BvVec:
res.bv = b->result;
res.bv[i] = NULL;
break;
case BvOff:
res.bo = (char *) b->result + b->off;
((struct berval *) (res.bo + tot_size))->bv_val = NULL;
tot_size = 0;
break;
}
n = 0;
do {
tag = ber_get_stringbv( ber, &bv, b->alloc );
if ( tag == LBER_DEFAULT ) {
goto nomem;
2003-07-08 11:46:20 +08:00
}
/* store my result */
switch (b->choice) {
case ChArray:
res.ca[n] = bv.bv_val;
break;
case BvArray:
res.ba[n] = bv;
break;
case BvVec:
bvp = ber_memalloc_x( sizeof( struct berval ),
ber->ber_memctx );
if ( !bvp ) {
ber_memfree_x( bv.bv_val, ber->ber_memctx );
goto nomem;
}
res.bv[n] = bvp;
*bvp = bv;
break;
case BvOff:
*(struct berval *)(res.bo + tot_size) = bv;
tot_size += siz;
break;
}
} while (++n < i);
return tag;
2003-07-08 11:46:20 +08:00
nomem:
if (b->choice != BvOff) { /* BvOff does not have b->alloc set */
while (--n >= 0) {
switch(b->choice) {
2003-07-08 11:46:20 +08:00
case ChArray:
ber_memfree_x(res.ca[n], ber->ber_memctx);
2003-07-08 11:46:20 +08:00
break;
case BvArray:
ber_memfree_x(res.ba[n].bv_val, ber->ber_memctx);
2003-07-08 11:46:20 +08:00
break;
case BvVec:
ber_memfree_x(res.bv[n]->bv_val, ber->ber_memctx);
ber_memfree_x(res.bv[n], ber->ber_memctx);
2003-07-08 11:46:20 +08:00
break;
default:
break;
}
}
}
ber_memfree_x(b->result, ber->ber_memctx);
b->result = NULL;
return LBER_DEFAULT;
}
ber_tag_t
ber_get_stringbv( BerElement *ber, struct berval *bv, int option )
1998-08-09 08:43:13 +08:00
{
ber_tag_t tag;
char *data;
1998-08-09 08:43:13 +08:00
tag = ber_skip_element( ber, bv );
if ( tag == LBER_DEFAULT ) {
2001-12-31 22:43:54 +08:00
bv->bv_val = NULL;
return tag;
}
1998-08-09 08:43:13 +08:00
data = bv->bv_val;
if ( option & LBER_BV_ALLOC ) {
2003-07-08 11:46:20 +08:00
bv->bv_val = (char *) ber_memalloc_x( bv->bv_len + 1,
ber->ber_memctx );
if ( bv->bv_val == NULL ) {
return LBER_DEFAULT;
}
if ( bv->bv_len != 0 ) {
memcpy( bv->bv_val, data, bv->bv_len );
}
data = bv->bv_val;
}
if ( !( option & LBER_BV_NOTERM ))
data[bv->bv_len] = '\0';
2001-12-31 22:43:54 +08:00
return tag;
}
ber_tag_t
ber_get_stringbv_null( BerElement *ber, struct berval *bv, int option )
{
ber_tag_t tag;
char *data;
tag = ber_skip_element( ber, bv );
if ( tag == LBER_DEFAULT || bv->bv_len == 0 ) {
bv->bv_val = NULL;
return tag;
}
data = bv->bv_val;
if ( option & LBER_BV_ALLOC ) {
bv->bv_val = (char *) ber_memalloc_x( bv->bv_len + 1,
ber->ber_memctx );
if ( bv->bv_val == NULL ) {
return LBER_DEFAULT;
}
memcpy( bv->bv_val, data, bv->bv_len );
data = bv->bv_val;
}
if ( !( option & LBER_BV_NOTERM ))
data[bv->bv_len] = '\0';
return tag;
}
2001-12-31 22:43:54 +08:00
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, LBER_BV_ALLOC );
2001-12-31 22:43:54 +08:00
*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
ber_get_stringa_null( BerElement *ber, char **buf )
{
BerValue bv;
ber_tag_t tag;
assert( buf != NULL );
tag = ber_get_stringbv_null( ber, &bv, LBER_BV_ALLOC );
*buf = bv.bv_val;
return tag;
}
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 );
2003-07-08 11:46:20 +08:00
*bv = (struct berval *) ber_memalloc_x( sizeof(struct berval),
ber->ber_memctx );
if ( *bv == NULL ) {
return LBER_DEFAULT;
}
1998-08-09 08:43:13 +08:00
tag = ber_get_stringbv( ber, *bv, LBER_BV_ALLOC );
2001-12-31 22:43:54 +08:00
if ( tag == LBER_DEFAULT ) {
ber_memfree_x( *bv, ber->ber_memctx );
*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_tag_t tag;
struct berval data;
1998-08-09 08:43:13 +08:00
unsigned char unusedbits;
assert( buf != NULL );
assert( blen != NULL );
if ( (tag = ber_skip_element( ber, &data )) == LBER_DEFAULT ) {
goto fail;
}
1998-08-09 08:43:13 +08:00
if ( --data.bv_len > (ber_len_t)-1 / 8 ) {
goto fail;
}
unusedbits = *(unsigned char *) data.bv_val++;
if ( unusedbits > 7 ) {
goto fail;
}
*buf = (char *) ber_memalloc_x( data.bv_len, ber->ber_memctx );
if ( *buf == NULL ) {
return LBER_DEFAULT;
}
memcpy( *buf, data.bv_val, data.bv_len );
1998-08-09 08:43:13 +08:00
*blen = data.bv_len * 8 - unusedbits;
return tag;
fail:
*buf = NULL;
return LBER_DEFAULT;
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 = ber_skip_tag( ber, &len );
1998-08-09 08:43:13 +08:00
return( len == 0 ? tag : LBER_DEFAULT );
1998-08-09 08:43:13 +08:00
}
ber_tag_t
ber_get_boolean(
BerElement *ber,
ber_int_t *boolval )
1998-08-09 08:43:13 +08:00
{
return ber_get_int( ber, boolval );
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( 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 ( *len == 0 ) {
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( last != NULL );
assert( LBER_VALID( ber ) );
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
}
/* 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;
char *s, **ss, ***sss;
struct berval data, *bval, **bvp, ***bvpp;
2002-01-04 04:04:31 +08:00
ber_int_t *i;
ber_len_t *l;
ber_tag_t *t;
2002-01-04 04:04:31 +08:00
ber_tag_t rc;
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
2007-10-18 09:35:07 +08:00
if ( ber->ber_debug & (LDAP_DEBUG_TRACE|LDAP_DEBUG_BER)) {
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 );
}
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 'A': /* octet string - allocate storage as needed,
* but return NULL if len == 0 */
ss = va_arg( ap, char ** );
rc = ber_get_stringa_null( ber, ss );
break;
1998-08-09 08:43:13 +08:00
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 '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 );
break;
1998-08-09 08:43:13 +08:00
case 'e': /* enumerated */
case 'i': /* integer */
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 'm': /* octet string in berval, in-place */
bval = va_arg( ap, struct berval * );
rc = ber_get_stringbv( ber, bval, 0 );
1998-08-09 08:43:13 +08:00
break;
case 'M': /* bvoffarray - must include address of
* a record len, and record offset.
* number of records will be returned thru
* len ptr on finish. parsed in-place.
*/
{
bgbvr cookie = { BvOff, 0 };
bvp = va_arg( ap, struct berval ** );
l = va_arg( ap, ber_len_t * );
cookie.siz = *l;
cookie.off = va_arg( ap, ber_len_t );
rc = ber_get_stringbvl( ber, &cookie );
*bvp = cookie.result;
*l = cookie.siz;
1998-08-09 08:43:13 +08:00
break;
}
1998-08-09 08:43:13 +08:00
case 'n': /* null */
rc = ber_get_null( ber );
break;
1998-08-09 08:43:13 +08:00
case 'o': /* octet string in a supplied berval */
bval = va_arg( ap, struct berval * );
rc = ber_get_stringbv( ber, bval, LBER_BV_ALLOC );
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 '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 '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
{
bgbvr cookie = {
ChArray, LBER_BV_ALLOC, sizeof( char * )
};
rc = ber_get_stringbvl( ber, &cookie );
*(va_arg( ap, char *** )) = cookie.result;
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
{
bgbvr cookie = {
BvVec, LBER_BV_ALLOC, sizeof( struct berval * )
};
rc = ber_get_stringbvl( ber, &cookie );
*(va_arg( ap, struct berval *** )) = cookie.result;
2001-12-31 22:43:54 +08:00
break;
}
2001-11-04 06:07:41 +08:00
2001-12-31 22:43:54 +08:00
case 'W': /* bvarray */
{
bgbvr cookie = {
BvArray, LBER_BV_ALLOC, sizeof( struct berval )
};
rc = ber_get_stringbvl( ber, &cookie );
*(va_arg( ap, struct berval ** )) = cookie.result;
break;
}
1998-08-09 08:43:13 +08:00
case 'x': /* skip the next element - whatever it is */
rc = ber_skip_element( ber, &data );
1998-08-09 08:43:13 +08:00
break;
case '{': /* begin sequence */
case '[': /* begin set */
switch ( fmt[1] ) {
case 'v': case 'V': case 'W': case 'M':
break;
default:
1998-08-09 08:43:13 +08:00
rc = ber_skip_tag( ber, &len );
break;
}
1998-08-09 08:43:13 +08:00
break;
case '}': /* end sequence */
case ']': /* end set */
break;
default:
if( ber->ber_debug ) {
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 );
}
1998-08-09 08:43:13 +08:00
rc = LBER_DEFAULT;
break;
}
}
va_end( ap );
if ( rc == LBER_DEFAULT ) {
2003-07-08 11:46:20 +08:00
/*
* Error. Reclaim malloced memory that was given to the caller.
* Set allocated pointers to NULL, "data length" outvalues to 0.
*/
va_start( ap, fmt );
2003-07-08 11:46:20 +08:00
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 */
case 'A':
ss = va_arg( ap, char ** );
ber_memfree_x( *ss, ber->ber_memctx );
*ss = NULL;
break;
case 'b': /* boolean */
case 'e': /* enumerated */
case 'i': /* integer */
(void) va_arg( ap, ber_int_t * );
break;
case 'l': /* length of next item */
*(va_arg( ap, ber_len_t * )) = 0;
break;
case 'm': /* berval in-place */
bval = va_arg( ap, struct berval * );
BER_BVZERO( bval );
break;
case 'M': /* BVoff array in-place */
bvp = va_arg( ap, struct berval ** );
ber_memfree_x( *bvp, ber->ber_memctx );
*bvp = NULL;
*(va_arg( ap, ber_len_t * )) = 0;
(void) va_arg( ap, ber_len_t );
break;
case 'o': /* octet string in a supplied berval */
bval = va_arg( ap, struct berval * );
ber_memfree_x( bval->bv_val, ber->ber_memctx );
BER_BVZERO( bval );
break;
case 'O': /* octet string - allocate & include length */
bvp = va_arg( ap, struct berval ** );
ber_bvfree_x( *bvp, ber->ber_memctx );
*bvp = NULL;
break;
case 's': /* octet string - in a buffer */
(void) va_arg( ap, char * );
*(va_arg( ap, ber_len_t * )) = 0;
break;
case 't': /* tag of next item */
case 'T': /* skip tag of next item */
(void) va_arg( ap, ber_tag_t * );
break;
case 'B': /* bit string - allocate storage as needed */
ss = va_arg( ap, char ** );
ber_memfree_x( *ss, ber->ber_memctx );
*ss = NULL;
*(va_arg( ap, ber_len_t * )) = 0; /* for length, in bits */
break;
case 'v': /* sequence of strings */
sss = va_arg( ap, char *** );
ber_memvfree_x( (void **) *sss, ber->ber_memctx );
*sss = NULL;
break;
case 'V': /* sequence of strings + lengths */
bvpp = va_arg( ap, struct berval *** );
ber_bvecfree_x( *bvpp, ber->ber_memctx );
*bvpp = NULL;
break;
case 'W': /* BerVarray */
bvp = va_arg( ap, struct berval ** );
ber_bvarray_free_x( *bvp, ber->ber_memctx );
*bvp = NULL;
break;
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 );
}
2003-07-08 11:46:20 +08:00
}
2003-07-08 11:46:20 +08:00
va_end( ap );
}
return rc;
1998-08-09 08:43:13 +08:00
}