summaryrefslogtreecommitdiff
path: root/usr.sbin/snmpd/ber.3
blob: 904e787855b4ce8dd0f88005738a24219c4a45bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
.\" $OpenBSD: ber.3,v 1.10 2012/09/17 16:30:34 reyk Exp $
.\"
.\" Copyright (c) 2007, 2012 Reyk Floeter <reyk@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: September 17 2012 $
.Dt BER 3
.Os
.Sh NAME
.Nm ber_get_element ,
.Nm ber_set_header ,
.Nm ber_link_elements ,
.Nm ber_unlink_elements ,
.Nm ber_replace_elements ,
.Nm ber_add_sequence ,
.Nm ber_add_set ,
.Nm ber_add_integer ,
.Nm ber_get_integer ,
.Nm ber_add_boolean ,
.Nm ber_get_boolean ,
.Nm ber_add_string ,
.Nm ber_add_nstring ,
.Nm ber_add_bitstring ,
.Nm ber_get_string ,
.Nm ber_get_nstring ,
.Nm ber_get_bitstring ,
.Nm ber_add_null ,
.Nm ber_get_null ,
.Nm ber_add_eoc ,
.Nm ber_get_eoc ,
.Nm ber_add_oid ,
.Nm ber_add_oidstring ,
.Nm ber_get_oid ,
.Nm ber_oid2ber ,
.Nm ber_string2oid ,
.Nm ber_printf_elements ,
.Nm ber_scanf_elements ,
.Nm ber_get_writebuf ,
.Nm ber_write_elements ,
.Nm ber_set_readbuf ,
.Nm ber_read_elements ,
.Nm ber_getpos ,
.Nm ber_free_elements ,
.Nm ber_calc_len ,
.Nm ber_set_application ,
.Nm ber_set_writecallback
.Nm ber_free
.Nd parse ASN.1 with Basic Encoding Rules
.Sh SYNOPSIS
.Fd #include <ber.h>
.Ft "struct ber_element *"
.Fn "ber_get_element" "unsigned long encoding"
.Ft "void"
.Fn "ber_set_header" "struct ber_element *elm" "int class" "unsigned long type"
.Ft "void"
.Fn "ber_link_elements" "struct ber_element *prev" "struct ber_element *elm"
.Ft "struct ber_element *"
.Fn "ber_unlink_elements" "struct ber_element *prev"
.Ft "void"
.Fn "ber_replace_elements" "struct ber_element *prev" "struct ber_element *elm"
.Ft "struct ber_element *"
.Fn "ber_add_sequence" "struct ber_element *prev"
.Ft "struct ber_element *"
.Fn "ber_add_set" "struct ber_element *prev"
.Ft "struct ber_element *"
.Fn "ber_add_integer" "struct ber_element *prev" "long long val"
.Ft "int"
.Fn "ber_get_integer" "struct ber_element *root" "long long *val"
.Ft "struct ber_element *"
.Fn "ber_add_boolean" "struct ber_element *prev" "int bool"
.Ft "int"
.Fn "ber_get_boolean" "struct ber_element *root" "int *bool"
.Ft "struct ber_element *"
.Fn "ber_add_string" "struct ber_element *prev" "const char *string"
.Ft "struct ber_element *"
.Fn "ber_add_nstring" "struct ber_element *prev" "const char *string" "size_t size"
.Ft "int"
.Fn "ber_get_string" "struct ber_element *root" "char **charbuf"
.Ft "int"
.Fn "ber_get_nstring" "struct ber_element *root" "void **buf" "size_t *size"
.Ft "struct ber_element *"
.Fn "ber_add_bitstring" "struct ber_element *prev" "const void *buf" "size_t size"
.Ft "int"
.Fn "ber_get_bitstring" "struct ber_element *root" "void **buf" "size_t *size"
.Ft "struct ber_element *"
.Fn "ber_add_null" "struct ber_element *prev"
.Ft "int"
.Fn "ber_get_null" "struct ber_element *root"
.Ft "struct ber_element *"
.Fn "ber_add_eoc" "struct ber_element *prev"
.Ft "int"
.Fn "ber_get_eoc" "struct ber_element *root"
.Ft "struct ber_element *"
.Fn "ber_add_oid" "struct ber_element *prev" "struct ber_oid *oid"
.Ft "struct ber_element *"
.Fn "ber_add_oidstring" "struct ber_element *prev" "const char *string"
.Ft "int"
.Fn "ber_get_oid" "struct ber_element *root" "struct ber_oid *oid"
.Ft "size_t"
.Fn "ber_oid2ber" "struct ber_oid *oid" "u_int8_t *buf" "size_t size"
.Ft "int"
.Fn "ber_string2oid" "const char *string" "struct ber_oid *oid"
.Ft "struct ber_element *"
.Fn "ber_printf_elements" "struct ber_element *prev" "char *format" "..."
.Ft "int"
.Fn "ber_scanf_elements" "struct ber_element *root" "char *format" "..."
.Ft "ssize_t"
.Fn "ber_get_writebuf" "struct ber *ber" "void **buf"
.Ft "int"
.Fn "ber_write_elements" "struct ber *ber" "struct ber_element *root"
.Ft "void"
.Fn "ber_set_readbuf" "struct ber *ber" "void *buf" "size_t len"
.Ft "struct"
.Fn "ber_element *ber_read_elements" "struct ber *ber" "struct ber_element *root"
.Ft off_t
.Fn "ber_getpos" "struct ber_element *elm"
.Ft "void"
.Fn "ber_free_elements" "struct ber_element *root"
.Ft "size_t"
.Fn "ber_calc_len" "struct ber_element *root"
.Ft "void"
.Fn "ber_set_application" "struct ber *ber" "unsigned long (*cb)(struct ber_element *)"
.Ft "void"
.Fn "ber_set_writecallback" "struct ber_element *elm" "void (*cb)(void *arg, size_t offs)" "void *arg"
.Ft "void"
.Fn "ber_free" "struct ber *ber"
.Sh DESCRIPTION
The
.Nm ber
API provides a mechanism to read and write ASN.1 streams and buffers
using the
.Ic Basic Encoding Rules .
.Sh BER ELEMENTS
.Fn ber_get_element ,
.Fn ber_set_header ,
.Fn ber_link_elements ,
.Fn ber_unlink_elements ,
.Fn ber_replace_elements ,
.Fn ber_calc_len
.Sh BER TYPES
.Fn ber_add_sequence ,
.Fn ber_add_set ,
.Fn ber_add_integer ,
.Fn ber_get_integer ,
.Fn ber_add_boolean ,
.Fn ber_get_boolean ,
.Fn ber_add_string ,
.Fn ber_add_nstring ,
.Fn ber_add_bitstring ,
.Fn ber_get_string ,
.Fn ber_get_nstring ,
.Fn ber_get_bitstring ,
.Fn ber_add_null ,
.Fn ber_get_null ,
.Fn ber_add_eoc ,
.Fn ber_get_eoc
.Sh OBJECT IDS
Object Identifiers are commonly used in ASN.1-based protocols.
These functions provide an interface to parse OIDs.
For internal representation of OIDs, the following structure
.Ft struct ber_oid
is being used:
.Bd -literal
#define BER_MIN_OID_LEN		2
#define BER_MAX_OID_LEN		128

struct ber_oid {
	u_int32_t	bo_id[BER_MAX_OID_LEN + 1];
	size_t		bo_n;
};
.Ed
.Pp
.Fn ber_add_oid ,
.Fn ber_add_oidstring ,
.Fn ber_get_oid ,
.Fn ber_oid2ber ,
.Fn ber_string2oid
.Sh FORMAT STRINGS
.Fn ber_printf_elements ,
.Fn ber_scanf_elements
.Sh I/O OPERATIONS
.Fn ber_get_writebuf ,
.Fn ber_write_elements ,
.Fn ber_set_readbuf ,
.Fn ber_read_elements ,
.Fn ber_getpos ,
.Fn ber_free_elements ,
.Fn ber_set_application ,
.Fn ber_set_writecallback ,
.Fn ber_free
.Sh RETURN VALUES
Upon successful completion
.Fn ber_get_integer ,
.Fn ber_get_boolean ,
.Fn ber_get_string ,
.Fn ber_get_nstring ,
.Fn ber_get_bitstring ,
.Fn ber_get_null ,
.Fn ber_get_eoc ,
.Fn ber_get_oid ,
.Fn ber_string2oid
and
.Fn ber_scanf_elements
return 0, while
.Fn ber_write_elements
returns the number of bytes written.
Otherwise, \-1 is returned and the global variable errno is
set to indicate the error.
.Sh SEE ALSO
.Xr socket 2
.Sh HISTORY
The
.Nm ber
manpage first appeared in
.Ox 4.3 .
.Sh AUTHORS
.An -nosplit
The
.Nm ber
library was written by
.An Claudio Jeker Aq claudio@openbsd.org ,
.An Marc Balmer Aq marc@openbsd.org
and
.An Reyk Floeter Aq reyk@openbsd.org .
.Sh BUGS
This manpage is a stub.