1
0
mirror of https://github.com/tmate-io/tmate-ssh-server.git synced 2020-11-18 19:53:51 -08:00

Removed some useless struct

This commit is contained in:
Nicolas Viennot 2013-06-11 02:41:28 -04:00
parent 4ae8ba3270
commit d11d8ababd
3 changed files with 19 additions and 32 deletions

View File

@ -144,17 +144,15 @@ static void random_sleep(void)
usleep(50000 + (rand() % 50000));
}
static void tmate_spawn_slave_client(struct tmate_ssh_client *ssh_client)
static void tmate_spawn_slave_client(struct tmate_ssh_client *client)
{
struct tmate_ssh_client_pty _client;
struct tmate_ssh_client_pty *client = &_client;
char *argv[] = {(char *)"attach", NULL};
char *token = ssh_client->username;
char *token = client->username;
int slave_pty;
int ret;
if (validate_token(token) < 0) {
ssh_echo(ssh_client, BAD_TOKEN_ERROR_STR);
ssh_echo(client, BAD_TOKEN_ERROR_STR);
tmate_fatal("Bad token");
}
@ -165,14 +163,10 @@ static void tmate_spawn_slave_client(struct tmate_ssh_client *ssh_client)
tmux_socket_fd = client_connect(socket_path, 0);
if (tmux_socket_fd < 0) {
random_sleep(); /* for timing attacks */
ssh_echo(ssh_client, EXPIRED_TOKEN_ERROR_STR);
ssh_echo(client, EXPIRED_TOKEN_ERROR_STR);
tmate_fatal("Expired token");
}
client->session = ssh_client->session;
client->channel = ssh_client->channel;
client->winsize_pty = ssh_client->winsize_pty;
if (openpty(&client->pty, &slave_pty, NULL, NULL, NULL) < 0)
tmate_fatal("Cannot allocate pty");

View File

@ -4,7 +4,7 @@
#include <libssh/callbacks.h>
#include <errno.h>
static void consume_channel(struct tmate_ssh_client_pty *client)
static void consume_channel(struct tmate_ssh_client *client)
{
ssize_t len, written;
char buf[4096];
@ -36,7 +36,7 @@ static void consume_channel(struct tmate_ssh_client_pty *client)
}
}
static void on_session_event(struct tmate_ssh_client_pty *client)
static void on_session_event(struct tmate_ssh_client *client)
{
ssh_execute_message_callbacks(client->session);
@ -53,7 +53,7 @@ static void __on_session_event(evutil_socket_t fd, short what, void *arg)
on_session_event(arg);
}
static int message_callback(struct tmate_ssh_client_pty *client,
static int message_callback(struct tmate_ssh_client *client,
ssh_message msg)
{
if (ssh_message_type(msg) == SSH_REQUEST_CHANNEL &&
@ -78,7 +78,7 @@ static int __message_callback(ssh_session session, ssh_message msg, void *arg)
return message_callback(arg, msg);
}
static void register_session_fd_event(struct tmate_ssh_client_pty *client)
static void register_session_fd_event(struct tmate_ssh_client *client)
{
ssh_set_message_callback(client->session, __message_callback, client);
@ -87,7 +87,7 @@ static void register_session_fd_event(struct tmate_ssh_client_pty *client)
event_add(&client->ev_ssh, NULL);
}
static void on_pty_event(struct tmate_ssh_client_pty *client)
static void on_pty_event(struct tmate_ssh_client *client)
{
ssize_t len, written;
char buf[4096];
@ -121,13 +121,13 @@ static void __on_pty_event(evutil_socket_t fd, short what, void *arg)
on_pty_event(arg);
}
void tmate_flush_pty(struct tmate_ssh_client_pty *client)
void tmate_flush_pty(struct tmate_ssh_client *client)
{
on_pty_event(client);
close(client->pty);
}
static void register_pty_event(struct tmate_ssh_client_pty *client)
static void register_pty_event(struct tmate_ssh_client *client)
{
setblocking(client->pty, 0);
event_assign(&client->ev_pty, ev_base, client->pty,
@ -135,7 +135,7 @@ static void register_pty_event(struct tmate_ssh_client_pty *client)
event_add(&client->ev_pty, NULL);
}
void tmate_ssh_client_pty_init(struct tmate_ssh_client_pty *client)
void tmate_ssh_client_pty_init(struct tmate_ssh_client *client)
{
ioctl(client->pty, TIOCSWINSZ, &client->winsize_pty);
register_session_fd_event(client);

21
tmate.h
View File

@ -78,26 +78,19 @@ struct tmate_ssh_client {
struct winsize winsize_pty;
struct event ev_ssh;
/* only for client-pty */
int pty;
struct event ev_pty;
};
extern void tmate_ssh_client_init(struct tmate_ssh_client *ssh_client,
extern void tmate_ssh_client_init(struct tmate_ssh_client *client,
struct tmate_encoder *encoder,
struct tmate_decoder *decoder);
/* tmate-ssh-client-pty.c */
struct tmate_ssh_client_pty {
ssh_session session;
ssh_channel channel;
int pty;
struct winsize winsize_pty;
struct event ev_ssh;
struct event ev_pty;
};
extern void tmate_ssh_client_pty_init(struct tmate_ssh_client_pty *client);
extern void tmate_flush_pty(struct tmate_ssh_client_pty *client);
extern void tmate_ssh_client_pty_init(struct tmate_ssh_client *client);
extern void tmate_flush_pty(struct tmate_ssh_client *client);
/* tmate-ssh-server.c */