comparison svr-chansession.c @ 972:eb5cb4f45cd6

Add SSH_CLIENT environment variable
author Ryan Cleere <ryan.cleere@rackspace.com>
date Mon, 20 Oct 2014 12:59:47 -0500
parents 0bb16232e7c4
children 7c9377467934
comparison
equal deleted inserted replaced
970:0bb16232e7c4 972:eb5cb4f45cd6
239 dropbear_assert(channel->typedata == NULL); 239 dropbear_assert(channel->typedata == NULL);
240 240
241 chansess = (struct ChanSess*)m_malloc(sizeof(struct ChanSess)); 241 chansess = (struct ChanSess*)m_malloc(sizeof(struct ChanSess));
242 chansess->cmd = NULL; 242 chansess->cmd = NULL;
243 chansess->connection_string = NULL; 243 chansess->connection_string = NULL;
244 chansess->client_string = NULL;
244 chansess->pid = 0; 245 chansess->pid = 0;
245 246
246 /* pty details */ 247 /* pty details */
247 chansess->master = -1; 248 chansess->master = -1;
248 chansess->slave = -1; 249 chansess->slave = -1;
615 m_free(remote_ip); 616 m_free(remote_ip);
616 m_free(remote_port); 617 m_free(remote_port);
617 return ret; 618 return ret;
618 } 619 }
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 }
635
620 /* Handle a command request from the client. This is used for both shell 636 /* Handle a command request from the client. This is used for both shell
621 * and command-execution requests, and passes the command to 637 * and command-execution requests, and passes the command to
622 * noptycommand or ptycommand as appropriate. 638 * noptycommand or ptycommand as appropriate.
623 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 639 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
624 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess, 640 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
676 692
677 /* uClinux will vfork(), so there'll be a race as 693 /* uClinux will vfork(), so there'll be a race as
678 connection_string is freed below. */ 694 connection_string is freed below. */
679 #ifndef USE_VFORK 695 #ifndef USE_VFORK
680 chansess->connection_string = make_connection_string(); 696 chansess->connection_string = make_connection_string();
697 chansess->client_string = make_client_string();
681 #endif 698 #endif
682 699
683 if (chansess->term == NULL) { 700 if (chansess->term == NULL) {
684 /* no pty */ 701 /* no pty */
685 ret = noptycommand(channel, chansess); 702 ret = noptycommand(channel, chansess);
692 ret = ptycommand(channel, chansess); 709 ret = ptycommand(channel, chansess);
693 } 710 }
694 711
695 #ifndef USE_VFORK 712 #ifndef USE_VFORK
696 m_free(chansess->connection_string); 713 m_free(chansess->connection_string);
714 m_free(chansess->client_string);
697 #endif 715 #endif
698 716
699 if (ret == DROPBEAR_FAILURE) { 717 if (ret == DROPBEAR_FAILURE) {
700 m_free(chansess->cmd); 718 m_free(chansess->cmd);
701 } 719 }
947 } 965 }
948 966
949 if (chansess->connection_string) { 967 if (chansess->connection_string) {
950 addnewvar("SSH_CONNECTION", chansess->connection_string); 968 addnewvar("SSH_CONNECTION", chansess->connection_string);
951 } 969 }
970
971 if (chansess->client_string) {
972 addnewvar("SSH_CLIENT", chansess->client_string);
973 }
952 974
953 #ifdef ENABLE_SVR_PUBKEY_OPTIONS 975 #ifdef ENABLE_SVR_PUBKEY_OPTIONS
954 if (chansess->original_command) { 976 if (chansess->original_command) {
955 addnewvar("SSH_ORIGINAL_COMMAND", chansess->original_command); 977 addnewvar("SSH_ORIGINAL_COMMAND", chansess->original_command);
956 } 978 }