otherwise initialize SELinux and load the policy. Patch from
Petter Reinholdtsen.
* Make quotes visible in example of the manual page of fstab-decode
+ * Sulogin: enforce reconnection of stdin/stdout/stderr if a device
+ was specified.
[ Petter Reinholdtsen ]
* Next release will be 2.89dsf.
* /dev/console if but only if /dev/console is used. On Linux
* this can be more than one device, e.g. a serial line as well
* as a virtual console as well as a simple printer.
+ *
+ * Returns 1 if stdout and stderr should be reconnected and 0
+ * otherwise.
*/
-void detect_consoles(const char *device, int fallback)
+int detect_consoles(const char *device, int fallback)
{
- int fd;
+ int fd, ret = 0;
#ifdef __linux__
char *attrib, *cmdline;
FILE *fc;
#endif
if (!device || *device == '\0')
fd = dup(fallback);
- else fd = open(device, O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC);
+ else {
+ fd = open(device, O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC);
+ ret = 1;
+ }
if (fd >= 0) {
DIR *dir;
goto fallback;
}
comparedev = st.st_rdev;
+
+ if (ret && (fstat(fallback, &st) < 0 || comparedev != st.st_rdev))
+ dup2(fd, fallback);
#ifdef __linux__
/*
* Check if the device detection for Linux system console should be used.
closedir(dir);
if (!consoles)
goto fallback;
- return;
+ return ret;
}
#ifdef __linux__
console:
}
closedir(dir);
fclose(fc);
- return;
+ return ret;
}
/*
* Detection of devices used for Linux system console using
free(attrib);
if (!consoles)
goto fallback;
- return;
+ return ret;
}
/*
if (consoles) {
if (!device || *device == '\0')
consoles->fd = fallback;
- return;
+ return ret;
}
#endif
goto fallback;
}
- return;
+ return ret;
}
#endif /* __linux __ */
fallback:
if (consoles)
consoles->fd = fallback;
}
+ return ret;
}
struct console *next;
};
extern struct console *consoles;
-extern void detect_consoles(const char *, int);
+extern int detect_consoles(const char *, int);
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.
*/
break;
}
fprintf(stderr, "Login incorrect.\n\r");
+ sleep(3);
}
if (alarm_rised) {
tcfinal(con);