Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


lber-decode(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |EXAMPLES |ERRORS |NOTES |SEE ALSO |ACKNOWLEDGEMENTS |COLOPHON

LBER_DECODE(3)           Library Functions ManualLBER_DECODE(3)

NAME        top

       ber_get_next, ber_skip_tag, ber_peek_tag, ber_scanf, ber_get_int,       ber_get_enum, ber_get_stringb, ber_get_stringa, ber_get_stringal,       ber_get_stringbv, ber_get_null, ber_get_boolean,       ber_get_bitstring, ber_first_element, ber_next_element - OpenLDAP       LBER simplified Basic Encoding Rules library routines for decoding

LIBRARY        top

       OpenLDAP LBER (liblber, -llber)

SYNOPSIS        top

#include <lber.h>ber_tag_t ber_get_next(Sockbuf *sb, ber_len_t *len, BerElement*ber);ber_tag_t ber_skip_tag(BerElement *ber, ber_len_t *len);ber_tag_t ber_peek_tag(BerElement *ber, ber_len_t *len);ber_tag_t ber_scanf(BerElement *ber, const char *fmt, ...);ber_tag_t ber_get_int(BerElement *ber, ber_int_t *num);ber_tag_t ber_get_enum(BerElement *ber, ber_int_t *num);ber_tag_t ber_get_stringb(BerElement *ber, char *buf, ber_len_t*len);ber_tag_t ber_get_stringa(BerElement *ber, char **buf);ber_tag_t ber_get_stringal(BerElement *ber, struct berval **bv);ber_tag_t ber_get_stringbv(BerElement *ber, struct berval *bv, intalloc);ber_tag_t ber_get_null(BerElement *ber);ber_tag_t ber_get_boolean(BerElement *ber, ber_int_t *bool);ber_tag_t ber_get_bitstringa(BerElement *ber, char **buf,ber_len_t *blen);ber_tag_t ber_first_element(BerElement *ber, ber_len_t *len, char**cookie);ber_tag_t ber_next_element(BerElement *ber, ber_len_t *len, constchar *cookie);

DESCRIPTION        top

       These routines provide a subroutine interface to a simplified       implementation of the Basic Encoding Rules of ASN.1.  The version       of BER these routines support is the one defined for the LDAP       protocol.  The encoding rules are the same as BER, except that       only definite form lengths are used, and bitstrings and octet       strings are always encoded in primitive form.  This man page       describes the decoding routines in the lber library.  Seelber-encode(3) for details on the corresponding encoding routines.       Consultlber-types(3) for information about types, allocators, and       deallocators.       Normally, the only routines that need to be called by an       application areber_get_next() to get the next BER element andber_scanf() to do the actual decoding.  In some cases,ber_peek_tag() may also need to be called in normal usage.  The       other routines are provided for those applications that need more       control thanber_scanf() provides.  In general, these routines       return the tag of the element decoded, or LBER_ERROR if an error       occurred.       Theber_get_next() routine is used to read the next BER element       from the given Sockbuf,sb.  It strips off and returns the leading       tag, strips off and returns the length of the entire element inlen, and sets upber for subsequent calls tober_scanf() et al to       decode the element. Seelber-sockbuf(3) for details of the Sockbuf       implementation of thesb parameter.       Theber_scanf() routine is used to decode a BER element in much       the same way thatscanf(3) works.  It reads fromber, a pointer to       a BerElement such as returned byber_get_next(), interprets the       bytes according to the format stringfmt, and stores the results       in its additional arguments.  The format string contains       conversion specifications which are used to direct the       interpretation of the BER element.  The format string can contain       the following characters.aOctet string.  A char ** should be supplied.  Memory is                 allocated, filled with the contents of the octet string,                 null-terminated, and returned in the parameter.  The                 caller should free the returned string usingber_memfree().AOctet string.  A variant of "a".  A char ** should be                 supplied.  Memory is allocated, filled with the contents                 of the octet string, null-terminated, and returned in                 the parameter, unless a zero-length string would result;                 in that case, the arg is set to NULL.  The caller should                 free the returned string usingber_memfree().sOctet string.  A char * buffer should be supplied,                 followed by a pointer to a ber_len_t initialized to the                 size of the buffer.  Upon return, the null-terminated                 octet string is put into the buffer, and the ber_len_t                 is set to the actual size of the octet string.OOctet string.  A struct ber_val ** should be supplied,                 which upon return points to a dynamically allocated                 struct berval containing the octet string and its                 length.  The caller should free the returned structure                 usingber_bvfree().oOctet string.  A struct ber_val * should be supplied,                 which upon return contains the dynamically allocated                 octet string and its length.  The caller should free the                 returned octet string usingber_memfree().mOctet string.  A struct ber_val * should be supplied,                 which upon return contains the octet string and its                 length.  The string resides in memory assigned to the                 BerElement, and must not be freed by the caller.bBoolean.  A pointer to a ber_int_t should be supplied.eEnumeration.  A pointer to a ber_int_t should be                 supplied.iInteger.  A pointer to a ber_int_t should be supplied.BBitstring.  A char ** should be supplied which will                 point to the dynamically allocated bits, followed by a                 ber_len_t *, which will point to the length (in bits) of                 the bitstring returned.nNull.  No parameter is required.  The element is simply                 skipped if it is recognized.vSequence of octet strings.  A char *** should be                 supplied, which upon return points to a dynamically                 allocated null-terminated array of char *'s containing                 the octet strings.  NULL is returned if the sequence is                 empty.  The caller should free the returned array and                 octet strings usingber_memvfree().VSequence of octet strings with lengths.  A struct berval                 *** should be supplied, which upon return points to a                 dynamically allocated null-terminated array of struct                 berval *'s containing the octet strings and their                 lengths.  NULL is returned if the sequence is empty.                 The caller should free the returned structures usingber_bvecfree().WSequence of octet strings with lengths.  A BerVarray *                 should be supplied, which upon return points to a                 dynamically allocated array of struct berval's                 containing the octet strings and their lengths. The                 array is terminated by a struct berval with a NULL                 bv_val string pointer.  NULL is returned if the sequence                 is empty.  The caller should free the returned                 structures usingber_bvarray_free().MSequence of octet strings with lengths.  This is a                 generalized form of the previous three formats.  A void                 ** (ptr) should be supplied, followed by a ber_len_t *                 (len) and a ber_len_t (off).  Upon return (ptr) will                 point to a dynamically allocated array whose elements                 are all of size (*len).  A struct berval will be filled                 starting at offset (off) in each element.  The strings                 in each struct berval reside in memory assigned to the                 BerElement and must not be freed by the caller.  The                 array is terminated by a struct berval with a NULL                 bv_val string pointer.  NULL is returned if the sequence                 is empty.  The number of elements in the array is also                 stored in (*len) on return.  The caller should free the                 returned array usingber_memfree().lLength of the next element.  A pointer to a ber_len_t                 should be supplied.tTag of the next element.  A pointer to a ber_tag_t                 should be supplied.TSkip element and return its tag.  A pointer to a                 ber_tag_t should be supplied.xSkip element.  The next element is skipped.{Begin sequence.  No parameter is required.  The initial                 sequence tag and length are skipped.}End sequence.  No parameter is required and no action is                 taken.[Begin set.  No parameter is required.  The initial set                 tag and length are skipped.]End set.  No parameter is required and no action is                 taken.       Theber_get_int() routine tries to interpret the next element as       an integer, returning the result innum.  The tag of whatever it       finds is returned on success, LBER_ERROR (-1) on failure.       Theber_get_stringb() routine is used to read an octet string into       a preallocated buffer.  Thelen parameter should be initialized to       the size of the buffer, and will contain the length of the octet       string read upon return.  The buffer should be big enough to take       the octet string value plus a terminating NULL byte.       Theber_get_stringa() routine is used to dynamically allocate       space into which an octet string is read.  The caller should free       the returned string usingber_memfree().       Theber_get_stringal() routine is used to dynamically allocate       space into which an octet string and its length are read.  It       takes a struct berval **, and returns the result in this       parameter.  The caller should free the returned structure usingber_bvfree().       Theber_get_stringbv() routine is used to read an octet string and       its length into the provided struct berval *. If thealloc       parameter is zero, the string will reside in memory assigned to       the BerElement, and must not be freed by the caller. If thealloc       parameter is non-zero, the string will be copied into dynamically       allocated space which should be returned usingber_memfree().       Theber_get_null() routine is used to read a NULL element.  It       returns the tag of the element it skips over.       Theber_get_boolean() routine is used to read a boolean value.  It       is called the same way thatber_get_int() is called.       Theber_get_enum() routine is used to read a enumeration value.       It is called the same way thatber_get_int() is called.       Theber_get_bitstringa() routine is used to read a bitstring       value.  It takes a char ** which will hold the dynamically       allocated bits, followed by an ber_len_t *, which will point to       the length (in bits) of the bitstring returned.  The caller should       free the returned string usingber_memfree().       Theber_first_element() routine is used to return the tag and       length of the first element in a set or sequence.  It also returns       incookie a magic cookie parameter that should be passed to       subsequent calls to ber_next_element(), which returns similar       information.

EXAMPLES        top

       Assume the variableber contains a lightweight BER encoding of the       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 usingber_scanf() as follows.             ber_int_t    scope, deref, size, time, attrsonly;             char   *dn, **attrs;             ber_tag_t tag;             tag = ber_scanf( ber, "{aeeiib{v}}",                 &dn, &scope, &deref,                 &size, &time, &attrsonly, &attrs );             if( tag == LBER_ERROR ) {                     /* error */             } else {                     /* success */             }             ber_memfree( dn );             ber_memvfree( attrs );

ERRORS        top

       If an error occurs during decoding, generally these routines       return LBER_ERROR ((ber_tag_t)-1).

NOTES        top

       The return values for all of these functions are declared in the<lber.h>header file.  Some routines may dynamically allocate       memory which must be freed by the caller using supplied       deallocation routines.

SEE ALSO        top

lber-encode(3),lber-memory(3),lber-sockbuf(3),lber-types(3)

ACKNOWLEDGEMENTS        top

OpenLDAP Softwareis developed and maintained by The OpenLDAP       Project <http://www.openldap.org/>.OpenLDAP Softwareis derived       from the University of Michigan LDAP 3.3 Release.

COLOPHON        top

       This page is part of theOpenLDAP (an open source implementation       of the Lightweight Directory Access Protocol) project.       Information about the project can be found at        ⟨http://www.openldap.org/⟩.  If you have a bug report for this       manual page, see ⟨http://www.openldap.org/its/⟩.  This page was       obtained from the project's upstream Git repository       ⟨https://git.openldap.org/openldap/openldap.git⟩ on 2025-08-11.       (At that time, the date of the most recent commit that was found       in the repository was 2025-08-05.)  If you discover any rendering       problems in this HTML version of the page, or you believe there is       a better or more up-to-date source for the page, or you have       corrections or improvements to the information in this COLOPHON       (which isnot part of the original manual page), send a mail to       man-pages@man7.orgOpenLDAP LDVERSION             RELEASEDATELBER_DECODE(3)

Pages that refer to this page:lber-encode(3)lber-memory(3)lber-sockbuf(3)lber-types(3)ldap(3)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp