comparison svr-session.c @ 26:0969767bca0d

snapshot of stuff
author Matt Johnston <matt@ucc.asn.au>
date Mon, 26 Jul 2004 02:44:20 +0000
parents 469950e86d0f
children f789045062e6
comparison
equal deleted inserted replaced
25:e4b6e2d569b2 26:0969767bca0d
48 static const packettype svr_packettypes[] = { 48 static const packettype svr_packettypes[] = {
49 /* TYPE, AUTHREQUIRED, FUNCTION */ 49 /* TYPE, AUTHREQUIRED, FUNCTION */
50 {SSH_MSG_SERVICE_REQUEST, recv_msg_service_request}, // server 50 {SSH_MSG_SERVICE_REQUEST, recv_msg_service_request}, // server
51 {SSH_MSG_USERAUTH_REQUEST, recv_msg_userauth_request}, //server 51 {SSH_MSG_USERAUTH_REQUEST, recv_msg_userauth_request}, //server
52 {SSH_MSG_KEXINIT, recv_msg_kexinit}, 52 {SSH_MSG_KEXINIT, recv_msg_kexinit},
53 {SSH_MSG_KEXDH_INIT, recv_msg_kexdh_init}, 53 {SSH_MSG_KEXDH_INIT, recv_msg_kexdh_init}, // server
54 {SSH_MSG_NEWKEYS, recv_msg_newkeys}, 54 {SSH_MSG_NEWKEYS, recv_msg_newkeys},
55 {SSH_MSG_CHANNEL_DATA, recv_msg_channel_data}, 55 {SSH_MSG_CHANNEL_DATA, recv_msg_channel_data},
56 {SSH_MSG_CHANNEL_WINDOW_ADJUST, recv_msg_channel_window_adjust}, 56 {SSH_MSG_CHANNEL_WINDOW_ADJUST, recv_msg_channel_window_adjust},
57 {SSH_MSG_GLOBAL_REQUEST, recv_msg_global_request_remotetcp}, 57 {SSH_MSG_GLOBAL_REQUEST, recv_msg_global_request_remotetcp},
58 {SSH_MSG_CHANNEL_REQUEST, recv_msg_channel_request}, 58 {SSH_MSG_CHANNEL_REQUEST, recv_msg_channel_request},
68 &svrchansess, 68 &svrchansess,
69 &chan_tcpdirect, 69 &chan_tcpdirect,
70 NULL /* Null termination is mandatory. */ 70 NULL /* Null termination is mandatory. */
71 }; 71 };
72 72
73 void svr_session(int sock, int childpipe, struct sockaddr* remoteaddr) { 73 void svr_session(int sock, int childpipe, char* remotehost) {
74 74
75 fd_set readfd, writefd;
76 struct timeval timeout; 75 struct timeval timeout;
77 int val;
78 76
79 crypto_init(); 77 crypto_init();
80 common_session_init(sock); 78 common_session_init(sock, remotehost);
81
82 ses.remoteaddr = remoteaddr;
83 ses.remotehost = getaddrhostname(remoteaddr);
84 79
85 /* Initialise server specific parts of the session */ 80 /* Initialise server specific parts of the session */
86 svr_ses.childpipe = childpipe; 81 svr_ses.childpipe = childpipe;
87 authinitialise(); 82 authinitialise();
88 chaninitialise(svr_chantypes); 83 chaninitialise(svr_chantypes);
109 seedrandom(); 104 seedrandom();
110 105
111 /* start off with key exchange */ 106 /* start off with key exchange */
112 send_msg_kexinit(); 107 send_msg_kexinit();
113 108
114 FD_ZERO(&readfd); 109 /* Run the main for loop. NULL is for the dispatcher - only the client
115 FD_ZERO(&writefd); 110 * code makes use of it */
111 session_loop(NULL);
116 112
117 /* main loop, select()s for all sockets in use */ 113 /* Not reached */
118 for(;;) {
119 114
120 timeout.tv_sec = SELECT_TIMEOUT;
121 timeout.tv_usec = 0;
122 FD_ZERO(&writefd);
123 FD_ZERO(&readfd);
124 assert(ses.payload == NULL);
125 if (ses.sock != -1) {
126 FD_SET(ses.sock, &readfd);
127 if (!isempty(&ses.writequeue)) {
128 FD_SET(ses.sock, &writefd);
129 }
130 }
131
132 /* set up for channels which require reading/writing */
133 if (ses.dataallowed) {
134 setchannelfds(&readfd, &writefd);
135 }
136 val = select(ses.maxfd+1, &readfd, &writefd, NULL, &timeout);
137
138 if (exitflag) {
139 dropbear_exit("Terminated by signal");
140 }
141
142 if (val < 0) {
143 if (errno == EINTR) {
144 continue;
145 } else {
146 dropbear_exit("Error in select");
147 }
148 }
149
150 /* check for auth timeout, rekeying required etc */
151 checktimeouts();
152
153 if (val == 0) {
154 /* timeout */
155 TRACE(("select timeout"));
156 continue;
157 }
158
159 /* process session socket's incoming/outgoing data */
160 if (ses.sock != -1) {
161 if (FD_ISSET(ses.sock, &writefd) && !isempty(&ses.writequeue)) {
162 write_packet();
163 }
164
165 if (FD_ISSET(ses.sock, &readfd)) {
166 read_packet();
167 }
168
169 /* Process the decrypted packet. After this, the read buffer
170 * will be ready for a new packet */
171 if (ses.payload != NULL) {
172 process_packet();
173 }
174 }
175
176 /* process pipes etc for the channels, ses.dataallowed == 0
177 * during rekeying ) */
178 if (ses.dataallowed) {
179 channelio(&readfd, &writefd);
180 }
181
182 } /* for(;;) */
183 } 115 }
184 116
185 /* failure exit - format must be <= 100 chars */ 117 /* failure exit - format must be <= 100 chars */
186 void svr_dropbear_exit(int exitcode, const char* format, va_list param) { 118 void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
187 119