version 1.131, 2001/07/02 22:52:56 |
version 1.132, 2001/07/17 21:04:56 |
|
|
return c; |
return c; |
} |
} |
|
|
|
static int |
|
channel_find_maxfd(void) |
|
{ |
|
int i, max = 0; |
|
Channel *c; |
|
|
|
for (i = 0; i < channels_alloc; i++) { |
|
c = channels[i]; |
|
if (c != NULL) { |
|
max = MAX(max, c->rfd); |
|
max = MAX(max, c->wfd); |
|
max = MAX(max, c->efd); |
|
} |
|
} |
|
return max; |
|
} |
|
|
|
int |
|
channel_close_fd(int *fdp) |
|
{ |
|
int ret = 0, fd = *fdp; |
|
|
|
if (fd != -1) { |
|
ret = close(fd); |
|
*fdp = -1; |
|
if (fd == channel_max_fd) |
|
channel_max_fd = channel_find_maxfd(); |
|
} |
|
return ret; |
|
} |
|
|
/* Close all channel fd/socket. */ |
/* Close all channel fd/socket. */ |
|
|
static void |
static void |
|
|
debug3("channel_close_fds: channel %d: r %d w %d e %d", |
debug3("channel_close_fds: channel %d: r %d w %d e %d", |
c->self, c->rfd, c->wfd, c->efd); |
c->self, c->rfd, c->wfd, c->efd); |
|
|
if (c->sock != -1) { |
channel_close_fd(&c->sock); |
close(c->sock); |
channel_close_fd(&c->rfd); |
c->sock = -1; |
channel_close_fd(&c->wfd); |
} |
channel_close_fd(&c->efd); |
if (c->rfd != -1) { |
|
close(c->rfd); |
|
c->rfd = -1; |
|
} |
|
if (c->wfd != -1) { |
|
close(c->wfd); |
|
c->wfd = -1; |
|
} |
|
if (c->efd != -1) { |
|
close(c->efd); |
|
c->efd = -1; |
|
} |
|
} |
} |
|
|
/* Free the channel and close its fd/socket. */ |
/* Free the channel and close its fd/socket. */ |
|
|
case SSH_CHANNEL_PORT_LISTENER: |
case SSH_CHANNEL_PORT_LISTENER: |
case SSH_CHANNEL_RPORT_LISTENER: |
case SSH_CHANNEL_RPORT_LISTENER: |
case SSH_CHANNEL_X11_LISTENER: |
case SSH_CHANNEL_X11_LISTENER: |
close(c->sock); |
channel_close_fd(&c->sock); |
channel_free(c); |
channel_free(c); |
break; |
break; |
} |
} |
|
|
log("X11 connection rejected because of wrong authentication."); |
log("X11 connection rejected because of wrong authentication."); |
buffer_clear(&c->input); |
buffer_clear(&c->input); |
buffer_clear(&c->output); |
buffer_clear(&c->output); |
close(c->sock); |
channel_close_fd(&c->sock); |
c->sock = -1; |
c->sock = -1; |
c->type = SSH_CHANNEL_CLOSED; |
c->type = SSH_CHANNEL_CLOSED; |
packet_start(SSH_MSG_CHANNEL_CLOSE); |
packet_start(SSH_MSG_CHANNEL_CLOSE); |
|
|
if (len <= 0) { |
if (len <= 0) { |
debug2("channel %d: closing write-efd %d", |
debug2("channel %d: closing write-efd %d", |
c->self, c->efd); |
c->self, c->efd); |
close(c->efd); |
channel_close_fd(&c->efd); |
c->efd = -1; |
|
} else { |
} else { |
buffer_consume(&c->extended, len); |
buffer_consume(&c->extended, len); |
c->local_consumed += len; |
c->local_consumed += len; |
|
|
if (len <= 0) { |
if (len <= 0) { |
debug2("channel %d: closing read-efd %d", |
debug2("channel %d: closing read-efd %d", |
c->self, c->efd); |
c->self, c->efd); |
close(c->efd); |
channel_close_fd(&c->efd); |
c->efd = -1; |
|
} else { |
} else { |
buffer_append(&c->extended, buf, len); |
buffer_append(&c->extended, buf, len); |
} |
} |
|
|
*/ |
*/ |
void |
void |
channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp, |
channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp, |
int rekeying) |
int *nallocp, int rekeying) |
{ |
{ |
int n; |
int n; |
u_int sz; |
u_int sz; |
|
|
n = MAX(*maxfdp, channel_max_fd); |
n = MAX(*maxfdp, channel_max_fd); |
|
|
sz = howmany(n+1, NFDBITS) * sizeof(fd_mask); |
sz = howmany(n+1, NFDBITS) * sizeof(fd_mask); |
if (*readsetp == NULL || n > *maxfdp) { |
/* perhaps check sz < nalloc/2 and shrink? */ |
if (*readsetp) |
if (*readsetp == NULL || sz > *nallocp) { |
xfree(*readsetp); |
*readsetp = xrealloc(*readsetp, sz); |
if (*writesetp) |
*writesetp = xrealloc(*writesetp, sz); |
xfree(*writesetp); |
*nallocp = sz; |
*readsetp = xmalloc(sz); |
|
*writesetp = xmalloc(sz); |
|
*maxfdp = n; |
|
} |
} |
|
*maxfdp = n; |
memset(*readsetp, 0, sz); |
memset(*readsetp, 0, sz); |
memset(*writesetp, 0, sz); |
memset(*writesetp, 0, sz); |
|
|