|
Lines 845-850
child_set_env(char ***envp, u_int *envsi
Link Here
|
| 845 |
} |
845 |
} |
| 846 |
|
846 |
|
| 847 |
/* |
847 |
/* |
|
|
848 |
* Returns the value of the given variable from the environment. |
| 849 |
* Returns NULL, if the variable is not found. |
| 850 |
*/ |
| 851 |
static char * |
| 852 |
child_get_env(char **envp, const char *name) |
| 853 |
{ |
| 854 |
u_int i, namelen; |
| 855 |
|
| 856 |
namelen = strlen(name); |
| 857 |
for (i = 0; envp[i]; i++) { |
| 858 |
if (strncmp(envp[i], name, namelen) == 0 && |
| 859 |
envp[i][namelen] == '=') |
| 860 |
break; |
| 861 |
} |
| 862 |
if (envp[i]) |
| 863 |
return &envp[i][namelen + 1]; |
| 864 |
|
| 865 |
return NULL; |
| 866 |
} |
| 867 |
|
| 868 |
/* |
| 848 |
* Reads environment variables from the given file and adds/overrides them |
869 |
* Reads environment variables from the given file and adds/overrides them |
| 849 |
* into the environment. If the file does not exist, this does nothing. |
870 |
* into the environment. If the file does not exist, this does nothing. |
| 850 |
* Otherwise, it must consist of empty lines, comments (line starts with '#') |
871 |
* Otherwise, it must consist of empty lines, comments (line starts with '#') |
|
Lines 889-894
read_environment_file(char ***env, u_int
Link Here
|
| 889 |
fclose(f); |
910 |
fclose(f); |
| 890 |
} |
911 |
} |
| 891 |
|
912 |
|
|
|
913 |
#ifdef HAVE_ETC_DEFAULT_LOGIN |
| 914 |
/* |
| 915 |
* Read /etc/default/login |
| 916 |
* This file is found and processed by login(1) at least on Solaris |
| 917 |
* and ReliantUNIX. |
| 918 |
* |
| 919 |
* Get PATH environment variable from: |
| 920 |
* PATH (for mere mortals) |
| 921 |
* SUPATH (for root) |
| 922 |
* Get umask setting from UMASK |
| 923 |
* |
| 924 |
* XXX There are other reasonable things to process in this file: |
| 925 |
* i.e. ALTSHELL, CONSOLE, DISABLE_RHOSTS, HZ, IDLEWEEKS, ULIMIT |
| 926 |
* |
| 927 |
*/ |
| 928 |
static void |
| 929 |
read_etc_default_login(char ***env, u_int *envsize, uid_t uid) |
| 930 |
{ |
| 931 |
char **edf_env, *edf; |
| 932 |
u_int i, edf_envsize; |
| 933 |
mode_t mask; |
| 934 |
|
| 935 |
/* |
| 936 |
* We don't want to copy the whole file to the childs environment, |
| 937 |
* so we use our own temporary environment here. |
| 938 |
* envsize=10 should be large enough, but child_set_env will expand |
| 939 |
* the array if necessary. |
| 940 |
*/ |
| 941 |
edf_envsize = 10; |
| 942 |
edf_env = xmalloc(edf_envsize * sizeof(char *)); |
| 943 |
edf_env[0] = NULL; |
| 944 |
|
| 945 |
read_environment_file(&edf_env, &edf_envsize, "/etc/default/login"); |
| 946 |
|
| 947 |
if (uid == 0) |
| 948 |
edf = child_get_env(edf_env, "SUPATH"); |
| 949 |
else |
| 950 |
edf = child_get_env(edf_env, "PATH"); |
| 951 |
if (edf != NULL) |
| 952 |
child_set_env(env, envsize, "PATH", edf); |
| 953 |
|
| 954 |
if ((edf = child_get_env(edf_env, "UMASK")) != NULL) |
| 955 |
if (sscanf(edf, "%5lo", &mask) == 1) |
| 956 |
umask(mask); |
| 957 |
|
| 958 |
for (i = 0; edf_env[i] != NULL; i++) |
| 959 |
xfree(edf_env[i]); |
| 960 |
xfree(edf_env); |
| 961 |
} |
| 962 |
#endif /* HAVE_ETC_DEFAULT_LOGIN */ |
| 963 |
|
| 892 |
void copy_environment(char **source, char ***env, u_int *envsize) |
964 |
void copy_environment(char **source, char ***env, u_int *envsize) |
| 893 |
{ |
965 |
{ |
| 894 |
char *var_name, *var_val; |
966 |
char *var_name, *var_val; |
|
Lines 954-968
do_setup_env(Session *s, const char *she
Link Here
|
| 954 |
* needed for loading shared libraries. So the path better |
1026 |
* needed for loading shared libraries. So the path better |
| 955 |
* remains intact here. |
1027 |
* remains intact here. |
| 956 |
*/ |
1028 |
*/ |
| 957 |
# ifdef SUPERUSER_PATH |
1029 |
# ifdef HAVE_ETC_DEFAULT_LOGIN |
| 958 |
child_set_env(&env, &envsize, "PATH", |
1030 |
read_etc_default_login(&env, &envsize, pw->pw_uid); |
| 959 |
s->pw->pw_uid == 0 ? SUPERUSER_PATH : _PATH_STDPATH); |
1031 |
# endif /* HAVE_ETC_DEFAULT_LOGIN */ |
| 960 |
# else |
|
|
| 961 |
child_set_env(&env, &envsize, "PATH", _PATH_STDPATH); |
| 962 |
# endif /* SUPERUSER_PATH */ |
| 963 |
# endif /* HAVE_CYGWIN */ |
1032 |
# endif /* HAVE_CYGWIN */ |
| 964 |
#endif /* HAVE_LOGIN_CAP */ |
1033 |
#endif /* HAVE_LOGIN_CAP */ |
| 965 |
|
1034 |
|
|
|
1035 |
/* |
| 1036 |
* Paranoia check: set at least a standard path |
| 1037 |
* if none is set yet. |
| 1038 |
*/ |
| 1039 |
if (child_get_env(env, "PATH") == NULL) { |
| 1040 |
#ifdef SUPERUSER_PATH |
| 1041 |
child_set_env(&env, &envsize, "PATH", |
| 1042 |
s->pw->pw_uid == 0 ? |
| 1043 |
SUPERUSER_PATH : _PATH_STDPATH); |
| 1044 |
#else |
| 1045 |
child_set_env(&env, &envsize, "PATH", _PATH_STDPATH); |
| 1046 |
#endif /* SUPERUSER_PATH */ |
| 1047 |
} |
| 966 |
snprintf(buf, sizeof buf, "%.200s/%.50s", |
1048 |
snprintf(buf, sizeof buf, "%.200s/%.50s", |
| 967 |
_PATH_MAILDIR, pw->pw_name); |
1049 |
_PATH_MAILDIR, pw->pw_name); |
| 968 |
child_set_env(&env, &envsize, "MAIL", buf); |
1050 |
child_set_env(&env, &envsize, "MAIL", buf); |