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