mirror of
https://github.com/tmate-io/tmate-ssh-server.git
synced 2020-11-18 19:53:51 -08:00
Quick refactor in tmate-slave.c
This commit is contained in:
parent
d11d8ababd
commit
79417f1619
6
server.c
6
server.c
@ -83,7 +83,13 @@ server_create_socket(void)
|
|||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
fatal("socket failed");
|
fatal("socket failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TMATE_SLAVE
|
||||||
|
if (access(sa.sun_path, F_OK) == 0)
|
||||||
|
tmate_fatal("session exists");
|
||||||
|
#else
|
||||||
unlink(sa.sun_path);
|
unlink(sa.sun_path);
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||||
fatal("socket failed");
|
fatal("socket failed");
|
||||||
|
@ -85,30 +85,9 @@ static int validate_token(const char *token)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tmate_spawn_slave_server(struct tmate_ssh_client *client)
|
static void random_sleep(void)
|
||||||
{
|
{
|
||||||
char *token;
|
usleep(50000 + (rand() % 50000));
|
||||||
struct tmate_encoder encoder;
|
|
||||||
struct tmate_decoder decoder;
|
|
||||||
|
|
||||||
token = get_random_token();
|
|
||||||
set_session_token(token);
|
|
||||||
free(token);
|
|
||||||
|
|
||||||
tmate_debug("Spawning tmux slave server %s", tmate_session_token);
|
|
||||||
|
|
||||||
tmux_socket_fd = server_create_socket();
|
|
||||||
if (tmux_socket_fd < 0)
|
|
||||||
tmate_fatal("Cannot create to the tmux socket");
|
|
||||||
|
|
||||||
tmate_encoder_init(&encoder);
|
|
||||||
tmate_decoder_init(&decoder);
|
|
||||||
tmate_encoder = &encoder;
|
|
||||||
|
|
||||||
tmate_ssh_client_init(client, &encoder, &decoder);
|
|
||||||
|
|
||||||
tmux_server_init(IDENTIFY_UTF8 | IDENTIFY_256COLOURS);
|
|
||||||
/* never reached */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ssh_echo(struct tmate_ssh_client *ssh_client,
|
static void ssh_echo(struct tmate_ssh_client *ssh_client,
|
||||||
@ -139,9 +118,32 @@ static void ssh_echo(struct tmate_ssh_client *ssh_client,
|
|||||||
" Nico" "\r\n" \
|
" Nico" "\r\n" \
|
||||||
" " "\r\n"
|
" " "\r\n"
|
||||||
|
|
||||||
static void random_sleep(void)
|
static void tmate_spawn_slave_server(struct tmate_ssh_client *client)
|
||||||
{
|
{
|
||||||
usleep(50000 + (rand() % 50000));
|
char *token;
|
||||||
|
struct tmate_encoder encoder;
|
||||||
|
struct tmate_decoder decoder;
|
||||||
|
|
||||||
|
token = get_random_token();
|
||||||
|
set_session_token(token);
|
||||||
|
free(token);
|
||||||
|
|
||||||
|
tmate_debug("Spawning tmux slave server %s", tmate_session_token);
|
||||||
|
|
||||||
|
tmux_socket_fd = server_create_socket();
|
||||||
|
if (tmux_socket_fd < 0)
|
||||||
|
tmate_fatal("Cannot create to the tmux socket");
|
||||||
|
|
||||||
|
ev_base = osdep_event_init();
|
||||||
|
|
||||||
|
tmate_encoder_init(&encoder);
|
||||||
|
tmate_decoder_init(&decoder);
|
||||||
|
tmate_encoder = &encoder;
|
||||||
|
|
||||||
|
tmate_ssh_client_init(client, &encoder, &decoder);
|
||||||
|
|
||||||
|
tmux_server_init(IDENTIFY_UTF8 | IDENTIFY_256COLOURS);
|
||||||
|
/* never reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tmate_spawn_slave_client(struct tmate_ssh_client *client)
|
static void tmate_spawn_slave_client(struct tmate_ssh_client *client)
|
||||||
@ -160,6 +162,8 @@ static void tmate_spawn_slave_client(struct tmate_ssh_client *client)
|
|||||||
|
|
||||||
tmate_debug("Spawn tmux slave client %s", tmate_session_token);
|
tmate_debug("Spawn tmux slave client %s", tmate_session_token);
|
||||||
|
|
||||||
|
ev_base = osdep_event_init();
|
||||||
|
|
||||||
tmux_socket_fd = client_connect(socket_path, 0);
|
tmux_socket_fd = client_connect(socket_path, 0);
|
||||||
if (tmux_socket_fd < 0) {
|
if (tmux_socket_fd < 0) {
|
||||||
random_sleep(); /* for timing attacks */
|
random_sleep(); /* for timing attacks */
|
||||||
@ -184,8 +188,6 @@ static void tmate_spawn_slave_client(struct tmate_ssh_client *client)
|
|||||||
|
|
||||||
void tmate_spawn_slave(struct tmate_ssh_client *client)
|
void tmate_spawn_slave(struct tmate_ssh_client *client)
|
||||||
{
|
{
|
||||||
ev_base = osdep_event_init();
|
|
||||||
|
|
||||||
if (client->role == TMATE_ROLE_SERVER)
|
if (client->role == TMATE_ROLE_SERVER)
|
||||||
tmate_spawn_slave_server(client);
|
tmate_spawn_slave_server(client);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user