From 161fc904f307f956ea295cccbdfe60cb71f539e9 Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Mon, 24 Nov 2025 17:01:08 +0800 Subject: [PATCH] Fix passwordless login and display alignment issues - Allow SSH_AUTH_METHOD_NONE for passwordless authentication - Replace all \n with \r\n in TUI rendering for proper line breaks - Fixes messages appearing misaligned on terminal --- src/ssh_server.c | 8 +++++--- src/tui.c | 15 +++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ssh_server.c b/src/ssh_server.c index 4549f9f..382b44a 100644 --- a/src/ssh_server.c +++ b/src/ssh_server.c @@ -126,7 +126,7 @@ static int read_username(client_t *client) { } } - client_printf(client, "\n"); + client_printf(client, "\r\n"); if (username[0] == '\0') { strcpy(client->username, "anonymous"); @@ -458,8 +458,10 @@ static int handle_auth(ssh_session session) { ssh_message_free(message); return 0; } else if (ssh_message_subtype(message) == SSH_AUTH_METHOD_NONE) { - /* Deny and ask for password */ - ssh_message_auth_set_methods(message, SSH_AUTH_METHOD_PASSWORD); + /* Accept passwordless authentication for open chatroom */ + ssh_message_auth_reply_success(message, 0); + ssh_message_free(message); + return 0; } } diff --git a/src/tui.c b/src/tui.c index ea5431b..58cdc15 100644 --- a/src/tui.c +++ b/src/tui.c @@ -45,7 +45,7 @@ void tui_render_screen(client_t *client) { for (int i = 0; i < padding; i++) { buffer[pos++] = ' '; } - pos += snprintf(buffer + pos, sizeof(buffer) - pos, ANSI_RESET "\n"); + pos += snprintf(buffer + pos, sizeof(buffer) - pos, ANSI_RESET "\r\n"); /* Messages area */ int msg_height = client->height - 3; @@ -74,13 +74,14 @@ void tui_render_screen(client_t *client) { for (int i = start; i < end; i++) { char msg_line[1024]; message_format(&g_room->messages[i], msg_line, sizeof(msg_line), client->width); - pos += snprintf(buffer + pos, sizeof(buffer) - pos, "%s\n", msg_line); + pos += snprintf(buffer + pos, sizeof(buffer) - pos, "%s\r\n", msg_line); } pthread_rwlock_unlock(&g_room->lock); /* Fill empty lines */ for (int i = end - start; i < msg_height; i++) { + buffer[pos++] = '\r'; buffer[pos++] = '\n'; } @@ -91,6 +92,7 @@ void tui_render_screen(client_t *client) { memcpy(buffer + pos, line_char, len); pos += len; } + buffer[pos++] = '\r'; buffer[pos++] = '\n'; /* Status/Input line */ @@ -165,7 +167,7 @@ void tui_render_command_output(client_t *client) { for (int i = 0; i < padding; i++) { buffer[pos++] = ' '; } - pos += snprintf(buffer + pos, sizeof(buffer) - pos, ANSI_RESET "\n"); + pos += snprintf(buffer + pos, sizeof(buffer) - pos, ANSI_RESET "\r\n"); /* Command output */ char *line = strtok(client->command_output, "\n"); @@ -181,7 +183,7 @@ void tui_render_command_output(client_t *client) { utf8_truncate(truncated, client->width); } - pos += snprintf(buffer + pos, sizeof(buffer) - pos, "%s\n", truncated); + pos += snprintf(buffer + pos, sizeof(buffer) - pos, "%s\r\n", truncated); line = strtok(NULL, "\n"); line_count++; } @@ -298,7 +300,7 @@ void tui_render_help(client_t *client) { for (int i = 0; i < padding; i++) { buffer[pos++] = ' '; } - pos += snprintf(buffer + pos, sizeof(buffer) - pos, ANSI_RESET "\n"); + pos += snprintf(buffer + pos, sizeof(buffer) - pos, ANSI_RESET "\r\n"); /* Help content */ const char *help_text = tui_get_help_text(client->help_lang); @@ -321,11 +323,12 @@ void tui_render_help(client_t *client) { if (end > line_count) end = line_count; for (int i = start; i < end && (i - start) < content_height - 1; i++) { - pos += snprintf(buffer + pos, sizeof(buffer) - pos, "%s\n", lines[i]); + pos += snprintf(buffer + pos, sizeof(buffer) - pos, "%s\r\n", lines[i]); } /* Fill remaining lines */ for (int i = end - start; i < content_height - 1; i++) { + buffer[pos++] = '\r'; buffer[pos++] = '\n'; }