Skip to content

Commit

Permalink
Chdir to homedir (closes mobile-shell#193) and honor .hushlogin (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Apr 19, 2012
1 parent b127a92 commit 1508d40
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -201,7 +201,7 @@ AM_CONDITIONAL([COND_THIRD_LIBSTDDJB],
[test x"$have_signalfd" = xno && test x"$with_skalibs" = xno])

# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h langinfo.h limits.h locale.h netinet/in.h stddef.h stdint.h inttypes.h stdlib.h string.h sys/ioctl.h sys/resource.h sys/socket.h sys/time.h termios.h unistd.h wchar.h wctype.h], [], [AC_MSG_ERROR([Missing required header file.])])
AC_CHECK_HEADERS([arpa/inet.h fcntl.h langinfo.h limits.h locale.h netinet/in.h stddef.h stdint.h inttypes.h stdlib.h string.h sys/ioctl.h sys/resource.h sys/socket.h sys/stat.h sys/time.h termios.h unistd.h wchar.h wctype.h], [], [AC_MSG_ERROR([Missing required header file.])])

AC_CHECK_HEADERS([pty.h util.h libutil.h paths.h])
AC_CHECK_HEADERS([endian.h sys/endian.h])
Expand Down
31 changes: 30 additions & 1 deletion src/frontend/mosh-server.cc
Expand Up @@ -39,6 +39,7 @@
#include <arpa/inet.h>
#include <getopt.h>
#include <time.h>
#include <sys/stat.h>

#ifdef HAVE_PATHS_H
#include <paths.h>
Expand Down Expand Up @@ -85,6 +86,8 @@ void print_usage( const char *argv0 )
}

void print_motd( void );
void chdir_homedir( void );
bool motd_hushed( void );

/* Simple spinloop */
void spin( void )
Expand Down Expand Up @@ -399,7 +402,9 @@ int run_server( const char *desired_ip, const char *desired_port,
exit( 1 );
}

if ( with_motd ) {
chdir_homedir();

if ( with_motd && (!motd_hushed()) ) {
print_motd();
}

Expand Down Expand Up @@ -711,3 +716,27 @@ void print_motd( void )

fclose( motd );
}

void chdir_homedir( void )
{
struct passwd *pw = getpwuid( geteuid() );
if ( pw == NULL ) {
perror( "getpwuid" );
/* non-fatal */
}

if ( chdir( pw->pw_dir ) < 0 ) {
perror( "chdir" );
}

if ( setenv( "PWD", pw->pw_dir, 1 ) < 0 ) {
perror( "setenv" );
}
}

bool motd_hushed( void )
{
/* must be in home directory already */
struct stat buf;
return (0 == lstat( ".hushlogin", &buf ));
}

0 comments on commit 1508d40

Please sign in to comment.