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