comparison svr-chansession.c @ 569:6f472dc54da7

- Set $SSH_CONNECTION - Document environment variables in the manpage
author Matt Johnston <matt@ucc.asn.au>
date Wed, 02 Sep 2009 14:47:12 +0000
parents 005530560594
children 8fd0ac8c8cab
comparison
equal deleted inserted replaced
568:005530560594 569:6f472dc54da7
220 220
221 dropbear_assert(channel->typedata == NULL); 221 dropbear_assert(channel->typedata == NULL);
222 222
223 chansess = (struct ChanSess*)m_malloc(sizeof(struct ChanSess)); 223 chansess = (struct ChanSess*)m_malloc(sizeof(struct ChanSess));
224 chansess->cmd = NULL; 224 chansess->cmd = NULL;
225 chansess->connection_string = NULL;
225 chansess->pid = 0; 226 chansess->pid = 0;
226 227
227 /* pty details */ 228 /* pty details */
228 chansess->master = -1; 229 chansess->master = -1;
229 chansess->slave = -1; 230 chansess->slave = -1;
578 579
579 TRACE(("leave sessionpty")) 580 TRACE(("leave sessionpty"))
580 return DROPBEAR_SUCCESS; 581 return DROPBEAR_SUCCESS;
581 } 582 }
582 583
584 static char* make_connection_string() {
585 char *local_ip, *local_port, *remote_ip, *remote_port;
586 size_t len;
587 char *ret;
588 get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip, &remote_port, 0);
589 len = strlen(local_ip) + strlen(local_port) + strlen(remote_ip) + strlen(remote_port) + 4;
590 ret = m_malloc(len);
591 snprintf(ret, len, "%s %s %s %s", remote_ip, remote_port, local_ip, local_port);
592 m_free(local_ip);
593 m_free(local_port);
594 m_free(remote_ip);
595 m_free(remote_port);
596 return ret;
597 }
598
583 /* Handle a command request from the client. This is used for both shell 599 /* Handle a command request from the client. This is used for both shell
584 * and command-execution requests, and passes the command to 600 * and command-execution requests, and passes the command to
585 * noptycommand or ptycommand as appropriate. 601 * noptycommand or ptycommand as appropriate.
586 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 602 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
587 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess, 603 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
635 dropbear_log(LOG_INFO, "user %s executing login shell", 651 dropbear_log(LOG_INFO, "user %s executing login shell",
636 ses.authstate.pw_name); 652 ses.authstate.pw_name);
637 } 653 }
638 #endif 654 #endif
639 655
640 // XXX set SSH_CONNECTION string here, since about to close socket... 656 /* uClinux will vfork(), so there'll be a race as
657 connection_string is freed below. */
658 #ifndef __uClinux__
659 chansess->connection_string = make_connection_string();
660 #endif
641 661
642 if (chansess->term == NULL) { 662 if (chansess->term == NULL) {
643 /* no pty */ 663 /* no pty */
644 ret = noptycommand(channel, chansess); 664 ret = noptycommand(channel, chansess);
645 } else { 665 } else {
646 /* want pty */ 666 /* want pty */
647 ret = ptycommand(channel, chansess); 667 ret = ptycommand(channel, chansess);
648 } 668 }
669
670 #ifndef __uClinux__
671 m_free(chansess->connection_string);
672 #endif
649 673
650 if (ret == DROPBEAR_FAILURE) { 674 if (ret == DROPBEAR_FAILURE) {
651 m_free(chansess->cmd); 675 m_free(chansess->cmd);
652 } 676 }
653 return ret; 677 return ret;
894 918
895 if (chansess->tty) { 919 if (chansess->tty) {
896 addnewvar("SSH_TTY", chansess->tty); 920 addnewvar("SSH_TTY", chansess->tty);
897 } 921 }
898 922
899 923 if (chansess->connection_string) {
924 addnewvar("SSH_CONNECTION", chansess->connection_string);
925 }
900 926
901 #ifdef ENABLE_SVR_PUBKEY_OPTIONS 927 #ifdef ENABLE_SVR_PUBKEY_OPTIONS
902 if (ses.authstate.pubkey_options && 928 if (ses.authstate.pubkey_options &&
903 ses.authstate.pubkey_options->original_command) { 929 ses.authstate.pubkey_options->original_command) {
904 addnewvar("SSH_ORIGINAL_COMMAND", 930 addnewvar("SSH_ORIGINAL_COMMAND",