aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-10 13:15:28 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-10 13:15:28 +0000
commita2f61012b6f93473ed002e6609557cb1cd81b7dd (patch)
tree51ce422afbda2249a5de22e834ed04e200e0961f
parentac074b3f87cc22c2ddadb074d630156fea720744 (diff)
downloadbusybox-w32-a2f61012b6f93473ed002e6609557cb1cd81b7dd.tar.gz
busybox-w32-a2f61012b6f93473ed002e6609557cb1cd81b7dd.tar.bz2
busybox-w32-a2f61012b6f93473ed002e6609557cb1cd81b7dd.zip
setup_environment: code shrink
run_shell: mark as NORETURN setup_environment, run_shell: add usage comments login: add FIXME :( function old new delta UNSPEC_print 64 66 +2 sulogin_main 509 506 -3 mkfs_minix_main 3070 3067 -3 login_main 1615 1612 -3 su_main 461 448 -13 setup_environment 261 206 -55 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/5 up/down: 2/-77) Total: -75 bytes text data bss dec hex filename 772578 1051 10724 784353 bf7e1 busybox_old 772502 1051 10724 784277 bf795 busybox_unstripped
-rw-r--r--include/libbb.h16
-rw-r--r--libbb/setup_environment.c25
-rw-r--r--loginutils/login.c7
-rw-r--r--loginutils/su.c7
-rw-r--r--loginutils/sulogin.c7
5 files changed, 41 insertions, 21 deletions
diff --git a/include/libbb.h b/include/libbb.h
index a4aa90da3..e5f03517f 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -780,6 +780,7 @@ char *bb_simplify_path(const char *path);
780extern void bb_do_delay(int seconds); 780extern void bb_do_delay(int seconds);
781extern void change_identity(const struct passwd *pw); 781extern void change_identity(const struct passwd *pw);
782extern const char *change_identity_e2str(const struct passwd *pw); 782extern const char *change_identity_e2str(const struct passwd *pw);
783extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) ATTRIBUTE_NORETURN;
783extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args); 784extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args);
784#if ENABLE_SELINUX 785#if ENABLE_SELINUX
785extern void renew_current_security_context(void); 786extern void renew_current_security_context(void);
@@ -790,6 +791,21 @@ extern void setfscreatecon_or_die(security_context_t scontext);
790#endif 791#endif
791extern void selinux_or_die(void); 792extern void selinux_or_die(void);
792extern int restricted_shell(const char *shell); 793extern int restricted_shell(const char *shell);
794
795/* setup_environment:
796 * if loginshell = 1: cd(pw->pw_dir), clear environment, then set
797 * TERM=(old value)
798 * USER=pw->pw_name, LOGNAME=pw->pw_name
799 * PATH=bb_default_[root_]path
800 * HOME=pw->pw_dir
801 * SHELL=shell
802 * else if changeenv = 1:
803 * if not root (if pw->pw_uid != 0):
804 * USER=pw->pw_name, LOGNAME=pw->pw_name
805 * HOME=pw->pw_dir
806 * SHELL=shell
807 * else does nothing
808 */
793extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw); 809extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw);
794extern int correct_password(const struct passwd *pw); 810extern int correct_password(const struct passwd *pw);
795/* Returns a ptr to static storage */ 811/* Returns a ptr to static storage */
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index a6f44f7f0..19a2c6db5 100644
--- a/libbb/setup_environment.c
+++ b/libbb/setup_environment.c
@@ -36,36 +36,35 @@ void setup_environment(const char *shell, int loginshell, int changeenv, const s
36 const char *term; 36 const char *term;
37 37
38 /* Change the current working directory to be the home directory 38 /* Change the current working directory to be the home directory
39 * of the user. It is a fatal error for this process to be unable 39 * of the user */
40 * to change to that directory. There is no "default" home
41 * directory.
42 * Some systems default to HOME=/
43 */
44 if (chdir(pw->pw_dir)) { 40 if (chdir(pw->pw_dir)) {
45 xchdir("/"); 41 xchdir("/");
46 fputs("warning: cannot change to home directory\n", stderr); 42 fputs("warning: cannot change to home directory\n", stderr);
47 } 43 }
48 44
49 /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. 45 /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH.
50 Unset all other environment variables. */ 46 Unset all other environment variables. */
51 term = getenv("TERM"); 47 term = getenv("TERM");
52 clearenv(); 48 clearenv();
53 if (term) 49 if (term)
54 xsetenv("TERM", term); 50 xsetenv("TERM", term);
55 xsetenv("HOME", pw->pw_dir); 51 xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path));
56 xsetenv("SHELL", shell); 52 goto shortcut;
57 xsetenv("USER", pw->pw_name); 53 // No, gcc (4.2.1) is not clever enougn to do it itself.
58 xsetenv("LOGNAME", pw->pw_name); 54 //xsetenv("USER", pw->pw_name);
59 xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path)); 55 //xsetenv("LOGNAME", pw->pw_name);
56 //xsetenv("HOME", pw->pw_dir);
57 //xsetenv("SHELL", shell);
60 } 58 }
61 else if (changeenv) { 59 else if (changeenv) {
62 /* Set HOME, SHELL, and if not becoming a super-user, 60 /* Set HOME, SHELL, and if not becoming a super-user,
63 USER and LOGNAME. */ 61 USER and LOGNAME. */
64 xsetenv("HOME", pw->pw_dir);
65 xsetenv("SHELL", shell);
66 if (pw->pw_uid) { 62 if (pw->pw_uid) {
63 shortcut:
67 xsetenv("USER", pw->pw_name); 64 xsetenv("USER", pw->pw_name);
68 xsetenv("LOGNAME", pw->pw_name); 65 xsetenv("LOGNAME", pw->pw_name);
69 } 66 }
67 xsetenv("HOME", pw->pw_dir);
68 xsetenv("SHELL", shell);
70 } 69 }
71} 70}
diff --git a/loginutils/login.c b/loginutils/login.c
index 5d5053840..7f8907543 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -432,7 +432,9 @@ int login_main(int argc, char **argv)
432 tmp = pw->pw_shell; 432 tmp = pw->pw_shell;
433 if (!tmp || !*tmp) 433 if (!tmp || !*tmp)
434 tmp = DEFAULT_SHELL; 434 tmp = DEFAULT_SHELL;
435 /* setup_environment params: shell, loginshell, changeenv, pw */
435 setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw); 436 setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw);
437 /* FIXME: login shell = 1 -> 3rd parameter is ignored! */
436 438
437 motd(); 439 motd();
438 440
@@ -463,7 +465,8 @@ int login_main(int argc, char **argv)
463 * should it leave SIGINT etc enabled or disabled? */ 465 * should it leave SIGINT etc enabled or disabled? */
464 signal(SIGINT, SIG_DFL); 466 signal(SIGINT, SIG_DFL);
465 467
466 run_shell(tmp, 1, 0, 0); /* exec the shell finally */ 468 /* Exec login shell with no additional parameters */
469 run_shell(tmp, 1, NULL, NULL);
467 470
468 return EXIT_FAILURE; 471 /* return EXIT_FAILURE; - not reached */
469} 472}
diff --git a/loginutils/su.c b/loginutils/su.c
index b4681fb6a..123907e28 100644
--- a/loginutils/su.c
+++ b/loginutils/su.c
@@ -36,7 +36,7 @@ int su_main(int argc, char **argv)
36 /* get user if specified */ 36 /* get user if specified */
37 if (argc) { 37 if (argc) {
38 opt_username = argv[0]; 38 opt_username = argv[0];
39// argc--; 39 //argc--; - not used below anyway
40 argv++; 40 argv++;
41 } 41 }
42 42
@@ -86,18 +86,19 @@ int su_main(int argc, char **argv)
86 compromise the account by allowing access with a standard 86 compromise the account by allowing access with a standard
87 shell. */ 87 shell. */
88 bb_error_msg("using restricted shell"); 88 bb_error_msg("using restricted shell");
89 opt_shell = 0; 89 opt_shell = NULL;
90 } 90 }
91#endif 91#endif
92 if (!opt_shell) 92 if (!opt_shell)
93 opt_shell = pw->pw_shell; 93 opt_shell = pw->pw_shell;
94 94
95 change_identity(pw); 95 change_identity(pw);
96 /* setup_environment params: shell, loginshell, changeenv, pw */
96 setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw); 97 setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw);
97 USE_SELINUX(set_current_security_context(NULL);) 98 USE_SELINUX(set_current_security_context(NULL);)
98 99
99 /* Never returns */ 100 /* Never returns */
100 run_shell(opt_shell, flags & SU_OPT_l, opt_command, (const char**)argv); 101 run_shell(opt_shell, flags & SU_OPT_l, opt_command, (const char**)argv);
101 102
102 return EXIT_FAILURE; 103 /* return EXIT_FAILURE; - not reached */
103} 104}
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index 5f0a4081d..5c73bda93 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -112,14 +112,15 @@ int sulogin_main(int argc, char **argv)
112 USE_SELINUX(renew_current_security_context()); 112 USE_SELINUX(renew_current_security_context());
113 113
114 shell = getenv("SUSHELL"); 114 shell = getenv("SUSHELL");
115 if (!shell) shell = getenv("sushell"); 115 if (!shell)
116 shell = getenv("sushell");
116 if (!shell) { 117 if (!shell) {
117 shell = "/bin/sh"; 118 shell = "/bin/sh";
118 if (pwd->pw_shell[0]) 119 if (pwd->pw_shell[0])
119 shell = pwd->pw_shell; 120 shell = pwd->pw_shell;
120 } 121 }
121 run_shell(shell, 1, 0, 0); 122 /* Exec login shell with no additional parameters. Never returns. */
122 /* never returns */ 123 run_shell(shell, 1, NULL, NULL);
123 124
124auth_error: 125auth_error:
125 bb_error_msg_and_die("no password entry for 'root'"); 126 bb_error_msg_and_die("no password entry for 'root'");