jcs's openbsd hax
openbsd
at jcs 191 lines 5.8 kB view raw
1.\" $OpenBSD: ober_get_string.3,v 1.8 2025/06/13 18:34:00 schwarze Exp $ 2.\" 3.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org> 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" 17.Dd $Mdocdate: June 13 2025 $ 18.Dt OBER_GET_STRING 3 19.Os 20.Sh NAME 21.Nm ober_get_null , 22.Nm ober_get_eoc , 23.Nm ober_get_integer , 24.Nm ober_get_enumerated , 25.Nm ober_get_boolean , 26.Nm ober_get_string , 27.Nm ober_get_nstring , 28.Nm ober_get_ostring , 29.Nm ober_get_bitstring , 30.Nm ober_get_oid , 31.Nm ober_getpos , 32.Nm ober_scanf_elements 33.Nd access properties of ASN.1 objects decoded from BER 34.Sh SYNOPSIS 35.Lb libutil 36.In sys/types.h 37.In ber.h 38.Ft int 39.Fn "ober_get_null" "struct ber_element *root" 40.Ft int 41.Fn "ober_get_eoc" "struct ber_element *root" 42.Ft int 43.Fn "ober_get_integer" "struct ber_element *root" "long long *val" 44.Ft int 45.Fn "ober_get_enumerated" "struct ber_element *root" "long long *val" 46.Ft int 47.Fn "ober_get_boolean" "struct ber_element *root" "int *bool" 48.Ft int 49.Fn "ober_get_string" "struct ber_element *root" "char **charbuf" 50.Ft int 51.Fn "ober_get_nstring" "struct ber_element *root" "void **buf" "size_t *size" 52.Ft int 53.Fn "ober_get_ostring" "struct ber_element *root" "struct ber_octetstring *ostring" 54.Ft int 55.Fn "ober_get_bitstring" "struct ber_element *root" "void **buf" "size_t *size" 56.Ft int 57.Fn "ober_get_oid" "struct ber_element *root" "struct ber_oid *oid" 58.Ft off_t 59.Fn "ober_getpos" "struct ber_element *elm" 60.Ft int 61.Fn "ober_scanf_elements" "struct ber_element *root" "char *format" "..." 62.Sh DESCRIPTION 63Functions which take two arguments save the value contained in the 64.Fa root 65element into the storage location pointed to by the second argument. 66If the storage location is 67.Dv NULL 68then only a type check is performed. 69Additionally, 70.Fn ober_get_nstring 71and 72.Fn ober_get_bitstring 73save the number of bytes contained in the string into 74.Pf * Fa size . 75If 76.Fa buf 77is 78.Dv NULL 79and size is not 80.Dv NULL , 81size is set. 82.Fa size 83must not be 84.Dv NULL 85to return a valid 86.Fa buf . 87.Pp 88.Fn ober_scanf_elements 89retrieves the values from zero or more elements starting at 90.Fa root . 91For each character in 92.Fa fmt , 93arguments of the types given in the following table are consumed 94and passed to the function listed, processing one 95.Vt ber_element 96per character. 97The following characters are valid: 98.Bl -column -offset indent\ 99 characte ober_get_enumerated_ "1: struct ber_element **" 100.It Sy character Ta Sy function Ta Sy arguments 101.It $ Ta see below Ta 0 102.It B Ta Fn ober_get_bitstring Ta 2: Vt void ** , size_t * 103.It b Ta Fn ober_get_boolean Ta 1: Vt int * 104.It d Ta Fn ober_get_integer Ta 1: Vt int * 105.It E Ta Fn ober_get_enumerated Ta 1: Vt long long * 106.It e Ta see below Ta 1: Vt struct ber_element ** 107.It i Ta Fn ober_get_integer Ta 1: Vt long long * 108.It o Ta Fn ober_get_oid Ta 1: Vt struct ber_oid * 109.It p Ta Fn ober_getpos Ta 1: Vt off_t * 110.It S Ta see below Ta 0 111.It s Ta Fn ober_get_string Ta 1: Vt char ** 112.It t Ta see below Ta 2: Vt int * , unsigned int * 113.It x Ta Fn ober_get_nstring Ta 2: Vt void **, size_t * 114.It \&( or { Ta see below Ta 0 115.It \&) or } Ta see below Ta 0 116.It \&. Ta Fn ober_get_eoc Ta 0 117.It 0 Ta Fn ober_get_null Ta 0 118.El 119.Pp 120For 121.Sq e , 122.Sq p , 123.Sq S , 124and 125.Sq t , 126the type of the element is not checked. 127For 128.Sq p 129and 130.Sq t , 131the pointer is not incremented to the next element. 132For 133.Sq e , 134a pointer to the element is stored in the corresponding pointer variable. 135For 136.Sq S , 137the element is skipped without extracting any information from it. 138For 139.Sq t , 140the class and type of the element are stored in the two corresponding 141variables, but if the element contains a value, that value is ignored. 142A 143.Sq $ 144mandates the end of a sequence or set. 145.Pp 146For an opening parenthesis or brace, it is checked that the element 147is a sequence or a set, and parsing continues with its children. 148For a closing parenthesis or brace, parsing of the current sequence 149or set is ended and parsing continues with the element following 150the sequence or set. 151.Sh RETURN VALUES 152.Fn ober_getpos 153returns the value of 154.Vt be_offs . 155.Pp 156.Fn ober_scanf_elements 157returns 0 for success or \-1 when encountering elements that do not 158agree with the expectations of 159.Fa fmt 160or when 161.Fa fmt 162is syntactically invalid. 163Even when 164.Fn ober_scanf_elements 165fails, some of the arguments may already have been filled in. 166.Pp 167The other functions return 0 if 168.Va root 169is of the requested type or \-1 otherwise. 170.Sh SEE ALSO 171.Xr ober_add_string 3 , 172.Xr ober_oid_cmp 3 , 173.Xr ober_read_elements 3 , 174.Xr ober_set_header 3 175.Sh STANDARDS 176ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: 177Information technology - ASN.1 encoding rules. 178.Sh HISTORY 179These functions first appeared as internal functions in 180.Xr snmpd 8 181in 182.Ox 4.2 183and were moved to libutil in 184.Ox 6.6 . 185.Sh AUTHORS 186.An -nosplit 187The BER library was written by 188.An Claudio Jeker Aq Mt claudio@openbsd.org , 189.An Marc Balmer Aq Mt marc@openbsd.org 190and 191.An Reyk Floeter Aq Mt reyk@openbsd.org .