summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
Diffstat (limited to 'session.c')
-rw-r--r--session.c80
1 files changed, 73 insertions, 7 deletions
diff --git a/session.c b/session.c
index 35328ecbb..4497f5c0b 100644
--- a/session.c
+++ b/session.c
@@ -802,6 +802,16 @@ child_set_env(char ***envp, u_int *envsizep, const char *name,
802 char **env; 802 char **env;
803 803
804 /* 804 /*
805 * If we're passed an uninitialized list, allocate a single null
806 * entry before continuing.
807 */
808 if (*envp == NULL && *envsizep == 0) {
809 *envp = xmalloc(sizeof(char *));
810 *envp[0] = NULL;
811 *envsizep = 1;
812 }
813
814 /*
805 * Find the slot where the value should be stored. If the variable 815 * Find the slot where the value should be stored. If the variable
806 * already exists, we reuse the slot; otherwise we append a new slot 816 * already exists, we reuse the slot; otherwise we append a new slot
807 * at the end of the array, expanding if necessary. 817 * at the end of the array, expanding if necessary.
@@ -877,6 +887,59 @@ read_environment_file(char ***env, u_int *envsize,
877 fclose(f); 887 fclose(f);
878} 888}
879 889
890#ifdef HAVE_ETC_DEFAULT_LOGIN
891/*
892 * Return named variable from specified environment, or NULL if not present.
893 */
894static char *
895child_get_env(char **env, const char *name)
896{
897 int i;
898 size_t len;
899
900 len = strlen(name);
901 for (i=0; env[i] != NULL; i++)
902 if (strncmp(name, env[i], len) == 0 && env[i][len] == '=')
903 return(env[i] + len + 1);
904 return NULL;
905}
906
907/*
908 * Read /etc/default/login.
909 * We pick up the PATH (or SUPATH for root) and UMASK.
910 */
911static void
912read_etc_default_login(char ***env, u_int *envsize, uid_t uid)
913{
914 char **tmpenv = NULL, *var;
915 u_int i;
916 size_t tmpenvsize = 0;
917 mode_t mask;
918
919 /*
920 * We don't want to copy the whole file to the child's environment,
921 * so we use a temporary environment and copy the variables we're
922 * interested in.
923 */
924 read_environment_file(&tmpenv, &tmpenvsize, "/etc/default/login");
925
926 if (uid == 0)
927 var = child_get_env(tmpenv, "SUPATH");
928 else
929 var = child_get_env(tmpenv, "PATH");
930 if (var != NULL)
931 child_set_env(env, envsize, "PATH", var);
932
933 if ((var = child_get_env(tmpenv, "UMASK")) != NULL)
934 if (sscanf(var, "%5lo", &mask) == 1)
935 umask(mask);
936
937 for (i = 0; tmpenv[i] != NULL; i++)
938 xfree(tmpenv[i]);
939 xfree(tmpenv);
940}
941#endif /* HAVE_ETC_DEFAULT_LOGIN */
942
880void copy_environment(char **source, char ***env, u_int *envsize) 943void copy_environment(char **source, char ***env, u_int *envsize)
881{ 944{
882 char *var_name, *var_val; 945 char *var_name, *var_val;
@@ -905,7 +968,7 @@ do_setup_env(Session *s, const char *shell)
905{ 968{
906 char buf[256]; 969 char buf[256];
907 u_int i, envsize; 970 u_int i, envsize;
908 char **env, *laddr; 971 char **env, *laddr, *path = NULL;
909 struct passwd *pw = s->pw; 972 struct passwd *pw = s->pw;
910 973
911 /* Initialize the environment. */ 974 /* Initialize the environment. */
@@ -949,12 +1012,15 @@ do_setup_env(Session *s, const char *shell)
949 * needed for loading shared libraries. So the path better 1012 * needed for loading shared libraries. So the path better
950 * remains intact here. 1013 * remains intact here.
951 */ 1014 */
952# ifdef SUPERUSER_PATH 1015# ifdef HAVE_ETC_DEFAULT_LOGIN
953 child_set_env(&env, &envsize, "PATH", 1016 read_etc_default_login(&env, &envsize, pw->pw_uid);
954 s->pw->pw_uid == 0 ? SUPERUSER_PATH : _PATH_STDPATH); 1017 path = child_get_env(env, "PATH");
955# else 1018# endif /* HAVE_ETC_DEFAULT_LOGIN */
956 child_set_env(&env, &envsize, "PATH", _PATH_STDPATH); 1019 if (path == NULL || *path == '\0') {
957# endif /* SUPERUSER_PATH */ 1020 child_set_env(&env, &envsize, "PATH",
1021 s->pw->pw_uid == 0 ?
1022 SUPERUSER_PATH : _PATH_STDPATH);
1023 }
958# endif /* HAVE_CYGWIN */ 1024# endif /* HAVE_CYGWIN */
959#endif /* HAVE_LOGIN_CAP */ 1025#endif /* HAVE_LOGIN_CAP */
960 1026