1*f0a07bbbSschwarze.\" $OpenBSD: ober_get_string.3,v 1.6 2021/03/31 19:31:35 schwarze Exp $ 2696b5899Stb.\" 3696b5899Stb.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> 4696b5899Stb.\" 5696b5899Stb.\" Permission to use, copy, modify, and distribute this software for any 6696b5899Stb.\" purpose with or without fee is hereby granted, provided that the above 7696b5899Stb.\" copyright notice and this permission notice appear in all copies. 8696b5899Stb.\" 9696b5899Stb.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10696b5899Stb.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11696b5899Stb.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12696b5899Stb.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13696b5899Stb.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14696b5899Stb.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15696b5899Stb.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16696b5899Stb.\" 17*f0a07bbbSschwarze.Dd $Mdocdate: March 31 2021 $ 18696b5899Stb.Dt OBER_GET_STRING 3 19696b5899Stb.Os 20696b5899Stb.Sh NAME 21696b5899Stb.Nm ober_get_null , 22696b5899Stb.Nm ober_get_eoc , 23696b5899Stb.Nm ober_get_integer , 24696b5899Stb.Nm ober_get_enumerated , 25696b5899Stb.Nm ober_get_boolean , 26696b5899Stb.Nm ober_get_string , 27696b5899Stb.Nm ober_get_nstring , 28696b5899Stb.Nm ober_get_ostring , 29696b5899Stb.Nm ober_get_bitstring , 30696b5899Stb.Nm ober_get_oid , 31696b5899Stb.Nm ober_getpos , 32696b5899Stb.Nm ober_scanf_elements 33696b5899Stb.Nd access properties of ASN.1 objects decoded from BER 34696b5899Stb.Sh SYNOPSIS 35696b5899Stb.In sys/types.h 36696b5899Stb.In ber.h 37696b5899Stb.Ft "int" 38696b5899Stb.Fn "ober_get_null" "struct ber_element *root" 39696b5899Stb.Ft "int" 40696b5899Stb.Fn "ober_get_eoc" "struct ber_element *root" 41696b5899Stb.Ft "int" 42696b5899Stb.Fn "ober_get_integer" "struct ber_element *root" "long long *val" 43696b5899Stb.Ft "int" 44696b5899Stb.Fn "ober_get_enumerated" "struct ber_element *root" "long long *val" 45696b5899Stb.Ft "int" 46696b5899Stb.Fn "ober_get_boolean" "struct ber_element *root" "int *bool" 47696b5899Stb.Ft "int" 48696b5899Stb.Fn "ober_get_string" "struct ber_element *root" "char **charbuf" 49696b5899Stb.Ft "int" 50696b5899Stb.Fn "ober_get_nstring" "struct ber_element *root" "void **buf" "size_t *size" 51696b5899Stb.Ft "int" 52696b5899Stb.Fn "ober_get_ostring" "struct ber_element *root" "struct ber_octetstring *ostring" 53696b5899Stb.Ft "int" 54696b5899Stb.Fn "ober_get_bitstring" "struct ber_element *root" "void **buf" "size_t *size" 55696b5899Stb.Ft "int" 56696b5899Stb.Fn "ober_get_oid" "struct ber_element *root" "struct ber_oid *oid" 57696b5899Stb.Ft off_t 58696b5899Stb.Fn "ober_getpos" "struct ber_element *elm" 59696b5899Stb.Ft "int" 60696b5899Stb.Fn "ober_scanf_elements" "struct ber_element *root" "char *format" "..." 61696b5899Stb.Sh DESCRIPTION 62696b5899StbFunctions which take two arguments save the value contained in the 63696b5899Stb.Fa root 64696b5899Stbelement into the storage location pointed to by the second argument. 65561e0011SmartijnIf the storage location is 66561e0011Smartijn.Dv NULL 67561e0011Smartijnthen only a type check is performed. 68696b5899StbAdditionally, 69696b5899Stb.Fn ober_get_nstring 70696b5899Stband 71696b5899Stb.Fn ober_get_bitstring 72696b5899Stbsave the number of bytes contained in the string into 73696b5899Stb.Pf * Fa size . 74561e0011SmartijnIf 75561e0011Smartijn.Fa buf 76561e0011Smartijnis 77561e0011Smartijn.Dv NULL 78561e0011Smartijnand size is not 79561e0011Smartijn.Dv NULL , 80561e0011Smartijnsize is set. 81561e0011Smartijn.Fa size 82561e0011Smartijnmust not be 83561e0011Smartijn.Dv NULL 84561e0011Smartijnto return a valid 85561e0011Smartijn.Fa buf . 86696b5899Stb.Pp 87696b5899Stb.Fn ober_scanf_elements 88696b5899Stbretrieves the values from zero or more elements starting at 89696b5899Stb.Fa root . 904e0a17bcSmartijnFor each character in 91696b5899Stb.Fa fmt , 92696b5899Stbarguments of the types given in the following table are consumed 93696b5899Stband passed to the function listed, processing one 94696b5899Stb.Vt ber_element 954e0a17bcSmartijnper character. 964e0a17bcSmartijnThe following characters are valid: 97*f0a07bbbSschwarze.Bl -column -offset indent\ 98*f0a07bbbSschwarze characte ober_get_enumerated_ "1: struct ber_element **" 994e0a17bcSmartijn.It Sy character Ta Sy function Ta Sy arguments 100b8d19846Smartijn.It $ Ta see below Ta 0 101696b5899Stb.It B Ta Fn ober_get_bitstring Ta 2: Vt void ** , size_t * 102696b5899Stb.It b Ta Fn ober_get_boolean Ta 1: Vt int * 103696b5899Stb.It d Ta Fn ober_get_integer Ta 1: Vt int * 104696b5899Stb.It E Ta Fn ober_get_enumerated Ta 1: Vt long long * 105696b5899Stb.It e Ta see below Ta 1: Vt struct ber_element ** 106696b5899Stb.It i Ta Fn ober_get_integer Ta 1: Vt long long * 107696b5899Stb.It o Ta Fn ober_get_oid Ta 1: Vt struct ber_oid * 108696b5899Stb.It p Ta Fn ober_getpos Ta 1: Vt off_t * 109696b5899Stb.It S Ta see below Ta 0 110696b5899Stb.It s Ta Fn ober_get_string Ta 1: Vt char ** 111696b5899Stb.It t Ta see below Ta 2: Vt int * , unsigned int * 112696b5899Stb.It x Ta Fn ober_get_nstring Ta 2: Vt void **, size_t * 113696b5899Stb.It \&( or { Ta see below Ta 0 114696b5899Stb.It \&) or } Ta see below Ta 0 115696b5899Stb.It \&. Ta Fn ober_get_eoc Ta 0 116696b5899Stb.It 0 Ta Fn ober_get_null Ta 0 117696b5899Stb.El 118696b5899Stb.Pp 119696b5899StbFor 120696b5899Stb.Sq e , 121696b5899Stb.Sq p , 122696b5899Stb.Sq S , 123696b5899Stband 124696b5899Stb.Sq t , 125696b5899Stbthe type of the element is not checked. 126696b5899StbFor 127696b5899Stb.Sq p 128696b5899Stband 129696b5899Stb.Sq t , 130696b5899Stbthe pointer is not incremented to the next element. 131696b5899StbFor 132696b5899Stb.Sq e , 133696b5899Stba pointer to the element is stored in the corresponding pointer variable. 134696b5899StbFor 135696b5899Stb.Sq S , 136696b5899Stbthe element is skipped without extracting any information from it. 137696b5899StbFor 138696b5899Stb.Sq t , 139696b5899Stbthe class and type of the element are stored in the two corresponding 140696b5899Stbvariables, but if the element contains a value, that value is ignored. 141b8d19846SmartijnA 142b8d19846Smartijn.Sq $ 143b8d19846Smartijnmandates the end of a sequence or set. 144696b5899Stb.Pp 145696b5899StbFor an opening parenthesis or brace, it is checked that the element 146696b5899Stbis a sequence or a set, and parsing continues with its children. 147696b5899StbFor a closing parenthesis or brace, parsing of the current sequence 148696b5899Stbor set is ended and parsing continues with the element following 149696b5899Stbthe sequence or set. 150696b5899Stb.Sh RETURN VALUES 151696b5899Stb.Fn ober_getpos 152696b5899Stbreturns the value of 153696b5899Stb.Vt be_offs . 154696b5899Stb.Pp 155696b5899Stb.Fn ober_scanf_elements 156696b5899Stbreturns 0 for success or \-1 when encountering elements that do not 157696b5899Stbagree with the expectations of 158696b5899Stb.Fa fmt 159696b5899Stbor when 160696b5899Stb.Fa fmt 161696b5899Stbis syntactically invalid. 162696b5899StbEven when 163696b5899Stb.Fn ober_scanf_elements 164696b5899Stbfails, some of the arguments may already have been filled in. 165696b5899Stb.Pp 166696b5899StbThe other functions return 0 if 167696b5899Stb.Va root 168696b5899Stbis of the requested type or \-1 otherwise. 169696b5899Stb.Sh SEE ALSO 170696b5899Stb.Xr ober_add_string 3 , 171696b5899Stb.Xr ober_oid_cmp 3 , 172696b5899Stb.Xr ober_read_elements 3 , 173696b5899Stb.Xr ober_set_header 3 174696b5899Stb.Sh STANDARDS 175696b5899StbITU-T Recommendation X.690, also known as ISO/IEC 8825-1: 176696b5899StbInformation technology - ASN.1 encoding rules. 177696b5899Stb.Sh HISTORY 178696b5899StbThese functions first appeared as internal functions in 179696b5899Stb.Xr snmpd 8 180696b5899Stbin 181696b5899Stb.Ox 4.2 182696b5899Stband were moved to libutil in 183696b5899Stb.Ox 6.6 . 184696b5899Stb.Sh AUTHORS 185696b5899Stb.An -nosplit 186696b5899StbThe BER library was written by 187696b5899Stb.An Claudio Jeker Aq Mt claudio@openbsd.org , 188696b5899Stb.An Marc Balmer Aq Mt marc@openbsd.org 189696b5899Stband 190696b5899Stb.An Reyk Floeter Aq Mt reyk@openbsd.org . 191