SEARCH
NEW RPMS
DIRECTORIES
ABOUT
FAQ
VARIOUS
BLOG

BotDetect - Real-Time Bot Detection API
 
 

MAN page from RedHat Other ldap-devel-3.3-3.i386.rpm

LBER-DECODE

Section: C Library Functions (3)
Updated: 18 November 1994
Index 

NAME

ber_get_next, ber_skiptag, ber_peek_tag, ber_scanf, ber_get_int, ber_get_stringb, ber_get_stringa, ber_get_null, ber_get_boolean, ber_get_bitstring, ber_first_element, ber_next_element - LBER simplified Basic Encoding Rules library routines for decoding 

SYNOPSIS

#include <lber.h>

typedef struct berelement {    char *ber_buf;    char *ber_ptr;    char *ber_end;    struct seqorset *ber_sos;    int ber_tag;    int ber_usertag;} BerElement;

typedef struct sockbuf {    int sb_sd;    BerElement sb_ber;} Sockbuf;

typedef struct berval {    unsigned long bv_len;    char *bv_val;};

ber_get_next(sb, len, ber)Sockbuf *sb;unsigned long *len;BerElement *ber;

ber_skip_tag(ber, len)BerElement *ber;unsigned long *len;

ber_peek_tag(ber, len)BerElement *ber;unsigned long *len;

ber_get_int(ber, num)BerElement *ber;long *num;

ber_get_stringb(ber, buf, len)BerElement *ber;char *buf;unsigned long *len;

ber_get_stringa(ber, buf)BerElement *ber;char **buf;

ber_get_stringal(ber, bv)BerElement *ber;struct berval **bv;

ber_get_null(ber)BerElement *ber;

ber_get_boolean(ber, bool)BerElement *ber;int *bool;

ber_get_bitstringa(ber, buf, blen)BerElement *ber;char **buf;unsigned long *blen;

ber_first_element(ber, len, cookie)BerElement *ber;unsigned long *len;char **cookie;

ber_next_element(ber, len, cookie)BerElement *ber;unsigned long *len;char *cookie;

ber_scanf(ber, fmt [, arg...] )BerElement *ber;char *fmt;

ber_bvfree(bv)struct berval *bv;

ber_bvecfree(bvec)struct berval **bvec;
 

DESCRIPTION

These routines provide a subroutine interface to a simplifiedimplementation of the Basic Encoding Rules of ASN.1. The versionof BER these routines support is the one defined for the LDAPprotocol. The encoding rules are the same as BER, except that only definite form lengths are used, and bitstrings and octet stringsare always encoded in primitive form. In addition, these lightweightBER routines restrict tags and class to fit in a single octet (thismeans the actual tag must be less than 31). When a "tag" is specifiedin the descriptions below, it refers to the tag, class, and primitiveor constructed bit in the first octet of the encoding. This man pagedescribes the decoding routines in the lber library. See lber-encode(3)for details on the corresponding encoding routines.

Normally, the only routines that need be called by an applicationare ber_get_next() to get the next BER element and ber_scanf()to do the actual decoding. In some cases, ber_peek_tag() may alsoneed to be called in normal usage. The other routines are provided for thoseapplications that need more control than ber_scanf() provides. Ingeneral, these routines return the tag of the element decoded, or-1 if an error occurred.

The ber_get_next() routine is used to read the next BER element fromthe given Sockbuf, sb. A Sockbuf consists of the descriptor(usually socket, but a file descriptor works just as well) from whichto read, and a BerElement structure usedto maintain a buffer. On the first call, the sb_ber struct shouldbe zeroed. It strips off and returns theleading tag byte, strips off and returns the length of theentire element in len,and sets up ber for subsequent calls to ber_scanf() et al to decodethe element.

The ber_scanf() routine is used to decode a BER element in much thesame way that scanf(3) works. It reads from ber, a pointer to aBerElement such as returned by ber_get_next(), interprets thebytes according to the format string fmt, and stores theresults in its additional arguments. The format string containsconversion specifications which are used to direct the interpretationof the BER element. The format string can contain the followingcharacters.

a
Octet string. A char ** should be supplied. Memory is allocated,filled with the contents of the octet string, null-terminated, andreturned in the parameter.
s
Octet string. A char * buffer should be supplied, followed by a pointerto an integer initialized to the size of the buffer. Upon return, thenull-terminated octet string is put into the buffer, and the integer isset to the actual size of the octet string.
O
Octet string. A struct ber_val ** should be supplied, which upon returnpoints to a malloced struct berval containing the octet string and itslength. ber_bvfree() can be called to free the malloced memory.
b
Boolean. A pointer to an integer should be supplied.
i
Integer. A pointer to an integer should be supplied.
B
Bitstring. A char ** should be supplied which will point to the mallocedbits, followed by an unsigned long *, which will point to the length(in bits) of the bitstring returned.
n
Null. No parameter is required. The element is simply skipped ifit is recognized.
v
Sequence of octet strings. A char *** should be supplied, which uponreturn points to a malloced null-terminated array of char *'scontaining the octet strings. NULL is returned if the sequence is empty.
V
Sequence of octet strings with lengths.A struct berval *** should be supplied, which uponreturn points to a malloced null-terminated array of struct berval *'scontaining the octet strings and their lengths.NULL is returned if the sequence is empty. ber_bvecfree() can be calledto free the malloced memory.
x
Skip element. The next element is skipped.
{
Begin sequence. No parameter is required. The initial sequence tagand length are skipped.
}
End sequence. No parameter is required and no action is taken.
[
Begin set. No parameter is required. The initial set tagand length are skipped.
]
End set. No parameter is required and no action is taken.

The ber_get_int() routine tries to interpret the next element as an integer,returning the result in num. The tag of whatever it finds is returnedon success, -1 on failure.

The ber_get_stringb() routine is used to read an octet string into apreallocated buffer. The len parameter should be initialized tothe size of the buffer, and will contain the length of the octet stringread upon return. The buffer should be big enough to take the octetstring value plus a terminating NULL byte.

The ber_get_stringa() routine is used to malloc space into which an octetstring is read.

The ber_get_stringal() routine is used to malloc space into which an octetstring and its length are read. It takes a struct berval **, and returnsthe result in this parameter.

The ber_get_null() routine is used to read a NULL element. It returnsthe tag of the element it skips over.

The ber_get_boolean() routine is used to read a boolean value. It is calledthe same way that ber_get_int() is called.

The ber_get_bitstringa() routine is used to read a bitstring value. Ittakes a char ** which will hold the malloced bits, followed by anunsigned long *, which will point to the length (in bits) of thebitstring returned.

The ber_first_element() routine is used to return the tag and lengthof the first element in a set or sequence. It also returns in cookiea magic cookie parameter that should be passed to subsequent calls tober_next_element(), which returns similar information. 

EXAMPLES

Assume the variable ber contains a lightweight BER encoding ofthe following ASN.1 object:

      AlmostASearchRequest := SEQUENCE {          baseObject      DistinguishedName,          scope           ENUMERATED {              baseObject    (0),              singleLevel   (1),              wholeSubtree  (2)          },          derefAliases    ENUMERATED {              neverDerefaliases   (0),              derefInSearching    (1),              derefFindingBaseObj (2),              alwaysDerefAliases  (3)          },          sizelimit       INTEGER (0 .. 65535),          timelimit       INTEGER (0 .. 65535),          attrsOnly       BOOLEAN,          attributes      SEQUENCE OF AttributeType      }

The element can be decoded using ber_scanf() as follows.

      int    scope, ali, size, time, attrsonly;      char   *dn, **attrs;      if ( ber_scanf( ber, "{aiiiib{v}}", &dn, &scope, &ali,          &size, &time, &attrsonly, &attrs ) == -1 )              /* error */      else              /* success */
 

ERRORS

If an error occurs during decoding, generally these routines return -1.

 

NOTES

The return values for all of these functions are declared in the<lber.h> header file. Some routines may malloc memory. 

SEE ALSO

lber-encode(3)ldap-parse(3)ldap-sync(3)ldap-async(3)

Yeong, W., Howes, T., and Hardcastle-Kille, S., "Lightweight Directory AccessProtocol", OSI-DS-26, April 1992.

Information Processing - Open Systems Interconnection - Model and Notation -Service Definition - Specification of Basic Encoding Rules for AbstractSyntax Notation One, International Organization for Standardization,International Standard 8825. 

AUTHOR

Tim Howes, University of Michigan


 

Index

NAME
SYNOPSIS
DESCRIPTION
EXAMPLES
ERRORS
NOTES
SEE ALSO
AUTHOR

This document was created byman2html,using the manual pages.
 
ICM Bot detect detector