Skip to content

Commit

Permalink
Merge branch 'master' into agent-forwarding-merge-20151128
Browse files Browse the repository at this point in the history
  • Loading branch information
rinne committed Mar 4, 2018
2 parents 953a7f5 + 10dca75 commit 34b5f40
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 88 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ language: cpp
sudo: required
dist: trusty

# Currently we're using the Travis Xcode 6.4/OS X 10.10 image to
# get i386/x86_64 fat binaries.
osx_image: xcode6.4
# Use macOS 10.12 + Xcode 9.1 + DEPLOYMENT_TARGET=10.12
osx_image: xcode9.1

# Linux dependencies
addons:
Expand Down Expand Up @@ -71,7 +70,7 @@ script:
- |
if test osx = "${TRAVIS_OS_NAME}" && test -n "${TRAVIS_TAG}"; then
cd macosx &&
env ZERO_AR_DATE=1 MACOSX_DEPLOYMENT_TARGET=10.10 ./build.sh &&
env ZERO_AR_DATE=1 MACOSX_DEPLOYMENT_TARGET=10.12 ./build.sh &&
shasum -a 256 "${TRAVIS_TAG}.pkg" "${TRAVIS_TAG}-osx-build-report.tbz" &&
cd -
fi
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4
SUBDIRS = scripts src man conf
EXTRA_DIST = autogen.sh ocb-license.html README.md COPYING.iOS
BUILT_SOURCES = version.h
AM_DISTCHECK_CONFIGURE_FLAGS = --enable-compile-warnings=distcheck --enable-examples
AM_DISTCHECK_CONFIGURE_FLAGS = --enable-compile-warnings=distcheck --enable-examples --enable-syslog

# non-Automake defines
CPPCHECK_FLAGS = --enable=all --template=gcc --force # -j8 disables unused function checking.
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ init:
# Install needed build dependencies
#
install:
- '%CYG_ROOT%\setup-x86_64.exe --quiet-mode --no-shortcuts --upgrade-also --packages autoconf,autogen,automake,cygwin-devel,git,gcc-core,gcc-g++,libncurses-devel,libprotobuf-devel,make,openssh,openssl-devel,perl,pkg-config,tmux,zlib-devel'
- '%CYG_ROOT%\setup-x86_64.exe --quiet-mode --no-shortcuts --upgrade-also --packages autoconf,autogen,automake,cygwin-devel,git,gcc-core,gcc-g++,libncurses-devel,libprotobuf-devel,make,openssh,openssl-devel,perl,perl_pods,pkg-config,tmux,zlib-devel'
- '%CYG_ROOT%\bin\cygcheck -dc cygwin'

#
Expand Down
11 changes: 11 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ AC_ARG_ENABLE(agent-forwarding,
[disable ssh agent forwarding in compile time]),
, enable_agent_forwarding=yes)

# Syslog
AC_ARG_ENABLE([syslog],
[AS_HELP_STRING([--enable-syslog], [Enable connection logging in mosh-server @<:@no@:>@])],
[enable_syslog="$enableval"],
[enable_syslog="no"])
AS_IF([test x"$enable_syslog" != xno],
[AC_CHECK_HEADERS([syslog.h],
[AC_DEFINE([HAVE_SYSLOG], [1], [Define if syslog is available.])],
[AS_IF([test x"$enable_syslog" = xcheck],
[AC_MSG_WARN([Unable to find syslog.h.])],
[AC_MSG_ERROR([--enable-syslog was given but syslog.h was not found.])])])])

AC_SEARCH_LIBS([compress], [z], , [AC_MSG_ERROR([Unable to find zlib.])])

Expand Down
2 changes: 1 addition & 1 deletion scripts/mosh.pl
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ sub predict_check {
delete $ENV{ 'SSH_CONNECTION' };
chdir; # $HOME
print "MOSH IP ${userhost}\n";
exec( $server, @server );
exec( "$server " . shell_quote( @server ) );
die "Cannot exec $server: $!\n";
}
if ( $use_remote_ip eq 'proxy' ) {
Expand Down
52 changes: 47 additions & 5 deletions src/frontend/mosh-server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
#ifdef HAVE_UTEMPTER
#include <utempter.h>
#endif
#ifdef HAVE_SYSLOG
#include <syslog.h>
#endif
#include <sys/socket.h>
#include <netdb.h>
#include <time.h>
Expand Down Expand Up @@ -285,6 +288,10 @@ int main( int argc, char *argv[] )

bool with_motd = false;

#ifdef HAVE_SYSLOG
openlog(argv[0], LOG_PID | LOG_NDELAY, LOG_AUTH);
#endif

/* Get shell */
char *my_argv[ 2 ];
string shell_name;
Expand Down Expand Up @@ -537,6 +544,10 @@ static int run_server( const char *desired_ip, const char *desired_port,
fatal_assert( 0 == sigaction( SIGHUP, &sa, NULL ) );
fatal_assert( 0 == sigaction( SIGPIPE, &sa, NULL ) );

#ifdef HAVE_SYSLOG
closelog();
#endif

/* close server-related file descriptors */
network.reset();

Expand Down Expand Up @@ -675,13 +686,23 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &

#ifdef HAVE_UTEMPTER
bool connected_utmp = false;

#endif
#if defined(HAVE_SYSLOG) || defined(HAVE_UTEMPTER)
bool force_connection_change_evt = false;
Addr saved_addr;
socklen_t saved_addr_len = 0;
#endif

agent.attach_oob(network.oob());

#ifdef HAVE_SYSLOG
struct passwd *pw = getpwuid( getuid() );
if (pw == NULL) {
throw NetworkException( std::string( "serve: getpwuid: " ) + strerror( errno ), 0 );
}
syslog(LOG_INFO, "user %s session begin", pw->pw_name);
#endif

bool child_released = false;

while ( true ) {
Expand Down Expand Up @@ -783,14 +804,25 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
if ( !network.shutdown_in_progress() ) {
network.set_current_state( terminal );
}

#if defined(HAVE_SYSLOG) || defined(HAVE_UTEMPTER)
#ifdef HAVE_UTEMPTER
/* update utmp entry if we have become "connected" */
if ( (!connected_utmp)
if (!connected_utmp) {
force_connection_change_evt = true;
} else {
force_connection_change_evt = false;
}
#else
force_connection_change_evt = false;
#endif

/**
* - HAVE_UTEMPTER - update utmp entry if we have become "connected"
* - HAVE_SYSLOG - log connection information to syslog
**/
if ( (force_connection_change_evt)
|| saved_addr_len != network.get_remote_addr_len()
|| memcmp( &saved_addr, &network.get_remote_addr(),
saved_addr_len ) != 0 ) {
utempter_remove_record( host_fd );

saved_addr = network.get_remote_addr();
saved_addr_len = network.get_remote_addr_len();
Expand All @@ -803,11 +835,18 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
throw NetworkException( std::string( "serve: getnameinfo: " ) + gai_strerror( errcode ), 0 );
}

#ifdef HAVE_UTEMPTER
utempter_remove_record( host_fd );
char tmp[ 64 ];
snprintf( tmp, 64, "%s via mosh [%d]", host, getpid() );
utempter_add_record( host_fd, tmp );

connected_utmp = true;
#endif

#ifdef HAVE_SYSLOG
syslog(LOG_INFO, "user %s connected from host: %s", pw->pw_name, host);
#endif
}
#endif

Expand Down Expand Up @@ -936,6 +975,9 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
}
}
}
#ifdef HAVE_SYSLOG
syslog(LOG_INFO, "user %s session end", pw->pw_name);
#endif
}

/* Print the motd from a given file, if available */
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/terminaloverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ void NotificationEngine::apply( Framebuffer &fb ) const

/* draw bar across top of screen */
Cell notification_bar( 0 );
notification_bar.get_renditions().foreground_color = 37;
notification_bar.get_renditions().background_color = 44;
notification_bar.get_renditions().set_foreground_color( 7 );
notification_bar.get_renditions().set_background_color( 4 );
notification_bar.append( 0x20 );

for ( int i = 0; i < fb.ds.get_width(); i++ ) {
Expand Down Expand Up @@ -273,8 +273,8 @@ void NotificationEngine::apply( Framebuffer &fb ) const
this_cell = fb.get_mutable_cell( 0, overlay_col );
fb.reset_cell( this_cell );
this_cell->get_renditions().set_attribute(Renditions::bold, true);
this_cell->get_renditions().foreground_color = 37;
this_cell->get_renditions().background_color = 44;
this_cell->get_renditions().set_foreground_color( 7 );
this_cell->get_renditions().set_background_color( 4 );

this_cell->append( ch );
this_cell->set_wide( chwidth == 2 );
Expand Down
50 changes: 27 additions & 23 deletions src/terminal/terminalframebuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,19 +505,24 @@ void Renditions::set_foreground_color( int num )
{
if ( (0 <= num) && (num <= 255) ) {
foreground_color = 30 + num;
} else if ( is_true_color( num ) ) {
foreground_color = num;
}
}

void Renditions::set_background_color( int num )
{
if ( (0 <= num) && (num <= 255) ) {
background_color = 40 + num;
} else if ( is_true_color( num ) ) {
background_color = num;
}
}

std::string Renditions::sgr( void ) const
{
std::string ret;
char col[64];

ret.append( "\033[0" );
if ( get_attribute( bold ) ) ret.append( ";1" );
Expand All @@ -527,35 +532,34 @@ std::string Renditions::sgr( void ) const
if ( get_attribute( inverse ) ) ret.append( ";7" );
if ( get_attribute( invisible ) ) ret.append( ";8" );

if ( foreground_color
&& (foreground_color <= 37) ) {
/* ANSI foreground color */
char col[ 8 ];
snprintf( col, 8, ";%d", foreground_color );
if ( foreground_color ) {
if ( is_true_color( foreground_color ) ) {
snprintf( col, sizeof( col ), ";38;2;%u;%u;%u",
(foreground_color >> 16) & 0xff,
(foreground_color >> 8) & 0xff,
foreground_color & 0xff);
} else if ( foreground_color > 37 ) { /* use 256-color set */
snprintf( col, sizeof( col ), ";38;5;%u", foreground_color - 30 );
} else { /* ANSI foreground color */
snprintf( col, sizeof( col ), ";%u", static_cast<unsigned int>( foreground_color ) );
}
ret.append( col );
}

if ( background_color
&& (background_color <= 47) ) {
char col[ 8 ];
snprintf( col, 8, ";%d", background_color );
if ( background_color ) {
if ( is_true_color( background_color ) ) {
snprintf( col, sizeof( col ), ";48;2;%u;%u;%u",
(background_color >> 16) & 0xff,
(background_color >> 8) & 0xff,
background_color & 0xff);
} else if ( background_color > 47 ) { /* use 256-color set */
snprintf( col, sizeof( col ), ";48;5;%u", background_color - 40 );
} else { /* ANSI background color */
snprintf( col, sizeof( col ), ";%u", static_cast<unsigned int>( background_color ) );
}
ret.append( col );
}

ret.append( "m" );

if ( foreground_color > 37 ) { /* use 256-color set */
char col[ 64 ];
snprintf( col, 64, "\033[38;5;%dm", foreground_color - 30 );
ret.append( col );
}

if ( background_color > 47 ) { /* use 256-color set */
char col[ 64 ];
snprintf( col, 64, "\033[48;5;%dm", background_color - 40 );
ret.append( col );
}

return ret;
}

Expand Down
23 changes: 17 additions & 6 deletions src/terminal/terminalframebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@
namespace Terminal {
using shared::shared_ptr;
using shared::make_shared;
typedef uint16_t color_type;
typedef uint32_t color_type;

class Renditions {
public:
typedef enum { bold, faint, italic, underlined, blink, inverse, invisible, SIZE } attribute_type;

// all together, a 32 bit word now...
unsigned int foreground_color : 12;
unsigned int background_color : 12;
private:
unsigned int attributes : 8;
static const uint64_t true_color_mask = 0x1000000;
uint64_t foreground_color : 25;
uint64_t background_color : 25;
uint64_t attributes : 8;

public:
Renditions( color_type s_background );
Expand All @@ -68,6 +68,17 @@ namespace Terminal {
void set_rendition( color_type num );
std::string sgr( void ) const;

static unsigned int make_true_color( unsigned int r, unsigned int g, unsigned int b ) {
return true_color_mask | (r << 16) | (g << 8) | b;
}

static bool is_true_color(unsigned int color) {
return (color & true_color_mask) != 0;
}

// unsigned int get_foreground_rendition() const { return foreground_color; }
unsigned int get_background_rendition() const { return background_color; }

bool operator==( const Renditions &x ) const
{
return ( attributes == x.attributes )
Expand Down Expand Up @@ -324,7 +335,7 @@ namespace Terminal {
void add_rendition( color_type x ) { renditions.set_rendition( x ); }
const Renditions& get_renditions( void ) const { return renditions; }
Renditions& get_renditions( void ) { return renditions; }
int get_background_rendition( void ) const { return renditions.background_color; }
int get_background_rendition( void ) const { return renditions.get_background_rendition(); }

void save_cursor( void );
void restore_cursor( void );
Expand Down
21 changes: 21 additions & 0 deletions src/terminal/terminalfunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,27 @@ static void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch )
i += 2;
continue;
}

/* True color support: ESC[ ... [34]8;2;<r>;<g>;<b> ... m */
if ( (rendition == 38 || rendition == 48) &&
(dispatch->param_count() - i >= 5) &&
(dispatch->getparam( i+1, -1 ) == 2)) {
unsigned int red = dispatch->getparam(i+2, 0);
unsigned int green = dispatch->getparam(i+3, 0);
unsigned int blue = dispatch->getparam(i+4, 0);
unsigned int color;

color = Renditions::make_true_color( red, green, blue );

if ( rendition == 38 ) {
fb->ds.set_foreground_color( color );
} else {
fb->ds.set_background_color( color );
}
i += 4;
continue;
}

fb->ds.add_rendition( rendition );
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ displaytests = \
emulation-attributes-16color.test \
emulation-attributes-256color8.test \
emulation-attributes-256color248.test \
emulation-attributes-truecolor.test \
emulation-attributes-bce.test \
emulation-back-tab.test \
emulation-cursor-motion.test \
emulation-multiline-scroll.test \
Expand Down
Loading

0 comments on commit 34b5f40

Please sign in to comment.