╭──────────╮ │← previous│ ╰──────────╯ ╭ changed ─────────────────╮ │src/serve_ssh_protocol.zig│ ╰──────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │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 │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────╮ │1736 try writeU32(&reply, allocator, local_id); │ │1737 try writeU32(&reply, allocator, initial_recv_window); │ │1738 try writeU32(&reply, allocator, max_packet_size); │ │1773 - try sc_cipher.writePacket(io, writer, reply.items); │ │1739 + try conn.sc_cipher.writePacket(conn.io, conn.writer, reply.items);│ │1740 │ │1741 return .{ │ │1742 .local_id = local_id, │ ╰────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1747 }; │ │1748 } │ │1749 │ │1784 -fn sendChannelOpenFailure( │ │1785 - io: std.Io, │ │1786 - allocator: std.mem.Allocator, │ │1787 - sc_cipher: *Cipher, │ │1788 - writer: *std.Io.Writer, │ │1789 - open_packet: []const u8, │ │1790 - reason: u32, │ │1791 - description: []const u8, │ │1792 -) !void { │ │1750 +fn sendChannelOpenFailure(conn: *Conn, open_packet: []const u8, reason: u32, description: []const u8) !void {│ │1751 + const allocator = conn.allocator; │ │1752 + │ │1753 // recover the sender_channel field from the CHANNEL_OPEN packet so we │ │1754 // address the failure to the correct id │ │1755 var r = std.Io.Reader.fixed(open_packet[1..]); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────╮ │1764 try writeU32(&reply, allocator, reason); │ │1765 try writeStringField(&reply, allocator, description); │ │1766 try writeStringField(&reply, allocator, ""); // language tag │ │1807 - try sc_cipher.writePacket(io, writer, reply.items); │ │1767 + try conn.sc_cipher.writePacket(conn.io, conn.writer, reply.items);│ │1768 } │ │1769 │ │1770 const RequestKind = enum { shell, exec }; │ ╰────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │1771 │ │1772 /// Returns the kind of session request if this triggered one, else null. │ │1813 -fn handleChannelRequest( │ │1814 - io: std.Io, │ │1815 - allocator: std.mem.Allocator, │ │1816 - sc_cipher: *Cipher, │ │1817 - writer: *std.Io.Writer, │ │1818 - ch: *Channel, │ │1819 - packet: []const u8, │ │1820 - pending_exec: *?[]u8, │ │1821 -) !?RequestKind { │ │1773 +fn handleChannelRequest(conn: *Conn, ch: *Channel, packet: []const u8, pending_exec: *?[]u8) !?RequestKind {│ │1774 + const allocator = conn.allocator; │ │1775 + │ │1776 // byte SSH_MSG_CHANNEL_REQUEST │ │1777 // uint32 recipient_channel (== our local_id) │ │1778 // string request_type │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │1791 const term = try takeStringField(allocator, &r, 64); │ │1792 defer allocator.free(term); │ │1793 ch.pty = try takePtySize(&r); │ │1840 - try replyChannelRequest(io, allocator, sc_cipher, writer, ch, want_reply, true);│ │1794 + try replyChannelRequest(conn, ch, want_reply, true); │ │1795 return null; │ │1796 } │ │1797 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │1798 if (std.mem.eql(u8, req_type, "env")) { │ │1799 // ignore environment variables silently (we don't pass them anywhere) │ │1846 - try replyChannelRequest(io, allocator, sc_cipher, writer, ch, want_reply, true);│ │1800 + try replyChannelRequest(conn, ch, want_reply, true); │ │1801 return null; │ │1802 } │ │1803 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │1806 const sz = try takePtySize(&r); │ │1807 if (ch.pty != null) ch.pty = sz; │ │1808 // spec: window-change MUST NOT request a reply, but accept either │ │1855 - try replyChannelRequest(io, allocator, sc_cipher, writer, ch, want_reply, true);│ │1809 + try replyChannelRequest(conn, ch, want_reply, true); │ │1810 return null; │ │1811 } │ │1812 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │1813 if (std.mem.eql(u8, req_type, "shell")) { │ │1860 - try replyChannelRequest(io, allocator, sc_cipher, writer, ch, want_reply, true);│ │1814 + try replyChannelRequest(conn, ch, want_reply, true); │ │1815 return .shell; │ │1816 } │ │1817 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯