@@ -505,5 +505,141 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
505
505
/* Set the new modes for the terminal. */
506
506
if (tcsetattr (fd , TCSANOW , & tio ) == -1 )
507
507
logit ("Setting tty modes failed: %.100s" , strerror (errno ));
508
+ #else
509
+ //struct termios tio;
510
+ u_int tio [255 ]; // win32 dummy
511
+ u_int tioFIELD ;
512
+ int opcode , baud ;
513
+ int n_bytes = 0 ;
514
+ int failure = 0 ;
515
+ u_int (* get_arg )(void );
516
+ int arg_size ;
517
+
518
+ if (compat20 ) {
519
+ * n_bytes_ptr = packet_get_int ();
520
+ if (* n_bytes_ptr == 0 )
521
+ return ;
522
+ get_arg = packet_get_int ;
523
+ arg_size = 4 ;
524
+ } else {
525
+ get_arg = packet_get_char ;
526
+ arg_size = 1 ;
527
+ }
528
+
529
+ /*
530
+ * Get old attributes for the terminal. We will modify these
531
+ * flags. I am hoping that if there are any machine-specific
532
+ * modes, they will initially have reasonable values.
533
+ */
534
+ //if (tcgetattr(fd, &tio) == -1) {
535
+ //logit("tcgetattr: %.100s", strerror(errno));
536
+ //failure = -1;
537
+ //}
538
+
539
+ for (;;) {
540
+ n_bytes += 1 ;
541
+ opcode = packet_get_char ();
542
+ switch (opcode ) {
543
+ case TTY_OP_END :
544
+ goto set ;
545
+
546
+ /* XXX: future conflict possible */
547
+ case TTY_OP_ISPEED_PROTO1 :
548
+ case TTY_OP_ISPEED_PROTO2 :
549
+ n_bytes += 4 ;
550
+ baud = packet_get_int ();
551
+ break ;
552
+
553
+ /* XXX: future conflict possible */
554
+ case TTY_OP_OSPEED_PROTO1 :
555
+ case TTY_OP_OSPEED_PROTO2 :
556
+ n_bytes += 4 ;
557
+ baud = packet_get_int ();
558
+ break ;
559
+
560
+ #define TTYCHAR (NAME , OP ) \
561
+ case OP: \
562
+ n_bytes += arg_size; \
563
+ tio[NAME] = special_char_decode(get_arg()); \
564
+ break;
565
+ #define TTYMODE (NAME , FIELD , OP ) \
566
+ case OP: \
567
+ n_bytes += arg_size; \
568
+ if (get_arg()) \
569
+ tioFIELD |= NAME; \
570
+ else \
571
+ tioFIELD &= ~NAME; \
572
+ break;
573
+
574
+ //#include "ttymodes.h"
575
+
576
+ #undef TTYCHAR
577
+ #undef TTYMODE
578
+
579
+ default :
580
+ debug ("Ignoring unsupported tty mode opcode %d (0x%x)" ,
581
+ opcode , opcode );
582
+ if (!compat20 ) {
583
+ /*
584
+ * SSH1:
585
+ * Opcodes 1 to 127 are defined to have
586
+ * a one-byte argument.
587
+ * Opcodes 128 to 159 are defined to have
588
+ * an integer argument.
589
+ */
590
+ if (opcode > 0 && opcode < 128 ) {
591
+ n_bytes += 1 ;
592
+ (void ) packet_get_char ();
593
+ break ;
594
+ } else if (opcode >= 128 && opcode < 160 ) {
595
+ n_bytes += 4 ;
596
+ (void ) packet_get_int ();
597
+ break ;
598
+ } else {
599
+ /*
600
+ * It is a truly undefined opcode (160 to 255).
601
+ * We have no idea about its arguments. So we
602
+ * must stop parsing. Note that some data
603
+ * may be left in the packet; hopefully there
604
+ * is nothing more coming after the mode data.
605
+ */
606
+ logit ("parse_tty_modes: unknown opcode %d" ,
607
+ opcode );
608
+ goto set ;
609
+ }
610
+ } else {
611
+ /*
612
+ * SSH2:
613
+ * Opcodes 1 to 159 are defined to have
614
+ * a uint32 argument.
615
+ * Opcodes 160 to 255 are undefined and
616
+ * cause parsing to stop.
617
+ */
618
+ if (opcode > 0 && opcode < 160 ) {
619
+ n_bytes += 4 ;
620
+ (void ) packet_get_int ();
621
+ break ;
622
+ } else {
623
+ logit ("parse_tty_modes: unknown opcode %d" ,
624
+ opcode );
625
+ goto set ;
626
+ }
627
+ }
628
+ }
629
+ }
630
+
631
+ set :
632
+ if (* n_bytes_ptr != n_bytes ) {
633
+ * n_bytes_ptr = n_bytes ;
634
+ logit ("parse_tty_modes: n_bytes_ptr != n_bytes: %d %d" ,
635
+ * n_bytes_ptr , n_bytes );
636
+ return ; /* Don't process bytes passed */
637
+ }
638
+ if (failure == -1 )
639
+ return ; /* Packet parsed ok but tcgetattr() failed */
640
+
641
+ /* Set the new modes for the terminal. */
642
+ //if (tcsetattr(fd, TCSANOW, &tio) == -1)
643
+ //logit("Setting tty modes failed: %.100s", strerror(errno));
508
644
#endif
509
645
}
0 commit comments