View | Details | Raw Unified | Return to bug 1424 | Differences between
and this patch

Collapse All | Expand All

(-)channels.c (+44 lines)
Lines 3237-3239 auth_request_forwarding(void) Link Here
3237
	packet_send();
3237
	packet_send();
3238
	packet_write_wait();
3238
	packet_write_wait();
3239
}
3239
}
3240
3241
/* for conversion of signals to/from ssh channel request names */
3242
3243
static struct {
3244
	int signo;
3245
	char *name;
3246
} no2name[] = {
3247
	{ SIGABRT,	"ABRT" },
3248
	{ SIGALRM,	"ALRM" },
3249
	{ SIGFPE,	"FPE" },
3250
	{ SIGHUP,	"HUP" },
3251
	{ SIGILL,	"ILL" },
3252
	{ SIGINT,	"INT" },
3253
	{ SIGKILL,	"KILL" },
3254
	{ SIGPIPE,	"PIPE" },
3255
	{ SIGQUIT,	"QUIT" },
3256
	{ SIGSEGV,	"SEGV" },
3257
	{ SIGTERM,	"TERM" },
3258
	{ SIGUSR1,	"USR1" },
3259
	{ SIGUSR2,	"USR2" },
3260
	{ -1,		 NULL }
3261
};
3262
3263
int
3264
chan_signame2no(char *name)
3265
{
3266
	int i;
3267
3268
	for (i = 0; no2name[i].signo != -1; i++)
3269
		if (strcmp(no2name[i].name, name) == 0)
3270
			return no2name[i].signo;
3271
	return -1;
3272
}
3273
3274
char *
3275
chan_signo2name(int signo)
3276
{
3277
	int i;
3278
3279
	for (i = 0; no2name[i].signo != -1; i++)
3280
		if (no2name[i].signo == signo)
3281
		return no2name[i].name;
3282
	return NULL;
3283
}
(-)channels.h (+3 lines)
Lines 247-250 void chan_rcvd_ieof(Channel *); Link Here
247
void	 chan_write_failed(Channel *);
247
void	 chan_write_failed(Channel *);
248
void	 chan_obuf_empty(Channel *);
248
void	 chan_obuf_empty(Channel *);
249
249
250
int     chan_signame2no(char *);
251
char   *chan_signo2name(int);
252
250
#endif
253
#endif
(-)clientloop.c (-10 / +43 lines)
Lines 950-955 client_process_control(fd_set *readset) Link Here
950
}
950
}
951
951
952
static void
952
static void
953
ssh_send_signal(char *signame)
954
{
955
	debug("sending signal %s to session %d", signame, session_ident);
956
	channel_request_start(session_ident, "signal", 0);
957
	packet_put_cstring(signame);
958
	packet_send();
959
	packet_write_wait();
960
}
961
962
static void
953
process_cmdline(void)
963
process_cmdline(void)
954
{
964
{
955
	void (*handler)(int);
965
	void (*handler)(int);
Lines 982-987 process_cmdline(void) Link Here
982
		    "Request remote forward");
992
		    "Request remote forward");
983
		logit("      -KR[bind_address:]port                 "
993
		logit("      -KR[bind_address:]port                 "
984
		    "Cancel remote forward");
994
		    "Cancel remote forward");
995
		if (compat20)
996
			logit("      -S[signal] or SIG[signal]              "
997
			    "Send signal");
985
		if (!options.permit_local_command)
998
		if (!options.permit_local_command)
986
			goto out;
999
			goto out;
987
		logit("      !args                                  "
1000
		logit("      !args                                  "
Lines 995-1000 process_cmdline(void) Link Here
995
		goto out;
1008
		goto out;
996
	}
1009
	}
997
1010
1011
	if (*s == 'S' && compat20) {
1012
		/* accept, eg, "SIGHUP" as a command */
1013
		if (strncmp(s, "SIG", 3) == 0)
1014
			s += 3;
1015
		else
1016
			s++;
1017
		ssh_send_signal(s);
1018
		goto out;
1019
	}
1020
998
	if (*s == 'K') {
1021
	if (*s == 'K') {
999
		delete = 1;
1022
		delete = 1;
1000
		s++;
1023
		s++;
Lines 1551-1556 client_loop(int have_pty, int escape_cha Link Here
1551
		if (FD_ISSET(connection_out, writeset))
1574
		if (FD_ISSET(connection_out, writeset))
1552
			packet_write_poll();
1575
			packet_write_poll();
1553
	}
1576
	}
1577
1578
	/*
1579
	 * If there was no shell or command requested, there will be no remote
1580
	 * exit status to be returned.  In that case, clear error code if the
1581
	 * connection was deliberately terminated at this end.
1582
	 */
1583
	if (no_shell_flag && received_signal == SIGTERM) {
1584
		received_signal = 0;
1585
		exit_status = 0;
1586
	}
1587
1588
	if (received_signal && compat20) {
1589
		char *signame = chan_signo2name(received_signal);
1590
		if (signame != NULL) {
1591
			debug("passed signal %s to server", signame);
1592
			ssh_send_signal(signame);
1593
		} else
1594
			debug("non-standard signal %s", signame);
1595
	}
1596
1554
	if (readset)
1597
	if (readset)
1555
		xfree(readset);
1598
		xfree(readset);
1556
	if (writeset)
1599
	if (writeset)
Lines 1573-1588 client_loop(int have_pty, int escape_cha Link Here
1573
		unset_nonblock(fileno(stdout));
1616
		unset_nonblock(fileno(stdout));
1574
	if (!isatty(fileno(stderr)))
1617
	if (!isatty(fileno(stderr)))
1575
		unset_nonblock(fileno(stderr));
1618
		unset_nonblock(fileno(stderr));
1576
1577
	/*
1578
	 * If there was no shell or command requested, there will be no remote
1579
	 * exit status to be returned.  In that case, clear error code if the
1580
	 * connection was deliberately terminated at this end.
1581
	 */
1582
	if (no_shell_flag && received_signal == SIGTERM) {
1583
		received_signal = 0;
1584
		exit_status = 0;
1585
	}
1586
1619
1587
	if (received_signal)
1620
	if (received_signal)
1588
		fatal("Killed by signal %d.", (int) received_signal);
1621
		fatal("Killed by signal %d.", (int) received_signal);
(-)session.c (-1 / +33 lines)
Lines 1989-1994 session_env_req(Session *s) Link Here
1989
}
1989
}
1990
1990
1991
static int
1991
static int
1992
session_signal_req(Session *s)
1993
{
1994
	char *signame;
1995
	int sig, success = 0;
1996
1997
	signame = packet_get_string(NULL);
1998
	sig = chan_signame2no(signame);
1999
	packet_check_eom();
2000
2001
	if (sig >= 0) {
2002
		if (s->pid > 0) {
2003
			debug("session_signal_req: signal %s, killpg(%d, %d)",
2004
			    signame, s->pid, sig);
2005
			temporarily_use_uid(s->pw);
2006
			if (killpg(s->pid, sig) < 0)
2007
				error("session_signal_req: killpg(%d, %d): %s",
2008
				    s->pid, sig, strerror(errno));
2009
			else
2010
				success = 1;
2011
			restore_uid();
2012
		}
2013
	} else
2014
		debug("session_signal_req: unknown signal %s", signame);
2015
2016
	xfree(signame);
2017
	return success;
2018
}
2019
2020
2021
static int
1992
session_auth_agent_req(Session *s)
2022
session_auth_agent_req(Session *s)
1993
{
2023
{
1994
	static int called = 0;
2024
	static int called = 0;
Lines 2043-2049 session_input_channel_req(Channel *c, co Link Here
2043
		success = session_window_change_req(s);
2073
		success = session_window_change_req(s);
2044
	} else if (strcmp(rtype, "break") == 0) {
2074
	} else if (strcmp(rtype, "break") == 0) {
2045
		success = session_break_req(s);
2075
		success = session_break_req(s);
2046
	}
2076
	} else if (strcmp(rtype, "signal") == 0) {
2077
		success = session_signal_req(s);
2078
 	}
2047
2079
2048
	return success;
2080
	return success;
2049
}
2081
}
(-)session.h (+2 lines)
Lines 78-81 void do_setusercontext(struct passwd *) Link Here
78
void	 child_set_env(char ***envp, u_int *envsizep, const char *name,
78
void	 child_set_env(char ***envp, u_int *envsizep, const char *name,
79
		       const char *value);
79
		       const char *value);
80
80
81
int     chan_signame2no(char *);
82
char   *chan_signo2name(int);
81
#endif
83
#endif

Return to bug 1424