Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
5.3 KiB

4 years ago
4 years ago
4 years ago
  1. .\" $OpenBSD: ber_get_string.3,v 1.7 2019/08/14 17:36:04 jmc 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: August 14 2019 $
  18. .Dt BER_GET_STRING 3
  19. .Os
  20. .Sh NAME
  21. .Nm ber_get_null ,
  22. .Nm ber_get_eoc ,
  23. .Nm ber_get_integer ,
  24. .Nm ber_get_enumerated ,
  25. .Nm ber_get_boolean ,
  26. .Nm ber_get_string ,
  27. .Nm ber_get_nstring ,
  28. .Nm ber_get_ostring ,
  29. .Nm ber_get_bitstring ,
  30. .Nm ber_get_oid ,
  31. .Nm ber_getpos ,
  32. .Nm ber_scanf_elements
  33. .Nd access properties of ASN.1 objects decoded from BER
  34. .Sh SYNOPSIS
  35. .In sys/types.h
  36. .In ber.h
  37. .Ft "int"
  38. .Fn "ber_get_null" "struct ber_element *root"
  39. .Ft "int"
  40. .Fn "ber_get_eoc" "struct ber_element *root"
  41. .Ft "int"
  42. .Fn "ber_get_integer" "struct ber_element *root" "long long *val"
  43. .Ft "int"
  44. .Fn "ber_get_enumerated" "struct ber_element *root" "long long *val"
  45. .Ft "int"
  46. .Fn "ber_get_boolean" "struct ber_element *root" "int *bool"
  47. .Ft "int"
  48. .Fn "ber_get_string" "struct ber_element *root" "char **charbuf"
  49. .Ft "int"
  50. .Fn "ber_get_nstring" "struct ber_element *root" "void **buf" "size_t *size"
  51. .Ft "int"
  52. .Fn "ber_get_ostring" "struct ber_element *root" "struct ber_octetstring *ostring"
  53. .Ft "int"
  54. .Fn "ber_get_bitstring" "struct ber_element *root" "void **buf" "size_t *size"
  55. .Ft "int"
  56. .Fn "ber_get_oid" "struct ber_element *root" "struct ber_oid *oid"
  57. .Ft off_t
  58. .Fn "ber_getpos" "struct ber_element *elm"
  59. .Ft "int"
  60. .Fn "ber_scanf_elements" "struct ber_element *root" "char *format" "..."
  61. .Sh DESCRIPTION
  62. Functions which take two arguments save the value contained in the
  63. .Fa root
  64. element into the storage location pointed to by the second argument.
  65. Additionally,
  66. .Fn ber_get_nstring
  67. and
  68. .Fn ber_get_bitstring
  69. save the number of bytes contained in the string into
  70. .Pf * Fa size .
  71. .Pp
  72. .Fn ber_scanf_elements
  73. retrieves the values from zero or more elements starting at
  74. .Fa root .
  75. For each byte in
  76. .Fa fmt ,
  77. arguments of the types given in the following table are consumed
  78. and passed to the function listed, processing one
  79. .Vt ber_element
  80. per byte.
  81. The following bytes are valid:
  82. .Bl -column -offset indent bytes ber_get_enumerated() "1: struct ber_element **"
  83. .It Sy byte Ta Sy function Ta Sy arguments
  84. .It B Ta Fn ber_get_bitstring Ta 2: Vt void ** , size_t *
  85. .It b Ta Fn ber_get_boolean Ta 1: Vt int *
  86. .It d Ta Fn ber_get_integer Ta 1: Vt int *
  87. .It E Ta Fn ber_get_enumerated Ta 1: Vt long long *
  88. .It e Ta see below Ta 1: Vt struct ber_element **
  89. .It i Ta Fn ber_get_integer Ta 1: Vt long long *
  90. .It o Ta Fn ber_get_oid Ta 1: Vt struct ber_oid *
  91. .It p Ta Fn ber_getpos Ta 1: Vt off_t *
  92. .It S Ta see below Ta 0
  93. .It s Ta Fn ber_get_string Ta 1: Vt char **
  94. .It t Ta see below Ta 2: Vt int * , unsigned int *
  95. .It x Ta Fn ber_get_nstring Ta 2: Vt void **, size_t *
  96. .It \&( or { Ta see below Ta 0
  97. .It \&) or } Ta see below Ta 0
  98. .It \&. Ta Fn ber_get_eoc Ta 0
  99. .It 0 Ta Fn ber_get_null Ta 0
  100. .El
  101. .Pp
  102. For
  103. .Sq e ,
  104. .Sq p ,
  105. .Sq S ,
  106. and
  107. .Sq t ,
  108. the type of the element is not checked.
  109. For
  110. .Sq p
  111. and
  112. .Sq t ,
  113. the pointer is not incremented to the next element.
  114. For
  115. .Sq e ,
  116. a pointer to the element is stored in the corresponding pointer variable.
  117. For
  118. .Sq S ,
  119. the element is skipped without extracting any information from it.
  120. For
  121. .Sq t ,
  122. the class and type of the element are stored in the two corresponding
  123. variables, but if the element contains a value, that value is ignored.
  124. .Pp
  125. For an opening parenthesis or brace, it is checked that the element
  126. is a sequence or a set, and parsing continues with its children.
  127. For a closing parenthesis or brace, parsing of the current sequence
  128. or set is ended and parsing continues with the element following
  129. the sequence or set.
  130. .Sh RETURN VALUES
  131. .Fn ber_getpos
  132. returns the value of
  133. .Vt be_offs .
  134. .Pp
  135. .Fn ber_scanf_elements
  136. returns 0 for success or \-1 when encountering elements that do not
  137. agree with the expectations of
  138. .Fa fmt
  139. or when
  140. .Fa fmt
  141. is syntactically invalid.
  142. Even when
  143. .Fn ber_scanf_elements
  144. fails, some of the arguments may already have been filled in.
  145. .Pp
  146. The other functions return 0 if
  147. .Va root
  148. is of the requested type or \-1 otherwise.
  149. .Sh SEE ALSO
  150. .Xr ber_add_string 3 ,
  151. .Xr ber_oid_cmp 3 ,
  152. .Xr ber_read_elements 3 ,
  153. .Xr ber_set_header 3
  154. .Sh STANDARDS
  155. ITU-T Recommendation X.690, also known as ISO/IEC 8825-1:
  156. Information technology - ASN.1 encoding rules.
  157. .Sh HISTORY
  158. These functions first appeared as internal functions in
  159. .Xr snmpd 8
  160. in
  161. .Ox 4.2
  162. and were moved to libutil in
  163. .Ox 6.6 .
  164. .Sh AUTHORS
  165. .An -nosplit
  166. The BER library was written by
  167. .An Claudio Jeker Aq Mt claudio@openbsd.org ,
  168. .An Marc Balmer Aq Mt marc@openbsd.org
  169. and
  170. .An Reyk Floeter Aq Mt reyk@openbsd.org .