ssh_request.h
Go to the documentation of this file.
1 /**
2  * @file ssh_request.h
3  * @brief Global request and channel request handling
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSH Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _SSH_REQUEST_H
32 #define _SSH_REQUEST_H
33 
34 //Dependencies
35 #include "ssh/ssh.h"
36 
37 //C++ guard
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 
43 /**
44  * @brief "tcpip-forward" global request parameters
45  **/
46 
47 typedef struct
48 {
50  uint32_t portNumToBind;
52 
53 
54 /**
55  * @brief "cancel-tcpip-forward" global request parameters
56  **/
57 
58 typedef struct
59 {
61  uint32_t portNumToBind;
63 
64 
65 /**
66  * @brief "elevation" global request parameters
67  **/
68 
69 typedef struct
70 {
73 
74 
75 /**
76  * @brief "pty-req" channel request parameters
77  **/
78 
79 typedef struct
80 {
82  uint32_t termWidthChars;
83  uint32_t termHeightRows;
84  uint32_t termWidthPixels;
85  uint32_t termHeightPixels;
88 
89 
90 /**
91  * @brief "x11-req" channel request parameters
92  **/
93 
94 typedef struct
95 {
99  uint32_t x11ScreenNum;
101 
102 
103 /**
104  * @brief "env" channel request parameters
105  **/
106 
107 typedef struct
108 {
111 } SshEnvParams;
112 
113 
114 /**
115  * @brief "exec" channel request parameters
116  **/
117 
118 typedef struct
119 {
121 } SshExecParams;
122 
123 
124 /**
125  * @brief "subsystem" channel request parameters
126  **/
127 
128 typedef struct
129 {
132 
133 
134 /**
135  * @brief "window-change" channel request parameters
136  **/
137 
138 typedef struct
139 {
140  uint32_t termWidthChars;
141  uint32_t termHeightRows;
142  uint32_t termWidthPixels;
145 
146 
147 /**
148  * @brief "xon-xoff" channel request parameters
149  **/
150 
151 typedef struct
152 {
155 
156 
157 /**
158  * @brief "signal" channel request parameters
159  **/
160 
161 typedef struct
162 {
165 
166 
167 /**
168  * @brief "exit-status" channel request parameters
169  **/
170 
171 typedef struct
172 {
173  uint32_t exitStatus;
175 
176 
177 /**
178  * @brief "exit-signal" channel request parameters
179  **/
180 
181 typedef struct
182 {
188 
189 
190 /**
191  * @brief "break" channel request parameters
192  **/
193 
194 typedef struct
195 {
196  uint32_t breakLen;
198 
199 
200 //SSH related functions
202  const char_t *requestName, const void *requestParams, bool_t wantReply);
203 
206 
207 error_t sshSendChannelRequest(SshChannel *channel, const char_t *requestType,
208  const void *requestParams, bool_t wantReply);
209 
212 
214  const char_t *requestName, const void *requestParams, bool_t wantReply,
215  uint8_t *p, size_t *length);
216 
218  uint8_t *p, size_t *written);
219 
221  uint8_t *p, size_t *written);
222 
224  uint8_t *p, size_t *written);
225 
226 error_t sshFormatRequestSuccess(SshConnection *connection, uint8_t *p,
227  size_t *length);
228 
229 error_t sshFormatRequestFailure(SshConnection *connection, uint8_t *p,
230  size_t *length);
231 
232 error_t sshFormatChannelRequest(SshChannel *channel, const char_t *requestType,
233  const void *requestParams, bool_t wantReply, uint8_t *p, size_t *length);
234 
236  uint8_t *p, size_t *written);
237 
239  uint8_t *p, size_t *written);
240 
242  uint8_t *p, size_t *written);
243 
245  uint8_t *p, size_t *written);
246 
248  uint8_t *p, size_t *written);
249 
251  uint8_t *p, size_t *written);
252 
254  uint8_t *p, size_t *written);
255 
256 error_t sshFormatChannelSuccess(SshChannel *channel, uint8_t *p,
257  size_t *length);
258 
259 error_t sshFormatChannelFailure(SshChannel *channel, uint8_t *p,
260  size_t *length);
261 
263  const uint8_t *message, size_t length);
264 
265 error_t sshParseTcpIpFwdParams(const uint8_t *p, size_t length,
266  SshTcpIpFwdParams *params);
267 
268 error_t sshParseCancelTcpIpFwdParams(const uint8_t *p, size_t length,
269  SshCancelTcpIpFwdParams *params);
270 
271 error_t sshParseElevationParams(const uint8_t *p, size_t length,
272  SshElevationParams *params);
273 
275  const uint8_t *message, size_t length);
276 
278  const uint8_t *message, size_t length);
279 
281  const uint8_t *message, size_t length);
282 
283 error_t sshParsePtyReqParams(const uint8_t *p, size_t length,
284  SshPtyReqParams *params);
285 
286 error_t sshParseExecParams(const uint8_t *p, size_t length,
287  SshExecParams *params);
288 
289 bool_t sshGetExecArg(const SshExecParams *params, uint_t index, SshString *arg);
290 
291 error_t sshParseSubsystemParams(const uint8_t *p, size_t length,
292  SshSubsystemParams *params);
293 
294 error_t sshParseWindowChangeParams(const uint8_t *p, size_t length,
295  SshWindowChangeParams *params);
296 
297 error_t sshParseSignalParams(const uint8_t *p, size_t length,
298  SshSignalParams *params);
299 
300 error_t sshParseExitStatusParams(const uint8_t *p, size_t length,
301  SshExitStatusParams *params);
302 
303 error_t sshParseBreakParams(const uint8_t *p, size_t length,
304  SshBreakParams *params);
305 
307  const uint8_t *message, size_t length);
308 
310  const uint8_t *message, size_t length);
311 
312 //C++ guard
313 #ifdef __cplusplus
314 }
315 #endif
316 
317 #endif
error_t sshSendChannelRequest(SshChannel *channel, const char_t *requestType, const void *requestParams, bool_t wantReply)
Send SSH_MSG_CHANNEL_REQUEST message.
Definition: ssh_request.c:179
error_t sshFormatSubsystemParams(const SshSubsystemParams *params, uint8_t *p, size_t *written)
Format "subsystem" channel request parameters.
Definition: ssh_request.c:771
error_t sshFormatExecParams(const SshExecParams *params, uint8_t *p, size_t *written)
Format "exec" channel request parameters.
Definition: ssh_request.c:745
"subsystem" channel request parameters
Definition: ssh_request.h:129
error_t sshParseBreakParams(const uint8_t *p, size_t length, SshBreakParams *params)
Parse "break" channel request parameters.
Definition: ssh_request.c:1733
uint32_t portNumToBind
Definition: ssh_request.h:50
int bool_t
Definition: compiler_port.h:53
error_t sshFormatSignalParams(const SshSignalParams *params, uint8_t *p, size_t *written)
Format "signal" channel request parameters.
Definition: ssh_request.c:847
error_t sshParseRequestFailure(SshConnection *connection, const uint8_t *message, size_t length)
Parse SSH_MSG_REQUEST_FAILURE message.
Definition: ssh_request.c:1245
Binary string.
Definition: ssh_types.h:67
"exit-signal" channel request parameters
Definition: ssh_request.h:182
error_t sshSendRequestSuccess(SshConnection *connection)
Send SSH_MSG_REQUEST_SUCCESS message.
Definition: ssh_request.c:108
error_t sshParseElevationParams(const uint8_t *p, size_t length, SshElevationParams *params)
Parse "elevation" global request parameters.
Definition: ssh_request.c:1186
uint8_t p
Definition: ndp.h:300
uint8_t message[]
Definition: chap.h:154
error_t sshParseCancelTcpIpFwdParams(const uint8_t *p, size_t length, SshCancelTcpIpFwdParams *params)
Parse "cancel-tcpip-forward" global request parameters.
Definition: ssh_request.c:1143
error_t sshParseGlobalRequest(SshConnection *connection, const uint8_t *message, size_t length)
Parse SSH_MSG_GLOBAL_REQUEST message.
Definition: ssh_request.c:989
"env" channel request parameters
Definition: ssh_request.h:108
error_t sshParseChannelRequest(SshConnection *connection, const uint8_t *message, size_t length)
Parse SSH_MSG_CHANNEL_REQUEST message.
Definition: ssh_request.c:1280
SshString addrToBind
Definition: ssh_request.h:49
"cancel-tcpip-forward" global request parameters
Definition: ssh_request.h:59
"exec" channel request parameters
Definition: ssh_request.h:119
SshString signalName
Definition: ssh_request.h:183
error_t sshFormatGlobalRequest(SshConnection *connection, const char_t *requestName, const void *requestParams, bool_t wantReply, uint8_t *p, size_t *length)
Format SSH_MSG_GLOBAL_REQUEST message.
Definition: ssh_request.c:324
bool_t sshGetExecArg(const SshExecParams *params, uint_t index, SshString *arg)
Retrieve the specified argument from an "exec" request.
Definition: ssh_request.c:1540
uint32_t termHeightRows
Definition: ssh_request.h:83
error_t sshParseTcpIpFwdParams(const uint8_t *p, size_t length, SshTcpIpFwdParams *params)
Parse "tcpip-forward" global request parameters.
Definition: ssh_request.c:1098
error_t sshSendRequestFailure(SshConnection *connection)
Send SSH_MSG_REQUEST_FAILURE message.
Definition: ssh_request.c:142
error_t sshFormatChannelRequest(SshChannel *channel, const char_t *requestType, const void *requestParams, bool_t wantReply, uint8_t *p, size_t *length)
Format SSH_MSG_CHANNEL_REQUEST message.
Definition: ssh_request.c:563
bool_t elevationPerformed
Definition: ssh_request.h:71
"signal" channel request parameters
Definition: ssh_request.h:162
uint32_t breakLen
Definition: ssh_request.h:196
error_t sshSendGlobalRequest(SshConnection *connection, const char_t *requestName, const void *requestParams, bool_t wantReply)
Send SSH_MSG_GLOBAL_REQUEST message.
Definition: ssh_request.c:55
uint32_t termWidthChars
Definition: ssh_request.h:82
error_t
Error codes.
Definition: error.h:43
error_t sshSendChannelSuccess(SshChannel *channel)
Send SSH_MSG_CHANNEL_SUCCESS message.
Definition: ssh_request.c:236
SshString languageTag
Definition: ssh_request.h:186
error_t sshFormatPtyReqParams(const SshPtyReqParams *params, uint8_t *p, size_t *written)
Format "pty-req" channel request parameters.
Definition: ssh_request.c:670
error_t sshParseExecParams(const uint8_t *p, size_t length, SshExecParams *params)
Parse "exec" channel request parameters.
Definition: ssh_request.c:1512
error_t sshFormatExitStatusParams(const SshExitStatusParams *params, uint8_t *p, size_t *written)
Format "exit-status" channel request parameters.
Definition: ssh_request.c:873
error_t sshFormatChannelFailure(SshChannel *channel, uint8_t *p, size_t *length)
Format SSH_MSG_CHANNEL_FAILURE message.
Definition: ssh_request.c:957
"x11-req" channel request parameters
Definition: ssh_request.h:95
error_t sshFormatTcpIpFwdParams(const SshTcpIpFwdParams *params, uint8_t *p, size_t *written)
Format "tcpip-forward" global request parameters.
Definition: ssh_request.c:400
error_t sshParseWindowChangeParams(const uint8_t *p, size_t length, SshWindowChangeParams *params)
Parse "window-change" channel request parameters.
Definition: ssh_request.c:1618
uint8_t length
Definition: tcp.h:368
SshString termEnvVar
Definition: ssh_request.h:81
String.
Definition: ssh_types.h:56
uint32_t termWidthPixels
Definition: ssh_request.h:84
SshString x11AuthCookie
Definition: ssh_request.h:98
"window-change" channel request parameters
Definition: ssh_request.h:139
SshString errorMessage
Definition: ssh_request.h:185
"exit-status" channel request parameters
Definition: ssh_request.h:172
char char_t
Definition: compiler_port.h:48
error_t sshFormatWindowChangeParams(const SshWindowChangeParams *params, uint8_t *p, size_t *written)
Format "window-change" channel request parameters.
Definition: ssh_request.c:797
error_t sshSendChannelFailure(SshChannel *channel)
Send SSH_MSG_CHANNEL_FAILURE message.
Definition: ssh_request.c:281
error_t sshParseRequestSuccess(SshConnection *connection, const uint8_t *message, size_t length)
Parse SSH_MSG_REQUEST_SUCCESS message.
Definition: ssh_request.c:1210
error_t sshParseChannelFailure(SshConnection *connection, const uint8_t *message, size_t length)
Parse SSH_MSG_CHANNEL_FAILURE message.
Definition: ssh_request.c:1849
SshString varValue
Definition: ssh_request.h:110
SshString x11AuthProtocol
Definition: ssh_request.h:97
"tcpip-forward" global request parameters
Definition: ssh_request.h:48
"xon-xoff" channel request parameters
Definition: ssh_request.h:152
SshString subsystemName
Definition: ssh_request.h:130
#define SshConnection
Definition: ssh.h:874
error_t sshParsePtyReqParams(const uint8_t *p, size_t length, SshPtyReqParams *params)
Parse "pty-req" channel request parameters.
Definition: ssh_request.c:1424
error_t sshParseChannelSuccess(SshConnection *connection, const uint8_t *message, size_t length)
Parse SSH_MSG_CHANNEL_SUCCESS message.
Definition: ssh_request.c:1759
"break" channel request parameters
Definition: ssh_request.h:195
SshString signalName
Definition: ssh_request.h:163
"elevation" global request parameters
Definition: ssh_request.h:70
SshString varName
Definition: ssh_request.h:109
error_t sshParseExitStatusParams(const uint8_t *p, size_t length, SshExitStatusParams *params)
Parse "exit-status" channel request parameters.
Definition: ssh_request.c:1708
SshString command
Definition: ssh_request.h:120
bool_t singleConnection
Definition: ssh_request.h:96
SshBinaryString termModes
Definition: ssh_request.h:86
error_t sshFormatRequestSuccess(SshConnection *connection, uint8_t *p, size_t *length)
Format SSH_MSG_REQUEST_SUCCESS message.
Definition: ssh_request.c:515
error_t sshParseSubsystemParams(const uint8_t *p, size_t length, SshSubsystemParams *params)
Parse "subsystem" channel request parameters.
Definition: ssh_request.c:1590
error_t sshFormatRequestFailure(SshConnection *connection, uint8_t *p, size_t *length)
Format SSH_MSG_REQUEST_FAILURE message.
Definition: ssh_request.c:538
error_t sshParseSignalParams(const uint8_t *p, size_t length, SshSignalParams *params)
Parse "signal" channel request parameters.
Definition: ssh_request.c:1680
uint32_t x11ScreenNum
Definition: ssh_request.h:99
unsigned int uint_t
Definition: compiler_port.h:50
error_t sshFormatElevationParams(const SshElevationParams *params, uint8_t *p, size_t *written)
Format "elevation" global request parameters.
Definition: ssh_request.c:488
"pty-req" channel request parameters
Definition: ssh_request.h:80
Secure Shell (SSH)
error_t sshFormatBreakParams(const SshBreakParams *params, uint8_t *p, size_t *written)
Format "break" channel request parameters.
Definition: ssh_request.c:899
error_t sshFormatCancelTcpIpFwdParams(const SshCancelTcpIpFwdParams *params, uint8_t *p, size_t *written)
Format "cancel-tcpip-forward" global request parameters.
Definition: ssh_request.c:445
uint32_t termHeightPixels
Definition: ssh_request.h:85
#define SshChannel
Definition: ssh.h:878
error_t sshFormatChannelSuccess(SshChannel *channel, uint8_t *p, size_t *length)
Format SSH_MSG_CHANNEL_SUCCESS message.
Definition: ssh_request.c:925