Skip to content

fix: complete PTY terminal modes and Shift key input support#41

Merged
inureyes merged 2 commits intomainfrom
fix/issue-40-pty-terminal-modes
Oct 14, 2025
Merged

fix: complete PTY terminal modes and Shift key input support#41
inureyes merged 2 commits intomainfrom
fix/issue-40-pty-terminal-modes

Conversation

@inureyes
Copy link
Member

Summary

This PR fixes critical issues preventing sudo password input from working correctly in interactive PTY sessions by completing terminal mode configuration and fixing Shift key input handling.

Changes

1. Complete Terminal Modes Configuration (RFC 4254)

Added all OpenSSH-compatible terminal mode settings for proper PTY behavior:

Control Characters:

  • VEOL, VEOL2: End-of-line characters
  • VSTART, VSTOP: Flow control (XON/XOFF)
  • VREPRINT: Reprint current line (Ctrl+R)
  • VWERASE: Erase word (Ctrl+W)
  • VLNEXT: Literal next character (Ctrl+V)
  • VDISCARD: Discard output (Ctrl+O)

Input Modes:

  • IGNPAR, PARMRK, INPCK: Parity handling
  • ISTRIP: 8th bit handling
  • INLCR, IGNCR: Line ending conversions

Local Modes:

  • NOFLSH: Flush behavior after signals
  • TOSTOP: Background process output control
  • PENDIN: Pending input behavior

Output Modes:

  • OCRNL, ONOCR, ONLRET: Line ending handling

Control Modes:

  • PARENB, PARODD: Parity configuration

2. Shift Key Input Bug Fix

Fixed key_event_to_bytes() function in src/pty/session.rs:

  • Previous behavior: Only accepted KeyModifiers::NONE, blocking uppercase letters and special characters
  • New behavior: Accepts characters with no modifiers OR SHIFT modifier
  • Unchanged: CONTROL, ALT, META combinations still handled separately

Root Cause Analysis

The issue occurred because:

  1. Incomplete terminal modes: PTY was configured with minimal modes, missing critical settings for interactive programs
  2. Shift key rejection: Input handler rejected all characters with SHIFT modifier, preventing:
    • Uppercase letters (e.g., 'A' = Shift+a)
    • Special characters requiring Shift (e.g., '!' = Shift+1)

Impact

Before

  • ❌ Passwords with uppercase letters failed on Linux remote hosts
  • ❌ Passwords with special characters requiring Shift failed
  • ⚠️ macOS localhost partially worked (simpler passwords without Shift)

After

  • ✅ All password types work correctly
  • ✅ Full uppercase and special character support
  • ✅ Complete OpenSSH-compatible terminal mode configuration
  • ✅ Proper behavior for sudo, passwd, and other interactive programs

Testing

Tested with:

  • sudo -s with complex passwords (uppercase + special characters)
  • passwd command for password changes
  • Both macOS localhost and Linux remote hosts
  • Various password complexity requirements

Related Issues

Closes #40

Files Changed

  • src/pty/session.rs: Terminal modes configuration and Shift key input handling

This commit fixes two critical issues preventing sudo password input
from working correctly in interactive PTY sessions:

1. Incomplete Terminal Modes Configuration
   - Added all OpenSSH-compatible terminal mode settings (RFC 4254)
   - Control characters: VEOL, VEOL2, VSTART, VSTOP, VREPRINT, VWERASE, VLNEXT, VDISCARD
   - Input modes: IGNPAR, PARMRK, INPCK, ISTRIP, INLCR, IGNCR
   - Local modes: NOFLSH, TOSTOP, PENDIN
   - Output modes: OCRNL, ONOCR, ONLRET
   - Control modes: PARENB, PARODD
   - These settings ensure proper terminal behavior for interactive programs

2. Shift Key Input Bug
   - Fixed key_event_to_bytes() to accept SHIFT modifier
   - Previously only accepted KeyModifiers::NONE, blocking uppercase letters
     and special characters that require Shift key
   - Now accepts characters with no modifiers or SHIFT modifier only
   - Rejects CONTROL, ALT, META combinations (handled separately)

Impact:
- Passwords with uppercase letters and special characters now work correctly
- Fixes issue where Linux remote hosts rejected password input
- macOS localhost previously worked due to simpler password requirements

Fixes #40
@inureyes inureyes added type:bug Something isn't working priority:high High priority issue labels Oct 14, 2025
@inureyes inureyes self-assigned this Oct 14, 2025
@inureyes inureyes merged commit 576f02d into main Oct 14, 2025
3 checks passed
@inureyes inureyes added the status:done Completed label Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:high High priority issue status:done Completed type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PTY mode: sudo password input fails in interactive sessions

1 participant