c - libssh2 和终端模式编码

标签 c ssh libssh2

Guacamole 项目正在使用 libssh2 库创建与服务器的 SSH 连接。我们确定的一件事是,在 SSH 中传递 VERASE 终端模式编码选项会很有用,这样远程系统就有更好的机会知道客户端为 Backspace 键发送的内容。 libssh2 包含一个函数 libssh2_channel_request_pty_ex(),该函数允许将有关终端的各种数据传递到 SSH 服务器,包括这些编码选项。该函数的文档在这里:

https://libssh2.org/libssh2_channel_request_pty_ex.html

modes 参数是一个 char *,它应该让您传递各种终端编码操作码和值,但我无法弄清楚如何将操作码和值一起放入 char *modes 变量中,以便以有效的方式传递它们。 有一个 Java SSH 客户端具有类似的选项,似乎使用 byte[] 对象来完成此操作,但即使它也没有很好的文档记录。

从libssh2和channel_request_pty()函数的源代码来看,modes中指定的数据似乎只是附加到构建的请求缓冲区中与请求 pty 时传递的其他数据(终端的名称和终端的大小)一起,所以我希望这个 char *modes 变量期望这些操作码和值是准确的SSH 服务器在通过线路传递并在另一端读取时所需的格式,但我对 SSH 不太熟悉,不知道该格式是什么,并且正在努力寻找对我有帮助的文档或代码示例弄清楚这一点。

任何人都可以提供提示、见解或示例吗?

最佳答案

RFC 4254定义 SSH 协议(protocol)消息。 Section 6.2描述请求 PTY 的消息:

  byte      SSH_MSG_CHANNEL_REQUEST
  uint32    recipient channel
  string    "pty-req"
  boolean   want_reply
  string    TERM environment variable value (e.g., vt100)
  uint32    terminal width, characters (e.g., 80)
  uint32    terminal height, rows (e.g., 24)
  uint32    terminal width, pixels (e.g., 640)
  uint32    terminal height, pixels (e.g., 480)
  string    encoded terminal modes

您可以看到此消息中的字段与 libssh2 PTY 请求函数的参数一致。 Libssh2 几乎肯定会从 modesmodes_len 参数填充“编码终端模式”字段。

Section 8 RFC 描述了终端模式的编码:

All 'encoded terminal modes' (as passed in a pty request) are encoded into a byte stream. It is intended that the coding be portable across different environments. The stream consists of opcode- argument pairs wherein the opcode is a byte value. Opcodes 1 to 159 have a single uint32 argument. Opcodes 160 to 255 are not yet defined, and cause parsing to stop (they should only be used after any other data). The stream is terminated by opcode TTY_OP_END (0x00)....

关于c - libssh2 和终端模式编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48890240/

相关文章:

c++ - 对于卷句柄,来自 FILE_END 的 SetFilePointer 始终失败

linux - 如何替换 Amazon EC2 实例的 key 对文件?

c++ - libssh2 远程文件属性上次修改时间错误的时区

objective-c - SSH 键盘交互认证

c - 循环遍历 C 预处理器中的 header

c - 将成员从struct初始化为外部函数的方向

c - 在 Linux 中跨共享库调用保留数据

ssh - 运行包含带 screen 的 STDIN 重定向的命令

windows - 在 Windows 下使用 GIT with/SSH key 文件的问题

c - 当来自 cmd 的 scp 工作时,使用 libssh2 scp 检索文件无法进行身份验证