26 typedef enum { OPENREQUEST_NONE,
27 OPENREQUEST_CHANNELONLY, OPENREQUEST_SESSION,
28 OPENREQUEST_LAST } OPENREQUEST_TYPE;
30 #ifdef USE_SSH_EXTENDED
31 typedef enum { SERVICE_NONE, SERVICE_SHELL, SERVICE_PORTFORWARD,
32 SERVICE_SUBSYSTEM, SERVICE_EXEC, SERVICE_LAST } SERVICE_TYPE;
34 typedef enum { SERVICE_NONE, SERVICE_SHELL, SERVICE_LAST } SERVICE_TYPE;
43 #ifdef USE_SSH_EXTENDED
55 assert(
isWritePtr( serviceType,
sizeof( SERVICE_TYPE ) ) );
58 *serviceType = SERVICE_NONE;
62 status = getChannelAttributeS( sessionInfoPtr,
70 "Missing channel type for channel activation" ) );
72 if( !
strCompare( typeString,
"subsystem", 9 ) )
74 *serviceType = SERVICE_SUBSYSTEM;
77 if( !
strCompare( typeString,
"direct-tcpip", 12 ) || \
78 !
strCompare( typeString,
"forwarded-tcpip", 15 ) )
80 *serviceType = SERVICE_PORTFORWARD;
85 *serviceType = SERVICE_EXEC;
91 *serviceType = SERVICE_SHELL;
95 #define getServiceType( sessionInfoPtr, serviceType ) \
97 *( serviceType ) = SERVICE_SHELL
118 readUint32( stream );
119 errorCode = readUint32( stream );
130 "Channel open failed, reason code %d",
135 "Channel open failed, error message '%s'",
136 sanitiseString( stringBuffer, CRYPT_MAX_TEXTSIZE,
186 #ifdef USE_SSH_EXTENDED
191 IN_ENUM( SERVICE )
const SERVICE_TYPE serviceType,
193 OPENREQUEST_TYPE *requestType )
195 const long channelNo = getCurrentChannelNo( sessionInfoPtr,
197 const int maxPacketSize = sessionInfoPtr->sendBufSize - \
200 BYTE arg1String[ CRYPT_MAX_TEXTSIZE + 8 ];
205 assert(
isWritePtr( requestType,
sizeof( OPENREQUEST_TYPE ) ) );
207 REQUIRES( serviceType > SERVICE_NONE && serviceType < SERVICE_LAST );
210 *requestType = OPENREQUEST_NONE;
214 if( serviceType != SERVICE_SHELL )
216 status = getChannelAttributeS( sessionInfoPtr,
218 arg1String, CRYPT_MAX_TEXTSIZE,
224 "Missing channel argument (%s) for channel "
226 ( serviceType == SERVICE_PORTFORWARD ) ? \
228 ( serviceType == SERVICE_EXEC ) ? \
230 "subsystem name" ) );
236 if( serviceType == SERVICE_PORTFORWARD )
238 status = sNetParseURL( &urlInfo, arg1String, arg1Len,
URL_TYPE_SSH );
243 "Invalid channel argument (host name/port) for "
244 "channel activation" ) );
248 *requestType = OPENREQUEST_CHANNELONLY;
254 *requestType = OPENREQUEST_SESSION;
265 if( serviceType == SERVICE_PORTFORWARD_REQUEST )
269 *requestType = OPENREQUEST_STANDALONE;
284 writeString32( stream,
"tcpip-forward", 13 );
286 writeString32( stream, urlInfo.host, urlInfo.
hostLen );
287 writeUint32( stream, urlInfo.
port );
288 return( wrapPacketSSH2( sessionInfoPtr, stream,
packetOffset ) );
317 status = openPacketStreamSSH( stream, sessionInfoPtr,
321 if( serviceType == SERVICE_SUBSYSTEM || serviceType == SERVICE_EXEC )
328 writeString32( stream,
"session", 7 );
332 if( serviceType == SERVICE_PORTFORWARD )
333 writeString32( stream,
"direct-tcpip", 12 );
336 ENSURES( serviceType == SERVICE_SHELL );
340 writeString32( stream,
"session", 7 );
343 writeUint32( stream, channelNo );
344 writeUint32( stream, getWindowSize( sessionInfoPtr ) );
345 status = writeUint32( stream, maxPacketSize );
346 if( serviceType == SERVICE_PORTFORWARD )
356 writeString32( stream, urlInfo.host, urlInfo.
hostLen );
357 writeUint32( stream, urlInfo.
port );
358 writeString32( stream,
"127.0.0.1", 9 );
359 status = writeUint32( stream, 22 );
362 status = wrapPacketSSH2( sessionInfoPtr, stream, 0,
FALSE,
TRUE );
365 sMemDisconnect( stream );
376 IN_ENUM( SERVICE )
const SERVICE_TYPE serviceType,
378 OPENREQUEST_TYPE *requestType )
380 const long channelNo = getCurrentChannelNo( sessionInfoPtr,
382 const int maxPacketSize = sessionInfoPtr->sendBufSize - \
388 assert(
isWritePtr( requestType,
sizeof( OPENREQUEST_TYPE ) ) );
390 REQUIRES( serviceType > SERVICE_NONE && serviceType < SERVICE_LAST );
394 *requestType = OPENREQUEST_SESSION;
421 status = openPacketStreamSSH( stream, sessionInfoPtr,
425 writeString32( stream,
"session", 7 );
426 writeUint32( stream, channelNo );
427 writeUint32( stream, getWindowSize( sessionInfoPtr ) );
428 status = writeUint32( stream, maxPacketSize );
430 status = wrapPacketSSH2( sessionInfoPtr, stream, 0,
FALSE,
TRUE );
433 sMemDisconnect( stream );
444 const SERVICE_TYPE serviceType )
446 const long channelNo = getCurrentChannelNo( sessionInfoPtr,
453 REQUIRES( serviceType > SERVICE_NONE && serviceType < SERVICE_LAST );
455 #ifdef USE_SSH_EXTENDED
460 if( serviceType == SERVICE_SUBSYSTEM )
462 BYTE arg1String[ CRYPT_MAX_TEXTSIZE + 8 ];
466 status = getChannelAttributeS( sessionInfoPtr,
468 arg1String, CRYPT_MAX_TEXTSIZE,
478 status = openPacketStreamSSH( stream, sessionInfoPtr,
482 writeUint32( stream, channelNo );
483 writeString32( stream,
"subsystem", 9 );
485 status = writeString32( stream, arg1String, arg1Len );
487 status = wrapPacketSSH2( sessionInfoPtr, stream, 0,
FALSE,
TRUE );
494 if( serviceType == SERVICE_EXEC )
496 BYTE arg1String[ CRYPT_MAX_TEXTSIZE + 8 ];
500 status = getChannelAttributeS( sessionInfoPtr,
502 arg1String, CRYPT_MAX_TEXTSIZE,
512 status = openPacketStreamSSH( stream, sessionInfoPtr,
516 writeUint32( stream, channelNo );
517 writeString32( stream,
"exec", 4 );
519 status = writeString32( stream, arg1String, arg1Len );
521 status = wrapPacketSSH2( sessionInfoPtr, stream, 0,
FALSE,
TRUE );
526 REQUIRES( serviceType == SERVICE_SHELL );
541 status = openPacketStreamSSH( stream, sessionInfoPtr,
545 writeUint32( stream, channelNo );
546 writeString32( stream,
"pty-req", 7 );
548 writeString32( stream,
"xterm", 5 );
549 writeUint32( stream, 80 );
550 writeUint32( stream, 48 );
551 writeUint32( stream, 0 );
552 writeUint32( stream, 0 );
553 status = writeUint32( stream, 0 );
555 status = wrapPacketSSH2( sessionInfoPtr, stream, 0,
FALSE,
TRUE );
571 writeUint32( stream, channelNo );
572 writeString32( stream,
"shell", 5 );
573 status = sputc( stream, 0 );
575 status = wrapPacketSSH2( sessionInfoPtr, stream, packetOffset,
586 SERVICE_TYPE serviceType;
587 OPENREQUEST_TYPE requestType;
588 const long channelNo = getCurrentChannelNo( sessionInfoPtr,
590 long currentChannelNo;
601 "No current channel information available to activate "
604 status = getChannelAttribute( sessionInfoPtr,
611 "Current channel has already been activated" ) );
615 status = getServiceType( sessionInfoPtr, &serviceType );
620 status = createOpenRequest( sessionInfoPtr, &stream, serviceType,
629 if( requestType == OPENREQUEST_STANDALONE )
631 status = sendPacketSSH2( sessionInfoPtr, &stream,
TRUE );
632 sMemDisconnect( &stream );
645 status = sendPacketSSH2( sessionInfoPtr, &stream,
TRUE );
646 sMemDisconnect( &stream );
664 sMemConnect( &stream, sessionInfoPtr->receiveBuffer, length );
668 status = getOpenFailInfo( sessionInfoPtr, &stream );
669 sMemDisconnect( &stream );
672 currentChannelNo = readUint32( &stream );
673 if( currentChannelNo != channelNo )
675 sMemDisconnect( &stream );
678 "Invalid channel number %lX in channel open confirmation, "
679 "should be %lX", currentChannelNo, channelNo ) );
681 status = currentChannelNo = readUint32( &stream );
682 sMemDisconnect( &stream );
687 "Invalid channel data in channel open confirmation for "
688 "channel %lX", channelNo ) );
695 if(
cryptStatusOK( status ) && currentChannelNo != channelNo )
700 status = setChannelExtAttribute( sessionInfoPtr,
706 const int windowSize = getWindowSize( sessionInfoPtr );
709 status = setChannelExtAttribute( sessionInfoPtr,
713 status = setChannelExtAttribute( sessionInfoPtr,
718 status = selectChannel( sessionInfoPtr, channelNo,
CHANNEL_BOTH );
721 if( requestType == OPENREQUEST_CHANNELONLY )
727 REQUIRES( requestType == OPENREQUEST_SESSION );
731 status = createSessionOpenRequest( sessionInfoPtr, &stream,
734 status = sendPacketSSH2( sessionInfoPtr, &stream,
TRUE );
735 sMemDisconnect( &stream );