Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/setup_environment.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/setup_environment.c
r821 r1770 29 29 */ 30 30 31 #include <stdio.h>32 #include <errno.h>33 #include <unistd.h>34 #include <string.h>35 #include <stdlib.h>36 #include <syslog.h>37 #include <ctype.h>38 31 #include "libbb.h" 39 32 40 41 42 #define DEFAULT_LOGIN_PATH "/bin:/usr/bin" 43 #define DEFAULT_ROOT_LOGIN_PATH "/usr/sbin:/bin:/usr/bin:/sbin" 44 45 static void xsetenv ( const char *key, const char *value ) 33 void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw) 46 34 { 47 if ( setenv ( key, value, 1 )) 48 bb_error_msg_and_die (bb_msg_memory_exhausted); 49 } 50 51 void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw ) 52 { 53 if ( loginshell ) { 35 if (loginshell) { 54 36 const char *term; 55 37 … … 60 42 * Some systems default to HOME=/ 61 43 */ 62 if ( chdir ( pw-> pw_dir )) { 63 if ( chdir ( "/" )) { 64 syslog ( LOG_WARNING, "unable to cd to %s' for user %s'\n", pw-> pw_dir, pw-> pw_name ); 65 bb_error_msg_and_die ( "cannot cd to home directory or /" ); 66 } 67 fputs ( "warning: cannot change to home directory\n", stderr ); 44 if (chdir(pw->pw_dir)) { 45 xchdir("/"); 46 fputs("warning: cannot change to home directory\n", stderr); 68 47 } 69 48 70 49 /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. 71 50 Unset all other environment variables. */ 72 term = getenv 73 clearenv ();74 if ( term)75 xsetenv ( "TERM", term);76 xsetenv ( "HOME", pw-> pw_dir);77 xsetenv ( "SHELL", shell);78 xsetenv ( "USER", pw-> pw_name);79 xsetenv ( "LOGNAME", pw-> pw_name);80 xsetenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH));51 term = getenv("TERM"); 52 clearenv(); 53 if (term) 54 xsetenv("TERM", term); 55 xsetenv("HOME", pw->pw_dir); 56 xsetenv("SHELL", shell); 57 xsetenv("USER", pw->pw_name); 58 xsetenv("LOGNAME", pw->pw_name); 59 xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path)); 81 60 } 82 else if ( changeenv) {61 else if (changeenv) { 83 62 /* Set HOME, SHELL, and if not becoming a super-user, 84 63 USER and LOGNAME. */ 85 xsetenv ( "HOME", pw-> pw_dir);86 xsetenv ( "SHELL", shell);87 if ( pw-> pw_uid) {88 xsetenv ( "USER", pw-> pw_name);89 xsetenv ( "LOGNAME", pw-> pw_name);64 xsetenv("HOME", pw->pw_dir); 65 xsetenv("SHELL", shell); 66 if (pw->pw_uid) { 67 xsetenv("USER", pw->pw_name); 68 xsetenv("LOGNAME", pw->pw_name); 90 69 } 91 70 } 92 71 } 93
Note:
See TracChangeset
for help on using the changeset viewer.