aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-31 17:34:44 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-31 17:34:44 +0000
commita02e6326055c1c1a55987926b9471c4a760b9689 (patch)
treea4e2c6524a05600038ce3e0b8526be8fb89af1ad
parent861773fd9a4ba0a118bea39db8413d209665ce53 (diff)
downloadbusybox-w32-a02e6326055c1c1a55987926b9471c4a760b9689.tar.gz
busybox-w32-a02e6326055c1c1a55987926b9471c4a760b9689.tar.bz2
busybox-w32-a02e6326055c1c1a55987926b9471c4a760b9689.zip
login: re-enable Ctrl-^C before execing shell.
git-svn-id: svn://busybox.net/trunk/busybox@16477 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--libbb/change_identity.c13
-rw-r--r--libbb/login.c119
-rw-r--r--loginutils/login.c14
3 files changed, 67 insertions, 79 deletions
diff --git a/libbb/change_identity.c b/libbb/change_identity.c
index 63c5ae1c8..3f888f523 100644
--- a/libbb/change_identity.c
+++ b/libbb/change_identity.c
@@ -28,14 +28,6 @@
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
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
39#include "libbb.h" 31#include "libbb.h"
40 32
41 33
@@ -44,8 +36,7 @@ const char *change_identity_e2str(const struct passwd *pw)
44{ 36{
45 if (initgroups(pw->pw_name, pw->pw_gid) == -1) 37 if (initgroups(pw->pw_name, pw->pw_gid) == -1)
46 return "cannot set groups"; 38 return "cannot set groups";
47 endgrent(); 39 endgrent(); /* ?? */
48
49 xsetgid(pw->pw_gid); 40 xsetgid(pw->pw_gid);
50 xsetuid(pw->pw_uid); 41 xsetuid(pw->pw_uid);
51 return NULL; 42 return NULL;
@@ -55,6 +46,6 @@ void change_identity(const struct passwd *pw)
55{ 46{
56 const char *err_msg = change_identity_e2str(pw); 47 const char *err_msg = change_identity_e2str(pw);
57 48
58 if(err_msg) 49 if (err_msg)
59 bb_perror_msg_and_die("%s", err_msg); 50 bb_perror_msg_and_die("%s", err_msg);
60} 51}
diff --git a/libbb/login.c b/libbb/login.c
index 646995b0b..6ebb9a6a0 100644
--- a/libbb/login.c
+++ b/libbb/login.c
@@ -36,83 +36,70 @@ void print_login_issue(const char *issue_file, const char *tty)
36 36
37 puts("\r"); /* start a new line */ 37 puts("\r"); /* start a new line */
38 38
39 if ((fd = fopen(issue_file, "r"))) { 39 fd = fopen(issue_file, "r");
40 while ((c = fgetc(fd)) != EOF) { 40 if (!fd)
41 outbuf = buf; 41 return;
42 buf[0] = c; 42 while ((c = fgetc(fd)) != EOF) {
43 if(c == '\n') { 43 outbuf = buf;
44 buf[1] = '\r'; 44 buf[0] = c;
45 buf[2] = 0; 45 buf[1] = '\0';
46 } else { 46 if(c == '\n') {
47 buf[1] = 0; 47 buf[1] = '\r';
48 } 48 buf[2] = '\0';
49 if (c == '\\' || c == '%') { 49 }
50 c = fgetc(fd); 50 if (c == '\\' || c == '%') {
51 switch (c) { 51 c = fgetc(fd);
52 case 's': 52 switch (c) {
53 outbuf = uts.sysname; 53 case 's':
54 break; 54 outbuf = uts.sysname;
55 55 break;
56 case 'n': 56 case 'n':
57 outbuf = uts.nodename; 57 outbuf = uts.nodename;
58 break; 58 break;
59 59 case 'r':
60 case 'r': 60 outbuf = uts.release;
61 outbuf = uts.release; 61 break;
62 break; 62 case 'v':
63 63 outbuf = uts.version;
64 case 'v': 64 break;
65 outbuf = uts.version; 65 case 'm':
66 break; 66 outbuf = uts.machine;
67 67 break;
68 case 'm': 68 case 'D':
69 outbuf = uts.machine; 69 case 'o':
70 break; 70 c = getdomainname(buf, sizeof(buf) - 1);
71 71 buf[c >= 0 ? c : 0] = '\0';
72 case 'D': 72 break;
73 case 'o': 73 case 'd':
74 c = getdomainname(buf, sizeof(buf) - 1); 74 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
75 buf[c >= 0 ? c : 0] = '\0'; 75 break;
76 break; 76 case 't':
77 77 strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
78 case 'd': 78 break;
79 strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); 79 case 'h':
80 break; 80 gethostname(buf, sizeof(buf) - 1);
81 81 buf[sizeof(buf) - 1] = '\0';
82 case 't': 82 break;
83 strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); 83 case 'l':
84 break; 84 outbuf = tty;
85 85 break;
86 case 'h': 86 default:
87 gethostname(buf, sizeof(buf) - 1); 87 buf[0] = c;
88 buf[sizeof(buf) - 1] = '\0';
89 break;
90
91 case 'l':
92 outbuf = tty;
93 break;
94
95 default:
96 buf[0] = c;
97 }
98 } 88 }
99 fputs(outbuf, stdout);
100 } 89 }
101 90 fputs(outbuf, stdout);
102 fclose(fd);
103
104 fflush(stdout);
105 } 91 }
92 fclose(fd);
93 fflush(stdout);
106} 94}
107 95
108void print_login_prompt(void) 96void print_login_prompt(void)
109{ 97{
110 char buf[MAXHOSTNAMELEN+1]; 98 char buf[MAXHOSTNAMELEN+1];
111 99
112 if(gethostname(buf, MAXHOSTNAMELEN) == 0) 100 if (gethostname(buf, MAXHOSTNAMELEN) == 0)
113 fputs(buf, stdout); 101 fputs(buf, stdout);
114 102
115 fputs(LOGIN, stdout); 103 fputs(LOGIN, stdout);
116 fflush(stdout); 104 fflush(stdout);
117} 105}
118
diff --git a/loginutils/login.c b/loginutils/login.c
index 8003922f9..04283007b 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -342,6 +342,7 @@ auth_failed:
342 fchown(0, pw->pw_uid, pw->pw_gid); 342 fchown(0, pw->pw_uid, pw->pw_gid);
343 fchmod(0, 0600); 343 fchmod(0, 0600);
344 344
345 /* TODO: be nommu-friendly, use spawn? */
345 if (ENABLE_LOGIN_SCRIPTS) { 346 if (ENABLE_LOGIN_SCRIPTS) {
346 char *script = getenv("LOGIN_PRE_SUID_SCRIPT"); 347 char *script = getenv("LOGIN_PRE_SUID_SCRIPT");
347 if (script) { 348 if (script) {
@@ -370,7 +371,6 @@ auth_failed:
370 setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw); 371 setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw);
371 372
372 motd(); 373 motd();
373 signal(SIGALRM, SIG_DFL); /* default alarm signal */
374 374
375 if (pw->pw_uid == 0) 375 if (pw->pw_uid == 0)
376 syslog(LOG_INFO, "root login%s", fromhost); 376 syslog(LOG_INFO, "root login%s", fromhost);
@@ -379,7 +379,17 @@ auth_failed:
379 * but let's play the game for now */ 379 * but let's play the game for now */
380 set_current_security_context(user_sid); 380 set_current_security_context(user_sid);
381#endif 381#endif
382 run_shell(tmp, 1, 0, 0); /* exec the shell finally. */ 382
383 // util-linux login also does:
384 // /* start new session */
385 // setsid();
386 // /* TIOCSCTTY: steal tty from other process group */
387 // if (ioctl(0, TIOCSCTTY, 1)) error_msg...
388
389 signal(SIGALRM, SIG_DFL); /* set signals to defaults */
390 signal(SIGINT, SIG_DFL);
391
392 run_shell(tmp, 1, 0, 0); /* exec the shell finally */
383 393
384 return EXIT_FAILURE; 394 return EXIT_FAILURE;
385} 395}