aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libbb.h6
-rw-r--r--libbb/change_identity.c12
-rw-r--r--loginutils/Config.in8
-rw-r--r--loginutils/login.c22
4 files changed, 39 insertions, 9 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 6bea048a3..7fbeb4fb7 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -490,9 +490,9 @@ void xprint_and_close_file(FILE *file);
490 490
491#define FAIL_DELAY 3 491#define FAIL_DELAY 3
492extern void bb_do_delay(int seconds); 492extern void bb_do_delay(int seconds);
493extern void change_identity ( const struct passwd *pw ); 493extern void change_identity(const struct passwd *pw);
494extern const char *change_identity_e2str ( const struct passwd *pw ); 494extern const char *change_identity_e2str(const struct passwd *pw);
495extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args); 495extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args);
496#ifdef CONFIG_SELINUX 496#ifdef CONFIG_SELINUX
497extern void renew_current_security_context(void); 497extern void renew_current_security_context(void);
498extern void set_current_security_context(security_context_t sid); 498extern void set_current_security_context(security_context_t sid);
diff --git a/libbb/change_identity.c b/libbb/change_identity.c
index 74ffccbd3..63c5ae1c8 100644
--- a/libbb/change_identity.c
+++ b/libbb/change_identity.c
@@ -40,21 +40,21 @@
40 40
41 41
42/* Become the user and group(s) specified by PW. */ 42/* Become the user and group(s) specified by PW. */
43const char *change_identity_e2str ( const struct passwd *pw ) 43const char *change_identity_e2str(const struct passwd *pw)
44{ 44{
45 if ( initgroups ( pw-> pw_name, pw-> pw_gid ) == -1 ) 45 if (initgroups(pw->pw_name, pw->pw_gid) == -1)
46 return "cannot set groups"; 46 return "cannot set groups";
47 endgrent ( ); 47 endgrent();
48 48
49 xsetgid(pw-> pw_gid); 49 xsetgid(pw->pw_gid);
50 xsetuid(pw->pw_uid); 50 xsetuid(pw->pw_uid);
51 return NULL; 51 return NULL;
52} 52}
53 53
54void change_identity ( const struct passwd *pw ) 54void change_identity(const struct passwd *pw)
55{ 55{
56 const char *err_msg = change_identity_e2str(pw); 56 const char *err_msg = change_identity_e2str(pw);
57 57
58 if(err_msg) 58 if(err_msg)
59 bb_perror_msg_and_die ( "%s", err_msg ); 59 bb_perror_msg_and_die("%s", err_msg);
60} 60}
diff --git a/loginutils/Config.in b/loginutils/Config.in
index 71e0a3ae1..6e45b706a 100644
--- a/loginutils/Config.in
+++ b/loginutils/Config.in
@@ -111,6 +111,14 @@ config CONFIG_LOGIN
111 Note that Busybox binary must be setuid root for this applet to 111 Note that Busybox binary must be setuid root for this applet to
112 work properly. 112 work properly.
113 113
114config CONFIG_LOGIN_SCRIPTS
115 bool "Support for login scripts"
116 depends on CONFIG_LOGIN
117 default n
118 help
119 Enable this if you want login to execute $LOGIN_PRE_SUID_SCRIPT
120 just prior to swithching from root to logged-in user.
121
114config CONFIG_FEATURE_SECURETTY 122config CONFIG_FEATURE_SECURETTY
115 bool "Support for /etc/securetty" 123 bool "Support for /etc/securetty"
116 default y 124 default y
diff --git a/loginutils/login.c b/loginutils/login.c
index 5b4edd8de..39d980fa8 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -15,6 +15,7 @@
15#include <sys/resource.h> 15#include <sys/resource.h>
16#include <sys/stat.h> 16#include <sys/stat.h>
17#include <sys/types.h> 17#include <sys/types.h>
18#include <sys/wait.h>
18#include <ctype.h> 19#include <ctype.h>
19#include <time.h> 20#include <time.h>
20 21
@@ -258,6 +259,27 @@ auth_ok:
258 chown ( full_tty, pw-> pw_uid, pw-> pw_gid ); 259 chown ( full_tty, pw-> pw_uid, pw-> pw_gid );
259 chmod ( full_tty, 0600 ); 260 chmod ( full_tty, 0600 );
260 261
262 if (ENABLE_LOGIN_SCRIPTS) {
263 char *script = getenv("LOGIN_PRE_SUID_SCRIPT");
264 if (script) {
265 char *t_argv[2] = { script, NULL };
266 switch(fork()) {
267 case -1: break;
268 case 0: /* child */
269 xchdir("/");
270 setenv("LOGIN_TTY", full_tty, 1);
271 setenv("LOGIN_USER", pw->pw_name, 1);
272 setenv("LOGIN_UID", utoa(pw->pw_uid), 1);
273 setenv("LOGIN_GID", utoa(pw->pw_gid), 1);
274 setenv("LOGIN_SHELL", pw->pw_shell, 1);
275 execvp(script, t_argv);
276 exit(1);
277 default: /* parent */
278 wait(NULL);
279 }
280 }
281 }
282
261 change_identity ( pw ); 283 change_identity ( pw );
262 tmp = pw-> pw_shell; 284 tmp = pw-> pw_shell;
263 if(!tmp || !*tmp) 285 if(!tmp || !*tmp)