diff --git a/Makefile.am b/Makefile.am index 764bb715..22ae602b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -183,7 +183,7 @@ dist_tmate_slave_SOURCES = \ tmate-daemon-decoder.c \ tmate-daemon-encoder.c \ tmate-msgpack.c \ - tmate-master.c \ + tmate-proxy.c \ tmate-slave.c \ tmate-ssh-client-pty.c \ tmate-ssh-daemon.c \ diff --git a/resize.c b/resize.c index 3ee4a726..4791e2a6 100644 --- a/resize.c +++ b/resize.c @@ -78,11 +78,11 @@ recalculate_sizes(void) } #ifdef TMATE_SLAVE - if (tmate_has_master()) { - if (tmate_session->master_sy < ssy) - ssy = tmate_session->master_sy; - if (tmate_session->master_sx < ssx) - ssx = tmate_session->master_sx; + if (tmate_has_proxy()) { + if (tmate_session->proxy_sy < ssy) + ssy = tmate_session->proxy_sy; + if (tmate_session->proxy_sx < ssx) + ssx = tmate_session->proxy_sx; } tmate_client_resize(ssx, ssy); diff --git a/tmate-master.c b/tmate-proxy.c similarity index 81% rename from tmate-master.c rename to tmate-proxy.c index ebac9ac6..36226aa8 100644 --- a/tmate-master.c +++ b/tmate-proxy.c @@ -7,7 +7,7 @@ #define CONTROL_PROTOCOL_VERSION 1 -#define pack(what, ...) _pack(&tmate_session->master_encoder, what, __VA_ARGS__) +#define pack(what, ...) _pack(&tmate_session->proxy_encoder, what, __VA_ARGS__) static void ctl_daemon_fwd_msg(struct tmate_session *session, struct tmate_unpacker *uk) @@ -142,13 +142,13 @@ static void ctl_pane_keys(struct tmate_session *session, static void ctl_resize(struct tmate_session *session, struct tmate_unpacker *uk) { - session->master_sx = (u_int)unpack_int(uk); - session->master_sy = (u_int)unpack_int(uk); + session->proxy_sx = (u_int)unpack_int(uk); + session->proxy_sy = (u_int)unpack_int(uk); recalculate_sizes(); } -void tmate_dispatch_master_message(struct tmate_session *session, - struct tmate_unpacker *uk) +void tmate_dispatch_proxy_message(struct tmate_session *session, + struct tmate_unpacker *uk) { int cmd = unpack_int(uk); switch (cmd) { @@ -157,14 +157,14 @@ void tmate_dispatch_master_message(struct tmate_session *session, dispatch(TMATE_CTL_REQUEST_SNAPSHOT, ctl_daemon_request_snapshot); dispatch(TMATE_CTL_PANE_KEYS, ctl_pane_keys); dispatch(TMATE_CTL_RESIZE, ctl_resize); - default: tmate_warn("Bad master message type: %d", cmd); + default: tmate_warn("Bad proxy message type: %d", cmd); } } void tmate_notify_client_join(struct tmate_session *session, struct client *c) { - if (!tmate_has_master()) + if (!tmate_has_proxy()) return; pack(array, 4); @@ -177,7 +177,7 @@ void tmate_notify_client_join(struct tmate_session *session, void tmate_notify_client_left(struct tmate_session *session, struct client *c) { - if (!tmate_has_master()) + if (!tmate_has_proxy()) return; pack(array, 2); @@ -185,13 +185,13 @@ void tmate_notify_client_left(struct tmate_session *session, pack(int, c->id); } -void tmate_send_master_daemon_msg(struct tmate_session *session, - struct tmate_unpacker *uk) +void tmate_send_proxy_daemon_msg(struct tmate_session *session, + struct tmate_unpacker *uk) { struct timespec time_diff, current_time; int i; - if (!tmate_has_master()) + if (!tmate_has_proxy()) return; pack(array, 2); @@ -202,9 +202,9 @@ void tmate_send_master_daemon_msg(struct tmate_session *session, pack(object, uk->argv[i]); } -void tmate_send_master_header(struct tmate_session *session) +void tmate_send_proxy_header(struct tmate_session *session) { - if (!tmate_has_master()) + if (!tmate_has_proxy()) return; pack(array, 6); @@ -216,16 +216,16 @@ void tmate_send_master_header(struct tmate_session *session) pack(string, session->session_token_ro); } -void tmate_init_master_session(struct tmate_session *session) +void tmate_init_proxy_session(struct tmate_session *session) { - if (!tmate_has_master()) + if (!tmate_has_proxy()) return; - session->master_sx = -1; - session->master_sy = -1; + session->proxy_sx = -1; + session->proxy_sy = -1; } -static int _tmate_connect_to_master(const char *hostname, int port) +static int _tmate_connect_to_proxy(const char *hostname, int port) { int sockfd = -1; struct sockaddr_in servaddr; @@ -245,22 +245,22 @@ static int _tmate_connect_to_master(const char *hostname, int port) servaddr.sin_port = htons(port); if (connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0) - tmate_fatal("Cannot connect to master at %s:%d", hostname, port); + tmate_fatal("Cannot connect to proxy at %s:%d", hostname, port); int flag = 1; if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)) < 0) - tmate_fatal("Can't set master socket to TCP_NODELAY"); + tmate_fatal("Can't set proxy socket to TCP_NODELAY"); if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0) - tmate_fatal("Can't set master socket to non-blocking"); + tmate_fatal("Can't set proxy socket to non-blocking"); - tmate_notice("Connected to master at %s:%d", hostname, port); + tmate_notice("Connected to proxy at %s:%d", hostname, port); return sockfd; } -int tmate_connect_to_master(void) +int tmate_connect_to_proxy(void) { - return _tmate_connect_to_master(tmate_settings->master_hostname, - tmate_settings->master_port); + return _tmate_connect_to_proxy(tmate_settings->proxy_hostname, + tmate_settings->proxy_port); } diff --git a/tmate-slave.c b/tmate-slave.c index b6a7aec7..af71cd3f 100644 --- a/tmate-slave.c +++ b/tmate-slave.c @@ -33,8 +33,8 @@ extern int client_connect(char *path, int start_server); struct tmate_settings _tmate_settings = { .keys_dir = TMATE_SSH_DEFAULT_KEYS_DIR, .ssh_port = TMATE_SSH_DEFAULT_PORT, - .master_hostname = NULL, - .master_port = TMATE_DEFAULT_MASTER_PORT, + .proxy_hostname = NULL, + .proxy_port = TMATE_DEFAULT_PROXY_PORT, .tmate_host = NULL, .log_level = LOG_NOTICE, .use_syslog = false, @@ -44,7 +44,7 @@ struct tmate_settings *tmate_settings = &_tmate_settings; static void usage(void) { - fprintf(stderr, "usage: tmate-slave [-k keys_dir] [-p port] [-m master_hostname] [-q master_port] [-s] [-v]\n"); + fprintf(stderr, "usage: tmate-slave [-k keys_dir] [-p port] [-x proxy_hostname] [-q proxy_port] [-s] [-v]\n"); } void tmate_get_random_bytes(void *buffer, ssize_t len) @@ -76,7 +76,7 @@ int main(int argc, char **argv, char **envp) { int opt; - while ((opt = getopt(argc, argv, "k:p:lvm:q:")) != -1) { + while ((opt = getopt(argc, argv, "k:p:lvx:q:")) != -1) { switch (opt) { case 'p': tmate_settings->ssh_port = atoi(optarg); @@ -90,11 +90,11 @@ int main(int argc, char **argv, char **envp) case 'v': tmate_settings->log_level++; break; - case 'm': - tmate_settings->master_hostname = xstrdup(optarg); + case 'x': + tmate_settings->proxy_hostname = xstrdup(optarg); break; case 'q': - tmate_settings->master_port = atoi(optarg); + tmate_settings->proxy_port = atoi(optarg); break; case 'h': tmate_settings->tmate_host = xstrdup(optarg); @@ -351,7 +351,7 @@ static void tmate_spawn_slave_daemon(struct tmate_session *session) close_fds_except((int[]){session->tmux_socket_fd, ssh_get_fd(session->ssh_client.session), log_file ? fileno(log_file) : -1, - session->master_fd}, 4); + session->proxy_fd}, 4); jail(); event_reinit(ev_base); @@ -420,7 +420,7 @@ static void tmate_spawn_slave_pty_client(struct tmate_session *session) tmate_client_pty_init(session); - /* the unused session->master_fd will get closed automatically */ + /* the unused session->proxy_fd will get closed automatically */ close_fds_except((int[]){STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, session->tmux_socket_fd, diff --git a/tmate-ssh-daemon.c b/tmate-ssh-daemon.c index 4c75de3f..3918aa4d 100644 --- a/tmate-ssh-daemon.c +++ b/tmate-ssh-daemon.c @@ -1,55 +1,55 @@ #include "tmate.h" #include -static void on_master_decoder_read(void *userdata, struct tmate_unpacker *uk) +static void on_proxy_decoder_read(void *userdata, struct tmate_unpacker *uk) { struct tmate_session *session = userdata; - tmate_dispatch_master_message(session, uk); + tmate_dispatch_proxy_message(session, uk); } -static void on_master_read(struct bufferevent *bev, void *_session) +static void on_proxy_read(struct bufferevent *bev, void *_session) { struct tmate_session *session = _session; - struct evbuffer *master_in; + struct evbuffer *proxy_in; ssize_t written; char *buf; size_t len; - master_in = bufferevent_get_input(session->bev_master); + proxy_in = bufferevent_get_input(session->bev_proxy); - while (evbuffer_get_length(master_in)) { - tmate_decoder_get_buffer(&session->master_decoder, &buf, &len); + while (evbuffer_get_length(proxy_in)) { + tmate_decoder_get_buffer(&session->proxy_decoder, &buf, &len); if (len == 0) tmate_fatal("No more room in client decoder. Message too big?"); - written = evbuffer_remove(master_in, buf, len); + written = evbuffer_remove(proxy_in, buf, len); if (written < 0) - tmate_fatal("Cannot read master buffer"); + tmate_fatal("Cannot read proxy buffer"); - tmate_decoder_commit(&session->master_decoder, written); + tmate_decoder_commit(&session->proxy_decoder, written); } } -static void on_master_encoder_write(void *userdata, struct evbuffer *buffer) +static void on_proxy_encoder_write(void *userdata, struct evbuffer *buffer) { struct tmate_session *session = userdata; - struct evbuffer *master_out; + struct evbuffer *proxy_out; size_t len; - master_out = bufferevent_get_output(session->bev_master); + proxy_out = bufferevent_get_output(session->bev_proxy); - if (evbuffer_add_buffer(master_out, buffer) < 0) - tmate_fatal("Cannot write to master buffer"); + if (evbuffer_add_buffer(proxy_out, buffer) < 0) + tmate_fatal("Cannot write to proxy buffer"); } -static void on_master_event(struct bufferevent *bev, short events, void *_session) +static void on_proxy_event(struct bufferevent *bev, short events, void *_session) { if (events & BEV_EVENT_EOF) - tmate_fatal("Connection to master closed"); + tmate_fatal("Connection to proxy closed"); if (events & BEV_EVENT_ERROR) - tmate_fatal("Connection to master error: %s", + tmate_fatal("Connection to proxy error: %s", evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR())); } @@ -57,7 +57,7 @@ static void on_daemon_decoder_read(void *userdata, struct tmate_unpacker *uk) { struct tmate_session *session = userdata; - tmate_send_master_daemon_msg(session, uk); + tmate_send_proxy_daemon_msg(session, uk); tmate_dispatch_daemon_message(session, uk); } @@ -117,23 +117,23 @@ static void on_daemon_encoder_write(void *userdata, struct evbuffer *buffer) } } -static void init_master(struct tmate_session *session) +static void init_proxy(struct tmate_session *session) { - /* session->master_fd is already connected */ - session->bev_master = bufferevent_socket_new(ev_base, session->master_fd, + /* session->proxy_fd is already connected */ + session->bev_proxy = bufferevent_socket_new(ev_base, session->proxy_fd, BEV_OPT_CLOSE_ON_FREE); - if (!session->bev_master) + if (!session->bev_proxy) tmate_fatal("Cannot setup socket bufferevent"); - bufferevent_setcb(session->bev_master, - on_master_read, NULL, on_master_event, session); - bufferevent_enable(session->bev_master, EV_READ | EV_WRITE); + bufferevent_setcb(session->bev_proxy, + on_proxy_read, NULL, on_proxy_event, session); + bufferevent_enable(session->bev_proxy, EV_READ | EV_WRITE); - tmate_encoder_init(&session->master_encoder, on_master_encoder_write, session); - tmate_decoder_init(&session->master_decoder, on_master_decoder_read, session); + tmate_encoder_init(&session->proxy_encoder, on_proxy_encoder_write, session); + tmate_decoder_init(&session->proxy_decoder, on_proxy_decoder_read, session); - tmate_init_master_session(session); - tmate_send_master_header(session); + tmate_init_proxy_session(session); + tmate_send_proxy_header(session); } void tmate_daemon_init(struct tmate_session *session) @@ -149,6 +149,6 @@ void tmate_daemon_init(struct tmate_session *session) tmate_encoder_init(&session->daemon_encoder, on_daemon_encoder_write, session); tmate_decoder_init(&session->daemon_decoder, on_daemon_decoder_read, session); - if (tmate_has_master()) - init_master(session); + if (tmate_has_proxy()) + init_proxy(session); } diff --git a/tmate-ssh-server.c b/tmate-ssh-server.c index 23a2184b..b6df5850 100644 --- a/tmate-ssh-server.c +++ b/tmate-ssh-server.c @@ -305,8 +305,8 @@ void tmate_ssh_server_main(struct tmate_session *session, setup_signals(); - if (tmate_has_master()) - close(tmate_connect_to_master()); + if (tmate_has_proxy()) + close(tmate_connect_to_proxy()); bind = prepare_ssh(keys_dir, port); @@ -323,12 +323,12 @@ void tmate_ssh_server_main(struct tmate_session *session, tmate_fatal("Error accepting connection: %s", ssh_get_error(bind)); /* - * We should die if we can't connect to master. This way the + * We should die if we can't connect to proxy. This way the * tmate daemon will pick another server to work on. */ - session->master_fd = -1; - if (tmate_has_master()) - session->master_fd = tmate_connect_to_master(); + session->proxy_fd = -1; + if (tmate_has_proxy()) + session->proxy_fd = tmate_connect_to_proxy(); if (get_ip(ssh_get_fd(client->session), client->ip_address, sizeof(client->ip_address)) < 0) @@ -341,7 +341,7 @@ void tmate_ssh_server_main(struct tmate_session *session, tmate_info("Child spawned pid=%d, ip=%s", pid, client->ip_address); ssh_free(client->session); - close(session->master_fd); + close(session->proxy_fd); } else { ssh_bind_free(bind); session->session_token = "init"; diff --git a/tmate.h b/tmate.h index 400d33d8..a8a21291 100644 --- a/tmate.h +++ b/tmate.h @@ -166,7 +166,7 @@ extern void tmate_ssh_server_main(struct tmate_session *session, #define TMATE_SSH_DEFAULT_KEYS_DIR "keys" -#define TMATE_DEFAULT_MASTER_PORT 7000 +#define TMATE_DEFAULT_PROXY_PORT 4002 #define TMATE_TOKEN_LEN 25 #define TMATE_WORKDIR "/tmp/tmate" @@ -175,8 +175,8 @@ extern void tmate_ssh_server_main(struct tmate_session *session, struct tmate_settings { const char *keys_dir; int ssh_port; - const char *master_hostname; - int master_port; + const char *proxy_hostname; + int proxy_port; const char *tmate_host; int log_level; bool use_syslog; @@ -196,11 +196,11 @@ struct tmate_session { int client_protocol_version; struct event ev_notify_timer; - int master_fd; - struct bufferevent *bev_master; - struct tmate_encoder master_encoder; - struct tmate_decoder master_decoder; - u_int master_sx, master_sy; + int proxy_fd; + struct bufferevent *bev_proxy; + struct tmate_encoder proxy_encoder; + struct tmate_decoder proxy_decoder; + u_int proxy_sx, proxy_sy; /* only for client-pty */ int pty; @@ -214,20 +214,20 @@ extern long tmate_get_random_long(void); extern void request_server_termination(void); extern void tmate_spawn_slave(struct tmate_session *session); -/* tmate-master.c */ +/* tmate-proxy.c */ -extern void tmate_dispatch_master_message(struct tmate_session *session, +extern void tmate_dispatch_proxy_message(struct tmate_session *session, struct tmate_unpacker *uk); -extern void tmate_send_master_daemon_msg(struct tmate_session *session, +extern void tmate_send_proxy_daemon_msg(struct tmate_session *session, struct tmate_unpacker *uk); -extern void tmate_send_master_header(struct tmate_session *session); -extern void tmate_init_master_session(struct tmate_session *session); +extern void tmate_send_proxy_header(struct tmate_session *session); +extern void tmate_init_proxy_session(struct tmate_session *session); -extern int tmate_connect_to_master(void); -static inline bool tmate_has_master(void) +extern int tmate_connect_to_proxy(void); +static inline bool tmate_has_proxy(void) { - return !!tmate_settings->master_hostname; + return !!tmate_settings->proxy_hostname; }