~ubuntu-branches/debian/stretch/dropbear/stretch

« back to all changes in this revision

Viewing changes to cli-chansession.c

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape, Matt Johnston, Gerrit Pape
  • Date: 2013-10-25 15:00:48 UTC
  • mfrom: (1.4.6)
  • Revision ID: package-import@ubuntu.com-20131025150048-3jq765x96xayk392
Tags: 2013.60-1
[ Matt Johnston ]
* New upstream release.

[ Gerrit Pape ]
* debian/diff/0004-cve-2013-4421.diff, 0005-user-disclosure.diff:
  remove; fixed upstream.
* debian/dropbear.postinst: don't fail if initramfs-tools it not
  installed (closes: #692653).

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
static void cli_closechansess(struct Channel *channel);
39
39
static int cli_initchansess(struct Channel *channel);
40
40
static void cli_chansessreq(struct Channel *channel);
41
 
 
42
41
static void send_chansess_pty_req(struct Channel *channel);
43
42
static void send_chansess_shell_req(struct Channel *channel);
 
43
static void cli_escape_handler(struct Channel *channel, unsigned char* buf, int *len);
 
44
 
44
45
 
45
46
static void cli_tty_setup();
46
47
 
70
71
                TRACE(("got exit-signal, ignoring it"))
71
72
        } else {
72
73
                TRACE(("unknown request '%s'", type))
73
 
                send_msg_channel_failure(channel);
 
74
                if (wantreply) {
 
75
                        send_msg_channel_failure(channel);
 
76
                }
74
77
                goto out;
75
78
        }
76
79
                
81
84
 
82
85
/* If the main session goes, we close it up */
83
86
static void cli_closechansess(struct Channel *UNUSED(channel)) {
 
87
        cli_tty_cleanup(); /* Restore tty modes etc */
84
88
 
85
89
        /* This channel hasn't gone yet, so we have > 1 */
86
90
        if (ses.chancount > 1) {
87
91
                dropbear_log(LOG_INFO, "Waiting for other channels to close...");
88
92
        }
89
 
 
90
 
        cli_tty_cleanup(); /* Restore tty modes etc */
91
 
 
92
93
}
93
94
 
94
95
void cli_start_send_channel_request(struct Channel *channel, 
374
375
 
375
376
        if (cli_opts.wantpty) {
376
377
                cli_tty_setup();
377
 
        }
 
378
                channel->read_mangler = cli_escape_handler;
 
379
                cli_ses.last_char = '\r';
 
380
        }       
378
381
 
379
382
        return 0; /* Success */
380
383
}
429
432
        TRACE(("leave cli_send_chansess_request"))
430
433
 
431
434
}
 
435
 
 
436
// returns 1 if the character should be consumed, 0 to pass through
 
437
static int
 
438
do_escape(unsigned char c) {
 
439
        switch (c) {
 
440
                case '.':
 
441
                        dropbear_exit("Terminated");
 
442
                        return 1;
 
443
                        break;
 
444
                case 0x1a:
 
445
                        // ctrl-z
 
446
                        cli_tty_cleanup();
 
447
                        kill(getpid(), SIGTSTP);
 
448
                        // after continuation
 
449
                        cli_tty_setup();
 
450
                        cli_ses.winchange = 1;
 
451
                        return 1;
 
452
                        break;
 
453
        }
 
454
        return 0;
 
455
}
 
456
 
 
457
static
 
458
void cli_escape_handler(struct Channel *channel, unsigned char* buf, int *len) {
 
459
        char c;
 
460
        int skip_char = 0;
 
461
 
 
462
        // only handle escape characters if they are read one at a time. simplifies
 
463
        // the code and avoids nasty people putting ~. at the start of a line to paste 
 
464
        if (*len != 1) {
 
465
                cli_ses.last_char = 0x0;
 
466
                return;
 
467
        }
 
468
 
 
469
        c = buf[0];
 
470
 
 
471
        if (cli_ses.last_char == DROPBEAR_ESCAPE_CHAR) {
 
472
                skip_char = do_escape(c);
 
473
                cli_ses.last_char = 0x0;
 
474
        } else {
 
475
                if (c == DROPBEAR_ESCAPE_CHAR) {
 
476
                        if (cli_ses.last_char == '\r') {
 
477
                                cli_ses.last_char = DROPBEAR_ESCAPE_CHAR;
 
478
                                skip_char = 1;
 
479
                        } else {
 
480
                                cli_ses.last_char = 0x0;
 
481
                        }
 
482
                } else {
 
483
                        cli_ses.last_char = c;
 
484
                }
 
485
        }
 
486
 
 
487
        if (skip_char) {
 
488
                *len = 0;
 
489
        }
 
490
}