comparison cli-session.c @ 26:0969767bca0d

snapshot of stuff
author Matt Johnston <matt@ucc.asn.au>
date Mon, 26 Jul 2004 02:44:20 +0000
parents
children f789045062e6
comparison
equal deleted inserted replaced
25:e4b6e2d569b2 26:0969767bca0d
1 #include "includes.h"
2 #include "session.h"
3 #include "dbutil.h"
4 #include "kex.h"
5 #include "ssh.h"
6 #include "packet.h"
7 #include "tcpfwd-direct.h"
8 #include "tcpfwd-remote.h"
9 #include "channel.h"
10 #include "random.h"
11
12 static void cli_remoteclosed();
13 static void cli_sessionloop();
14
15 struct clientsession cli_ses; /* GLOBAL */
16
17 static const packettype cli_packettypes[] = {
18 /* TYPE, AUTHREQUIRED, FUNCTION */
19 {SSH_MSG_KEXINIT, recv_msg_kexinit},
20 {SSH_MSG_KEXDH_REPLY, recv_msg_kexdh_reply}, // client
21 {SSH_MSG_NEWKEYS, recv_msg_newkeys},
22 {SSH_MSG_CHANNEL_DATA, recv_msg_channel_data},
23 {SSH_MSG_CHANNEL_WINDOW_ADJUST, recv_msg_channel_window_adjust},
24 {SSH_MSG_GLOBAL_REQUEST, recv_msg_global_request_remotetcp},
25 {SSH_MSG_CHANNEL_REQUEST, recv_msg_channel_request},
26 {SSH_MSG_CHANNEL_OPEN, recv_msg_channel_open},
27 {SSH_MSG_CHANNEL_EOF, recv_msg_channel_eof},
28 {SSH_MSG_CHANNEL_CLOSE, recv_msg_channel_close},
29 {SSH_MSG_CHANNEL_OPEN_CONFIRMATION, recv_msg_channel_open_confirmation},
30 {SSH_MSG_CHANNEL_OPEN_FAILURE, recv_msg_channel_open_failure},
31 {0, 0} /* End */
32 };
33
34 static const struct ChanType *cli_chantypes[] = {
35 // &clichansess,
36 /* &chan_tcpdirect etc, though need to only allow if we've requested
37 * that forwarding */
38 NULL /* Null termination */
39 };
40 void cli_session(int sock, char* remotehost) {
41
42 crypto_init();
43 common_session_init(sock, remotehost);
44
45 chaninitialise(cli_chantypes);
46
47 /* For printing "remote host closed" for the user */
48 session_remoteclosed = cli_remoteclosed;
49
50 /* packet handlers */
51 ses.packettypes = cli_packettypes;
52
53 /* Ready to go */
54 sessinitdone = 1;
55
56 /* Exchange identification */
57 session_identification();
58
59 seedrandom();
60
61 send_msg_kexinit();
62
63 /* XXX here we do stuff differently */
64
65 session_loop(cli_sessionloop);
66
67 /* Not reached */
68
69
70 }
71
72 static void cli_sessionloop() {
73
74 switch (cli_ses.state) {
75
76 KEXINIT_RCVD:
77 /* We initiate the KEX. If DH wasn't the correct type, the KEXINIT
78 * negotiation would have failed. */
79 send_msg_kexdh_init();
80 cli_ses.state = KEXDH_INIT_SENT;
81 break;
82
83 default:
84 break;
85 }
86
87 if (cli_ses.donefirstkex && !cli_ses.authdone) {
88
89
90
91 }
92
93 /* called when the remote side closes the connection */
94 static void cli_remoteclosed() {
95
96 /* XXX TODO perhaps print a friendlier message if we get this but have
97 * already sent/received disconnect message(s) ??? */
98 close(ses.sock);
99 ses.sock = -1;
100 dropbear_exit("%s closed the connection", ses.remotehost);
101 }