/*
* Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* 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.
*/
/* decode.c - ber input decoding routines */
#include "lber-int.h"
/*
* Note: ber_get_tag() only uses the ber_end and ber_ptr elements of ber.
* will need to be changed.
*/
/* return the tag - LBER_DEFAULT returned means trouble */
{
unsigned char xbyte;
char *tagp;
int i;
return( LBER_DEFAULT );
return( (ber_uint_t) xbyte );
for ( i = 1; i < sizeof(ber_int_t); i++ ) {
return( LBER_DEFAULT );
if ( ! (xbyte & LBER_MORE_TAG_MASK) )
break;
}
/* tag too big! */
if ( i == sizeof(ber_int_t) )
return( LBER_DEFAULT );
/* want leading, not trailing 0's */
}
/*
* Note: ber_skip_tag() only uses the ber_end and ber_ptr elements of ber.
* If that changes, the implementation of ber_peek_tag() will need to
* be changed.
*/
{
unsigned char lc;
/*
* 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
*/
/*
* First, we read the tag.
*/
return( LBER_DEFAULT );
/*
* Next, read the length. The first byte contains the length of
* the length. If bit 8 is set, the length is the long form,
* otherwise it's the short form. We don't allow a length that's
* greater than what we can hold in an unsigned long.
*/
return( LBER_DEFAULT );
if ( lc & 0x80 ) {
if ( noctets > sizeof(ber_uint_t) )
return( LBER_DEFAULT );
!= noctets )
return( LBER_DEFAULT );
} else {
}
return( tag );
}
/*
* Note: Previously, we passed the "ber" parameter directly to ber_skip_tag(),
* saving and restoring the ber_ptr element only. We now take advantage
* of the fact that the only ber structure elements touched by ber_skip_tag()
* are ber_end and ber_ptr. If that changes, this code must change too.
*/
{
}
static int
{
int i;
/*
* 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_slen_t) )
return( -1 );
/* read into the low-order bytes of netnum */
return( -1 );
/* This sets the required sign extension */
if ( len != 0) {
} else {
value = 0;
}
for ( i = 0; i < len; i++ )
return( len );
}
{
return( LBER_DEFAULT );
/*
* len is being demoted to a long here -- possible conversion error
*/
return( LBER_DEFAULT );
else
return( tag );
}
{
#ifdef STR_TRANSLATION
char *transbuf;
#endif /* STR_TRANSLATION */
return( LBER_DEFAULT );
return( LBER_DEFAULT );
/*
* datalen is being demoted to a long here -- possible conversion error
*/
return( LBER_DEFAULT );
#ifdef STR_TRANSLATION
++datalen;
0 ) != 0 ) {
return( LBER_DEFAULT );
}
NSLBERI_FREE( transbuf );
return( LBER_DEFAULT );
}
NSLBERI_FREE( transbuf );
--datalen;
}
#endif /* STR_TRANSLATION */
return( tag );
}
{
return( LBER_DEFAULT );
return( LBER_DEFAULT );
/*
* datalen is being demoted to a long here -- possible conversion error
*/
return( LBER_DEFAULT );
#ifdef STR_TRANSLATION
++datalen;
!= 0 ) {
NSLBERI_FREE( *buf );
return( LBER_DEFAULT );
}
}
#endif /* STR_TRANSLATION */
return( tag );
}
{
== NULL ) {
return( LBER_DEFAULT );
}
return( LBER_DEFAULT );
}
== NULL ) {
return( LBER_DEFAULT );
}
/*
* len is being demoted to a long here -- possible conversion error
*/
return( LBER_DEFAULT );
#ifdef STR_TRANSLATION
++len;
&len, 1 ) != 0 ) {
return( LBER_DEFAULT );
}
}
#endif /* STR_TRANSLATION */
return( tag );
}
{
unsigned char unusedbits;
return( LBER_DEFAULT );
--datalen;
return( LBER_DEFAULT );
return( LBER_DEFAULT );
/*
* datalen is being demoted to a long here -- possible conversion error
*/
return( LBER_DEFAULT );
return( tag );
}
{
return( LBER_DEFAULT );
if ( len != 0 )
return( LBER_DEFAULT );
return( tag );
}
{
int rc;
return( rc );
}
{
/* skip the sequence header, use the len to mark where to stop */
return( LBER_ERROR );
}
return( LBER_END_OF_SEQORSET );
}
}
{
return( LBER_END_OF_SEQORSET );
}
}
/* VARARGS */
{
char *last, *p;
int *i, j;
ber_tag_t *t;
#ifdef LDAP_DEBUG
if ( lber_debug & 64 ) {
ber_err_print( msg );
}
#endif
switch ( *p ) {
case 'a': /* octet string - allocate storage as needed */
break;
case 'b': /* boolean */
break;
case 'e': /* enumerated */
case 'i': /* int */
break;
case 'l': /* length of next item */
break;
case 'n': /* null */
break;
case 's': /* octet string - in a buffer */
break;
case 'o': /* octet string in a supplied berval */
break;
case 'O': /* octet string - allocate & include length */
break;
case 'B': /* bit string - allocate storage as needed */
break;
case 't': /* tag of next item */
break;
case 'T': /* skip tag of next item */
break;
case 'v': /* sequence of strings */
j = 0;
array_size = 0;
&& rc != LBER_DEFAULT;
/* Make room for at least 15 strings */
array_size = 16;
} else {
/* We'v overflowed our buffer */
}
}
j++;
}
if ( rc != LBER_DEFAULT &&
tag != LBER_END_OF_SEQORSET ) {
rc = LBER_DEFAULT;
}
if ( j > 0 )
break;
case 'V': /* sequence of strings + lengths */
j = 0;
&& rc != LBER_DEFAULT;
2 * sizeof(struct berval *) );
} else {
*bv,
(j + 2) * sizeof(struct berval *) );
}
j++;
}
if ( rc != LBER_DEFAULT &&
tag != LBER_END_OF_SEQORSET ) {
rc = LBER_DEFAULT;
}
if ( j > 0 )
break;
case 'x': /* skip the next element - whatever it is */
break;
break;
case '{': /* begin sequence */
case '[': /* begin set */
if ( *(p + 1) != 'v' && *(p + 1) != 'V' )
break;
case '}': /* end sequence */
case ']': /* end set */
break;
default:
{
ber_err_print( msg );
}
rc = LBER_DEFAULT;
break;
}
}
if (rc == LBER_DEFAULT) {
switch ( *fmt ) {
case 'a': /* octet string - allocate storage as needed */
NSLBERI_FREE(*ss);
break;
case 'b': /* boolean */
break;
case 'e': /* enumerated */
case 'i': /* int */
break;
case 'l': /* length of next item */
break;
case 'n': /* null */
break;
case 's': /* octet string - in a buffer */
break;
case 'o': /* octet string in a supplied berval */
break;
case 'O': /* octet string - allocate & include length */
ber_bvfree(*bvp);
break;
case 'B': /* bit string - allocate storage as needed */
break;
case 't': /* tag of next item */
break;
case 'T': /* skip tag of next item */
break;
case 'v': /* sequence of strings */
ber_svecfree(*sss);
break;
case 'V': /* sequence of strings + lengths */
ber_bvecfree(*bv);
break;
case 'x': /* skip the next element - whatever it is */
break;
case '{': /* begin sequence */
case '[': /* begin set */
break;
case '}': /* end sequence */
case ']': /* end set */
break;
default:
break;
}
} /* for */
} /* if */
return( rc );
}
void
{
}
NSLBERI_FREE( (char *) bv );
}
}
void
{
int i;
ber_bvfree( bv[i] );
}
NSLBERI_FREE( (char *) bv );
}
}
struct berval *
{
== NULL ) {
return( NULL );
}
} else {
== NULL ) {
return( NULL );
}
}
return( new );
}
void
{
int i;
return;
NSLBERI_FREE( vals[i] );
NSLBERI_FREE( (char *) vals );
}
#ifdef STR_TRANSLATION
void
)
{
}
#endif /* STR_TRANSLATION */