2002-06-13 11:59:10 +08:00
|
|
|
.TH LBER_ENCODE 3 "RELEASEDATE" "OpenLDAP LDVERSION"
|
1999-09-12 12:41:47 +08:00
|
|
|
.\" $OpenLDAP$
|
2016-01-30 03:32:05 +08:00
|
|
|
.\" Copyright 1998-2016 The OpenLDAP Foundation All Rights Reserved.
|
1999-09-12 12:41:47 +08:00
|
|
|
.\" Copying restrictions apply. See COPYRIGHT/LICENSE.
|
1998-08-09 08:43:13 +08:00
|
|
|
.SH NAME
|
2007-07-25 03:11:39 +08:00
|
|
|
ber_alloc_t, ber_flush, ber_flush2, ber_printf, ber_put_int, ber_put_enum, ber_put_ostring, ber_put_string, ber_put_null, ber_put_boolean, ber_put_bitstring, ber_start_seq, ber_start_set, ber_put_seq, ber_put_set \- OpenLDAP LBER simplified Basic Encoding Rules library routines for encoding
|
2002-06-21 15:32:54 +08:00
|
|
|
.SH LIBRARY
|
2009-06-03 08:43:44 +08:00
|
|
|
OpenLDAP LBER (liblber, \-llber)
|
1998-08-09 08:43:13 +08:00
|
|
|
.SH SYNOPSIS
|
2002-01-25 20:34:57 +08:00
|
|
|
.B #include <lber.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "BerElement *ber_alloc_t(int " options ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_flush(Sockbuf *" sb ", BerElement *" ber ", int " freeit ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2006-04-10 06:29:42 +08:00
|
|
|
.BI "int ber_flush2(Sockbuf *" sb ", BerElement *" ber ", int " freeit ");"
|
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_printf(BerElement *" ber ", const char *" fmt ", ...);"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_put_int(BerElement *" ber ", ber_int_t " num ", ber_tag_t " tag ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_put_enum(BerElement *" ber ", ber_int_t " num ", ber_tag_t " tag ");"
|
2000-05-14 07:08:25 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_put_ostring(BerElement *" ber ", const char *" str ", ber_len_t " len ", ber_tag_t " tag ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_put_string(BerElement *" ber ", const char *" str ", ber_tag_t " tag ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_put_null(BerElement *" ber ", ber_tag_t " tag ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_put_boolean(BerElement *" ber ", ber_int_t " bool ", ber_tag_t " tag ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_put_bitstring(BerElement *" ber ", const char *" str ", ber_len_t " blen ", ber_tag_t " tag ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_start_seq(BerElement *" ber ", ber_tag_t " tag ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_start_set(BerElement *" ber ", ber_tag_t " tag ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_put_seq(BerElement *" ber ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
.BI "int ber_put_set(BerElement *" ber ");"
|
1998-08-09 08:43:13 +08:00
|
|
|
.SH DESCRIPTION
|
|
|
|
.LP
|
|
|
|
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
|
2002-01-25 20:34:57 +08:00
|
|
|
are always encoded in primitive form. This
|
1998-08-09 08:43:13 +08:00
|
|
|
man page describes the encoding routines in the lber library. See
|
2002-01-25 20:34:57 +08:00
|
|
|
.BR lber-decode (3)
|
|
|
|
for details on the corresponding decoding routines. Consult
|
|
|
|
.BR lber-types (3)
|
|
|
|
for information about types, allocators, and deallocators.
|
|
|
|
.LP
|
|
|
|
Normally, the only routines that need to be called by an application
|
|
|
|
are
|
|
|
|
.BR ber_alloc_t ()
|
|
|
|
to allocate a BER element for encoding,
|
|
|
|
.BR ber_printf ()
|
|
|
|
to do the actual encoding, and
|
2006-04-10 06:29:42 +08:00
|
|
|
.BR ber_flush2 ()
|
2002-01-25 20:34:57 +08:00
|
|
|
to actually write the element. The other routines are provided for those
|
|
|
|
applications that need more control than
|
|
|
|
.BR ber_printf ()
|
|
|
|
provides. In
|
1998-08-09 08:43:13 +08:00
|
|
|
general, these routines return the length of the element encoded, or
|
2003-01-19 21:10:17 +08:00
|
|
|
-1 if an error occurred.
|
2002-01-25 20:34:57 +08:00
|
|
|
.LP
|
|
|
|
The
|
|
|
|
.BR ber_alloc_t ()
|
|
|
|
routine is used to allocate a new BER element. It
|
|
|
|
should be called with an argument of LBER_USE_DER.
|
|
|
|
.LP
|
|
|
|
The
|
2006-04-10 06:29:42 +08:00
|
|
|
.BR ber_flush2 ()
|
2002-01-25 20:34:57 +08:00
|
|
|
routine is used to actually write the element to a socket
|
|
|
|
(or file) descriptor, once it has been fully encoded (using
|
|
|
|
.BR ber_printf ()
|
|
|
|
and friends). See
|
2002-05-09 10:07:41 +08:00
|
|
|
.BR lber-sockbuf (3)
|
2002-01-25 20:34:57 +08:00
|
|
|
for more details on the Sockbuf implementation of the \fIsb\fP parameter.
|
|
|
|
If the \fIfreeit\fP parameter is non-zero, the supplied \fIber\fP will
|
2006-04-10 06:29:42 +08:00
|
|
|
be freed.
|
|
|
|
If \fILBER_FLUSH_FREE_ON_SUCCESS\fP is used, the \fIber\fP is only freed
|
|
|
|
when successfully flushed, otherwise it is left intact;
|
|
|
|
if \fILBER_FLUSH_FREE_ON_ERROR\fP is used, the \fIber\fP is only freed
|
|
|
|
when an error occurs, otherwise it is left intact;
|
|
|
|
if \fILBER_FLUSH_FREE_ALWAYS\fP is used, the \fIber\fP is freed anyway.
|
|
|
|
This function differs from the original
|
|
|
|
.BR ber_flush (3)
|
|
|
|
function, whose behavior corresponds to that indicated
|
|
|
|
for \fILBER_FLUSH_FREE_ON_SUCCESS\fP.
|
|
|
|
Note that in the future, the behavior of
|
|
|
|
.BR ber_flush (3)
|
|
|
|
with \fIfreeit\fP non-zero might change into that of
|
|
|
|
.BR ber_flush2 (3)
|
|
|
|
with \fIfreeit\fP set to \fILBER_FLUSH_FREE_ALWAYS\fP.
|
2002-01-25 20:34:57 +08:00
|
|
|
.LP
|
|
|
|
The
|
|
|
|
.BR ber_printf ()
|
|
|
|
routine is used to encode a BER element in much the same way that
|
|
|
|
.BR sprintf (3)
|
|
|
|
works. One important difference, though, is
|
1998-08-09 08:43:13 +08:00
|
|
|
that some state information is kept with the \fIber\fP parameter so
|
2002-01-25 20:34:57 +08:00
|
|
|
that multiple calls can be made to
|
|
|
|
.BR ber_printf ()
|
|
|
|
to append things to the end of the BER element.
|
|
|
|
.BR Ber_printf ()
|
|
|
|
writes to \fIber\fP, a pointer to a BerElement such as returned by
|
|
|
|
.BR ber_alloc_t ().
|
|
|
|
It interprets and
|
1998-08-09 08:43:13 +08:00
|
|
|
formats its arguments according to the format string \fIfmt\fP.
|
|
|
|
The format string can contain the following characters:
|
|
|
|
.RS
|
|
|
|
.LP
|
|
|
|
.TP 3
|
2002-01-25 20:34:57 +08:00
|
|
|
.B b
|
2000-05-13 09:44:58 +08:00
|
|
|
Boolean. An ber_int_t parameter should be supplied. A boolean element
|
1998-08-09 08:43:13 +08:00
|
|
|
is output.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B e
|
2000-05-14 07:08:25 +08:00
|
|
|
Enumeration. An ber_int_t parameter should be supplied. An
|
|
|
|
enumeration element is output.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B i
|
2000-05-13 09:44:58 +08:00
|
|
|
Integer. An ber_int_t parameter should be supplied. An integer element
|
1998-08-09 08:43:13 +08:00
|
|
|
is output.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B B
|
1998-08-09 08:43:13 +08:00
|
|
|
Bitstring. A char * pointer to the start of the bitstring is supplied,
|
|
|
|
followed by the number of bits in the bitstring. A bitstring element
|
|
|
|
is output.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B n
|
1998-08-09 08:43:13 +08:00
|
|
|
Null. No parameter is required. A null element is output.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B o
|
1998-08-09 08:43:13 +08:00
|
|
|
Octet string. A char * is supplied, followed by the length of the
|
|
|
|
string pointed to. An octet string element is output.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B O
|
2000-05-14 07:08:25 +08:00
|
|
|
Octet string. A struct berval * is supplied.
|
|
|
|
An octet string element is output.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B s
|
1998-08-09 08:43:13 +08:00
|
|
|
Octet string. A null-terminated string is supplied. An octet string
|
|
|
|
element is output, not including the trailing NULL octet.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B t
|
2000-05-13 09:44:58 +08:00
|
|
|
Tag. A ber_tag_t specifying the tag to give the next element
|
|
|
|
is provided. This works across calls.
|
1998-08-09 08:43:13 +08:00
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B v
|
1998-08-09 08:43:13 +08:00
|
|
|
Several octet strings. A null-terminated array of char *'s is
|
|
|
|
supplied. Note that a construct like '{v}' is required to get
|
|
|
|
an actual SEQUENCE OF octet strings.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B V
|
2000-05-14 07:08:25 +08:00
|
|
|
Several octet strings. A null-terminated array of struct berval *'s
|
|
|
|
is supplied. Note that a construct like '{V}' is required to get
|
|
|
|
an actual SEQUENCE OF octet strings.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B W
|
|
|
|
Several octet strings. An array of struct berval's is supplied. The
|
|
|
|
array is terminated by a struct berval with a NULL bv_val.
|
|
|
|
Note that a construct like '{W}' is required to get
|
|
|
|
an actual SEQUENCE OF octet strings.
|
|
|
|
.TP
|
|
|
|
.B {
|
1998-08-09 08:43:13 +08:00
|
|
|
Begin sequence. No parameter is required.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B }
|
1998-08-09 08:43:13 +08:00
|
|
|
End sequence. No parameter is required.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B [
|
1998-08-09 08:43:13 +08:00
|
|
|
Begin set. No parameter is required.
|
|
|
|
.TP
|
2002-01-25 20:34:57 +08:00
|
|
|
.B ]
|
1998-08-09 08:43:13 +08:00
|
|
|
End set. No parameter is required.
|
|
|
|
.RE
|
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
The
|
|
|
|
.BR ber_put_int ()
|
|
|
|
routine writes the integer element \fInum\fP to the BER element \fIber\fP.
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
The
|
|
|
|
.BR ber_put_enum ()
|
|
|
|
routine writes the enumeration element \fInum\fP to the BER element \fIber\fP.
|
2000-05-14 07:08:25 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
The
|
|
|
|
.BR ber_put_boolean ()
|
|
|
|
routine writes the boolean value given by \fIbool\fP to the BER element.
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
The
|
|
|
|
.BR ber_put_bitstring ()
|
|
|
|
routine writes \fIblen\fP bits starting
|
1998-08-09 08:43:13 +08:00
|
|
|
at \fIstr\fP as a bitstring value to the given BER element. Note
|
|
|
|
that \fIblen\fP is the length \fIin bits\fP of the bitstring.
|
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
The
|
|
|
|
.BR ber_put_ostring ()
|
|
|
|
routine writes \fIlen\fP bytes starting at
|
1998-08-09 08:43:13 +08:00
|
|
|
\fIstr\fP to the BER element as an octet string.
|
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
The
|
|
|
|
.BR ber_put_string ()
|
|
|
|
routine writes the null-terminated string (minus
|
1998-08-09 08:43:13 +08:00
|
|
|
the terminating '\0') to the BER element as an octet string.
|
|
|
|
.LP
|
2002-01-25 20:34:57 +08:00
|
|
|
The
|
|
|
|
.BR ber_put_null ()
|
|
|
|
routine writes a NULL element to the BER element.
|
|
|
|
.LP
|
|
|
|
The
|
|
|
|
.BR ber_start_seq ()
|
|
|
|
routine is used to start a sequence in the BER element. The
|
|
|
|
.BR ber_start_set ()
|
|
|
|
routine works similarly.
|
|
|
|
The end of the sequence or set is marked by the nearest matching call to
|
|
|
|
.BR ber_put_seq ()
|
|
|
|
or
|
|
|
|
.BR ber_put_set (),
|
|
|
|
respectively.
|
1998-08-09 08:43:13 +08:00
|
|
|
.SH EXAMPLES
|
|
|
|
Assuming the following variable declarations, and that the variables
|
|
|
|
have been assigned appropriately, an lber encoding of
|
|
|
|
the 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
|
|
|
|
.LP
|
|
|
|
can be achieved like so:
|
|
|
|
.LP
|
|
|
|
.nf
|
2000-05-13 09:44:58 +08:00
|
|
|
int rc;
|
|
|
|
ber_int_t scope, ali, size, time, attrsonly;
|
1998-08-09 08:43:13 +08:00
|
|
|
char *dn, **attrs;
|
2000-05-14 07:08:25 +08:00
|
|
|
BerElement *ber;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/* ... fill in values ... */
|
2000-05-14 07:08:25 +08:00
|
|
|
|
2000-05-13 09:44:58 +08:00
|
|
|
ber = ber_alloc_t( LBER_USE_DER );
|
|
|
|
|
|
|
|
if ( ber == NULL ) {
|
2003-06-29 23:34:32 +08:00
|
|
|
/* error */
|
2000-05-14 07:08:25 +08:00
|
|
|
}
|
2000-05-13 09:44:58 +08:00
|
|
|
|
|
|
|
rc = ber_printf( ber, "{siiiib{v}}", dn, scope, ali,
|
|
|
|
size, time, attrsonly, attrs );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2009-06-03 08:43:44 +08:00
|
|
|
if( rc == \-1 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
/* error */
|
2000-05-13 09:44:58 +08:00
|
|
|
} else {
|
1998-08-09 08:43:13 +08:00
|
|
|
/* success */
|
2000-05-13 09:44:58 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
.fi
|
|
|
|
.SH ERRORS
|
2009-06-03 08:43:44 +08:00
|
|
|
If an error occurs during encoding, generally these routines return \-1.
|
1998-08-09 08:43:13 +08:00
|
|
|
.LP
|
|
|
|
.SH NOTES
|
|
|
|
.LP
|
|
|
|
The return values for all of these functions are declared in the
|
|
|
|
<lber.h> header file.
|
|
|
|
.SH SEE ALSO
|
2002-05-09 10:07:41 +08:00
|
|
|
.BR lber-decode (3),
|
|
|
|
.BR lber-memory (3),
|
|
|
|
.BR lber-sockbuf (3),
|
2000-05-13 09:44:58 +08:00
|
|
|
.BR lber-types (3)
|
1998-10-25 09:41:42 +08:00
|
|
|
.SH ACKNOWLEDGEMENTS
|
2007-01-03 04:25:16 +08:00
|
|
|
.so ../Project
|