Add Explicit Session Exit Controls Mini-Features ä2+3
This commit is contained in:
+46
-5
@@ -460,6 +460,28 @@ static void report_command_result(esp_err_t error, int command_result)
|
||||
}
|
||||
}
|
||||
|
||||
static int command_exit(int argc, char **argv)
|
||||
{
|
||||
(void)argv;
|
||||
if (argc != 1) {
|
||||
printf("Usage: exit\n");
|
||||
return 1;
|
||||
}
|
||||
if (!admin_ssh_console_dispatch_is_remote()) {
|
||||
printf("The exit command is available only from an administrative SSH session.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
esp_err_t error = admin_ssh_console_dispatch_defer(
|
||||
ADMIN_SSH_DEFER_DISCONNECT, s_dispatch_token.session_id);
|
||||
if (error != ESP_OK) {
|
||||
printf("Could not schedule SSH session close: %s\n", esp_err_to_name(error));
|
||||
return 1;
|
||||
}
|
||||
printf("SSH session close scheduled after output drains.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dispatch_registered_command(admin_request_t *request)
|
||||
{
|
||||
FILE *saved_stdout = stdout;
|
||||
@@ -724,6 +746,18 @@ esp_err_t admin_ssh_console_init(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t admin_ssh_console_register_commands(void)
|
||||
{
|
||||
const esp_console_cmd_t command = {
|
||||
.command = "exit",
|
||||
.help = "Close the current administrative SSH session",
|
||||
.hint = NULL,
|
||||
.func = &command_exit,
|
||||
.argtable = NULL,
|
||||
};
|
||||
return esp_console_cmd_register(&command);
|
||||
}
|
||||
|
||||
esp_err_t admin_ssh_console_start_uart_frontend(void)
|
||||
{
|
||||
taskENTER_CRITICAL(&s_lock);
|
||||
@@ -1003,10 +1037,15 @@ bool admin_ssh_console_feed_input(const admin_ssh_console_token_t *token,
|
||||
secure_wipe(completed, sizeof(completed));
|
||||
continue;
|
||||
}
|
||||
if (value == '\r' || value == '\n') {
|
||||
bool exit_requested = value == 0x04U && session->input_length == 0U;
|
||||
if (value == '\r' || value == '\n' || exit_requested) {
|
||||
session->discard_next_lf = value == '\r';
|
||||
history_commit_locked(session);
|
||||
memcpy(request.line, session->input, session->input_length);
|
||||
if (exit_requested) {
|
||||
memcpy(request.line, "exit", sizeof("exit"));
|
||||
} else {
|
||||
history_commit_locked(session);
|
||||
memcpy(request.line, session->input, session->input_length);
|
||||
}
|
||||
request.origin = ADMIN_REQUEST_SSH;
|
||||
request.token = *token;
|
||||
request.principal = session->principal;
|
||||
@@ -1015,8 +1054,10 @@ bool admin_ssh_console_feed_input(const admin_ssh_console_token_t *token,
|
||||
session->input_cursor = 0U;
|
||||
session->history_position = -1;
|
||||
session->command_pending = true;
|
||||
(void)append_output_locked(session, (const uint8_t *)"\r\n",
|
||||
sizeof("\r\n") - 1U);
|
||||
(void)append_output_locked(session,
|
||||
(const uint8_t *)(exit_requested ? "^D\r\n" : "\r\n"),
|
||||
exit_requested ? sizeof("^D\r\n") - 1U
|
||||
: sizeof("\r\n") - 1U);
|
||||
submit = true;
|
||||
} else if (value == 0x03U) {
|
||||
secure_wipe(session->input, sizeof(session->input));
|
||||
|
||||
Reference in New Issue
Block a user