comparison svr-chansession.c @ 1830:c32976db772f

Merge
author Matt Johnston <matt@ucc.asn.au>
date Mon, 11 Oct 2021 15:46:49 +0800
parents a7cc3332d8ab 1edf4f143e12
children 90ac15aeac43
comparison
equal deleted inserted replaced
1829:a7cc3332d8ab 1830:c32976db772f
931 /* Clean up, drop to user privileges, set up the environment and execute 931 /* Clean up, drop to user privileges, set up the environment and execute
932 * the command/shell. This function does not return. */ 932 * the command/shell. This function does not return. */
933 static void execchild(const void *user_data) { 933 static void execchild(const void *user_data) {
934 const struct ChanSess *chansess = user_data; 934 const struct ChanSess *chansess = user_data;
935 char *usershell = NULL; 935 char *usershell = NULL;
936 char *cp = NULL;
937 char *envcp = getenv("LANG");
938 if (envcp != NULL) {
939 cp = m_strdup(envcp);
940 }
936 941
937 /* with uClinux we'll have vfork()ed, so don't want to overwrite the 942 /* with uClinux we'll have vfork()ed, so don't want to overwrite the
938 * hostkey. can't think of a workaround to clear it */ 943 * hostkey. can't think of a workaround to clear it */
939 #if !DROPBEAR_VFORK 944 #if !DROPBEAR_VFORK
940 /* wipe the hostkey */ 945 /* wipe the hostkey */
943 948
944 /* overwrite the prng state */ 949 /* overwrite the prng state */
945 seedrandom(); 950 seedrandom();
946 #endif 951 #endif
947 952
948 /* clear environment */ 953 /* clear environment if -e was not set */
949 /* if we're debugging using valgrind etc, we need to keep the LD_PRELOAD 954 /* if we're debugging using valgrind etc, we need to keep the LD_PRELOAD
950 * etc. This is hazardous, so should only be used for debugging. */ 955 * etc. This is hazardous, so should only be used for debugging. */
956 if ( !svr_opts.pass_on_env) {
951 #ifndef DEBUG_VALGRIND 957 #ifndef DEBUG_VALGRIND
952 #ifdef HAVE_CLEARENV 958 #ifdef HAVE_CLEARENV
953 clearenv(); 959 clearenv();
954 #else /* don't HAVE_CLEARENV */ 960 #else /* don't HAVE_CLEARENV */
955 /* Yay for posix. */ 961 /* Yay for posix. */
956 if (environ) { 962 if (environ) {
957 environ[0] = NULL; 963 environ[0] = NULL;
958 } 964 }
959 #endif /* HAVE_CLEARENV */ 965 #endif /* HAVE_CLEARENV */
960 #endif /* DEBUG_VALGRIND */ 966 #endif /* DEBUG_VALGRIND */
967 }
961 968
962 #if DROPBEAR_SVR_MULTIUSER 969 #if DROPBEAR_SVR_MULTIUSER
963 /* We can only change uid/gid as root ... */ 970 /* We can only change uid/gid as root ... */
964 if (getuid() == 0) { 971 if (getuid() == 0) {
965 972
989 addnewvar("USER", ses.authstate.pw_name); 996 addnewvar("USER", ses.authstate.pw_name);
990 addnewvar("LOGNAME", ses.authstate.pw_name); 997 addnewvar("LOGNAME", ses.authstate.pw_name);
991 addnewvar("HOME", ses.authstate.pw_dir); 998 addnewvar("HOME", ses.authstate.pw_dir);
992 addnewvar("SHELL", get_user_shell()); 999 addnewvar("SHELL", get_user_shell());
993 addnewvar("PATH", DEFAULT_PATH); 1000 addnewvar("PATH", DEFAULT_PATH);
1001 if (cp != NULL) {
1002 addnewvar("LANG", cp);
1003 m_free(cp);
1004 }
994 if (chansess->term != NULL) { 1005 if (chansess->term != NULL) {
995 addnewvar("TERM", chansess->term); 1006 addnewvar("TERM", chansess->term);
996 } 1007 }
997 1008
998 if (chansess->tty) { 1009 if (chansess->tty) {