|
Lines 771-776
Link Here
|
| 771 |
} |
771 |
} |
| 772 |
|
772 |
|
| 773 |
/* |
773 |
/* |
|
|
774 |
* Returns the value of the given variable from the environment. |
| 775 |
* Returns NULL, if the variable is not found. |
| 776 |
*/ |
| 777 |
static char * |
| 778 |
child_get_env(char **envp, const char *name) |
| 779 |
{ |
| 780 |
u_int i, namelen; |
| 781 |
|
| 782 |
namelen = strlen(name); |
| 783 |
for (i = 0; envp[i]; i++) { |
| 784 |
if (strncmp(envp[i], name, namelen) == 0 && |
| 785 |
envp[i][namelen] == '=') |
| 786 |
break; |
| 787 |
} |
| 788 |
if(envp[i]) |
| 789 |
return &envp[i][namelen + 1]; |
| 790 |
|
| 791 |
return NULL; |
| 792 |
} |
| 793 |
|
| 794 |
/* |
| 774 |
* Reads environment variables from the given file and adds/overrides them |
795 |
* Reads environment variables from the given file and adds/overrides them |
| 775 |
* into the environment. If the file does not exist, this does nothing. |
796 |
* into the environment. If the file does not exist, this does nothing. |
| 776 |
* Otherwise, it must consist of empty lines, comments (line starts with '#') |
797 |
* Otherwise, it must consist of empty lines, comments (line starts with '#') |
|
Lines 811-816
Link Here
|
| 811 |
fclose(f); |
832 |
fclose(f); |
| 812 |
} |
833 |
} |
| 813 |
|
834 |
|
|
|
835 |
#ifdef HAVE_ETC_DEFAULT_LOGIN |
| 836 |
/* |
| 837 |
* Read /etc/default/login |
| 838 |
* This file is found and processed by login(1) at least on Solaris |
| 839 |
* and ReliantUNIX. |
| 840 |
* |
| 841 |
* Get PATH environment variable from: |
| 842 |
* PATH (for mere mortals) |
| 843 |
* SUPATH (for root) |
| 844 |
* Get umask setting from UMASK |
| 845 |
* |
| 846 |
* XXX There are other reasonable things to process in this file: |
| 847 |
* i.e. ALTSHELL, CONSOLE, DISABLE_RHOSTS, HZ, IDLEWEEKS, ULIMIT |
| 848 |
* |
| 849 |
*/ |
| 850 |
static void |
| 851 |
read_etc_default_login(char ***env, u_int *envsize, uid_t uid) |
| 852 |
{ |
| 853 |
char **edf_env, *edf; |
| 854 |
u_int i, edf_envsize; |
| 855 |
mode_t mask; |
| 856 |
|
| 857 |
/* |
| 858 |
* We don't want to copy the whole file to the childs environment, |
| 859 |
* so we use our own temporary environment here. |
| 860 |
*/ |
| 861 |
edf_envsize = 10; |
| 862 |
edf_env = xmalloc(edf_envsize * sizeof(char *)); |
| 863 |
edf_env[0] = NULL; |
| 864 |
|
| 865 |
read_environment_file(&edf_env, &edf_envsize, "/etc/default/login"); |
| 866 |
|
| 867 |
if(uid) |
| 868 |
edf = child_get_env(edf_env, "PATH"); |
| 869 |
else |
| 870 |
edf = child_get_env(edf_env, "SUPATH"); |
| 871 |
if(edf != NULL) |
| 872 |
child_set_env(env, envsize, "PATH", edf); |
| 873 |
|
| 874 |
if((edf = child_get_env(edf_env, "UMASK")) != NULL) |
| 875 |
if (sscanf(edf, "%o", &mask) == 1) |
| 876 |
umask(mask); |
| 877 |
|
| 878 |
for(i = 0; edf_env[i]; i++) |
| 879 |
xfree(edf_env[i]); |
| 880 |
xfree(edf_env); |
| 881 |
} |
| 882 |
#endif /* HAVE_ETC_DEFAULT_LOGIN */ |
| 883 |
|
| 814 |
void copy_environment(char **source, char ***env, u_int *envsize) |
884 |
void copy_environment(char **source, char ***env, u_int *envsize) |
| 815 |
{ |
885 |
{ |
| 816 |
char *var_name, *var_val; |
886 |
char *var_name, *var_val; |
|
Lines 871-885
Link Here
|
| 871 |
* needed for loading shared libraries. So the path better |
941 |
* needed for loading shared libraries. So the path better |
| 872 |
* remains intact here. |
942 |
* remains intact here. |
| 873 |
*/ |
943 |
*/ |
| 874 |
# ifdef SUPERUSER_PATH |
944 |
# ifdef HAVE_ETC_DEFAULT_LOGIN |
| 875 |
child_set_env(&env, &envsize, "PATH", |
945 |
read_etc_default_login(&env, &envsize, pw->pw_uid); |
| 876 |
s->pw->pw_uid == 0 ? SUPERUSER_PATH : _PATH_STDPATH); |
946 |
# endif /* HAVE_ETC_DEFAULT_LOGIN */ |
| 877 |
# else |
|
|
| 878 |
child_set_env(&env, &envsize, "PATH", _PATH_STDPATH); |
| 879 |
# endif /* SUPERUSER_PATH */ |
| 880 |
# endif /* HAVE_CYGWIN */ |
947 |
# endif /* HAVE_CYGWIN */ |
| 881 |
#endif /* HAVE_LOGIN_CAP */ |
948 |
#endif /* HAVE_LOGIN_CAP */ |
| 882 |
|
949 |
|
|
|
950 |
/* |
| 951 |
* Paranoia check: set at least a standard path |
| 952 |
* if none is set yet. |
| 953 |
*/ |
| 954 |
if(child_get_env(env, "PATH") == NULL) { |
| 955 |
#ifdef SUPERUSER_PATH |
| 956 |
child_set_env(&env, &envsize, "PATH", |
| 957 |
s->pw->pw_uid == 0 ? |
| 958 |
SUPERUSER_PATH : _PATH_STDPATH); |
| 959 |
#else |
| 960 |
child_set_env(&env, &envsize, "PATH", _PATH_STDPATH); |
| 961 |
#endif /* SUPERUSER_PATH */ |
| 962 |
} |
| 883 |
snprintf(buf, sizeof buf, "%.200s/%.50s", |
963 |
snprintf(buf, sizeof buf, "%.200s/%.50s", |
| 884 |
_PATH_MAILDIR, pw->pw_name); |
964 |
_PATH_MAILDIR, pw->pw_name); |
| 885 |
child_set_env(&env, &envsize, "MAIL", buf); |
965 |
child_set_env(&env, &envsize, "MAIL", buf); |