--- mosh-1.2.3/src/frontend/mosh-server.cc 2012/12/25 18:01:40 1.1 +++ mosh-1.2.3/src/frontend/mosh-server.cc 2012/12/25 18:14:26 @@ -244,10 +244,17 @@ char *my_argv[ 2 ]; if ( !command_argv ) { /* get shell name */ - struct passwd *pw = getpwuid( geteuid() ); + struct passwd *pw = NULL; + char *ln = getenv( "LOGNAME" ); + if ( ln ) { + pw = getpwnam( ln ); + } if ( pw == NULL ) { - perror( "getpwuid" ); - exit( 1 ); + pw = getpwuid( geteuid() ); + if ( pw == NULL ) { + perror( "getpwuid" ); + exit( 1 ); + } } string shell_path( pw->pw_shell ); @@ -754,10 +761,17 @@ void chdir_homedir( void ) { - struct passwd *pw = getpwuid( geteuid() ); + struct passwd *pw = NULL; + char *ln = getenv( "LOGNAME" ); + if ( ln ) { + pw = getpwnam( ln ); + } if ( pw == NULL ) { - perror( "getpwuid" ); - return; /* non-fatal */ + pw = getpwuid( geteuid() ); + if ( pw == NULL ) { + perror( "getpwuid" ); + return; /* non-fatal */ + } } if ( chdir( pw->pw_dir ) < 0 ) { @@ -793,11 +807,18 @@ { #ifdef HAVE_UTMPX_H /* get username */ - const struct passwd *pw = getpwuid( geteuid() ); + const struct passwd *pw = NULL; + char *ln = getenv( "LOGNAME" ); + if ( ln ) { + pw = getpwnam( ln ); + } if ( pw == NULL ) { - perror( "getpwuid" ); - /* non-fatal */ - return; + pw = getpwuid( geteuid() ); + if ( pw == NULL ) { + perror( "getpwuid" ); + /* non-fatal */ + return; + } } const string username( pw->pw_name );