[Patch] Add SSH_CLIENT environment variable

Ryan Cleere rcleere at gmail.com
Tue Oct 21 02:39:21 WST 2014


I had a problem where bash was not overwriting the default PATH variable
which defaults to '/usr/bin:/bin'. This was causing remote management to
fail because it couldn't find the commands in the PATH. I found that for
bash to execute ~/.bashrc the environment variable 'SSH_CLIENT' needs to be
set. Openssh sets the variable to "remoteip remote_port local_port", which
is very similar to 'SSH_CONNECTION'. This patch sets the 'SSH_CLIENT'
environment variable which causes bash to execute .bashrc upon startup.

Thanks,
Ryan

Author: Ryan <rcleere at gmail.com>
Date:   Mon Oct 20 12:59:47 2014 -0500

    Add SSH_CLIENT environment variable

diff --git a/chansession.h b/chansession.h
index 1a01d04..50ba8f0 100644
--- a/chansession.h
+++ b/chansession.h
@@ -54,6 +54,9 @@ struct ChanSess {
        /* Used to set $SSH_CONNECTION in the child session.
        Is only set temporarily before forking */
        char *connection_string;
+
+       /* Used to set $SSH_CLIENT in the child session. */
+       char *client_string;

 #ifndef DISABLE_X11FWD
        struct Listener * x11listener;
diff --git a/svr-chansession.c b/svr-chansession.c
index 6c73778..b3c5c87 100644
--- a/svr-chansession.c
+++ b/svr-chansession.c
@@ -241,6 +241,7 @@ static int newchansess(struct Channel *channel) {
        chansess = (struct ChanSess*)m_malloc(sizeof(struct ChanSess));
        chansess->cmd = NULL;
        chansess->connection_string = NULL;
+       chansess->client_string = NULL;
        chansess->pid = 0;

        /* pty details */
@@ -617,6 +618,21 @@ static char* make_connection_string() {
        return ret;
 }

+static char* make_client_string() {
+       char *local_ip, *local_port, *remote_ip, *remote_port;
+       size_t len;
+       char *ret;
+       get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip,
&remote_port, 0);
+       len = strlen(local_ip) + strlen(local_port) + strlen(remote_ip) +
strlen(remote_port) + 4;
+       ret = m_malloc(len);
+       snprintf(ret, len, "%s %s %s", remote_ip, remote_port, local_port);
+       m_free(local_ip);
+       m_free(local_port);
+       m_free(remote_ip);
+       m_free(remote_port);
+       return ret;
+}
+
 /* Handle a command request from the client. This is used for both shell
  * and command-execution requests, and passes the command to
  * noptycommand or ptycommand as appropriate.
@@ -678,6 +694,7 @@ static int sessioncommand(struct Channel *channel,
struct ChanSess *chansess,
        connection_string is freed below. */
 #ifndef USE_VFORK
        chansess->connection_string = make_connection_string();
+       chansess->client_string = make_client_string();
 #endif

        if (chansess->term == NULL) {
@@ -694,6 +711,7 @@ static int sessioncommand(struct Channel *channel,
struct ChanSess *chansess,

 #ifndef USE_VFORK
        m_free(chansess->connection_string);
+       m_free(chansess->client_string);
 #endif

        if (ret == DROPBEAR_FAILURE) {
@@ -949,6 +967,10 @@ static void execchild(void *user_data) {
        if (chansess->connection_string) {
                addnewvar("SSH_CONNECTION", chansess->connection_string);
        }
+
+       if (chansess->client_string) {
+               addnewvar("SSH_CLIENT", chansess->client_string);
+       }

 #ifdef ENABLE_SVR_PUBKEY_OPTIONS
        if (chansess->original_command) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ucc.gu.uwa.edu.au/pipermail/dropbear/attachments/20141020/e25475d0/attachment.htm 


More information about the Dropbear mailing list