Terminal parameters patch

Stephen Hurd <[email protected]> Wed, 25 Jun 2014 00:38:43 -0700
Newsgroups gmane.comp.encryption.cryptlib
Message-ID <[email protected]>
The current SSH client always advertises a terminal type of "xterm" with
dimensions of 80x48.  This patch allows control over that (if set before
the session is activated).

I had problems with the ACL permissions... for some reason, the
commented macros ended up as zero rather than the expected value.  This
will obviously need to be fixed before inclusion.

At some point, (if it's not already there) I would like to add server
support for this as well... with some sort of notification thing so the
server can adjust itself as appropriate for the changed window size. 
Also, adding support for the client to send a notification of window
size change would be useful in most cases (but not mine - yet).

Feedback welcome.

_______________________________________________
Cryptlib mailing list
[email protected] via Mail: [email protected]
Archive: ftp://ftp.franken.de/pub/crypt/cryptlib/archives/
http://news.gmane.org/gmane.comp.encryption.cryptlib
Posts from non-subscribed addresses are blocked to prevent spam, please
subscribe in order to post messages.
terminal-params.patch (text/x-diff, 4.7 KB)
diff -ur ../cl.patched/cryptlib.h ./cryptlib.h
--- ../cl.patched/cryptlib.h	2014-06-20 12:40:45.000000000 -0700
+++ ./cryptlib.h	2014-06-20 12:47:00.000000000 -0700
@@ -1237,6 +1237,11 @@
 	CRYPT_SESSINFO_SSL_OPTIONS,		/* SSL/TLS protocol options */
 	CRYPT_SESSINFO_TSP_MSGIMPRINT,	/* TSP message imprint */
 
+	/* Terminal attributes */
+	CRYPT_SESSINFO_SSH_TERMINAL,	/* TERM string sent to remote */
+	CRYPT_SESSINFO_SSH_WIDTH,	/* Terminal width */
+	CRYPT_SESSINFO_SSH_HEIGHT,	/* Terminal height */
+
 	/* Used internally */
 	CRYPT_SESSINFO_LAST, CRYPT_USERINFO_FIRST = 7000,
 
diff -ur ../cl.patched/kernel/attr_acl.c ./kernel/attr_acl.c
--- ../cl.patched/kernel/attr_acl.c	2014-06-20 12:40:39.000000000 -0700
+++ ./kernel/attr_acl.c	2014-06-20 20:32:54.000000000 -0700
@@ -3742,6 +3742,25 @@
 		MKPERM_TSP( xWD_xWD ),
 		ROUTE( OBJECT_TYPE_SESSION ), &objectCtxHash ),
 
+	MKACL_S(	/* SSH client: Read/write */
+		CRYPT_SESSINFO_SSH_TERMINAL,
+		ST_NONE, ST_NONE, ST_SESS_SSH, 
+		0xffffffff /*MKPERM_SSH_EXT( RWD_RWD )*/,
+		ROUTE( OBJECT_TYPE_SESSION ),
+		RANGE( 1, CRYPT_MAX_TEXTSIZE ) ),
+	MKACL_N(	/* SSH client: Read/write */
+		CRYPT_SESSINFO_SSH_WIDTH,
+		ST_NONE, ST_NONE, ST_SESS_SSH, 
+		0xffffffff /*MKPERM_SSH_EXT( RWD_RWD )*/,
+		ROUTE( OBJECT_TYPE_SESSION ),
+		RANGE( 1, 800 ) ),
+	MKACL_N(	/* SSH client: Read/write */
+		CRYPT_SESSINFO_SSH_HEIGHT,
+		ST_NONE, ST_NONE, ST_SESS_SSH, 
+		0xffffffff /*MKPERM_SSH_EXT( RWD_RWD )*/,
+		ROUTE( OBJECT_TYPE_SESSION ),
+		RANGE( 1, 800 ) ),
+
 	MKACL_END(), MKACL_END()
 	};
 
diff -ur ../cl.patched/session/sess_attr.c ./session/sess_attr.c
--- ../cl.patched/session/sess_attr.c	2014-06-20 12:40:41.000000000 -0700
+++ ./session/sess_attr.c	2014-06-20 20:33:27.000000000 -0700
@@ -323,6 +323,8 @@
 						TRUE : FALSE;
 			return( CRYPT_OK );
 
+		case CRYPT_SESSINFO_SSH_WIDTH:
+		case CRYPT_SESSINFO_SSH_HEIGHT:
 		case CRYPT_SESSINFO_SERVER_PORT:
 		case CRYPT_SESSINFO_CLIENT_PORT:
 			{
@@ -392,6 +394,7 @@
 			return( CRYPT_ERROR_NOTFOUND );
 			}
 
+		case CRYPT_SESSINFO_SSH_TERMINAL:
 		case CRYPT_SESSINFO_USERNAME:
 		case CRYPT_SESSINFO_PASSWORD:
 		case CRYPT_SESSINFO_SERVER_FINGERPRINT:
@@ -532,6 +535,13 @@
 			return( status );
 			}
 
+		case CRYPT_SESSINFO_SSH_WIDTH:
+			return( addSessionInfo( &sessionInfoPtr->attributeList,
+									CRYPT_SESSINFO_SSH_WIDTH, value ) );
+		case CRYPT_SESSINFO_SSH_HEIGHT:
+			return( addSessionInfo( &sessionInfoPtr->attributeList,
+									CRYPT_SESSINFO_SSH_HEIGHT, value ) );
+
 		case CRYPT_SESSINFO_SERVER_PORT:
 			/* If there's already a transport session or network socket 
 			   specified then we can't set a port as well */
@@ -883,6 +893,7 @@
 									  attribute, data, dataLength, flags ) );
 			}
 
+		case CRYPT_SESSINFO_SSH_TERMINAL:
 		case CRYPT_SESSINFO_SERVER_FINGERPRINT:
 			/* Remember the value */
 			return( addSessionInfoS( &sessionInfoPtr->attributeList,
@@ -938,6 +949,9 @@
 			sessionInfoPtr->writeTimeout = CRYPT_ERROR;
 			return( CRYPT_OK );
 
+		case CRYPT_SESSINFO_SSH_TERMINAL:
+		case CRYPT_SESSINFO_SSH_WIDTH:
+		case CRYPT_SESSINFO_SSH_HEIGHT:
 		case CRYPT_SESSINFO_USERNAME:
 		case CRYPT_SESSINFO_PASSWORD:
 		case CRYPT_SESSINFO_SERVER_NAME:
diff -ur ../cl.patched/session/ssh2_msgc.c ./session/ssh2_msgc.c
--- ../cl.patched/session/ssh2_msgc.c	2014-06-20 12:40:41.000000000 -0700
+++ ./session/ssh2_msgc.c	2014-06-20 20:36:36.000000000 -0700
@@ -447,6 +447,12 @@
 												CHANNEL_WRITE );
 	int packetOffset, status;
 
+	MESSAGE_DATA	term;
+	BYTE termString[ CRYPT_MAX_TEXTSIZE + 8 ];
+	int value;
+
+	term.data=termString;
+	term.length=CRYPT_MAX_TEXTSIZE;
 	assert( isWritePtr( sessionInfoPtr, sizeof( SESSION_INFO ) ) );
 	assert( isWritePtr( stream, sizeof( STREAM ) ) );
 
@@ -545,9 +551,18 @@
 	writeUint32( stream, channelNo );
 	writeString32( stream, "pty-req", 7 );
 	sputc( stream, 0 );					/* No reply */
-	writeString32( stream, "xterm", 5 );/* Generic */
-	writeUint32( stream, 80 );
-	writeUint32( stream, 48 );			/* 48 x 80 (24 x 80 is so 1970s) */
+	if( cryptStatusError( status = getSessionAttributeS( sessionInfoPtr, &term, CRYPT_SESSINFO_SSH_TERMINAL) ) )
+		writeString32( stream, "xterm", 5 );/* Generic */
+	else
+		writeString32( stream, term.data, term.length );/* Generic */
+	if( cryptStatusError( getSessionAttribute( sessionInfoPtr, &value, CRYPT_SESSINFO_SSH_WIDTH ) ) )
+		writeUint32( stream, 80 );
+	else
+		writeUint32( stream, value);
+	if( cryptStatusError( getSessionAttribute( sessionInfoPtr, &value, CRYPT_SESSINFO_SSH_HEIGHT ) ) )
+		writeUint32( stream, 48 );		/* 48 x 80 (24 x 80 is so 1970s) */
+	else
+		writeUint32( stream, value);
 	writeUint32( stream, 0 );
 	writeUint32( stream, 0 );			/* No graphics capabilities */
 	status = writeUint32( stream, 0 );	/* No special TTY modes */