╭ changed ─────────────────╮ │src/serve_ssh_protocol.zig│ ╰──────────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────╮ │← previous│ ╰──────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1626 │ │1627 switch (msg_type) { │ │1646 - SSH_MSG_GLOBAL_REQUEST => try handleGlobalRequest(io, allocator, sc_cipher, writer, packet),│ │1628 + SSH_MSG_GLOBAL_REQUEST => try handleGlobalRequest(conn, packet), │ │1629 │ │1630 SSH_MSG_CHANNEL_OPEN => { │ │1631 if (channel != null) { │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1650 - try sendChannelOpenFailure(io, allocator, sc_cipher, writer, packet, SSH_OPEN_RESOURCE_SHORTAGE, "only one channel per connection");│ │1632 + try sendChannelOpenFailure(conn, packet, SSH_OPEN_RESOURCE_SHORTAGE, "only one channel per connection"); │ │1633 continue; │ │1634 } │ │1653 - channel = try handleChannelOpen(io, allocator, sc_cipher, writer, packet) orelse continue; │ │1635 + channel = try handleChannelOpen(conn, packet) orelse continue; │ │1636 }, │ │1637 │ │1638 SSH_MSG_CHANNEL_REQUEST => { │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1639 const ch = if (channel) |*c| c else continue; │ │1658 - const start_request = try handleChannelRequest(io, allocator, sc_cipher, writer, ch, packet, &pending_exec);│ │1640 + const start_request = try handleChannelRequest(conn, ch, packet, &pending_exec); │ │1641 if (start_request) |req_kind| { │ │1642 const request: Request = switch (req_kind) { │ │1643 .shell => .{ .shell = ch.pty }, │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────╮ │1644 .exec => .{ .exec = pending_exec.? },│ │1645 }; │ │1646 var sess = SessionCtx{ │ │1665 - .io = io, │ │1666 - .allocator = allocator, │ │1667 - .reader = reader, │ │1668 - .writer = writer, │ │1669 - .cs_cipher = cs_cipher, │ │1670 - .sc_cipher = sc_cipher, │ │1671 - .rekey = rekey, │ │1647 + .conn = conn, │ │1648 .channel = ch, │ │1649 .fingerprint = fingerprint.*, │ │1650 }; │ ╰───────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1668 const ch = if (channel) |*c| c else continue; │ │1669 // before shell/exec the client shouldn't be sending data, but │ │1670 // some clients are chatty; discard and refill window. │ │1695 - try discardChannelData(io, allocator, sc_cipher, writer, ch, packet, msg_type == SSH_MSG_CHANNEL_EXTENDED_DATA);│ │1671 + try discardChannelData(conn, ch, packet, msg_type == SSH_MSG_CHANNEL_EXTENDED_DATA); │ │1672 }, │ │1673 │ │1674 SSH_MSG_CHANNEL_EOF => { │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────╮ │1685 } │ │1686 } │ │1687 │ │1712 -fn handleGlobalRequest( │ │1713 - io: std.Io, │ │1714 - allocator: std.mem.Allocator, │ │1715 - sc_cipher: *Cipher, │ │1716 - writer: *std.Io.Writer, │ │1717 - packet: []const u8, │ │1718 -) !void { │ │1688 +fn handleGlobalRequest(conn: *Conn, packet: []const u8) !void {│ │1689 // byte SSH_MSG_GLOBAL_REQUEST │ │1690 // string request_name │ │1691 // boolean want_reply │ ╰─────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1692 // …request-specific data we ignore │ │1693 var r = std.Io.Reader.fixed(packet[1..]); │ │1724 - const name = try takeStringField(allocator, &r, 256); │ │1725 - defer allocator.free(name); │ │1694 + const name = try takeStringField(conn.allocator, &r, 256); │ │1695 + defer conn.allocator.free(name); │ │1696 const want_reply = (try r.takeByte()) != 0; │ │1697 if (want_reply) { │ │1728 - try sc_cipher.writePacket(io, writer, &[_]u8{SSH_MSG_REQUEST_FAILURE}); │ │1698 + try conn.sc_cipher.writePacket(conn.io, conn.writer, &[_]u8{SSH_MSG_REQUEST_FAILURE});│ │1699 } │ │1700 } │ │1701 │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────╮ │1702 /// Parse a CHANNEL_OPEN. On a session channel, send CHANNEL_OPEN_CONFIRMATION│ │1703 /// and return the new Channel. On other types, send CHANNEL_OPEN_FAILURE and │ │1704 /// return null. │ │1735 -fn handleChannelOpen( │ │1736 - io: std.Io, │ │1737 - allocator: std.mem.Allocator, │ │1738 - sc_cipher: *Cipher, │ │1739 - writer: *std.Io.Writer, │ │1740 - packet: []const u8, │ │1741 -) !?Channel { │ │1705 +fn handleChannelOpen(conn: *Conn, packet: []const u8) !?Channel { │ │1706 + const allocator = conn.allocator; │ │1707 + │ │1708 // byte SSH_MSG_CHANNEL_OPEN │ │1709 // string channel_type │ │1710 // uint32 sender_channel (peer's id) │ ╰────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1718 const max_packet = try r.takeInt(u32, .big); │ │1719 │ │1720 if (!std.mem.eql(u8, ch_type, "session")) { │ │1755 - try sendChannelOpenFailure(io, allocator, sc_cipher, writer, packet, SSH_OPEN_UNKNOWN_CHANNEL_TYPE, "only session channels are supported");│ │1721 + try sendChannelOpenFailure(conn, packet, SSH_OPEN_UNKNOWN_CHANNEL_TYPE, "only session channels are supported"); │ │1722 return null; │ │1723 } │ │1724 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1725 // a zero max_packet would leave writeChannel looping without progress │ │1726 if (max_packet == 0) { │ │1761 - try sendChannelOpenFailure(io, allocator, sc_cipher, writer, packet, SSH_OPEN_RESOURCE_SHORTAGE, "max packet size must be non-zero");│ │1727 + try sendChannelOpenFailure(conn, packet, SSH_OPEN_RESOURCE_SHORTAGE, "max packet size must be non-zero"); │ │1728 return null; │ │1729 } │ │1730 │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯