version 1.126, 2001/06/20 13:56:39 |
version 1.127, 2001/06/23 15:12:17 |
|
|
static char *auth_sock_name = NULL; |
static char *auth_sock_name = NULL; |
static char *auth_sock_dir = NULL; |
static char *auth_sock_dir = NULL; |
|
|
|
|
/* AF_UNSPEC or AF_INET or AF_INET6 */ |
/* AF_UNSPEC or AF_INET or AF_INET6 */ |
extern int IPv4or6; |
extern int IPv4or6; |
|
|
/* helper */ |
/* helper */ |
void port_open_helper(Channel *c, char *rtype); |
static void port_open_helper(Channel *c, char *rtype); |
|
|
/* -- channel core */ |
/* -- channel core */ |
|
|
|
|
* when the channel consumer/producer is ready, e.g. shell exec'd |
* when the channel consumer/producer is ready, e.g. shell exec'd |
*/ |
*/ |
|
|
void |
static void |
channel_register_fds(Channel *c, int rfd, int wfd, int efd, |
channel_register_fds(Channel *c, int rfd, int wfd, int efd, |
int extusage, int nonblock) |
int extusage, int nonblock) |
{ |
{ |
|
|
|
|
/* Close all channel fd/socket. */ |
/* Close all channel fd/socket. */ |
|
|
void |
static void |
channel_close_fds(Channel *c) |
channel_close_fds(Channel *c) |
{ |
{ |
debug3("channel_close_fds: channel %d: r %d w %d e %d", |
debug3("channel_close_fds: channel %d: r %d w %d e %d", |
|
|
chan_fn *channel_pre[SSH_CHANNEL_MAX_TYPE]; |
chan_fn *channel_pre[SSH_CHANNEL_MAX_TYPE]; |
chan_fn *channel_post[SSH_CHANNEL_MAX_TYPE]; |
chan_fn *channel_post[SSH_CHANNEL_MAX_TYPE]; |
|
|
void |
static void |
channel_pre_listener(Channel *c, fd_set * readset, fd_set * writeset) |
channel_pre_listener(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
FD_SET(c->sock, readset); |
FD_SET(c->sock, readset); |
} |
} |
|
|
void |
static void |
channel_pre_connecting(Channel *c, fd_set * readset, fd_set * writeset) |
channel_pre_connecting(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
debug3("channel %d: waiting for connection", c->self); |
debug3("channel %d: waiting for connection", c->self); |
FD_SET(c->sock, writeset); |
FD_SET(c->sock, writeset); |
} |
} |
|
|
void |
static void |
channel_pre_open_13(Channel *c, fd_set * readset, fd_set * writeset) |
channel_pre_open_13(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
if (buffer_len(&c->input) < packet_get_maxsize()) |
if (buffer_len(&c->input) < packet_get_maxsize()) |
|
|
FD_SET(c->sock, writeset); |
FD_SET(c->sock, writeset); |
} |
} |
|
|
void |
static void |
channel_pre_open_15(Channel *c, fd_set * readset, fd_set * writeset) |
channel_pre_open_15(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
/* test whether sockets are 'alive' for read/write */ |
/* test whether sockets are 'alive' for read/write */ |
|
|
} |
} |
} |
} |
|
|
void |
static void |
channel_pre_open_20(Channel *c, fd_set * readset, fd_set * writeset) |
channel_pre_open_20(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
if (c->istate == CHAN_INPUT_OPEN && |
if (c->istate == CHAN_INPUT_OPEN && |
|
|
} |
} |
} |
} |
|
|
void |
static void |
channel_pre_input_draining(Channel *c, fd_set * readset, fd_set * writeset) |
channel_pre_input_draining(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
if (buffer_len(&c->input) == 0) { |
if (buffer_len(&c->input) == 0) { |
|
|
} |
} |
} |
} |
|
|
void |
static void |
channel_pre_output_draining(Channel *c, fd_set * readset, fd_set * writeset) |
channel_pre_output_draining(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
if (buffer_len(&c->output) == 0) |
if (buffer_len(&c->output) == 0) |
|
|
* XXX All this happens at the client side. |
* XXX All this happens at the client side. |
* Returns: 0 = need more data, -1 = wrong cookie, 1 = ok |
* Returns: 0 = need more data, -1 = wrong cookie, 1 = ok |
*/ |
*/ |
int |
static int |
x11_open_helper(Buffer *b) |
x11_open_helper(Buffer *b) |
{ |
{ |
u_char *ucp; |
u_char *ucp; |
|
|
return 1; |
return 1; |
} |
} |
|
|
void |
static void |
channel_pre_x11_open_13(Channel *c, fd_set * readset, fd_set * writeset) |
channel_pre_x11_open_13(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
int ret = x11_open_helper(&c->output); |
int ret = x11_open_helper(&c->output); |
|
|
} |
} |
} |
} |
|
|
void |
static void |
channel_pre_x11_open(Channel *c, fd_set * readset, fd_set * writeset) |
channel_pre_x11_open(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
int ret = x11_open_helper(&c->output); |
int ret = x11_open_helper(&c->output); |
|
|
} |
} |
|
|
/* try to decode a socks4 header */ |
/* try to decode a socks4 header */ |
int |
static int |
channel_decode_socks4(Channel *c, fd_set * readset, fd_set * writeset) |
channel_decode_socks4(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
u_char *p, *host; |
u_char *p, *host; |
|
|
} |
} |
|
|
/* dynamic port forwarding */ |
/* dynamic port forwarding */ |
void |
static void |
channel_pre_dynamic(Channel *c, fd_set * readset, fd_set * writeset) |
channel_pre_dynamic(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
u_char *p; |
u_char *p; |
|
|
} |
} |
|
|
/* This is our fake X11 server socket. */ |
/* This is our fake X11 server socket. */ |
void |
static void |
channel_post_x11_listener(Channel *c, fd_set * readset, fd_set * writeset) |
channel_post_x11_listener(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
Channel *nc; |
Channel *nc; |
|
|
} |
} |
} |
} |
|
|
void |
static void |
port_open_helper(Channel *c, char *rtype) |
port_open_helper(Channel *c, char *rtype) |
{ |
{ |
int direct; |
int direct; |
|
|
/* |
/* |
* This socket is listening for connections to a forwarded TCP/IP port. |
* This socket is listening for connections to a forwarded TCP/IP port. |
*/ |
*/ |
void |
static void |
channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset) |
channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
Channel *nc; |
Channel *nc; |
|
|
* This is the authentication agent socket listening for connections from |
* This is the authentication agent socket listening for connections from |
* clients. |
* clients. |
*/ |
*/ |
void |
static void |
channel_post_auth_listener(Channel *c, fd_set * readset, fd_set * writeset) |
channel_post_auth_listener(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
Channel *nc; |
Channel *nc; |
|
|
} |
} |
} |
} |
|
|
void |
static void |
channel_post_connecting(Channel *c, fd_set * readset, fd_set * writeset) |
channel_post_connecting(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
int err = 0; |
int err = 0; |
|
|
} |
} |
} |
} |
|
|
int |
static int |
channel_handle_rfd(Channel *c, fd_set * readset, fd_set * writeset) |
channel_handle_rfd(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
char buf[16*1024]; |
char buf[16*1024]; |
|
|
} |
} |
return 1; |
return 1; |
} |
} |
int |
static int |
channel_handle_wfd(Channel *c, fd_set * readset, fd_set * writeset) |
channel_handle_wfd(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
struct termios tio; |
struct termios tio; |
|
|
} |
} |
return 1; |
return 1; |
} |
} |
int |
static int |
channel_handle_efd(Channel *c, fd_set * readset, fd_set * writeset) |
channel_handle_efd(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
char buf[16*1024]; |
char buf[16*1024]; |
|
|
} |
} |
return 1; |
return 1; |
} |
} |
int |
static int |
channel_check_window(Channel *c) |
channel_check_window(Channel *c) |
{ |
{ |
if (c->type == SSH_CHANNEL_OPEN && |
if (c->type == SSH_CHANNEL_OPEN && |
|
|
return 1; |
return 1; |
} |
} |
|
|
void |
static void |
channel_post_open_1(Channel *c, fd_set * readset, fd_set * writeset) |
channel_post_open_1(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
channel_handle_rfd(c, readset, writeset); |
channel_handle_rfd(c, readset, writeset); |
channel_handle_wfd(c, readset, writeset); |
channel_handle_wfd(c, readset, writeset); |
} |
} |
|
|
void |
static void |
channel_post_open_2(Channel *c, fd_set * readset, fd_set * writeset) |
channel_post_open_2(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
channel_handle_rfd(c, readset, writeset); |
channel_handle_rfd(c, readset, writeset); |
|
|
channel_check_window(c); |
channel_check_window(c); |
} |
} |
|
|
void |
static void |
channel_post_output_drain_13(Channel *c, fd_set * readset, fd_set * writeset) |
channel_post_output_drain_13(Channel *c, fd_set * readset, fd_set * writeset) |
{ |
{ |
int len; |
int len; |
|
|
} |
} |
} |
} |
|
|
void |
static void |
channel_handler_init_20(void) |
channel_handler_init_20(void) |
{ |
{ |
channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_20; |
channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_20; |
|
|
channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_2; |
channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_2; |
} |
} |
|
|
void |
static void |
channel_handler_init_13(void) |
channel_handler_init_13(void) |
{ |
{ |
channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_13; |
channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_13; |
|
|
channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_1; |
channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_1; |
} |
} |
|
|
void |
static void |
channel_handler_init_15(void) |
channel_handler_init_15(void) |
{ |
{ |
channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_15; |
channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_15; |
|
|
channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_1; |
channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_1; |
} |
} |
|
|
void |
static void |
channel_handler_init(void) |
channel_handler_init(void) |
{ |
{ |
int i; |
int i; |
|
|
channel_handler_init_15(); |
channel_handler_init_15(); |
} |
} |
|
|
void |
static void |
channel_handler(chan_fn *ftab[], fd_set * readset, fd_set * writeset) |
channel_handler(chan_fn *ftab[], fd_set * readset, fd_set * writeset) |
{ |
{ |
static int did_init = 0; |
static int did_init = 0; |
|
|
} |
} |
} |
} |
|
|
char * |
static char * |
reason2txt(int reason) |
reason2txt(int reason) |
{ |
{ |
switch(reason) { |
switch(reason) { |
|
|
|
|
|
|
/* return socket to remote host, port */ |
/* return socket to remote host, port */ |
int |
static int |
connect_to(const char *host, u_short port) |
connect_to(const char *host, u_short port) |
{ |
{ |
struct addrinfo hints, *ai, *aitop; |
struct addrinfo hints, *ai, *aitop; |
|
|
#define X_UNIX_PATH "/tmp/.X11-unix/X" |
#define X_UNIX_PATH "/tmp/.X11-unix/X" |
#endif |
#endif |
|
|
static |
static int |
int |
|
connect_local_xsocket(u_int dnr) |
connect_local_xsocket(u_int dnr) |
{ |
{ |
static const char *const x_sockets[] = { |
static const char *const x_sockets[] = { |