#include <sys/ioctl.h>
#if defined(__GLIBC__)
# include <crypt.h>
-# define dovoid(f) if ((f)){}
#endif
#ifdef __linux__
# include <sys/statfs.h>
# ifndef MNT_DETACH
# define MNT_DETACH 2
# endif
+# define dovoid(f) if ((f)){}
#endif
#define BS CTRL('h')
struct termios tty;
char *ret = pass;
unsigned char tc;
- char ascval;
+ char c, ascval;
int eightbit;
- int c, fd;
+ int fd;
if (con->flags & CON_NOTTY)
goto out;
cp->eol = *ptr = '\0';
eightbit = ((con->flags & CON_SERIAL) == 0 || (tty.c_cflag & (PARODD|PARENB)) == 0);
- while (cp->eol == 0) {
+ while (cp->eol == '\0') {
if (read(fd, &c, 1) < 1) {
if (errno == EINTR || errno == EAGAIN) {
usleep(1000);
}
switch (ascval) {
+ case 0:
+ *ptr = '\0';
+ goto quit;
case CR:
case NL:
*ptr = '\0';
char *tty = NULL;
struct passwd *pwd;
int c, status = 0;
+ int reconnect = 0;
int opt_e = 0;
struct console *con;
pid_t pid;
}
/*
- * See if we have a timeout flag.
+ * See if we have a timeout flag.
*/
opterr = 0;
while((c = getopt(argc, argv, "ept:")) != EOF) switch(c) {
saved_sighup = signal(SIGHUP, SIG_IGN);
/*
- * See if we need to open an other tty device.
+ * See if we need to open an other tty device.
*/
if (optind < argc)
tty = argv[optind];
tty = getenv("CONSOLE");
/*
- * Detect possible consoles, use stdin as fallback.
+ * Detect possible consoles, use stdin as fallback.
+ * If an optional tty is given, reconnect it to stdin.
*/
- detect_consoles(tty, 0);
+ reconnect = detect_consoles(tty, 0);
/*
* Should not happen
exit(1);
}
+ /*
+ * If previous stdin was not the speified tty and therefore reconnected
+ * to the specified tty also reconnect stdout and stderr.
+ */
+ if (reconnect) {
+ if (isatty(1) == 0)
+ dup2(0, 1);
+ if (isatty(2) == 0)
+ dup2(0, 2);
+ }
+
/*
* Get the root password.
*/
while (1) {
char *passwd = pwd->pw_passwd;
char *answer;
- int failed = 0;
+ int failed = 0, doshell = 0;
doprompt(passwd, con);
if ((answer = getpasswd(con)) == NULL)
break;
- if (passwd[0] == '\0' ||
- strcmp(crypt(answer, passwd), passwd) == 0) {
+ if (passwd[0] == '\0')
+ doshell++;
+ else {
+ char *cryptbuf;
+ cryptbuf = crypt(answer, passwd);
+ if (cryptbuf == NULL)
+ fprintf(stderr, "sulogin: crypt failed: %m\n\r");
+ else if (strcmp(cryptbuf, pwd->pw_passwd) == 0)
+ doshell++;
+ }
+
+ if (doshell) {
*usemask |= (1<<con->id);
sushell(pwd);
*usemask &= ~(1<<con->id);
failed++;
}
+
signal(SIGQUIT, SIG_IGN);
signal(SIGTSTP, SIG_IGN);
signal(SIGINT, SIG_IGN);
break;
}
fprintf(stderr, "Login incorrect.\n\r");
+ sleep(3);
}
if (alarm_rised) {
tcfinal(con);
- printf("Timed out.\n\r");
+ fprintf(stderr, "Timed out.\n\r");
}
/*
* User may pressed Control-D.