|
|
169b953 |
--- util-linux-2.13-pre1/login-utils/login.c.ctty3 2005-08-02 18:10:24.000000000 +0200
|
|
|
169b953 |
+++ util-linux-2.13-pre1/login-utils/login.c 2005-08-15 15:51:35.000000000 +0200
|
|
|
169b953 |
@@ -285,7 +285,21 @@
|
|
|
169b953 |
updwtmp(_PATH_BTMP, &ut);
|
|
|
169b953 |
#endif
|
|
|
169b953 |
}
|
|
|
169b953 |
-#endif /* HAVE_SECURITY_PAM_MISC_H */
|
|
|
169b953 |
+
|
|
|
169b953 |
+static int childPid = 0;
|
|
|
169b953 |
+static volatile int got_sig = 0;
|
|
|
169b953 |
+
|
|
|
169b953 |
+static void
|
|
|
169b953 |
+parent_sig_handler(int signal)
|
|
|
169b953 |
+{
|
|
|
169b953 |
+ if(childPid)
|
|
|
169b953 |
+ kill(-childPid, signal);
|
|
|
169b953 |
+ else
|
|
|
169b953 |
+ got_sig = 1;
|
|
|
169b953 |
+ if(signal == SIGTERM)
|
|
|
169b953 |
+ kill(-childPid, SIGHUP); /* because the shell often ignores SIGTERM */
|
|
|
169b953 |
+}
|
|
|
169b953 |
+#endif /* HAVE_SECURITY_PAM_MISC_H */
|
|
|
169b953 |
|
|
|
169b953 |
int
|
|
|
169b953 |
main(int argc, char **argv)
|
|
|
169b953 |
@@ -307,7 +321,7 @@
|
|
|
169b953 |
int retcode;
|
|
|
169b953 |
pam_handle_t *pamh = NULL;
|
|
|
169b953 |
struct pam_conv conv = { misc_conv, NULL };
|
|
|
169b953 |
- pid_t childPid;
|
|
|
169b953 |
+ struct sigaction sa, oldsa_hup, oldsa_term;
|
|
|
169b953 |
#else
|
|
|
169b953 |
char *salt, *pp;
|
|
|
169b953 |
#endif
|
|
|
169b953 |
@@ -1023,7 +1037,18 @@
|
|
|
169b953 |
* We must fork before setuid() because we need to call
|
|
|
169b953 |
* pam_close_session() as root.
|
|
|
169b953 |
*/
|
|
|
169b953 |
+ memset(&sa, 0, sizeof(sa));
|
|
|
169b953 |
+ sa.sa_handler = SIG_IGN;
|
|
|
169b953 |
+ sigaction(SIGINT, &sa, NULL);
|
|
|
169b953 |
+
|
|
|
169b953 |
+ sigaction(SIGHUP, &sa, &oldsa_hup); /* ignore while we detach from the tty */
|
|
|
169b953 |
+ ioctl(0, TIOCNOTTY, NULL);
|
|
|
169b953 |
+
|
|
|
169b953 |
+ sa.sa_handler = parent_sig_handler;
|
|
|
169b953 |
+ sigaction(SIGHUP, &sa, NULL);
|
|
|
169b953 |
+ sigaction(SIGTERM, &sa, &oldsa_term);
|
|
|
169b953 |
|
|
|
169b953 |
+ closelog();
|
|
|
169b953 |
childPid = fork();
|
|
|
169b953 |
if (childPid < 0) {
|
|
|
169b953 |
int errsv = errno;
|
|
|
169b953 |
@@ -1034,19 +1059,20 @@
|
|
|
169b953 |
}
|
|
|
169b953 |
|
|
|
169b953 |
if (childPid) {
|
|
|
169b953 |
- /* parent - wait for child to finish, then cleanup session */
|
|
|
169b953 |
- signal(SIGHUP, SIG_IGN);
|
|
|
169b953 |
- signal(SIGINT, SIG_IGN);
|
|
|
169b953 |
- signal(SIGQUIT, SIG_IGN);
|
|
|
169b953 |
- signal(SIGTSTP, SIG_IGN);
|
|
|
169b953 |
- signal(SIGTTIN, SIG_IGN);
|
|
|
169b953 |
- signal(SIGTTOU, SIG_IGN);
|
|
|
169b953 |
-
|
|
|
169b953 |
- wait(NULL);
|
|
|
169b953 |
+ close(0); close(1); close(2);
|
|
|
169b953 |
+ sa.sa_handler = SIG_IGN;
|
|
|
169b953 |
+ sigaction(SIGQUIT, &sa, NULL);
|
|
|
169b953 |
+ sigaction(SIGINT, &sa, NULL);
|
|
|
169b953 |
+ while(wait(NULL) == -1 && errno == EINTR) /**/ ;
|
|
|
169b953 |
+ openlog("login", LOG_ODELAY, LOG_AUTHPRIV);
|
|
|
169b953 |
PAM_END;
|
|
|
169b953 |
exit(0);
|
|
|
169b953 |
}
|
|
|
169b953 |
|
|
|
169b953 |
+ sigaction(SIGHUP, &oldsa_hup, NULL);
|
|
|
169b953 |
+ sigaction(SIGTERM, &oldsa_term, NULL);
|
|
|
169b953 |
+ if(got_sig) exit(1);
|
|
|
169b953 |
+
|
|
|
169b953 |
/* child */
|
|
|
169b953 |
/*
|
|
|
169b953 |
* Problem: if the user's shell is a shell like ash that doesnt do
|
|
|
169b953 |
@@ -1058,14 +1084,15 @@
|
|
|
169b953 |
setsid();
|
|
|
169b953 |
|
|
|
169b953 |
/* make sure we have a controlling tty */
|
|
|
169b953 |
- opentty(ttyn);
|
|
|
169b953 |
openlog("login", LOG_ODELAY, LOG_AUTHPRIV); /* reopen */
|
|
|
169b953 |
|
|
|
169b953 |
/*
|
|
|
169b953 |
* TIOCSCTTY: steal tty from other process group.
|
|
|
169b953 |
*/
|
|
|
169b953 |
- if (ioctl(0, TIOCSCTTY, 1))
|
|
|
169b953 |
- syslog(LOG_ERR, _("TIOCSCTTY failed: %m"));
|
|
|
169b953 |
+ if (ioctl(0, TIOCSCTTY, (char *)1)) {
|
|
|
169b953 |
+ syslog(LOG_ERR, _("Couldn't set controlling terminal: %s"), strerror(errno));
|
|
|
169b953 |
+ exit(1);
|
|
|
169b953 |
+ }
|
|
|
169b953 |
#endif
|
|
|
169b953 |
signal(SIGINT, SIG_DFL);
|
|
|
169b953 |
|