comparison svr-packet.c @ 4:fe6bca95afa7

Makefile.in contains updated files required
author Matt Johnston <matt@ucc.asn.au>
date Tue, 01 Jun 2004 02:46:09 +0000
parents
children db2c8e6fb284
comparison
equal deleted inserted replaced
-1:000000000000 4:fe6bca95afa7
1 /*
2 * Dropbear - a SSH2 server
3 *
4 * Copyright (c) 2002,2003 Matt Johnston
5 * All rights reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE. */
24
25 #include "includes.h"
26 #include "packet.h"
27 #include "session.h"
28 #include "dbutil.h"
29 #include "ssh.h"
30 #include "algo.h"
31 #include "buffer.h"
32 #include "kex.h"
33 #include "random.h"
34 #include "service.h"
35 #include "auth.h"
36 #include "channel.h"
37
38 static void svr_process_postauth_packet(unsigned int type);
39
40 /* process a decrypted packet, call the appropriate handler */
41 void svr_process_packet() {
42
43 unsigned char type;
44
45 TRACE(("enter process_packet"));
46
47 type = buf_getbyte(ses.payload);
48 TRACE(("process_packet: packet type = %d", type));
49
50 /* these packets we can receive at any time, regardless of expecting
51 * other packets: */
52 switch(type) {
53
54 case SSH_MSG_IGNORE:
55 case SSH_MSG_DEBUG:
56 TRACE(("received SSH_MSG_IGNORE or SSH_MSG_DEBUG"));
57 goto out;
58
59 case SSH_MSG_UNIMPLEMENTED:
60 /* debugging XXX */
61 TRACE(("SSH_MSG_UNIMPLEMENTED"));
62 dropbear_exit("received SSH_MSG_UNIMPLEMENTED");
63
64 case SSH_MSG_DISCONNECT:
65 /* TODO cleanup? */
66 dropbear_close("Disconnect received");
67 }
68
69 /* Check if we should ignore this packet. Used currently only for
70 * KEX code, with first_kex_packet_follows */
71 if (ses.ignorenext) {
72 TRACE(("Ignoring packet, type = %d", type));
73 ses.ignorenext = 0;
74 goto out;
75 }
76
77 /* check that we aren't expecting a particular packet */
78 if (ses.expecting && ses.expecting != type) {
79 /* TODO send disconnect? */
80 dropbear_exit("unexpected packet type %d, expected %d", type,
81 ses.expecting);
82 }
83
84 /* handle the packet depending on type */
85 ses.expecting = 0;
86
87 switch (type) {
88
89 case SSH_MSG_SERVICE_REQUEST:
90 recv_msg_service_request();
91 break;
92
93 case SSH_MSG_USERAUTH_REQUEST:
94 recv_msg_userauth_request();
95 break;
96
97 case SSH_MSG_KEXINIT:
98 recv_msg_kexinit();
99 break;
100
101 case SSH_MSG_KEXDH_INIT:
102 recv_msg_kexdh_init();
103 break;
104
105 case SSH_MSG_NEWKEYS:
106 recv_msg_newkeys();
107 break;
108
109 /* this is ugly, need to make a cleaner way to do it */
110 case SSH_MSG_CHANNEL_DATA:
111 case SSH_MSG_CHANNEL_WINDOW_ADJUST:
112 case SSH_MSG_CHANNEL_REQUEST:
113 case SSH_MSG_CHANNEL_OPEN:
114 case SSH_MSG_CHANNEL_EOF:
115 case SSH_MSG_CHANNEL_CLOSE:
116 case SSH_MSG_CHANNEL_OPEN_CONFIRMATION:
117 case SSH_MSG_CHANNEL_OPEN_FAILURE:
118 case SSH_MSG_GLOBAL_REQUEST:
119 /* these should be checked for authdone below */
120 svr_process_postauth_packet(type);
121 break;
122
123 default:
124 /* TODO this possibly should be handled */
125 TRACE(("preauth unknown packet"));
126 recv_unimplemented();
127 break;
128 }
129
130 out:
131 buf_free(ses.payload);
132 ses.payload = NULL;
133
134 TRACE(("leave process_packet"));
135 }
136
137 /* process a packet, and also check that auth has been done */
138 static void svr_process_postauth_packet(unsigned int type) {
139
140 /* messages following here require userauth before use */
141
142 /* IF YOU ADD MORE PACKET TYPES, MAKE SURE THEY'RE ALSO ADDED TO THE LIST
143 * IN process_packet() XXX XXX XXX */
144 if (!svr_ses.authstate.authdone) {
145 dropbear_exit("received message %d before userauth", type);
146 }
147
148 switch (type) {
149
150 case SSH_MSG_CHANNEL_DATA:
151 recv_msg_channel_data();
152 break;
153
154 case SSH_MSG_CHANNEL_WINDOW_ADJUST:
155 recv_msg_channel_window_adjust();
156 break;
157
158 #ifndef DISABLE_REMOTETCPFWD
159 case SSH_MSG_GLOBAL_REQUEST:
160 /* currently only used for remote tcp, so we cheat a little */
161 recv_msg_global_request_remotetcp();
162 break;
163 #endif
164
165 case SSH_MSG_CHANNEL_REQUEST:
166 recv_msg_channel_request();
167 break;
168
169 case SSH_MSG_CHANNEL_OPEN:
170 recv_msg_channel_open();
171 break;
172
173 case SSH_MSG_CHANNEL_EOF:
174 recv_msg_channel_eof();
175 break;
176
177 case SSH_MSG_CHANNEL_CLOSE:
178 recv_msg_channel_close();
179 break;
180
181 #ifdef USE_LISTENERS /* for x11, tcp fwd etc */
182 case SSH_MSG_CHANNEL_OPEN_CONFIRMATION:
183 recv_msg_channel_open_confirmation();
184 break;
185
186 case SSH_MSG_CHANNEL_OPEN_FAILURE:
187 recv_msg_channel_open_failure();
188 break;
189 #endif
190
191 default:
192 TRACE(("unknown packet()"));
193 recv_unimplemented();
194 break;
195 }
196 }