comparison common-session.c @ 479:e3db1f7a2e43

- Split main socket var into ses.sock_in/ses.sock_out in preparation for -J proxy_cmd option (and some prelim options for that)
author Matt Johnston <matt@ucc.asn.au>
date Mon, 15 Sep 2008 12:51:50 +0000
parents 7e43f5e473b9
children 7ad49f34a122
comparison
equal deleted inserted replaced
477:657c045054ab 479:e3db1f7a2e43
50 int exitflag = 0; /* GLOBAL */ 50 int exitflag = 0; /* GLOBAL */
51 51
52 52
53 53
54 /* called only at the start of a session, set up initial state */ 54 /* called only at the start of a session, set up initial state */
55 void common_session_init(int sock, char* remotehost) { 55 void common_session_init(int sock_in, int sock_out, char* remotehost) {
56 56
57 TRACE(("enter session_init")) 57 TRACE(("enter session_init"))
58 58
59 ses.remotehost = remotehost; 59 ses.remotehost = remotehost;
60 60
61 ses.sock = sock; 61 ses.sock_in = sock_in;
62 ses.maxfd = sock; 62 ses.sock_out = sock_out;
63 ses.maxfd = MAX(sock_in, sock_out);
63 64
64 ses.connect_time = 0; 65 ses.connect_time = 0;
65 ses.last_packet_time = 0; 66 ses.last_packet_time = 0;
66 67
67 if (pipe(ses.signal_pipe) < 0) { 68 if (pipe(ses.signal_pipe) < 0) {
135 timeout.tv_sec = select_timeout(); 136 timeout.tv_sec = select_timeout();
136 timeout.tv_usec = 0; 137 timeout.tv_usec = 0;
137 FD_ZERO(&writefd); 138 FD_ZERO(&writefd);
138 FD_ZERO(&readfd); 139 FD_ZERO(&readfd);
139 dropbear_assert(ses.payload == NULL); 140 dropbear_assert(ses.payload == NULL);
140 if (ses.sock != -1) { 141 if (ses.sock_in != -1) {
141 FD_SET(ses.sock, &readfd); 142 FD_SET(ses.sock_in, &readfd);
142 if (!isempty(&ses.writequeue)) { 143 }
143 FD_SET(ses.sock, &writefd); 144 if (ses.sock_out != -1 && !isempty(&ses.writequeue)) {
144 } 145 FD_SET(ses.sock_out, &writefd);
145 } 146 }
146 147
147 /* We get woken up when signal handlers write to this pipe. 148 /* We get woken up when signal handlers write to this pipe.
148 SIGCHLD in svr-chansession is the only one currently. */ 149 SIGCHLD in svr-chansession is the only one currently. */
149 FD_SET(ses.signal_pipe[0], &readfd); 150 FD_SET(ses.signal_pipe[0], &readfd);
181 182
182 /* check for auth timeout, rekeying required etc */ 183 /* check for auth timeout, rekeying required etc */
183 checktimeouts(); 184 checktimeouts();
184 185
185 /* process session socket's incoming/outgoing data */ 186 /* process session socket's incoming/outgoing data */
186 if (ses.sock != -1) { 187 if (ses.sock_out != -1) {
187 if (FD_ISSET(ses.sock, &writefd) && !isempty(&ses.writequeue)) { 188 if (FD_ISSET(ses.sock_out, &writefd) && !isempty(&ses.writequeue)) {
188 write_packet(); 189 write_packet();
189 } 190 }
190 191 }
191 if (FD_ISSET(ses.sock, &readfd)) { 192
193 if (ses.sock_in != -1) {
194 if (FD_ISSET(ses.sock_in, &readfd)) {
192 read_packet(); 195 read_packet();
193 } 196 }
194 197
195 /* Process the decrypted packet. After this, the read buffer 198 /* Process the decrypted packet. After this, the read buffer
196 * will be ready for a new packet */ 199 * will be ready for a new packet */
246 int len = 0; 249 int len = 0;
247 char done = 0; 250 char done = 0;
248 int i; 251 int i;
249 252
250 /* write our version string, this blocks */ 253 /* write our version string, this blocks */
251 if (atomicio(write, ses.sock, LOCAL_IDENT "\r\n", 254 if (atomicio(write, ses.sock_out, LOCAL_IDENT "\r\n",
252 strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) { 255 strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) {
253 ses.remoteclosed(); 256 ses.remoteclosed();
254 } 257 }
255 258
256 /* If they send more than 50 lines, something is wrong */ 259 /* If they send more than 50 lines, something is wrong */
257 for (i = 0; i < 50; i++) { 260 for (i = 0; i < 50; i++) {
258 len = ident_readln(ses.sock, linebuf, sizeof(linebuf)); 261 len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf));
259 262
260 if (len < 0 && errno != EINTR) { 263 if (len < 0 && errno != EINTR) {
261 /* It failed */ 264 /* It failed */
262 break; 265 break;
263 } 266 }