diff --git a/Userland/Services/SSHServer/SSHClient.cpp b/Userland/Services/SSHServer/SSHClient.cpp index ce35d2475eb..aca0e7ab9df 100644 --- a/Userland/Services/SSHServer/SSHClient.cpp +++ b/Userland/Services/SSHServer/SSHClient.cpp @@ -636,6 +636,11 @@ ErrorOr SSHClient::handle_channel_request(GenericMessage& message) return {}; } + if (request_type == "window-change"sv.bytes()) { + TRY(handle_channel_window_change(session, message)); + return {}; + } + return Error::from_string_literal("Unsupported channel request"); } @@ -887,6 +892,38 @@ ErrorOr SSHClient::handle_channel_pseudo_terminal(Session& session, Generi return TRY(send_channel_success_message(session)); } +// 6.7. Window Dimension Change Message +// https://datatracker.ietf.org/doc/html/rfc4254#section-6.7 +ErrorOr SSHClient::handle_channel_window_change(Session& session, GenericMessage& message) +{ + u32 width_characters = TRY(message.payload.read_value>()); + u32 height_rows = TRY(message.payload.read_value>()); + u32 width_pixels = TRY(message.payload.read_value>()); + u32 height_pixels = TRY(message.payload.read_value>()); + + dbgln_if(SSH_DEBUG, "PTY window change: w={}, h={}, w_px={}, h_px={}", + width_characters, height_rows, width_pixels, height_pixels); + + if (!session.system.has()) + return Error::from_string_literal("Requested a window change while no shell is present"); + + winsize ws { + .ws_row = static_cast(height_rows), + .ws_col = static_cast(width_characters), + .ws_xpixel = static_cast(width_pixels), + .ws_ypixel = static_cast(height_pixels), + }; + + auto maybe_error = Core::System::tcsetwinsize(session.system.get().stdin_->fd(), ws); + + if (maybe_error.is_error()) { + dbgln("Unable to set pty dimensions: {}", maybe_error.error()); + } + + // "A response SHOULD NOT be sent to this message." + return {}; +} + ErrorOr SSHClient::send_channel_success_message(Session const& session) { AllocatingMemoryStream stream; diff --git a/Userland/Services/SSHServer/SSHClient.h b/Userland/Services/SSHServer/SSHClient.h index d814f4b34a2..4f25a7c244a 100644 --- a/Userland/Services/SSHServer/SSHClient.h +++ b/Userland/Services/SSHServer/SSHClient.h @@ -85,6 +85,7 @@ private: ErrorOr handle_channel_data(GenericMessage&); ErrorOr handle_channel_subsystem(Session&, GenericMessage&); ErrorOr handle_channel_pseudo_terminal(Session&, GenericMessage&); + ErrorOr handle_channel_window_change(Session&, GenericMessage&); ErrorOr handle_channel_exec(NonnullRefPtr const&, GenericMessage&); ErrorOr handle_channel_shell(NonnullRefPtr const&); ErrorOr send_channel_success_message(Session const&);