⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lber-decode.3

📁 开放源码的ldap系统
💻 3
字号:
.TH LBER_DECODE 3 "12 July 2000" "OpenLDAP LDVERSION".\" $OpenLDAP: pkg/ldap/doc/man/man3/lber-decode.3,v 1.4.8.2 2000/07/29 01:53:04 kurt Exp $.\" Copyright 1998-2000 The OpenLDAP Foundation All Rights Reserved..\" Copying restrictions apply.  See COPYRIGHT/LICENSE..SH NAMEber_get_next, ber_skip_tag, ber_peek_tag, ber_scanf, ber_get_int, ber_get_enum, 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.SH SYNOPSIS.nf.ft B#include <lber.h>.ft.fi.LP.nf.ft Bber_tag_t ber_get_next(	Sockbuf *sb,	ber_len_t \(**len,	BerElement \(**ber);.ft.fi.LP.nf.ft Bber_tag_t ber_skip_tag(	BerElement \(**ber,	ber_len_t long \(**len);.ft.fi.LP.nf.ft Bber_tag_t ber_peek_tag(	BerElement \(**ber,	ber_len_t \(**len);.ft.fi.LP.nf.ft Bber_tag_t ber_scanf(	BerElement \(**ber,	const char \(**fmt, ...);.ft.fi.LP.nf.ft Bber_tag_t ber_get_int(	BerElement \(**ber,	ber_int_t \(**num);.ft.fi.LP.nf.ft Bber_tag_t ber_get_enum(	BerElement \(**ber,	ber_int_t \(**num);.ft.fi.LP.nf.ft Bber_tag_t ber_get_stringb(	BerElement \(**ber,	char \(**buf,	ber_len_t \(**len);.ft.fi.LP.nf.ft Bber_tag_t ber_get_stringa(	BerElement \(**ber,	char \(***buf);.ft.fi.LP.nf.ft Bber_tag_t ber_get_stringal(	BerElement \(**ber,	struct berval \(***bv);.ft.fi.LP.nf.ft Bber_tag_t ber_get_null(	BerElement \(**ber );.ft.fi.LP.nf.ft Bber_tag_t ber_get_boolean(	BerElement \(**ber,	ber_int_t \(**bool);.ft.fi.LP.nf.ft Bber_tag_t ber_get_bitstringa(	BerElement \(**ber,	char \(***buf,	ber_len_t \(**blen);.ft.fi.LP.nf.ft Bber_tag_t ber_first_element(	BerElement \(**ber,	ber_len_t \(**len,	char \(***cookie);.ft.fi.LP.nf.ft Bber_tag_t ber_next_element(	BerElement \(**ber,	ber_len_t \(**len,	const char \(**cookie);.SH DESCRIPTION.LPThese 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.Consult lber-types(3) for information about types, allocators, and deallocators..LPNormally, 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..LPThe ber_get_next() routine is used to read the next BER element fromthe given Sockbuf, \fIsb\fP.  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 \fIsb_ber\fP struct shouldbe zeroed.  It strips off and returns theleading tag byte, strips off and returns the length of theentire element in \fIlen\fP,and sets up \fIber\fP for subsequent calls to ber_scanf() et al to decodethe element..LPThe ber_scanf() routine is used to decode a BER element in much thesame way that scanf(3) works.  It reads from \fIber\fP, a pointer to aBerElement such as returned by ber_get_next(), interprets thebytes according to the format string \fIfmt\fP, 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..RS.LP.TP 3.SM aOctet string.  A char ** should be supplied.  Memory is allocated,filled with the contents of the octet string, null-terminated, andreturned in the parameter.The caller should free the returned ber_val using ber_memfree()..TP.SM sOctet string.  A char * buffer should be supplied, followed by a pointerto a ber_len_t 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..TP.SM OOctet string.  A struct ber_val ** should be supplied, which upon returnpoints to a dynamically allocated struct berval containing the octet stringand its length.The caller should free the returned structure using ber_bvfree()..TP.SM oOctet string.  A struct ber_val * should be supplied, which upon returnpoints containing the dynamically allocated octet string and its length.The caller should free the returned octet string using ber_memfree()..TP.SM bBoolean.  A pointer to a ber_int_t should be supplied..TP.SM eEnumeration.  A pointer to a ber_int_t should be supplied..TP.SM iInteger.  A pointer to a ber_int_t should be supplied..TP.SM BBitstring.  A char ** should be supplied which will point to thedynamically allocatedbits, followed by an ber_len_t *, which will point to the length(in bits) of the bitstring returned..TP.SM nNull.  No parameter is required.  The element is simply skipped ifit is recognized..TP.SM vSequence of octet strings.  A char *** should be supplied, which uponreturn points to a dynamically allocated null-terminated array of char *'scontaining the octet strings.  NULL is returned if the sequence is empty.The caller should free the returned array and octet strings usingber_memvfree()..TP.SM VSequence of octet strings with lengths.A struct berval *** should be supplied, which uponreturn points to a dynamically allocated null-terminated array ofstruct berval *'scontaining the octet strings and their lengths.NULL is returned if the sequence is empty.  The caller should free the returned structures using ber_bvecfree()..TP.SM lLength of the next element.  A pointer to a ber_len_t should be supplied..TP.SM tTag of the next element.  A pointer to a ber_tag_t should be supplied..TP.SM TSkip element and return its tag.  A pointer to a ber_tag_t should be supplied..TP.SM xSkip element.  The next element is skipped..TP.SM {Begin sequence.  No parameter is required.  The initial sequence tagand length are skipped..TP.SM }End sequence.  No parameter is required and no action is taken..TP.SM [Begin set.  No parameter is required.  The initial set tagand length are skipped..TP.SM ]End set.  No parameter is required and no action is taken..RE.LPThe ber_get_int() routine tries to interpret the next element as an integer,returning the result in \fInum\fP.  The tag of whatever it finds is returnedon success, LBER_ERROR (\-1) on failure..LPThe ber_get_stringb() routine is used to read an octet string into apreallocated buffer.  The \fIlen\fP 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..LPThe ber_get_stringa() routine is used to dynamically allocate space intowhich an octet string is read.The caller should free the returned string using ber_memfree()..LPThe ber_get_stringal() routine is used to dynamically allocate spaceinto which an octet string and its length are read.  It takes astruct berval **, and returns the result in this parameter.The caller should free the returned structure using ber_bvfree()..LPThe ber_get_null() routine is used to read a NULL element.  It returnsthe tag of the element it skips over..LPThe ber_get_boolean() routine is used to read a boolean value.It is called the same way that ber_get_int() is called..LPThe ber_get_enum() routine is used to read a enumeration value.It is called the same way that ber_get_int() is called..LPThe ber_get_bitstringa() routine is used to read a bitstring value.  Ittakes a char ** which will hold the dynamically allocated bits, followed by anber_len_t *, which will point to the length (in bits) of the bitstring returned.The caller should free the returned string using ber_memfree()..LPThe ber_first_element() routine is used to return the tag and lengthof the first element in a set or sequence.  It also returns in \fIcookie\fPa magic cookie parameter that should be passed to subsequent calls tober_next_element(), which returns similar information..SH EXAMPLESAssume the variable \fIber\fP contains a lightweight BER encoding ofthe following ASN.1 object:.LP.nf      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      }.fi.LPThe element can be decoded using ber_scanf() as follows..LP.nf      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 );.fi.SH ERRORSIf an error occurs during decoding, generally these routines returnLBER_ERROR (\-1)..LP.SH NOTES.LPThe return values for all of these functions are declared in the<lber.h> header file.Some routines may dynamically allocate memorywhich must be freed by the caller using supplied deallocation routines..SH SEE ALSO.BR lber-encode (3).BR lber-memory (3).BR lber-types (3).BR ldap-parse (3).BR ldap-sync (3).BR ldap-async (3).SH ACKNOWLEDGEMENTS.B	OpenLDAPis developed and maintained by The OpenLDAP Project (http://www.openldap.org/)..B	OpenLDAPis derived from University of Michigan LDAP 3.3 Release.  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -