LBER_TYPES(3)
π LBER_TYPES π
okay so bestie, this is a page from the Library Functions Manual, and it's literally all about the OpenLDAP LBER types and allocation functions. yes, all of them. buckle up π
β¨ NAME β¨
ber_int_t, ber_uint_t, ber_len_t, ber_slen_t, ber_tag_t, struct berval, BerValue, BerVarray, BerElement, ber_bvfree, ber_bvecfree, ber_bvecadd, ber_bvarray_free, ber_bvarray_add, ber_bvdup, ber_dupbv, ber_bvstr, ber_bvstrdup, ber_str2bv, ber_alloc_t, ber_init, ber_init2, ber_free β OpenLDAP LBER types and allocation functions π«Ά
π LIBRARY π
OpenLDAP LBER (liblber, -llber)
π₯ SYNOPSIS π₯
#include <lber.h>
typedef impl_tag_t ber_tag_t;
typedef impl_int_t ber_int_t;
typedef impl_uint_t ber_uint_t;
typedef impl_len_t ber_len_t;
typedef impl_slen_t ber_slen_t;
typedef struct berval {
ber_len_t bv_len;
char *bv_val;
} BerValue, *BerVarray;
typedef struct berelement BerElement;
void ber_bvfree(struct berval *bv);
void ber_bvecfree(struct berval **bvec);
void ber_bvecadd(struct berval ***bvec, struct berval *bv);
void ber_bvarray_free(struct berval *bvarray);
void ber_bvarray_add(BerVarray *bvarray, BerValue *bv);
struct berval *ber_bvdup(const struct berval *bv);
struct berval *ber_dupbv(const struct berval *dst, struct berval *src);
struct berval *ber_bvstr(const char *str);
struct berval *ber_bvstrdup(const char *str);
struct berval *ber_str2bv(const char *str, ber_len_t len, int dup,
struct berval *bv);
BerElement *ber_alloc_t(int options);
BerElement *ber_init(struct berval *bv);
void ber_init2(BerElement *ber, struct berval *bv, int options);
void ber_free(BerElement *ber, int freebuf);
πΈ DESCRIPTION πΈ
these are the basic types and structures defined for use with the Lightweight BER library. the whole squad. let's go through them one by one π
ber_int_t is a signed integer of at least 32 bits. it's commonly equivalent to int. and ber_uint_t is the unsigned variant of ber_int_t.
ber_len_t is an unsigned integer of at least 32 bits used to represent a length. it's commonly equivalent to a size_t. ber_slen_t is the signed variant to ber_len_t.
ber_tag_t is an unsigned integer of at least 32 bits used to represent a BER tag. it's commonly equivalent to a unsigned long.
the actual definitions of the integral impl_TYPE_t types are platform specific π so like, don't assume, bestie.
BerValue, commonly used as struct berval, is used to hold an arbitrary sequence of octets. bv_val points to bv_len octets. and listen β bv_val is not necessarily terminated by a NULL (zero) octet. so do not go treating it like a C string, i'm begging π
ber_bvfree()β frees aBerValue, pointed to by bv, returned from this API. if bv isNULL, the routine does nothing. iconique, no crash energy.ber_bvecfree()β frees an array ofBerValues (and the array), pointed to by bvec, returned from this API. if bvec isNULL, the routine does nothing.ber_bvecadd()β appends the bv pointer to the bvec array. space for the array is allocated as needed. the end of the array is marked by aNULLpointer.ber_bvarray_free()β frees an array ofBerValues (and the array), pointed to by bvarray, returned from this API. if bvarray isNULL, the routine does nothing.ber_bvarray_add()β appends the contents of theBerValuepointed to by bv to the bvarray array. space for the new element is allocated as needed. the end of the array is marked by aBerValuewith aNULLbv_valfield.
π¦ copying stuff around π¦
ber_bvdup() returns a copy of a BerValue. the routine returns NULL upon error (e.g. out of memory). the caller should use ber_bvfree() to deallocate the resulting BerValue.
ber_dupbv() copies a BerValue from src to dst. if dst is NULL a new BerValue will be allocated to hold the copy. the routine returns NULL upon error, otherwise it returns a pointer to the copy. if dst is NULL the caller should use ber_bvfree() to deallocate the resulting BerValue, otherwise ber_memfree() should be used to deallocate the dst->bv_val.
ngl the memory-freeing rules here are giving "two different cleanup paths" and if you mix them up it's gonna be a bad time πber_bvdup()is internally implemented asber_dupbv(NULL, bv).ber_bvdup()is provided only for compatibility with an expired draft of the LDAP C API βber_dupbv()is the preferred interface. periodt.
π§ string-flavoured BerValues π§
ber_bvstr() returns a BerValue containing the string pointed to by str. ber_bvstrdup() returns a BerValue containing a copy of the string pointed to by str.
ber_str2bv() returns a BerValue containing the string pointed to by str, whose length may be optionally specified in len. if dup is non-zero, the BerValue will contain a copy of str. if len is zero, the number of bytes to copy will be determined by strlen(3), otherwise len bytes will be copied. if bv is non-NULL, the result will be stored in the given BerValue, otherwise a new BerValue will be allocated to store the result.
NOTE: bothber_bvstr()andber_bvstrdup()are implemented as macros usingber_str2bv()in this version of the library. so like, they're not real functions, they're macros π
π BerElement, the mysterious one π
BerElement is an opaque structure used to maintain state information used in encoding and decoding. main character energy, honestly.
ber_alloc_t()β used to create an emptyBerElementstructure. ifLBER_USE_DERis specified for the options parameter then data lengths for data written to theBerElementwill be encoded in the minimal number of octets required, otherwise they will always be written as four byte values.ber_init()β creates aBerElementstructure that is initialized with a copy of the data in its bv parameter.ber_init2()β initializes an existingBerElementber using the data in the bv parameter. the data is referenced directly, not copied. the options parameter is the same as forber_alloc_t().ber_free()β frees aBerElementpointed to by ber. if ber isNULL, the routine does nothing. if freebuf is zero, the internal buffer is not freed.
ok but theber_init()vsber_init2()difference is so important β one copies, one does not π don't come for me when your buffer goes out of scope, i warned you π
π SEE ALSO π
lber-encode(3), lber-decode(3), lber-memory(3)
π ACKNOWLEDGEMENTS π
OpenLDAP Software is developed and maintained by The OpenLDAP Project <http://www.openldap.org/>. OpenLDAP Software is derived from the University of Michigan LDAP 3.3 Release.
okay that's the whole page bestie, go forth and encode π¦π
OpenLDAP 2.6.16 β dated 2026/10/21 β that's the version and date, mwah, slay, goodbye πβ¨
π¦ where this page comes from
- fedora 44: openldap-devel 2.6.16-1.fc44 Β· OLDAP-2.8
- fedora 44: openldap-devel 2.6.16-1.fc44 Β· OLDAP-2.8
- Copyright 1998-2026 The OpenLDAP Foundation All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms