diff options
Diffstat (limited to 'channels.c')
-rw-r--r-- | channels.c | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/channels.c b/channels.c index 38a65a07f..29a842fcf 100644 --- a/channels.c +++ b/channels.c | |||
@@ -16,7 +16,7 @@ arbitrary tcp/ip connections, and the authentication agent connection. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "includes.h" | 18 | #include "includes.h" |
19 | RCSID("$Id: channels.c,v 1.1 1999/10/27 03:42:44 damien Exp $"); | 19 | RCSID("$Id: channels.c,v 1.2 1999/10/28 05:23:30 damien Exp $"); |
20 | 20 | ||
21 | #include "ssh.h" | 21 | #include "ssh.h" |
22 | #include "packet.h" | 22 | #include "packet.h" |
@@ -108,7 +108,8 @@ void channel_permit_all_opens() | |||
108 | 108 | ||
109 | int channel_allocate(int type, int sock, char *remote_name) | 109 | int channel_allocate(int type, int sock, char *remote_name) |
110 | { | 110 | { |
111 | int i, old_channels; | 111 | int i, found; |
112 | Channel *c; | ||
112 | 113 | ||
113 | /* Update the maximum file descriptor value. */ | 114 | /* Update the maximum file descriptor value. */ |
114 | if (sock > channel_max_fd_value) | 115 | if (sock > channel_max_fd_value) |
@@ -128,41 +129,38 @@ int channel_allocate(int type, int sock, char *remote_name) | |||
128 | } | 129 | } |
129 | 130 | ||
130 | /* Try to find a free slot where to put the new channel. */ | 131 | /* Try to find a free slot where to put the new channel. */ |
131 | for (i = 0; i < channels_alloc; i++) | 132 | for (found = -1, i = 0; i < channels_alloc; i++) |
132 | if (channels[i].type == SSH_CHANNEL_FREE) | 133 | if (channels[i].type == SSH_CHANNEL_FREE) |
133 | { | 134 | { |
134 | /* Found a free slot. Initialize the fields and return its number. */ | 135 | /* Found a free slot. */ |
135 | buffer_init(&channels[i].input); | 136 | found = i; |
136 | buffer_init(&channels[i].output); | 137 | break; |
137 | channels[i].self = i; | ||
138 | channels[i].type = type; | ||
139 | channels[i].x11 = 0; | ||
140 | channels[i].sock = sock; | ||
141 | channels[i].remote_id = -1; | ||
142 | channels[i].remote_name = remote_name; | ||
143 | chan_init_iostates(&channels[i]); | ||
144 | return i; | ||
145 | } | 138 | } |
146 | 139 | ||
147 | /* There are no free slots. Must expand the array. */ | 140 | if (found == -1) |
148 | old_channels = channels_alloc; | 141 | { |
149 | channels_alloc += 10; | 142 | /* There are no free slots. Take last+1 slot and expand the array. */ |
150 | channels = xrealloc(channels, channels_alloc * sizeof(Channel)); | 143 | found = channels_alloc; |
151 | for (i = old_channels; i < channels_alloc; i++) | 144 | channels_alloc += 10; |
152 | channels[i].type = SSH_CHANNEL_FREE; | 145 | debug("channel: expanding %d", channels_alloc); |
153 | 146 | channels = xrealloc(channels, channels_alloc * sizeof(Channel)); | |
154 | /* We know that the next one after the old maximum channel number is now | 147 | for (i = found; i < channels_alloc; i++) |
155 | available. Initialize and return its number. */ | 148 | channels[i].type = SSH_CHANNEL_FREE; |
156 | buffer_init(&channels[old_channels].input); | 149 | } |
157 | buffer_init(&channels[old_channels].output); | 150 | |
158 | channels[old_channels].self = old_channels; | 151 | /* Initialize and return new channel number. */ |
159 | channels[old_channels].type = type; | 152 | c=&channels[found]; |
160 | channels[old_channels].x11 = 0; | 153 | buffer_init(&c->input); |
161 | channels[old_channels].sock = sock; | 154 | buffer_init(&c->output); |
162 | channels[old_channels].remote_id = -1; | 155 | chan_init_iostates(c); |
163 | channels[old_channels].remote_name = remote_name; | 156 | c->self = found; |
164 | chan_init_iostates(&channels[old_channels]); | 157 | c->type = type; |
165 | return old_channels; | 158 | c->x11 = 0; |
159 | c->sock = sock; | ||
160 | c->remote_id = -1; | ||
161 | c->remote_name = remote_name; | ||
162 | debug("channel %d: new [%s]", found, remote_name); | ||
163 | return found; | ||
166 | } | 164 | } |
167 | 165 | ||
168 | /* Free the channel and close its socket. */ | 166 | /* Free the channel and close its socket. */ |
@@ -336,10 +334,10 @@ void channel_prepare_select(fd_set *readset, fd_set *writeset) | |||
336 | packet_put_int(ch->remote_id); | 334 | packet_put_int(ch->remote_id); |
337 | packet_send(); | 335 | packet_send(); |
338 | }else{ | 336 | }else{ |
339 | debug("X11 rejected %d 0x%x 0x%x", ch->self, ch->istate, ch->ostate); | 337 | debug("X11 rejected %d i%d/o%d", ch->self, ch->istate, ch->ostate); |
340 | chan_read_failed(ch); | 338 | chan_read_failed(ch); |
341 | chan_write_failed(ch); | 339 | chan_write_failed(ch); |
342 | debug("X11 rejected %d 0x%x 0x%x", ch->self, ch->istate, ch->ostate); | 340 | debug("X11 rejected %d i%d/o%d", ch->self, ch->istate, ch->ostate); |
343 | } | 341 | } |
344 | break; | 342 | break; |
345 | 343 | ||
@@ -407,9 +405,9 @@ void channel_after_select(fd_set *readset, fd_set *writeset) | |||
407 | break; | 405 | break; |
408 | } | 406 | } |
409 | remote_hostname = get_remote_hostname(newsock); | 407 | remote_hostname = get_remote_hostname(newsock); |
410 | snprintf(buf, sizeof buf, "port %d, connection from %.200s port %d", | 408 | snprintf(buf, sizeof buf, "listen port %d:%.100s:%d, connect from %.200s:%d", |
411 | ch->listening_port, remote_hostname, | 409 | ch->listening_port, ch->path, ch->host_port, |
412 | get_peer_port(newsock)); | 410 | remote_hostname, get_peer_port(newsock)); |
413 | xfree(remote_hostname); | 411 | xfree(remote_hostname); |
414 | newch = channel_allocate(SSH_CHANNEL_OPENING, newsock, | 412 | newch = channel_allocate(SSH_CHANNEL_OPENING, newsock, |
415 | xstrdup(buf)); | 413 | xstrdup(buf)); |
@@ -830,8 +828,9 @@ char *channel_open_message() | |||
830 | case SSH_CHANNEL_X11_OPEN: | 828 | case SSH_CHANNEL_X11_OPEN: |
831 | case SSH_CHANNEL_INPUT_DRAINING: | 829 | case SSH_CHANNEL_INPUT_DRAINING: |
832 | case SSH_CHANNEL_OUTPUT_DRAINING: | 830 | case SSH_CHANNEL_OUTPUT_DRAINING: |
833 | snprintf(buf, sizeof buf, " #%d/%d %.300s\r\n", | 831 | snprintf(buf, sizeof buf, " #%d %.300s (t%d r%d i%d o%d)\r\n", |
834 | c->self,c->type,c->remote_name); | 832 | c->self,c->remote_name, |
833 | c->type,c->remote_id, c->istate,c->ostate); | ||
835 | buffer_append(&buffer, buf, strlen(buf)); | 834 | buffer_append(&buffer, buf, strlen(buf)); |
836 | continue; | 835 | continue; |
837 | default: | 836 | default: |