Annotation of src/usr.bin/ssh/opacket.c, Revision 1.3
1.1 markus 1: /* Written by Markus Friedl. Placed in the public domain. */
2:
3: #include "ssherr.h"
4: #include "packet.h"
5: #include "log.h"
6:
7: struct ssh *active_state, *backup_state;
8:
9: /* Map old to new API */
10:
11: void
12: ssh_packet_start(struct ssh *ssh, u_char type)
13: {
14: int r;
15:
16: if ((r = sshpkt_start(ssh, type)) != 0)
17: fatal("%s: %s", __func__, ssh_err(r));
18: }
19:
20: void
21: ssh_packet_put_char(struct ssh *ssh, int value)
22: {
23: u_char ch = value;
24: int r;
25:
26: if ((r = sshpkt_put_u8(ssh, ch)) != 0)
27: fatal("%s: %s", __func__, ssh_err(r));
28: }
29:
30: void
31: ssh_packet_put_int(struct ssh *ssh, u_int value)
32: {
33: int r;
34:
35: if ((r = sshpkt_put_u32(ssh, value)) != 0)
36: fatal("%s: %s", __func__, ssh_err(r));
37: }
38:
39: void
40: ssh_packet_put_int64(struct ssh *ssh, u_int64_t value)
41: {
42: int r;
43:
44: if ((r = sshpkt_put_u64(ssh, value)) != 0)
45: fatal("%s: %s", __func__, ssh_err(r));
46: }
47:
48: void
49: ssh_packet_put_string(struct ssh *ssh, const void *buf, u_int len)
50: {
51: int r;
52:
53: if ((r = sshpkt_put_string(ssh, buf, len)) != 0)
54: fatal("%s: %s", __func__, ssh_err(r));
55: }
56:
57: void
58: ssh_packet_put_cstring(struct ssh *ssh, const char *str)
59: {
60: int r;
61:
62: if ((r = sshpkt_put_cstring(ssh, str)) != 0)
63: fatal("%s: %s", __func__, ssh_err(r));
64: }
65:
66: void
67: ssh_packet_put_raw(struct ssh *ssh, const void *buf, u_int len)
68: {
69: int r;
70:
71: if ((r = sshpkt_put(ssh, buf, len)) != 0)
72: fatal("%s: %s", __func__, ssh_err(r));
73: }
74:
75: #ifdef WITH_OPENSSL
76: void
77: ssh_packet_put_bignum(struct ssh *ssh, BIGNUM * value)
78: {
79: int r;
80:
81: if ((r = sshpkt_put_bignum1(ssh, value)) != 0)
82: fatal("%s: %s", __func__, ssh_err(r));
83: }
84:
85: void
86: ssh_packet_put_bignum2(struct ssh *ssh, BIGNUM * value)
87: {
88: int r;
89:
90: if ((r = sshpkt_put_bignum2(ssh, value)) != 0)
91: fatal("%s: %s", __func__, ssh_err(r));
92: }
93:
94: void
95: ssh_packet_put_ecpoint(struct ssh *ssh, const EC_GROUP *curve,
96: const EC_POINT *point)
97: {
98: int r;
99:
100: if ((r = sshpkt_put_ec(ssh, point, curve)) != 0)
101: fatal("%s: %s", __func__, ssh_err(r));
102: }
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: #ifdef WITH_OPENSSL
148: void
149: ssh_packet_get_bignum(struct ssh *ssh, BIGNUM * value)
150: {
151: int r;
152:
153: if ((r = sshpkt_get_bignum1(ssh, value)) != 0)
154: fatal("%s: %s", __func__, ssh_err(r));
155: }
156:
157: void
158: ssh_packet_get_bignum2(struct ssh *ssh, BIGNUM * value)
159: {
160: int r;
161:
162: if ((r = sshpkt_get_bignum2(ssh, value)) != 0)
163: fatal("%s: %s", __func__, ssh_err(r));
164: }
165:
166: void
167: ssh_packet_get_ecpoint(struct ssh *ssh, const EC_GROUP *curve, EC_POINT *point)
168: {
169: int r;
170:
171: if ((r = sshpkt_get_ec(ssh, point, curve)) != 0)
172: fatal("%s: %s", __func__, ssh_err(r));
173: }
174: #endif /* WITH_OPENSSL */
175:
176: void *
177: ssh_packet_get_string(struct ssh *ssh, u_int *length_ptr)
178: {
179: int r;
180: size_t len;
181: u_char *val;
182:
183: if ((r = sshpkt_get_string(ssh, &val, &len)) != 0)
184: fatal("%s: %s", __func__, ssh_err(r));
185: if (length_ptr != NULL)
186: *length_ptr = (u_int)len;
187: return val;
188: }
189:
190: const void *
191: ssh_packet_get_string_ptr(struct ssh *ssh, u_int *length_ptr)
192: {
193: int r;
194: size_t len;
195: const u_char *val;
196:
197: if ((r = sshpkt_get_string_direct(ssh, &val, &len)) != 0)
198: fatal("%s: %s", __func__, ssh_err(r));
199: if (length_ptr != NULL)
200: *length_ptr = (u_int)len;
201: return val;
202: }
203:
204: char *
205: ssh_packet_get_cstring(struct ssh *ssh, u_int *length_ptr)
206: {
207: int r;
208: size_t len;
209: char *val;
210:
211: if ((r = sshpkt_get_cstring(ssh, &val, &len)) != 0)
212: fatal("%s: %s", __func__, ssh_err(r));
213: if (length_ptr != NULL)
214: *length_ptr = (u_int)len;
215: return val;
216: }
217:
218: /* Old API, that had to be reimplemented */
219:
220: void
221: packet_set_connection(int fd_in, int fd_out)
222: {
223: active_state = ssh_packet_set_connection(active_state, fd_in, fd_out);
1.3 ! djm 224: if (active_state == NULL)
! 225: fatal("%s: ssh_packet_set_connection failed", __func__);
1.1 markus 226: }
227:
228: void
229: packet_backup_state(void)
230: {
231: ssh_packet_backup_state(active_state, backup_state);
232: }
233:
234: void
235: packet_restore_state(void)
236: {
237: ssh_packet_restore_state(active_state, backup_state);
238: }
239:
240: u_int
241: packet_get_char(void)
242: {
243: return (ssh_packet_get_char(active_state));
244: }
245:
246: u_int
247: packet_get_int(void)
248: {
249: return (ssh_packet_get_int(active_state));
250: }
251:
252: int
253: packet_read_seqnr(u_int32_t *seqnr)
254: {
255: u_char type;
256: int r;
257:
1.3 ! djm 258: if ((r = ssh_packet_read_seqnr(active_state, &type, seqnr)) != 0)
! 259: sshpkt_fatal(active_state, __func__, r);
1.1 markus 260: return type;
261: }
262:
263: int
264: packet_read_poll_seqnr(u_int32_t *seqnr)
265: {
266: u_char type;
267: int r;
268:
269: if ((r = ssh_packet_read_poll_seqnr(active_state, &type, seqnr)))
1.3 ! djm 270: sshpkt_fatal(active_state, __func__, r);
1.1 markus 271: return type;
272: }
273:
274: void
275: packet_close(void)
276: {
277: ssh_packet_close(active_state);
278: active_state = NULL;
1.2 djm 279: }
280:
281: void
282: packet_process_incoming(const char *buf, u_int len)
283: {
284: int r;
285:
286: if ((r = ssh_packet_process_incoming(active_state, buf, len)) != 0)
1.3 ! djm 287: sshpkt_fatal(active_state, __func__, r);
! 288: }
! 289:
! 290: void
! 291: packet_write_wait(void)
! 292: {
! 293: int r;
! 294:
! 295: if ((r = ssh_packet_write_wait(active_state)) != 0)
! 296: sshpkt_fatal(active_state, __func__, r);
! 297: }
! 298:
! 299: void
! 300: packet_write_poll(void)
! 301: {
! 302: int r;
! 303:
! 304: if ((r = ssh_packet_write_poll(active_state)) != 0)
! 305: sshpkt_fatal(active_state, __func__, r);
! 306: }
! 307:
! 308: void
! 309: packet_read_expect(int expected_type)
! 310: {
! 311: int r;
! 312:
! 313: if ((r = ssh_packet_read_expect(active_state, expected_type)) != 0)
! 314: sshpkt_fatal(active_state, __func__, r);
1.1 markus 315: }