diff --git a/protocols/ssh/src/client.c b/protocols/ssh/src/client.c index 8f680ac0..76697e10 100644 --- a/protocols/ssh/src/client.c +++ b/protocols/ssh/src/client.c @@ -56,11 +56,20 @@ /* Client plugin arguments */ const char* GUAC_CLIENT_ARGS[] = { "hostname", + "port", "username", "password", NULL }; +enum __SSH_ARGS_IDX { + IDX_HOSTNAME, + IDX_PORT, + IDX_USERNAME, + IDX_PASSWORD, + SSH_ARGS_COUNT +}; + int guac_client_init(guac_client* client, int argc, char** argv) { guac_socket* socket = client->socket; @@ -77,15 +86,15 @@ int guac_client_init(guac_client* client, int argc, char** argv) { client_data->clipboard_data = NULL; client_data->term_channel = NULL; - if (argc != 3) { + if (argc != SSH_ARGS_COUNT) { guac_client_log_error(client, "Wrong number of arguments"); return -1; } /* Read parameters */ - strcpy(client_data->hostname, argv[0]); - strcpy(client_data->username, argv[1]); - strcpy(client_data->password, argv[2]); + strcpy(client_data->hostname, argv[IDX_HOSTNAME]); + strcpy(client_data->username, argv[IDX_USERNAME]); + strcpy(client_data->password, argv[IDX_PASSWORD]); /* Set up I-bar pointer */ client_data->ibar_cursor = guac_ssh_create_ibar(client); @@ -93,8 +102,8 @@ int guac_client_init(guac_client* client, int argc, char** argv) { /* Set up blank pointer */ client_data->blank_cursor = guac_ssh_create_blank(client); - /* Send name and dimensions */ - guac_protocol_send_name(socket, "Terminal"); + /* Send initial name */ + guac_protocol_send_name(socket, client_data->hostname); /* Initialize pointer */ client_data->current_cursor = client_data->blank_cursor; diff --git a/protocols/ssh/src/ssh_client.c b/protocols/ssh/src/ssh_client.c index a0fa9810..960eedec 100644 --- a/protocols/ssh/src/ssh_client.c +++ b/protocols/ssh/src/ssh_client.c @@ -74,7 +74,7 @@ static char* prompt(guac_client* client, const char* title, char* str, int size, while (pos < size && read(stdin_fd, &in_byte, 1) == 1) { /* Backspace */ - if (in_byte == 0x08) { + if (in_byte == 0x7F) { if (pos > 0) { guac_terminal_write_all(stdout_fd, "\b \b", 3); @@ -82,8 +82,8 @@ static char* prompt(guac_client* client, const char* title, char* str, int size, } } - /* Newline (end of input */ - else if (in_byte == 0x0A) { + /* CR (end of input */ + else if (in_byte == 0x0D) { guac_terminal_write_all(stdout_fd, "\r\n", 2); break; } @@ -131,6 +131,8 @@ void* ssh_client_thread(void* data) { guac_client* client = (guac_client*) data; ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data; + char name[1024]; + guac_socket* socket = client->socket; char buffer[8192]; int bytes_read = -1234; @@ -144,11 +146,16 @@ void* ssh_client_thread(void* data) { prompt(client, "Login as: ", client_data->username, sizeof(client_data->username), true) == NULL) return NULL; + /* Send new name */ + snprintf(name, sizeof(name)-1, "%s@%s", client_data->username, client_data->hostname); + guac_protocol_send_name(socket, name); + /* Get password */ if (client_data->password[0] == 0 && prompt(client, "Password: ", client_data->password, sizeof(client_data->password), false) == NULL) return NULL; + /* Clear screen */ guac_terminal_write_all(stdout_fd, "\x1B[H\x1B[J", 6);