dbclient -e option (part 1 of 3: intro)

2016-05-13 Thread Nik Soggia
Hello everybody,
today I was fiddling with c-kermit and zssh to test in-band file transfers.
Both tools insist adding the "-e none" to the command line arguments to tell 
openssh to make the session fully transparent.
dbclient instead prints its version and quits because treats "-e" as a switch 
and "none" becomes the hostname.

I have two solutions:

- a mini-invasive surgery (adds 0 bytes to the binary) to move the "case 'e'" 
in cli-runopts.c in the right spot so that -e can accept arguments still doing 
nothing and printing the warning message as before (see part 2), or
- a full implementation of the -e argument adding 80 bytes of bloat :), in part 
3.

personally I like the bloated solution so "dbclient -e $'\x1d'" can bring back 
the handy '^]' I miss from the old telnet times where escapes were not 
printable.

I hope you will review my second patch and include it upstream.
Best regards,



dbclient -e option (part 2 of 3: trivial patch)

2016-05-13 Thread Nik Soggia
here is the trivial patch. -e is still a no-op but it will accept arguments

--- 2016.73.old/cli-runopts.c   2016-03-18 15:44:43.0 +0100
+++ 2016.73.new/cli-runopts.c   2016-05-13 18:55:00.0 +0100
@@ -297,7 +297,6 @@
break;
  #endif
case 'F':
-   case 'e':
  #ifndef ENABLE_USER_ALGO_LIST
case 'c':
case 'm':
@@ -313,6 +312,7 @@
print_version();
exit(EXIT_SUCCESS);
break;
+   case 'e':
case 'b':
next = &dummy;
/* FALLTHROUGH */


dbclient -e option (part 3 of 3: full implementation)

2016-05-13 Thread Nik Soggia
here is the -e full implementation.
enjoy!

diff -Naur dropbear-2016.73.old/cli-chansession.c 
dropbear-2016.73.new/cli-chansession.c
--- 2016.73.old/cli-chansession.c   2016-03-18 15:44:43.0 +0100
+++ 2016.73.new/cli-chansession.c   2016-05-13 18:55:00.0 +0100
@@ -372,7 +372,9 @@

if (cli_opts.wantpty) {
cli_tty_setup();
-   channel->read_mangler = cli_escape_handler;
+   if (cli_opts.escapechar != '\0') {
+   channel->read_mangler = cli_escape_handler;
+   }
cli_ses.last_char = '\r';
}   

@@ -465,13 +467,13 @@

c = buf[0];

-   if (cli_ses.last_char == DROPBEAR_ESCAPE_CHAR) {
+   if (cli_ses.last_char == cli_opts.escapechar) {
skip_char = do_escape(c);
cli_ses.last_char = 0x0;
} else {
-   if (c == DROPBEAR_ESCAPE_CHAR) {
+   if (c == cli_opts.escapechar) {
if (cli_ses.last_char == '\r') {
-   cli_ses.last_char = DROPBEAR_ESCAPE_CHAR;
+   cli_ses.last_char = cli_opts.escapechar;
skip_char = 1;
} else {
cli_ses.last_char = 0x0;
diff -Naur dropbear-2016.73.old/cli-runopts.c dropbear-2016.73.new/cli-runopts.c
--- 2016.73.old/cli-runopts.c   2016-03-18 15:44:43.0 +0100
+++ 2016.73.new/cli-runopts.c   2016-05-13 18:55:00.0 +0100
@@ -91,6 +91,7 @@
  #ifdef ENABLE_USER_ALGO_LIST
"-c  Specify preferred 
ciphers ('-c help' to list options)\n"
"-m  Specify preferred MACs 
for packet verification (or '-m help')\n"
+   "-e  Sets the escape character 
for sessions with a pty\n"
  #endif
"-VVersion\n"
  #ifdef DEBUG_TRACE
@@ -127,6 +128,7 @@
unsigned int cmdlen;
char* dummy = NULL; /* Not used for anything real */

+   char* escape = NULL;
char* recv_window_arg = NULL;
char* keepalive_arg = NULL;
char* idle_timeout_arg = NULL;
@@ -218,6 +220,9 @@
opt = OPT_AUTHKEY;
break;
  #endif
+   case 'e': /* escape char */
+   next = &escape;
+   break;
case 't': /* we want a pty */
cli_opts.wantpty = 1;
break;
@@ -297,7 +302,6 @@
break;
  #endif
case 'F':
-   case 'e':
  #ifndef ENABLE_USER_ALGO_LIST
case 'c':
case 'm':
@@ -420,6 +424,14 @@
cli_opts.remoteport = "22";
}

+   if (escape == NULL) {
+   cli_opts.escapechar = DROPBEAR_ESCAPE_CHAR;
+   } else if (strcmp ("none", escape) == 0) {
+   cli_opts.escapechar = '\0';
+   } else {
+   cli_opts.escapechar = escape[0] & 0xff;
+   }
+
/* If not explicitly specified with -t or -T, we don't want a pty if
 * there's a command, but we do otherwise */
if (cli_opts.wantpty == 9) {
diff -Naur dropbear-2016.73.old/dbclient.1 dropbear-2016.73.new/dbclient.1
--- 2016.73.old/dbclient.1  2016-03-18 15:44:43.0 +0100
+++ 2016.73.new/dbclient.1  2016-05-13 18:55:00.0 +0100
@@ -147,6 +147,9 @@
  .B \-s
  The specified command will be requested as a subsystem, used for sftp. 
Dropbear doesn't implement sftp itself but the OpenSSH sftp client can be used 
eg \fIsftp -S dbclient user@host\fR
  .TP
+.B \-e \fIcharacter
+Sets the escape character for sessions with a pty (default: '~'). Setting the 
character to an empty string or "none" disables any escapes and makes the 
session fully transparent.
+.TP
  .B \-V
  Print the version

diff -Naur dropbear-2016.73.old/runopts.h dropbear-2016.73.new/runopts.h
--- 2016.73.old/runopts.h   2016-03-18 15:44:43.0 +0100
+++ 2016.73.new/runopts.h   2016-05-13 18:55:00.0 +0100
@@ -131,6 +131,7 @@
char *username;

char *cmd;
+   int escapechar;
int wantpty;
int always_accept_key;
int no_hostkey_check;


Re: dbclient -e option (part 4 of 3: yes, 4!)

2016-05-13 Thread Nik Soggia

Il 13/05/2016 19:15, Nik Soggia wrote:


enjoy!


Mailman chewed up the patches. here they are again.
Regards,

begin-base64 644 dropbear-2016.73.patches.tar.xz
/Td6WFoAAATm1rRGAgAhARwQz1jM4Cf/BgRdADIciiK0MVw05AIwZdZ4
/bXMXoPQaplmL8aQpyYaqjR0h4ffYr13XhCT7WF/QyUgJP023d0MHFNKyQqE
xGcBSeGSzuPuP9EzkKNMsILJ9f3poUccvdZ+sAPEd5SeJ4oIuHcoiTyMK1vx
/nAThR7tagP06+FpgAP3IGvxjjEGHzKOpJnADnD1mewHkXuT3zMRRnEhTLgH
IvFH2WZlX2DNGCYd8+6b1vY8pQY9a4feTf5KLWfOEPQHd2ovzhdQIyoTqr8t
ri4xC0j9AKy/PzV4KWcNMg3z3e91paClO9UGzyNeiYRVZM8Vl5rvYK5FUpu6
FiRraD2oN1GEDrcAJH08MaPAyx+ikgTYZNRRaefiQ4qmlJ5KDNqkUJIRZiHg
zeRRo8TwWFx4Axh+Eggjcj2R6Xks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