diff --git a/logsrvd/logsrvd.c b/logsrvd/logsrvd.c index 790ff8a0d..250a7ba4e 100644 --- a/logsrvd/logsrvd.c +++ b/logsrvd/logsrvd.c @@ -638,6 +638,11 @@ handle_winsize(ChangeWindowSize *msg, struct connection_closure *closure) debug_return_bool(false); } + if (closure->relay_closure != NULL) { + /* Forward ChangeWindowSize to connected relay. */ + debug_return_bool(relay_winsize(msg, closure)); + } + sudo_debug_printf(SUDO_DEBUG_INFO, "%s: received ChangeWindowSize", __func__); @@ -670,6 +675,11 @@ handle_suspend(CommandSuspend *msg, struct connection_closure *closure) debug_return_bool(false); } + if (closure->relay_closure != NULL) { + /* Forward CommandSuspend to connected relay. */ + debug_return_bool(relay_suspend(msg, closure)); + } + sudo_debug_printf(SUDO_DEBUG_INFO, "%s: received CommandSuspend", __func__); diff --git a/logsrvd/logsrvd.h b/logsrvd/logsrvd.h index 47cd4876f..d3048ad28 100644 --- a/logsrvd/logsrvd.h +++ b/logsrvd/logsrvd.h @@ -193,6 +193,8 @@ bool relay_exit(ExitMessage *msg, struct connection_closure *closure); bool relay_restart(RestartMessage *msg, struct connection_closure *closure); bool relay_alert(AlertMessage *msg, struct connection_closure *closure); bool relay_iobuf(int iofd, IoBuffer *iobuf, struct connection_closure *closure); +bool relay_suspend(CommandSuspend *msg, struct connection_closure *closure); +bool relay_winsize(ChangeWindowSize *msg, struct connection_closure *closure); bool relay_shutdown(struct connection_closure *closure); #endif /* SUDO_LOGSRVD_H */ diff --git a/logsrvd/logsrvd_relay.c b/logsrvd/logsrvd_relay.c index 6c54d95f9..26a0b09f6 100644 --- a/logsrvd/logsrvd_relay.c +++ b/logsrvd/logsrvd_relay.c @@ -1201,6 +1201,68 @@ relay_alert(AlertMessage *msg, struct connection_closure *closure) debug_return_bool(ret); } +/* + * Relay a CommandSuspend from the client to the relay server. + */ +bool +relay_suspend(CommandSuspend *msg, struct connection_closure *closure) +{ + struct relay_closure *relay_closure = closure->relay_closure; + struct sudo_event_base *evbase = closure->evbase; + ClientMessage client_msg = CLIENT_MESSAGE__INIT; + bool ret; + debug_decl(relay_suspend, SUDO_DEBUG_UTIL); + + sudo_debug_printf(SUDO_DEBUG_INFO, + "%s: relaying CommandSuspend from %s to %s (%s)", __func__, + closure->ipaddr, relay_closure->relay_name.name, + relay_closure->relay_name.ipaddr); + + client_msg.u.suspend_event = msg; + client_msg.type_case = CLIENT_MESSAGE__TYPE_SUSPEND_EVENT; + ret = fmt_client_message(closure, &client_msg); + if (ret) { + if (sudo_ev_add(evbase, relay_closure->write_ev, NULL, false) == -1) { + sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, + "unable to add server write event"); + ret = false; + } + } + + debug_return_bool(ret); +} + +/* + * Relay a ChangeWindowSize from the client to the relay server. + */ +bool +relay_winsize(ChangeWindowSize *msg, struct connection_closure *closure) +{ + struct relay_closure *relay_closure = closure->relay_closure; + struct sudo_event_base *evbase = closure->evbase; + ClientMessage client_msg = CLIENT_MESSAGE__INIT; + bool ret; + debug_decl(relay_winsize, SUDO_DEBUG_UTIL); + + sudo_debug_printf(SUDO_DEBUG_INFO, + "%s: relaying ChangeWindowSize from %s to %s (%s)", __func__, + closure->ipaddr, relay_closure->relay_name.name, + relay_closure->relay_name.ipaddr); + + client_msg.u.winsize_event = msg; + client_msg.type_case = CLIENT_MESSAGE__TYPE_WINSIZE_EVENT; + ret = fmt_client_message(closure, &client_msg); + if (ret) { + if (sudo_ev_add(evbase, relay_closure->write_ev, NULL, false) == -1) { + sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, + "unable to add server write event"); + ret = false; + } + } + + debug_return_bool(ret); +} + /* * Relay an IoBuffer from the client to the relay server. */