Skip to content

Commit 7a4555f

Browse files
committed
Merge pull request mobile-shell#1297 from intelfx/work/agent
2 parents d1174bb + cc4c44e commit 7a4555f

26 files changed

+1332
-27
lines changed

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ clean-local:
5353
cppcheck:
5454
cppcheck $(CPPCHECK_FLAGS) -include src/include/config.h -I src/include \
5555
-I src/crypto -I src/frontend -I src/network -I src/protobufs \
56-
-I src/statesync -I src/terminal -I src/util \
56+
-I src/statesync -I src/terminal -I src/util -I src/agent \
5757
-I /usr/include -I /usr/include/google/protobuf -I/usr/include/openssl \
5858
src
5959

configure.ac

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ AS_IF([test x"$enable_syslog" != xno],
209209
[AC_MSG_WARN([Unable to find syslog.h.])],
210210
[AC_MSG_ERROR([--enable-syslog was given but syslog.h was not found.])])])])
211211

212+
AC_ARG_ENABLE([agent-forwarding],
213+
[AS_HELP_STRING([--disable-agent-forwarding], [Build support for SSH agent forwarding @<:@yes@:>@])],
214+
[enable_agent_forwarding="$enableval"],
215+
[enable_agent_forwarding="yes"])
216+
AS_IF([test x"$enable_agent_forwarding" != xno],
217+
[AC_DEFINE([SUPPORT_AGENT_FORWARDING], [1], [Define to build support for SSH agent forwarding.])])
218+
212219
# Checks for libraries.
213220
AC_ARG_ENABLE([static-libraries],
214221
[AS_HELP_STRING([--enable-static-libraries], [Enable all static linking options below @<:@no@:>@])])
@@ -260,6 +267,7 @@ AC_SEARCH_LIBS([clock_gettime], [rt])
260267

261268
# Checks for header files.
262269
AC_CHECK_HEADERS(m4_normalize([
270+
errno.h
263271
fcntl.h
264272
langinfo.h
265273
limits.h
@@ -287,6 +295,8 @@ AC_CHECK_HEADERS([endian.h sys/endian.h])
287295
AC_CHECK_HEADERS([utmpx.h])
288296
AC_CHECK_HEADERS([termio.h])
289297
AC_CHECK_HEADERS([sys/uio.h])
298+
AC_CHECK_HEADERS([sys/un.h])
299+
AC_CHECK_HEADERS([sys/types.h])
290300
AC_CHECK_HEADERS([memory tr1/memory])
291301

292302
# Checks for typedefs, structures, and compiler characteristics.
@@ -588,6 +598,7 @@ AC_CONFIG_FILES([
588598
src/protobufs/Makefile
589599
src/statesync/Makefile
590600
src/terminal/Makefile
601+
src/agent/Makefile
591602
src/util/Makefile
592603
scripts/Makefile
593604
src/examples/Makefile

man/mosh.1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ OpenSSH command to remotely execute mosh-server on remote machine (default: "ssh
114114

115115
An alternate ssh port can be specified with, \fIe.g.\fP, \-\-ssh="ssh \-p 2222".
116116

117+
.TP
118+
.B \-\-forward-agent
119+
Enable ssh authentication agent forwarding. If you use this, please be
120+
aware of the security implications.
121+
117122
.TP
118123
.B \-\-ssh-pty\fP
119124
.B \-\-no-ssh-pty\fP
@@ -134,6 +139,10 @@ confident. This generally means a previous prediction on the same row
134139
of the terminal has been confirmed by the server, without any
135140
intervening control character keystrokes.
136141

142+
.TP
143+
.B \-A
144+
Synonym for \-\-forward-agent
145+
137146
.TP
138147
.B \-a
139148
Synonym for \-\-predict=always

scripts/mosh.pl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ BEGIN
7979

8080
my $term_init = 1;
8181

82+
my $forward_agent = 0;
83+
8284
my $localhost = undef;
8385

8486
my $ssh_pty = 1;
@@ -118,6 +120,8 @@ BEGIN
118120
(example: "ssh -p 2222")
119121
(default: "ssh")
120122
123+
-A --forward-agent enable ssh agent forwarding
124+
121125
--no-ssh-pty do not allocate a pseudo tty on ssh connection
122126
123127
--no-init do not send terminal initialization string
@@ -152,6 +156,10 @@ sub predict_check {
152156
}
153157
}
154158

159+
# Make GetOptions behave more like traditional UNIX parsers.
160+
# As a side effect, parse short options case-sensitively (which we need for -A).
161+
Getopt::Long::Configure( "bundling" );
162+
155163
GetOptions( 'client=s' => \$client,
156164
'server=s' => \$server,
157165
'predict=s' => \$predict,
@@ -164,6 +172,8 @@ sub predict_check {
164172
'6' => sub { $family = 'inet6' },
165173
'p=s' => \$port_request,
166174
'ssh=s' => sub { @ssh = shellwords($_[1]); },
175+
'A' => \$forward_agent,
176+
'forward-agent!' => \$forward_agent,
167177
'ssh-pty!' => \$ssh_pty,
168178
'init!' => \$term_init,
169179
'local' => \$localhost,
@@ -376,6 +386,10 @@ sub predict_check {
376386
}
377387
my @server = ( 'new' );
378388

389+
if ( $forward_agent ) {
390+
push @server, ( '-A' );
391+
}
392+
379393
push @server, ( '-c', $colors );
380394

381395
push @server, @bind_arguments;
@@ -462,7 +476,14 @@ sub predict_check {
462476
$ENV{ 'MOSH_KEY' } = $key;
463477
$ENV{ 'MOSH_PREDICTION_DISPLAY' } = $predict;
464478
$ENV{ 'MOSH_NO_TERM_INIT' } = '1' if !$term_init;
465-
exec {$client} ("$client", "-# @cmdline |", $ip, $port);
479+
480+
my @client_av = ();
481+
if ( $forward_agent ) {
482+
push @client_av, ( '-A' );
483+
}
484+
push @client_av, ( $ip, $port );
485+
486+
exec {$client} ("$client", "-# @cmdline |", @client_av);
466487
}
467488

468489
sub shell_quote { join ' ', map {(my $a = $_) =~ s/'/'\\''/g; "'$a'"} @_ }

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SUBDIRS = include protobufs util crypto terminal network statesync frontend examples tests fuzz
1+
SUBDIRS = include protobufs util crypto terminal network statesync agent frontend examples tests fuzz

src/agent/Makefile.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
AM_CPPFLAGS = -I$(top_srcdir) $(TINFO_CFLAGS) $(protobuf_CFLAGS)
2+
AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CFLAGS) $(MISC_CXXFLAGS) $(CODE_COVERAGE_CXXFLAGS)
3+
AM_LDFLAGS = $(HARDEN_LDFLAGS) $(CODE_COVERAGE_LIBS)
4+
5+
noinst_LIBRARIES = libmoshagent.a
6+
7+
libmoshagent_a_SOURCES = agent.cc agent.h

0 commit comments

Comments
 (0)