Skip to content

Commit 2dca3c6

Browse files
authored
Document how to reply to channel requests (#381)
1 parent 7dee935 commit 2dca3c6

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

russh/src/server/mod.rs

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,27 @@ pub trait Handler: Sized {
396396

397397
/// The client requests a pseudo-terminal with the given
398398
/// specifications.
399+
///
400+
/// **Note:** Success or failure should be communicated to the client by calling
401+
/// `session.channel_success(channel)` or `session.channel_failure(channel)` respectively. For
402+
/// instance:
403+
///
404+
/// ```ignore
405+
/// async fn pty_request(
406+
/// &mut self,
407+
/// channel: ChannelId,
408+
/// term: &str,
409+
/// col_width: u32,
410+
/// row_height: u32,
411+
/// pix_width: u32,
412+
/// pix_height: u32,
413+
/// modes: &[(Pty, u32)],
414+
/// session: &mut Session,
415+
/// ) -> Result<(), Self::Error> {
416+
/// session.channel_success(channel);
417+
/// Ok(())
418+
/// }
419+
/// ```
399420
#[allow(unused_variables, clippy::too_many_arguments)]
400421
async fn pty_request(
401422
&mut self,
@@ -412,6 +433,25 @@ pub trait Handler: Sized {
412433
}
413434

414435
/// The client requests an X11 connection.
436+
///
437+
/// **Note:** Success or failure should be communicated to the client by calling
438+
/// `session.channel_success(channel)` or `session.channel_failure(channel)` respectively. For
439+
/// instance:
440+
///
441+
/// ```ignore
442+
/// async fn x11_request(
443+
/// &mut self,
444+
/// channel: ChannelId,
445+
/// single_connection: bool,
446+
/// x11_auth_protocol: &str,
447+
/// x11_auth_cookie: &str,
448+
/// x11_screen_number: u32,
449+
/// session: &mut Session,
450+
/// ) -> Result<(), Self::Error> {
451+
/// session.channel_success(channel);
452+
/// Ok(())
453+
/// }
454+
/// ```
415455
#[allow(unused_variables)]
416456
async fn x11_request(
417457
&mut self,
@@ -428,6 +468,23 @@ pub trait Handler: Sized {
428468
/// The client wants to set the given environment variable. Check
429469
/// these carefully, as it is dangerous to allow any variable
430470
/// environment to be set.
471+
///
472+
/// **Note:** Success or failure should be communicated to the client by calling
473+
/// `session.channel_success(channel)` or `session.channel_failure(channel)` respectively. For
474+
/// instance:
475+
///
476+
/// ```ignore
477+
/// async fn env_request(
478+
/// &mut self,
479+
/// channel: ChannelId,
480+
/// variable_name: &str,
481+
/// variable_value: &str,
482+
/// session: &mut Session,
483+
/// ) -> Result<(), Self::Error> {
484+
/// session.channel_success(channel);
485+
/// Ok(())
486+
/// }
487+
/// ```
431488
#[allow(unused_variables)]
432489
async fn env_request(
433490
&mut self,
@@ -440,6 +497,21 @@ pub trait Handler: Sized {
440497
}
441498

442499
/// The client requests a shell.
500+
///
501+
/// **Note:** Success or failure should be communicated to the client by calling
502+
/// `session.channel_success(channel)` or `session.channel_failure(channel)` respectively. For
503+
/// instance:
504+
///
505+
/// ```ignore
506+
/// async fn shell_request(
507+
/// &mut self,
508+
/// channel: ChannelId,
509+
/// session: &mut Session,
510+
/// ) -> Result<(), Self::Error> {
511+
/// session.channel_success(channel);
512+
/// Ok(())
513+
/// }
514+
/// ```
443515
#[allow(unused_variables)]
444516
async fn shell_request(
445517
&mut self,
@@ -451,6 +523,22 @@ pub trait Handler: Sized {
451523

452524
/// The client sends a command to execute, to be passed to a
453525
/// shell. Make sure to check the command before doing so.
526+
///
527+
/// **Note:** Success or failure should be communicated to the client by calling
528+
/// `session.channel_success(channel)` or `session.channel_failure(channel)` respectively. For
529+
/// instance:
530+
///
531+
/// ```ignore
532+
/// async fn exec_request(
533+
/// &mut self,
534+
/// channel: ChannelId,
535+
/// data: &[u8],
536+
/// session: &mut Session,
537+
/// ) -> Result<(), Self::Error> {
538+
/// session.channel_success(channel);
539+
/// Ok(())
540+
/// }
541+
/// ```
454542
#[allow(unused_variables)]
455543
async fn exec_request(
456544
&mut self,
@@ -463,6 +551,22 @@ pub trait Handler: Sized {
463551

464552
/// The client asks to start the subsystem with the given name
465553
/// (such as sftp).
554+
///
555+
/// **Note:** Success or failure should be communicated to the client by calling
556+
/// `session.channel_success(channel)` or `session.channel_failure(channel)` respectively. For
557+
/// instance:
558+
///
559+
/// ```ignore
560+
/// async fn subsystem_request(
561+
/// &mut self,
562+
/// channel: ChannelId,
563+
/// name: &str,
564+
/// session: &mut Session,
565+
/// ) -> Result<(), Self::Error> {
566+
/// session.channel_success(channel);
567+
/// Ok(())
568+
/// }
569+
/// ```
466570
#[allow(unused_variables)]
467571
async fn subsystem_request(
468572
&mut self,
@@ -474,6 +578,25 @@ pub trait Handler: Sized {
474578
}
475579

476580
/// The client's pseudo-terminal window size has changed.
581+
///
582+
/// **Note:** Success or failure should be communicated to the client by calling
583+
/// `session.channel_success(channel)` or `session.channel_failure(channel)` respectively. For
584+
/// instance:
585+
///
586+
/// ```ignore
587+
/// async fn window_change_request(
588+
/// &mut self,
589+
/// channel: ChannelId,
590+
/// col_width: u32,
591+
/// row_height: u32,
592+
/// pix_width: u32,
593+
/// pix_height: u32,
594+
/// session: &mut Session,
595+
/// ) -> Result<(), Self::Error> {
596+
/// session.channel_success(channel);
597+
/// Ok(())
598+
/// }
599+
/// ```
477600
#[allow(unused_variables)]
478601
async fn window_change_request(
479602
&mut self,
@@ -488,6 +611,21 @@ pub trait Handler: Sized {
488611
}
489612

490613
/// The client requests OpenSSH agent forwarding
614+
///
615+
/// **Note:** Success or failure should be communicated to the client by calling
616+
/// `session.channel_success(channel)` or `session.channel_failure(channel)` respectively. For
617+
/// instance:
618+
///
619+
/// ```ignore
620+
/// async fn agent_request(
621+
/// &mut self,
622+
/// channel: ChannelId,
623+
/// session: &mut Session,
624+
/// ) -> Result<bool, Self::Error> {
625+
/// session.channel_success(channel);
626+
/// Ok(())
627+
/// }
628+
/// ```
491629
#[allow(unused_variables)]
492630
async fn agent_request(
493631
&mut self,

0 commit comments

Comments
 (0)