*/
#include "includes.h"
-RCSID("$OpenBSD: channels.c,v 1.161 2002/01/21 23:27:10 markus Exp $");
+RCSID("$OpenBSD: channels.c,v 1.167 2002/02/06 14:55:15 markus Exp $");
#include "ssh.h"
#include "ssh1.h"
c->remote_name = remote_name;
c->remote_window = 0;
c->remote_maxpacket = 0;
- c->cb_fn = NULL;
- c->cb_arg = NULL;
- c->cb_event = 0;
c->force_drain = 0;
c->single_connection = 0;
c->detach_user = NULL;
+ c->confirm = NULL;
c->input_filter = NULL;
debug("channel %d: new [%s]", found, remote_name);
return c;
}
void
-channel_request(int id, char *service, int wantconfirm)
+channel_request_start(int local_id, char *service, int wantconfirm)
{
- channel_request_start(id, service, wantconfirm);
- packet_send();
- debug("channel request %d: %s", id, service) ;
-}
-void
-channel_request_start(int id, char *service, int wantconfirm)
-{
- Channel *c = channel_lookup(id);
+ Channel *c = channel_lookup(local_id);
if (c == NULL) {
- log("channel_request: %d: bad id", id);
+ log("channel_request_start: %d: unknown channel id", local_id);
return;
}
+ debug("channel request %d: %s", local_id, service) ;
packet_start(SSH2_MSG_CHANNEL_REQUEST);
packet_put_int(c->remote_id);
packet_put_cstring(service);
packet_put_char(wantconfirm);
}
void
-channel_register_callback(int id, int mtype, channel_callback_fn *fn, void *arg)
+channel_register_confirm(int id, channel_callback_fn *fn)
{
Channel *c = channel_lookup(id);
if (c == NULL) {
- log("channel_register_callback: %d: bad id", id);
+ log("channel_register_comfirm: %d: bad id", id);
return;
}
- c->cb_event = mtype;
- c->cb_fn = fn;
- c->cb_arg = arg;
+ c->confirm = fn;
}
void
channel_register_cleanup(int id, channel_callback_fn *fn)
{
Channel *nc;
struct sockaddr addr;
- int newsock, on = 1;
+ int newsock;
socklen_t addrlen;
char buf[16384], *remote_ipaddr;
int remote_port;
error("accept: %.100s", strerror(errno));
return;
}
- if (setsockopt(newsock, IPPROTO_TCP, TCP_NODELAY, &on,
- sizeof on) == -1)
- error("setsockopt TCP_NODELAY: %.100s",
- strerror(errno));
+ set_nodelay(newsock);
remote_ipaddr = get_peer_ipaddr(newsock);
remote_port = get_peer_port(newsock);
snprintf(buf, sizeof buf, "X11 connection from %.200s port %d",
SSH_CHANNEL_OPENING, newsock, newsock, -1,
c->local_window_max, c->local_maxpacket,
0, xstrdup(buf), 1);
- if (nc == NULL) {
- close(newsock);
- xfree(remote_ipaddr);
- return;
- }
if (compat20) {
packet_start(SSH2_MSG_CHANNEL_OPEN);
packet_put_cstring("x11");
nextstate, newsock, newsock, -1,
c->local_window_max, c->local_maxpacket,
0, xstrdup(rtype), 1);
- if (nc == NULL) {
- error("channel_post_port_listener: no new channel:");
- close(newsock);
- return;
- }
nc->listening_port = c->listening_port;
nc->host_port = c->host_port;
strlcpy(nc->path, c->path, sizeof(nc->path));
SSH_CHANNEL_OPENING, newsock, newsock, -1,
c->local_window_max, c->local_maxpacket,
0, name, 1);
- if (nc == NULL) {
- error("channel_post_auth_listener: channel_new failed");
- xfree(name);
- close(newsock);
- }
if (compat20) {
packet_start(SSH2_MSG_CHANNEL_OPEN);
packet_put_cstring("auth-agent@openssh.com");
if (compat20) {
c->remote_window = packet_get_int();
c->remote_maxpacket = packet_get_int();
- if (c->cb_fn != NULL && c->cb_event == type) {
+ if (c->confirm) {
debug2("callback start");
- c->cb_fn(c->self, c->cb_arg);
+ c->confirm(c->self, NULL);
debug2("callback done");
}
debug("channel %d: open confirm rwindow %d rmax %d", c->self,
channel_free(c);
}
-void
-channel_input_channel_request(int type, u_int32_t seq, void *ctxt)
-{
- int id;
- Channel *c;
-
- id = packet_get_int();
- c = channel_lookup(id);
-
- if (c == NULL ||
- (c->type != SSH_CHANNEL_OPEN && c->type != SSH_CHANNEL_LARVAL))
- packet_disconnect("Received request for "
- "non-open channel %d.", id);
- if (c->cb_fn != NULL && c->cb_event == type) {
- debug2("callback start");
- c->cb_fn(c->self, c->cb_arg);
- debug2("callback done");
- } else {
- char *service = packet_get_string(NULL);
- debug("channel %d: rcvd request for %s", c->self, service);
- debug("cb_fn %p cb_event %d", c->cb_fn , c->cb_event);
- xfree(service);
- }
-}
-
void
channel_input_window_adjust(int type, u_int32_t seq, void *ctxt)
{
c = channel_new("connected socket",
SSH_CHANNEL_CONNECTING, sock, sock, -1, 0, 0, 0,
originator_string, 1);
- if (c == NULL) {
- error("channel_input_port_open: channel_new failed");
- close(sock);
- } else {
- c->remote_id = remote_id;
- }
+ c->remote_id = remote_id;
}
if (c == NULL) {
packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE);
c = channel_new("port listener", type, sock, sock, -1,
CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT,
0, xstrdup("port listener"), 1);
- if (c == NULL) {
- error("channel_setup_fwd_listener: channel_new failed");
- close(sock);
- continue;
- }
strlcpy(c->path, host, sizeof(c->path));
c->host_port = port_to_connect;
c->listening_port = listen_port;
* an error occurs.
*/
int
-x11_create_display_inet(int x11_display_offset, int gateway_ports,
+x11_create_display_inet(int x11_display_offset, int x11_use_localhost,
int single_connection)
{
Channel *nc = NULL;
port = 6000 + display_number;
memset(&hints, 0, sizeof(hints));
hints.ai_family = IPv4or6;
- hints.ai_flags = gateway_ports ? AI_PASSIVE : 0;
+ hints.ai_flags = x11_use_localhost ? 0: AI_PASSIVE;
hints.ai_socktype = SOCK_STREAM;
snprintf(strport, sizeof strport, "%d", port);
if ((gaierr = getaddrinfo(NULL, strport, &hints, &aitop)) != 0) {
SSH_CHANNEL_X11_LISTENER, sock, sock, -1,
CHAN_X11_WINDOW_DEFAULT, CHAN_X11_PACKET_DEFAULT,
0, xstrdup("X11 inet listener"), 1);
- if (nc != NULL)
- nc->single_connection = single_connection;
+ nc->single_connection = single_connection;
}
/* Return the display number for the DISPLAY environment variable. */
int
x11_connect_display(void)
{
- int display_number, sock = 0, on = 1;
+ int display_number, sock = 0;
const char *display;
char buf[1024], *cp;
struct addrinfo hints, *ai, *aitop;
strerror(errno));
return -1;
}
- if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &on, sizeof on) == -1)
- error("setsockopt TCP_NODELAY: %.100s", strerror(errno));
+ set_nodelay(sock);
return sock;
}
c = channel_new("connected x11 socket",
SSH_CHANNEL_X11_OPEN, sock, sock, -1, 0, 0, 0,
remote_host, 1);
- if (c == NULL) {
- error("x11_input_open: channel_new failed");
- close(sock);
- } else {
- c->remote_id = remote_id;
- c->force_drain = 1;
- }
+ c->remote_id = remote_id;
+ c->force_drain = 1;
}
if (c == NULL) {
/* Send refusal to the remote host. */
SSH_CHANNEL_AUTH_SOCKET, sock, sock, -1,
CHAN_X11_WINDOW_DEFAULT, CHAN_X11_PACKET_DEFAULT,
0, xstrdup("auth socket"), 1);
- if (nc == NULL) {
- error("auth_input_request_forwarding: channel_new failed");
- auth_sock_cleanup_proc(pw);
- fatal_remove_cleanup(auth_sock_cleanup_proc, pw);
- close(sock);
- return 0;
- }
strlcpy(nc->path, auth_sock_name, sizeof(nc->path));
return 1;
}
name = xstrdup("authentication agent connection");
c = channel_new("", SSH_CHANNEL_OPEN, sock, sock,
-1, 0, 0, 0, name, 1);
- if (c == NULL) {
- error("auth_input_open_request: channel_new failed");
- xfree(name);
- close(sock);
- } else {
- c->remote_id = remote_id;
- c->force_drain = 1;
- }
+ c->remote_id = remote_id;
+ c->force_drain = 1;
}
if (c == NULL) {
packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE);