Skip to main content

ExecStreamHandler

Trait ExecStreamHandler 

Source
pub trait ExecStreamHandler: Send + Sync {
    // Required methods
    fn claims(&self, command: &str) -> bool;
    fn run(
        &self,
        user: &str,
        env: &SessionEnv,
        command: &str,
        stream: ChannelStream,
    ) -> Result<()>;
}
Expand description

Server-side hook called when a client sends an "exec" channel request, before the synchronous CommandHandler runs. Lets a stream-mode handler (SCP, custom RPC) claim the channel and drive it as a real bidirectional pipe rather than the buffer-and-return shape of CommandHandler::handle.

The dispatcher consults the overlay in two phases:

  1. claims is called synchronously in the connection thread with just the command string. Return true to claim the request — the dispatcher then sends request_success, registers a per-channel runtime, and hands off to run.
  2. run executes on a dedicated thread per claimed channel, with a live ChannelStream it can Read/Write until the transaction finishes. Dropping the stream emits EOF+Close to the peer.

Both hooks run in the per-connection process after the Config::on_session_open drop-to-user has already happened, so handlers see the authenticated user’s filesystem permissions.

Required Methods§

Source

fn claims(&self, command: &str) -> bool

Cheap synchronous decision based on the command string only. Return true to claim; false to fall through to the buffered CommandHandler.

Source

fn run( &self, user: &str, env: &SessionEnv, command: &str, stream: ChannelStream, ) -> Result<()>

Execute the claimed command on a dedicated thread. The handler owns stream until it returns; on return the stream drops, emitting EOF+Close automatically. env is a snapshot of the session-level environment at the time of the claim.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§