comparison svr-chansession.c @ 974:7c9377467934

Combine code for SSH_CONNECTION and SSH_CLIENT
author Matt Johnston <matt@ucc.asn.au>
date Tue, 21 Oct 2014 22:33:49 +0800
parents eb5cb4f45cd6
children d3925ed45a85
comparison
equal deleted inserted replaced
973:3fbb9a72fb75 974:7c9377467934
601 601
602 TRACE(("leave sessionpty")) 602 TRACE(("leave sessionpty"))
603 return DROPBEAR_SUCCESS; 603 return DROPBEAR_SUCCESS;
604 } 604 }
605 605
606 static char* make_connection_string() { 606 static void make_connection_string(struct ChanSess *chansess) {
607 char *local_ip, *local_port, *remote_ip, *remote_port; 607 char *local_ip, *local_port, *remote_ip, *remote_port;
608 size_t len; 608 size_t len;
609 char *ret;
610 get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip, &remote_port, 0); 609 get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip, &remote_port, 0);
611 len = strlen(local_ip) + strlen(local_port) + strlen(remote_ip) + strlen(remote_port) + 4; 610
612 ret = m_malloc(len); 611 /* "remoteip remoteport localip localport" */
613 snprintf(ret, len, "%s %s %s %s", remote_ip, remote_port, local_ip, local_port); 612 len = strlen(local_ip) + strlen(remote_ip) + 20;
613 chansess->connection_string = m_malloc(len);
614 snprintf(chansess->connection_string, len, "%s %s %s %s", remote_ip, remote_port, local_ip, local_port);
615
616 /* deprecated but bash only loads .bashrc if SSH_CLIENT is set */
617 /* "remoteip remoteport localport" */
618 len = strlen(remote_ip) + 20;
619 chansess->client_string = m_malloc(len);
620 snprintf(chansess->client_string, len, "%s %s %s", remote_ip, remote_port, local_port);
621
614 m_free(local_ip); 622 m_free(local_ip);
615 m_free(local_port); 623 m_free(local_port);
616 m_free(remote_ip); 624 m_free(remote_ip);
617 m_free(remote_port); 625 m_free(remote_port);
618 return ret;
619 }
620
621 static char* make_client_string() {
622 char *local_ip, *local_port, *remote_ip, *remote_port;
623 size_t len;
624 char *ret;
625 get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip, &remote_port, 0);
626 len = strlen(local_ip) + strlen(local_port) + strlen(remote_ip) + strlen(remote_port) + 4;
627 ret = m_malloc(len);
628 snprintf(ret, len, "%s %s %s", remote_ip, remote_port, local_port);
629 m_free(local_ip);
630 m_free(local_port);
631 m_free(remote_ip);
632 m_free(remote_port);
633 return ret;
634 } 626 }
635 627
636 /* Handle a command request from the client. This is used for both shell 628 /* Handle a command request from the client. This is used for both shell
637 * and command-execution requests, and passes the command to 629 * and command-execution requests, and passes the command to
638 * noptycommand or ptycommand as appropriate. 630 * noptycommand or ptycommand as appropriate.
691 #endif 683 #endif
692 684
693 /* uClinux will vfork(), so there'll be a race as 685 /* uClinux will vfork(), so there'll be a race as
694 connection_string is freed below. */ 686 connection_string is freed below. */
695 #ifndef USE_VFORK 687 #ifndef USE_VFORK
696 chansess->connection_string = make_connection_string(); 688 make_connection_string(chansess);
697 chansess->client_string = make_client_string();
698 #endif 689 #endif
699 690
700 if (chansess->term == NULL) { 691 if (chansess->term == NULL) {
701 /* no pty */ 692 /* no pty */
702 ret = noptycommand(channel, chansess); 693 ret = noptycommand(channel, chansess);