GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/ssh/lib/../opacket.c Lines: 0 81 0.0 %
Date: 2017-11-13 Branches: 0 56 0.0 %

Line Branch Exec Source
1
/* $OpenBSD: opacket.c,v 1.7 2017/10/20 01:56:39 djm Exp $ */
2
/* Written by Markus Friedl. Placed in the public domain.  */
3
4
#include "ssherr.h"
5
#include "packet.h"
6
#include "log.h"
7
8
struct ssh *active_state, *backup_state;
9
10
/* Map old to new API */
11
12
void
13
ssh_packet_start(struct ssh *ssh, u_char type)
14
{
15
	int r;
16
17
	if ((r = sshpkt_start(ssh, type)) != 0)
18
		fatal("%s: %s", __func__, ssh_err(r));
19
}
20
21
void
22
ssh_packet_put_char(struct ssh *ssh, int value)
23
{
24
	u_char ch = value;
25
	int r;
26
27
	if ((r = sshpkt_put_u8(ssh, ch)) != 0)
28
		fatal("%s: %s", __func__, ssh_err(r));
29
}
30
31
void
32
ssh_packet_put_int(struct ssh *ssh, u_int value)
33
{
34
	int r;
35
36
	if ((r = sshpkt_put_u32(ssh, value)) != 0)
37
		fatal("%s: %s", __func__, ssh_err(r));
38
}
39
40
void
41
ssh_packet_put_int64(struct ssh *ssh, u_int64_t value)
42
{
43
	int r;
44
45
	if ((r = sshpkt_put_u64(ssh, value)) != 0)
46
		fatal("%s: %s", __func__, ssh_err(r));
47
}
48
49
void
50
ssh_packet_put_string(struct ssh *ssh, const void *buf, u_int len)
51
{
52
	int r;
53
54
	if ((r = sshpkt_put_string(ssh, buf, len)) != 0)
55
		fatal("%s: %s", __func__, ssh_err(r));
56
}
57
58
void
59
ssh_packet_put_cstring(struct ssh *ssh, const char *str)
60
{
61
	int r;
62
63
	if ((r = sshpkt_put_cstring(ssh, str)) != 0)
64
		fatal("%s: %s", __func__, ssh_err(r));
65
}
66
67
void
68
ssh_packet_put_raw(struct ssh *ssh, const void *buf, u_int len)
69
{
70
	int r;
71
72
	if ((r = sshpkt_put(ssh, buf, len)) != 0)
73
		fatal("%s: %s", __func__, ssh_err(r));
74
}
75
76
77
#ifdef WITH_OPENSSL
78
void
79
ssh_packet_put_bignum2(struct ssh *ssh, BIGNUM * value)
80
{
81
	int r;
82
83
	if ((r = sshpkt_put_bignum2(ssh, value)) != 0)
84
		fatal("%s: %s", __func__, ssh_err(r));
85
}
86
87
void
88
ssh_packet_put_ecpoint(struct ssh *ssh, const EC_GROUP *curve,
89
    const EC_POINT *point)
90
{
91
	int r;
92
93
	if ((r = sshpkt_put_ec(ssh, point, curve)) != 0)
94
		fatal("%s: %s", __func__, ssh_err(r));
95
}
96
#endif /* WITH_OPENSSL */
97
98
void
99
ssh_packet_send(struct ssh *ssh)
100
{
101
	int r;
102
103
	if ((r = sshpkt_send(ssh)) != 0)
104
		fatal("%s: %s", __func__, ssh_err(r));
105
}
106
107
u_int
108
ssh_packet_get_char(struct ssh *ssh)
109
{
110
	u_char ch;
111
	int r;
112
113
	if ((r = sshpkt_get_u8(ssh, &ch)) != 0)
114
		fatal("%s: %s", __func__, ssh_err(r));
115
	return ch;
116
}
117
118
u_int
119
ssh_packet_get_int(struct ssh *ssh)
120
{
121
	u_int val;
122
	int r;
123
124
	if ((r = sshpkt_get_u32(ssh, &val)) != 0)
125
		fatal("%s: %s", __func__, ssh_err(r));
126
	return val;
127
}
128
129
u_int64_t
130
ssh_packet_get_int64(struct ssh *ssh)
131
{
132
	u_int64_t val;
133
	int r;
134
135
	if ((r = sshpkt_get_u64(ssh, &val)) != 0)
136
		fatal("%s: %s", __func__, ssh_err(r));
137
	return val;
138
}
139
140
141
#ifdef WITH_OPENSSL
142
void
143
ssh_packet_get_bignum2(struct ssh *ssh, BIGNUM * value)
144
{
145
	int r;
146
147
	if ((r = sshpkt_get_bignum2(ssh, value)) != 0)
148
		fatal("%s: %s", __func__, ssh_err(r));
149
}
150
151
void
152
ssh_packet_get_ecpoint(struct ssh *ssh, const EC_GROUP *curve, EC_POINT *point)
153
{
154
	int r;
155
156
	if ((r = sshpkt_get_ec(ssh, point, curve)) != 0)
157
		fatal("%s: %s", __func__, ssh_err(r));
158
}
159
#endif /* WITH_OPENSSL */
160
161
void *
162
ssh_packet_get_string(struct ssh *ssh, u_int *length_ptr)
163
{
164
	int r;
165
	size_t len;
166
	u_char *val;
167
168
	if ((r = sshpkt_get_string(ssh, &val, &len)) != 0)
169
		fatal("%s: %s", __func__, ssh_err(r));
170
	if (length_ptr != NULL)
171
		*length_ptr = (u_int)len;
172
	return val;
173
}
174
175
const void *
176
ssh_packet_get_string_ptr(struct ssh *ssh, u_int *length_ptr)
177
{
178
	int r;
179
	size_t len;
180
	const u_char *val;
181
182
	if ((r = sshpkt_get_string_direct(ssh, &val, &len)) != 0)
183
		fatal("%s: %s", __func__, ssh_err(r));
184
	if (length_ptr != NULL)
185
		*length_ptr = (u_int)len;
186
	return val;
187
}
188
189
char *
190
ssh_packet_get_cstring(struct ssh *ssh, u_int *length_ptr)
191
{
192
	int r;
193
	size_t len;
194
	char *val;
195
196
	if ((r = sshpkt_get_cstring(ssh, &val, &len)) != 0)
197
		fatal("%s: %s", __func__, ssh_err(r));
198
	if (length_ptr != NULL)
199
		*length_ptr = (u_int)len;
200
	return val;
201
}
202
203
/* Old API, that had to be reimplemented */
204
205
void
206
packet_set_connection(int fd_in, int fd_out)
207
{
208
	active_state = ssh_packet_set_connection(active_state, fd_in, fd_out);
209
	if (active_state == NULL)
210
		fatal("%s: ssh_packet_set_connection failed", __func__);
211
}
212
213
u_int
214
packet_get_char(void)
215
{
216
	return (ssh_packet_get_char(active_state));
217
}
218
219
u_int
220
packet_get_int(void)
221
{
222
	return (ssh_packet_get_int(active_state));
223
}
224
225
int
226
packet_read_seqnr(u_int32_t *seqnr)
227
{
228
	u_char type;
229
	int r;
230
231
	if ((r = ssh_packet_read_seqnr(active_state, &type, seqnr)) != 0)
232
		sshpkt_fatal(active_state, __func__, r);
233
	return type;
234
}
235
236
int
237
packet_read_poll_seqnr(u_int32_t *seqnr)
238
{
239
	u_char type;
240
	int r;
241
242
	if ((r = ssh_packet_read_poll_seqnr(active_state, &type, seqnr)))
243
		sshpkt_fatal(active_state, __func__, r);
244
	return type;
245
}
246
247
void
248
packet_close(void)
249
{
250
	ssh_packet_close(active_state);
251
	active_state = NULL;
252
}
253
254
void
255
packet_process_incoming(const char *buf, u_int len)
256
{
257
	int r;
258
259
	if ((r = ssh_packet_process_incoming(active_state, buf, len)) != 0)
260
		sshpkt_fatal(active_state, __func__, r);
261
}
262
263
void
264
packet_write_wait(void)
265
{
266
	int r;
267
268
	if ((r = ssh_packet_write_wait(active_state)) != 0)
269
		sshpkt_fatal(active_state, __func__, r);
270
}
271
272
void
273
packet_write_poll(void)
274
{
275
	int r;
276
277
	if ((r = ssh_packet_write_poll(active_state)) != 0)
278
		sshpkt_fatal(active_state, __func__, r);
279
}
280
281
void
282
packet_read_expect(int expected_type)
283
{
284
	int r;
285
286
	if ((r = ssh_packet_read_expect(active_state, expected_type)) != 0)
287
		sshpkt_fatal(active_state, __func__, r);
288
}