login: re-enable Ctrl-^C before execing shell.

This commit is contained in:
Denis Vlasenko 2006-10-31 17:34:44 +00:00
parent 3b8ff68ec8
commit 6ae8079e2d
3 changed files with 68 additions and 80 deletions

View File

@ -28,14 +28,6 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <ctype.h>
#include "libbb.h" #include "libbb.h"
@ -44,8 +36,7 @@ const char *change_identity_e2str(const struct passwd *pw)
{ {
if (initgroups(pw->pw_name, pw->pw_gid) == -1) if (initgroups(pw->pw_name, pw->pw_gid) == -1)
return "cannot set groups"; return "cannot set groups";
endgrent(); endgrent(); /* ?? */
xsetgid(pw->pw_gid); xsetgid(pw->pw_gid);
xsetuid(pw->pw_uid); xsetuid(pw->pw_uid);
return NULL; return NULL;

View File

@ -36,15 +36,16 @@ void print_login_issue(const char *issue_file, const char *tty)
puts("\r"); /* start a new line */ puts("\r"); /* start a new line */
if ((fd = fopen(issue_file, "r"))) { fd = fopen(issue_file, "r");
if (!fd)
return;
while ((c = fgetc(fd)) != EOF) { while ((c = fgetc(fd)) != EOF) {
outbuf = buf; outbuf = buf;
buf[0] = c; buf[0] = c;
buf[1] = '\0';
if(c == '\n') { if(c == '\n') {
buf[1] = '\r'; buf[1] = '\r';
buf[2] = 0; buf[2] = '\0';
} else {
buf[1] = 0;
} }
if (c == '\\' || c == '%') { if (c == '\\' || c == '%') {
c = fgetc(fd); c = fgetc(fd);
@ -52,58 +53,45 @@ void print_login_issue(const char *issue_file, const char *tty)
case 's': case 's':
outbuf = uts.sysname; outbuf = uts.sysname;
break; break;
case 'n': case 'n':
outbuf = uts.nodename; outbuf = uts.nodename;
break; break;
case 'r': case 'r':
outbuf = uts.release; outbuf = uts.release;
break; break;
case 'v': case 'v':
outbuf = uts.version; outbuf = uts.version;
break; break;
case 'm': case 'm':
outbuf = uts.machine; outbuf = uts.machine;
break; break;
case 'D': case 'D':
case 'o': case 'o':
c = getdomainname(buf, sizeof(buf) - 1); c = getdomainname(buf, sizeof(buf) - 1);
buf[c >= 0 ? c : 0] = '\0'; buf[c >= 0 ? c : 0] = '\0';
break; break;
case 'd': case 'd':
strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
break; break;
case 't': case 't':
strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
break; break;
case 'h': case 'h':
gethostname(buf, sizeof(buf) - 1); gethostname(buf, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
break; break;
case 'l': case 'l':
outbuf = tty; outbuf = tty;
break; break;
default: default:
buf[0] = c; buf[0] = c;
} }
} }
fputs(outbuf, stdout); fputs(outbuf, stdout);
} }
fclose(fd); fclose(fd);
fflush(stdout); fflush(stdout);
} }
}
void print_login_prompt(void) void print_login_prompt(void)
{ {
@ -115,4 +103,3 @@ void print_login_prompt(void)
fputs(LOGIN, stdout); fputs(LOGIN, stdout);
fflush(stdout); fflush(stdout);
} }

View File

@ -342,6 +342,7 @@ auth_failed:
fchown(0, pw->pw_uid, pw->pw_gid); fchown(0, pw->pw_uid, pw->pw_gid);
fchmod(0, 0600); fchmod(0, 0600);
/* TODO: be nommu-friendly, use spawn? */
if (ENABLE_LOGIN_SCRIPTS) { if (ENABLE_LOGIN_SCRIPTS) {
char *script = getenv("LOGIN_PRE_SUID_SCRIPT"); char *script = getenv("LOGIN_PRE_SUID_SCRIPT");
if (script) { if (script) {
@ -370,7 +371,6 @@ auth_failed:
setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw); setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw);
motd(); motd();
signal(SIGALRM, SIG_DFL); /* default alarm signal */
if (pw->pw_uid == 0) if (pw->pw_uid == 0)
syslog(LOG_INFO, "root login%s", fromhost); syslog(LOG_INFO, "root login%s", fromhost);
@ -379,7 +379,17 @@ auth_failed:
* but let's play the game for now */ * but let's play the game for now */
set_current_security_context(user_sid); set_current_security_context(user_sid);
#endif #endif
run_shell(tmp, 1, 0, 0); /* exec the shell finally. */
// util-linux login also does:
// /* start new session */
// setsid();
// /* TIOCSCTTY: steal tty from other process group */
// if (ioctl(0, TIOCSCTTY, 1)) error_msg...
signal(SIGALRM, SIG_DFL); /* set signals to defaults */
signal(SIGINT, SIG_DFL);
run_shell(tmp, 1, 0, 0); /* exec the shell finally */
return EXIT_FAILURE; return EXIT_FAILURE;
} }