login: re-enable Ctrl-^C before execing shell.
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 31 Oct 2006 17:34:44 +0000 (17:34 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 31 Oct 2006 17:34:44 +0000 (17:34 -0000)
libbb/change_identity.c
libbb/login.c
loginutils/login.c

index 63c5ae1c8996d59d05a14629806abd8d60c23dfe..3f888f523bd1f53a97f7e824545b15b82af8c82f 100644 (file)
  * 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"
 
 
@@ -44,8 +36,7 @@ const char *change_identity_e2str(const struct passwd *pw)
 {
        if (initgroups(pw->pw_name, pw->pw_gid) == -1)
                return "cannot set groups";
-       endgrent();
-
+       endgrent(); /* ?? */
        xsetgid(pw->pw_gid);
        xsetuid(pw->pw_uid);
        return NULL;
@@ -55,6 +46,6 @@ void change_identity(const struct passwd *pw)
 {
        const char *err_msg = change_identity_e2str(pw);
 
-       if(err_msg)
+       if (err_msg)
                bb_perror_msg_and_die("%s", err_msg);
 }
index 646995b0bcc27cd938c4db78284f51b4510de11e..6ebb9a6a0c577250207a9e5a4ac51ba16ee825a8 100644 (file)
@@ -36,83 +36,70 @@ void print_login_issue(const char *issue_file, const char *tty)
 
        puts("\r");     /* start a new line */
 
-       if ((fd = fopen(issue_file, "r"))) {
-               while ((c = fgetc(fd)) != EOF) {
-                       outbuf = buf;
-                       buf[0] = c;
-                       if(c == '\n') {
-                               buf[1] = '\r';
-                               buf[2] = 0;
-                       } else {
-                               buf[1] = 0;
-                       }
-                       if (c == '\\' || c == '%') {
-                               c = fgetc(fd);
-                               switch (c) {
-                                       case 's':
-                                               outbuf = uts.sysname;
-                                               break;
-
-                                       case 'n':
-                                               outbuf = uts.nodename;
-                                               break;
-
-                                       case 'r':
-                                               outbuf = uts.release;
-                                               break;
-
-                                       case 'v':
-                                               outbuf = uts.version;
-                                               break;
-
-                                       case 'm':
-                                               outbuf = uts.machine;
-                                               break;
-
-                                       case 'D':
-                                       case 'o':
-                                               c = getdomainname(buf, sizeof(buf) - 1);
-                                               buf[c >= 0 ? c : 0] = '\0';
-                                               break;
-
-                                       case 'd':
-                                               strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
-                                               break;
-
-                                       case 't':
-                                               strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
-                                               break;
-
-                                       case 'h':
-                                               gethostname(buf, sizeof(buf) - 1);
-                                               buf[sizeof(buf) - 1] = '\0';
-                                               break;
-
-                                       case 'l':
-                                               outbuf = tty;
-                                               break;
-
-                                       default:
-                                               buf[0] = c;
-                               }
+       fd = fopen(issue_file, "r");
+       if (!fd)
+               return;
+       while ((c = fgetc(fd)) != EOF) {
+               outbuf = buf;
+               buf[0] = c;
+               buf[1] = '\0';
+               if(c == '\n') {
+                       buf[1] = '\r';
+                       buf[2] = '\0';
+               }
+               if (c == '\\' || c == '%') {
+                       c = fgetc(fd);
+                       switch (c) {
+                       case 's':
+                               outbuf = uts.sysname;
+                               break;
+                       case 'n':
+                               outbuf = uts.nodename;
+                               break;
+                       case 'r':
+                               outbuf = uts.release;
+                               break;
+                       case 'v':
+                               outbuf = uts.version;
+                               break;
+                       case 'm':
+                               outbuf = uts.machine;
+                               break;
+                       case 'D':
+                       case 'o':
+                               c = getdomainname(buf, sizeof(buf) - 1);
+                               buf[c >= 0 ? c : 0] = '\0';
+                               break;
+                       case 'd':
+                               strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
+                               break;
+                       case 't':
+                               strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
+                               break;
+                       case 'h':
+                               gethostname(buf, sizeof(buf) - 1);
+                               buf[sizeof(buf) - 1] = '\0';
+                               break;
+                       case 'l':
+                               outbuf = tty;
+                               break;
+                       default:
+                               buf[0] = c;
                        }
-                       fputs(outbuf, stdout);
                }
-
-               fclose(fd);
-
-               fflush(stdout);
+               fputs(outbuf, stdout);
        }
+       fclose(fd);
+       fflush(stdout);
 }
 
 void print_login_prompt(void)
 {
        char buf[MAXHOSTNAMELEN+1];
 
-       if(gethostname(buf, MAXHOSTNAMELEN) == 0)
+       if (gethostname(buf, MAXHOSTNAMELEN) == 0)
                fputs(buf, stdout);
 
        fputs(LOGIN, stdout);
        fflush(stdout);
 }
-
index 8003922f90ad0af5c8f6ec28e8b4cf6f174edf6f..04283007b213e1a7908c2aa059cee19e2b3d86f2 100644 (file)
@@ -342,6 +342,7 @@ auth_failed:
        fchown(0, pw->pw_uid, pw->pw_gid);
        fchmod(0, 0600);
 
+       /* TODO: be nommu-friendly, use spawn? */
        if (ENABLE_LOGIN_SCRIPTS) {
                char *script = getenv("LOGIN_PRE_SUID_SCRIPT");
                if (script) {
@@ -370,7 +371,6 @@ auth_failed:
        setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw);
 
        motd();
-       signal(SIGALRM, SIG_DFL);       /* default alarm signal */
 
        if (pw->pw_uid == 0)
                syslog(LOG_INFO, "root login%s", fromhost);
@@ -379,7 +379,17 @@ auth_failed:
         * but let's play the game for now */
        set_current_security_context(user_sid);
 #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;
 }