Print {,/var}/run/motd.dynamic on Ubuntu.

This commit is contained in:
John Hood
2017-03-24 22:37:02 -04:00
parent 3f0ac51071
commit 32b1e6ee4b
+18 -7
View File
@@ -118,7 +118,7 @@ static void print_usage( FILE *stream, const char *argv0 )
fprintf( stream, "Usage: %s new [-s] [-v] [-i LOCALADDR] [-p PORT[:PORT2]] [-c COLORS] [-l NAME=VALUE] [-- COMMAND...]\n", argv0 );
}
static void print_motd( void );
static bool print_motd( const char *filename );
static void chdir_homedir( void );
static bool motd_hushed( void );
static void warn_unattached( const string & ignore_entry );
@@ -554,9 +554,19 @@ static int run_server( const char *desired_ip, const char *desired_port,
chdir_homedir();
if ( with_motd && (!motd_hushed()) ) {
// On illumos motd is printed by /etc/profile.
#ifndef __sun
/* On illumos motd is printed by /etc/profile */
print_motd();
// For Ubuntu, try and print one of {,/var}/run/motd.dynamic.
// This file is only updated when pam_motd is run, but when
// mosh-server is run in the usual way with ssh via the script,
// this always happens.
// XXX Hackish knowledge of Ubuntu PAM configuration.
// But this seems less awful than build-time detection with autoconf.
if (!print_motd("/run/motd.dynamic")) {
print_motd("/var/run/motd.dynamic");
}
// Always print traditional /etc/motd.
print_motd("/etc/motd");
#endif
warn_unattached( utmp_entry );
}
@@ -880,12 +890,12 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
}
}
/* OpenSSH prints the motd on startup, so we will too */
static void print_motd( void )
/* Print the motd from a given file, if available */
static bool print_motd( const char *filename )
{
FILE *motd = fopen( "/etc/motd", "r" );
FILE *motd = fopen( filename, "r" );
if ( !motd ) {
return; /* don't report error on missing or forbidden motd */
return false;
}
const int BUFSIZE = 256;
@@ -903,6 +913,7 @@ static void print_motd( void )
}
fclose( motd );
return true;
}
static void chdir_homedir( void )