comparison cli-runopts.c @ 578:44f486b72427

- tcpfwd bindaddr support against trunk. needs merging.
author Matt Johnston <matt@ucc.asn.au>
date Sat, 27 Feb 2010 11:51:19 +0000
parents f9b5dc0cba61
children 8c737cd7c1af
comparison
equal deleted inserted replaced
576:c470649fb627 578:44f486b72427
626 626
627 cli_opts.own_user = m_strdup(pw->pw_name); 627 cli_opts.own_user = m_strdup(pw->pw_name);
628 } 628 }
629 629
630 #ifdef ENABLE_CLI_ANYTCPFWD 630 #ifdef ENABLE_CLI_ANYTCPFWD
631 /* Turn a "listenport:remoteaddr:remoteport" string into into a forwarding 631 /* Turn a "[listenaddr:]listenport:remoteaddr:remoteport" string into into a forwarding
632 * set, and add it to the forwarding list */ 632 * set, and add it to the forwarding list */
633 static void addforward(const char* origstr, m_list *fwdlist) { 633 static void addforward(const char* origstr, m_list *fwdlist) {
634 634
635 char *part1 = NULL, *part2 = NULL, *part3 = NULL, *part4 = NULL;
636 char * listenaddr = NULL;
635 char * listenport = NULL; 637 char * listenport = NULL;
638 char * connectaddr = NULL;
636 char * connectport = NULL; 639 char * connectport = NULL;
637 char * connectaddr = NULL;
638 struct TCPFwdEntry* newfwd = NULL; 640 struct TCPFwdEntry* newfwd = NULL;
639 char * str = NULL; 641 char * str = NULL;
640 642
641 TRACE(("enter addforward")) 643 TRACE(("enter addforward"))
642 644
643 /* We need to split the original argument up. This var 645 /* We need to split the original argument up. This var
644 is never free()d. */ 646 is never free()d. */
645 str = m_strdup(origstr); 647 str = m_strdup(origstr);
646 648
647 listenport = str; 649 part1 = str;
648 650
649 connectaddr = strchr(str, ':'); 651 part2 = strchr(str, ':');
650 if (connectaddr == NULL) { 652 if (part2 == NULL) {
651 TRACE(("connectaddr == NULL")) 653 TRACE(("part2 == NULL"))
652 goto fail; 654 goto fail;
653 } 655 }
654 *connectaddr = '\0'; 656 *part2 = '\0';
655 connectaddr++; 657 part2++;
656 658
657 connectport = strchr(connectaddr, ':'); 659 part3 = strchr(part2, ':');
658 if (connectport == NULL) { 660 if (part3 == NULL) {
659 TRACE(("connectport == NULL")) 661 TRACE(("part3 == NULL"))
660 goto fail; 662 goto fail;
661 } 663 }
662 *connectport = '\0'; 664 *part3 = '\0';
663 connectport++; 665 part3++;
666
667 part4 = strchr(part3, ':');
668 if (part4) {
669 *part4 = '\0';
670 part4++;
671 }
672
673 if (part4) {
674 listenaddr = part1;
675 listenport = part2;
676 connectaddr = part3;
677 connectport = part4;
678 } else {
679 listenaddr = NULL;
680 listenport = part1;
681 connectaddr = part2;
682 connectport = part3;
683 }
684
685 }
664 686
665 newfwd = m_malloc(sizeof(struct TCPFwdEntry)); 687 newfwd = m_malloc(sizeof(struct TCPFwdEntry));
666 688
667 /* Now we check the ports - note that the port ints are unsigned, 689 /* Now we check the ports - note that the port ints are unsigned,
668 * the check later only checks for >= MAX_PORT */ 690 * the check later only checks for >= MAX_PORT */
674 if (m_str_to_uint(connectport, &newfwd->connectport) == DROPBEAR_FAILURE) { 696 if (m_str_to_uint(connectport, &newfwd->connectport) == DROPBEAR_FAILURE) {
675 TRACE(("bad connectport strtoul")) 697 TRACE(("bad connectport strtoul"))
676 goto fail; 698 goto fail;
677 } 699 }
678 700
701 newfwd->listenaddr = listenaddr;
679 newfwd->connectaddr = connectaddr; 702 newfwd->connectaddr = connectaddr;
680 703
681 if (newfwd->listenport > 65535) { 704 if (newfwd->listenport > 65535) {
682 TRACE(("listenport > 65535")) 705 TRACE(("listenport > 65535"))
683 goto badport; 706 goto badport;