diff svr-chansession.c @ 1342:8747c2b19152

merge 2017.75
author Matt Johnston <matt@ucc.asn.au>
date Thu, 18 May 2017 22:59:38 +0800
parents 79225928bf59
children 06d52bcb8094
line wrap: on
line diff
--- a/svr-chansession.c	Thu May 18 22:58:18 2017 +0800
+++ b/svr-chansession.c	Thu May 18 22:59:38 2017 +0800
@@ -254,13 +254,13 @@
 
 	channel->typedata = chansess;
 
-#ifndef DISABLE_X11FWD
+#if DROPBEAR_X11FWD
 	chansess->x11listener = NULL;
 	chansess->x11authprot = NULL;
 	chansess->x11authcookie = NULL;
 #endif
 
-#ifdef ENABLE_SVR_AGENTFWD
+#if DROPBEAR_SVR_AGENTFWD
 	chansess->agentlistener = NULL;
 	chansess->agentfile = NULL;
 	chansess->agentdir = NULL;
@@ -301,7 +301,7 @@
 	m_free(chansess->cmd);
 	m_free(chansess->term);
 
-#ifdef ENABLE_SVR_PUBKEY_OPTIONS
+#if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
 	m_free(chansess->original_command);
 #endif
 
@@ -315,11 +315,11 @@
 		m_free(chansess->tty);
 	}
 
-#ifndef DISABLE_X11FWD
+#if DROPBEAR_X11FWD
 	x11cleanup(chansess);
 #endif
 
-#ifdef ENABLE_SVR_AGENTFWD
+#if DROPBEAR_SVR_AGENTFWD
 	svr_agentcleanup(chansess);
 #endif
 
@@ -373,11 +373,11 @@
 		ret = sessioncommand(channel, chansess, 1, 0);
 	} else if (strcmp(type, "subsystem") == 0) {
 		ret = sessioncommand(channel, chansess, 1, 1);
-#ifndef DISABLE_X11FWD
+#if DROPBEAR_X11FWD
 	} else if (strcmp(type, "x11-req") == 0) {
 		ret = x11req(chansess);
 #endif
-#ifdef ENABLE_SVR_AGENTFWD
+#if DROPBEAR_SVR_AGENTFWD
 	} else if (strcmp(type, "[email protected]") == 0) {
 		ret = svr_agentreq(chansess);
 #endif
@@ -603,7 +603,7 @@
 	return DROPBEAR_SUCCESS;
 }
 
-#ifndef USE_VFORK
+#if !DROPBEAR_VFORK
 static void make_connection_string(struct ChanSess *chansess) {
 	char *local_ip, *local_port, *remote_ip, *remote_port;
 	size_t len;
@@ -634,7 +634,7 @@
 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
 		int iscmd, int issubsys) {
 
-	unsigned int cmdlen;
+	unsigned int cmdlen = 0;
 	int ret;
 
 	TRACE(("enter sessioncommand"))
@@ -671,8 +671,16 @@
 		}
 	}
 	
-	/* take public key option 'command' into account */
-	svr_pubkey_set_forced_command(chansess);
+
+	/* take global command into account */
+	if (svr_opts.forced_command) {
+		chansess->original_command = chansess->cmd ? : m_strdup("");
+		chansess->cmd = m_strdup(svr_opts.forced_command);
+	} else {
+		/* take public key option 'command' into account */
+		svr_pubkey_set_forced_command(chansess);
+	}
+
 
 #ifdef LOG_COMMANDS
 	if (chansess->cmd) {
@@ -686,7 +694,7 @@
 
 	/* uClinux will vfork(), so there'll be a race as 
 	connection_string is freed below. */
-#ifndef USE_VFORK
+#if !DROPBEAR_VFORK
 	make_connection_string(chansess);
 #endif
 
@@ -702,7 +710,7 @@
 		ret = ptycommand(channel, chansess);
 	}
 
-#ifndef USE_VFORK
+#if !DROPBEAR_VFORK
 	m_free(chansess->connection_string);
 	m_free(chansess->client_string);
 #endif
@@ -776,7 +784,7 @@
 		return DROPBEAR_FAILURE;
 	}
 	
-#ifdef USE_VFORK
+#if DROPBEAR_VFORK
 	pid = vfork();
 #else
 	pid = fork();
@@ -896,7 +904,7 @@
 
 	/* with uClinux we'll have vfork()ed, so don't want to overwrite the
 	 * hostkey. can't think of a workaround to clear it */
-#ifndef USE_VFORK
+#if !DROPBEAR_VFORK
 	/* wipe the hostkey */
 	sign_key_free(svr_opts.hostkey);
 	svr_opts.hostkey = NULL;
@@ -965,7 +973,7 @@
 		addnewvar("SSH_CLIENT", chansess->client_string);
 	}
 	
-#ifdef ENABLE_SVR_PUBKEY_OPTIONS
+#if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
 	if (chansess->original_command) {
 		addnewvar("SSH_ORIGINAL_COMMAND", chansess->original_command);
 	}
@@ -976,11 +984,11 @@
 		dropbear_exit("Error changing directory");
 	}
 
-#ifndef DISABLE_X11FWD
+#if DROPBEAR_X11FWD
 	/* set up X11 forwarding if enabled */
 	x11setauth(chansess);
 #endif
-#ifdef ENABLE_SVR_AGENTFWD
+#if DROPBEAR_SVR_AGENTFWD
 	/* set up agent env variable */
 	svr_agentset(chansess);
 #endif