You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Implement PTY/shell session support for server (#129) (#153)
* feat: Implement PTY/shell session support for server (#129)
Add Unix PTY handling for interactive shell sessions in bssh-server:
- Create pty.rs module for PTY master/slave pair management with async I/O
- Create shell.rs module for shell process spawning and I/O forwarding
- Implement shell_request handler to start interactive shell sessions
- Implement window_change_request handler for terminal resizing
- Update data handler to forward SSH data to active shell sessions
- Add shell session state tracking to ChannelState
- Enable nix crate 'term' and 'fs' features for PTY operations
* fix(security): Fix PTY fd handling and add shell validation
Priority: CRITICAL/MEDIUM
Issues addressed:
- Fixed file descriptor leak via mem::forget by using dup() for each stdio fd
- Added shell path validation before spawning process
- Added bounds checking for window size dimensions (clamp to u16::MAX)
- Improved error context for TIOCSWINSZ ioctl failures
- Fixed clippy warning for const assertions in tests
Review-Iteration: 1
* test(server): Add comprehensive tests for PTY/shell modules
- Add unit tests for PTY configuration, winsize, and boundary values
- Add unit tests for PTY master operations (resize, config, path)
- Add tests for shell session structures and validation
- Update ARCHITECTURE.md with PTY/shell module documentation
- Update server-configuration.md with shell session architecture
The bssh-server supports interactive shell sessions through a PTY (pseudo-terminal) subsystem. This enables users to connect and run interactive programs like vim, top, or bash.
409
+
410
+
### PTY Management
411
+
412
+
The PTY module (`src/server/pty.rs`) handles pseudo-terminal operations:
413
+
414
+
**Key Components:**
415
+
- **PtyMaster**: Manages the master side of a PTY pair
416
+
- Opens PTY pair using `openpty()` from the nix crate
417
+
- Provides async I/O via tokio's `AsyncFd`
418
+
- Handles window resize events with `TIOCSWINSZ` ioctl
419
+
- Configurable terminal type and dimensions
420
+
421
+
**Configuration:**
422
+
```rust
423
+
use bssh::server::pty::{PtyConfig, PtyMaster};
424
+
425
+
// Create PTY with custom configuration
426
+
let config = PtyConfig::new(
427
+
"xterm-256color".to_string(), // Terminal type
428
+
80, // Columns
429
+
24, // Rows
430
+
0, // Pixel width (optional)
431
+
0, // Pixel height (optional)
432
+
);
433
+
434
+
let pty = PtyMaster::open(config)?;
435
+
```
436
+
437
+
### Shell Session Handler
438
+
439
+
The shell module (`src/server/shell.rs`) manages interactive SSH shell sessions:
0 commit comments