From 7fa3bcae122080188742b037d70e2f087ccbdb89 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Fri, 14 Oct 2016 07:27:00 -0300 Subject: Prevent /etc/ttys to miss essential lines We do not create /etc/ttys from scratch but we change it on every boot. If original file is corrupted for some reason we can end up with a file missing essential lines. Added a check to verify if these lines are missing and add them back in this case --- src/etc/inc/pfsense-utils.inc | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'src/etc/inc/pfsense-utils.inc') diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc index 05cd77c..8b628d5 100644 --- a/src/etc/inc/pfsense-utils.inc +++ b/src/etc/inc/pfsense-utils.inc @@ -1215,17 +1215,54 @@ function setup_serial_port($when = "save", $path = "") { $console_type = 'al.Pc'; $serial_type = 'al.' . $serialspeed; } + + $console_line = "console none unknown off secure\n"; + $ttyv0_line = "ttyv0 \"/usr/libexec/getty {$console_type}\" cons25 on secure\n"; + $ttyu_line = "\"/usr/libexec/getty {$serial_type}\" cons25 {$on_off} secure\n"; + + $found = array(); + foreach ($ttys_split as $tty) { if (stristr($tty, "ttyv0")) { - fwrite($fd, "ttyv0 \"/usr/libexec/getty {$console_type}\" cons25 on secure\n"); - } else if (stristr($tty, "ttyu")) { + $found['ttyv0'] = 1; + fwrite($fd, $ttyv0_line); + } elseif (stristr($tty, "ttyu")) { $ttyn = substr($tty, 0, 5); - fwrite($fd, "{$ttyn} \"/usr/libexec/getty {$serial_type}\" cons25 {$on_off} secure\n"); + $found[$ttyn] = 1; + fwrite($fd, "{$ttyn} {$ttyu_line}"); + } elseif (substr($tty, 0, 7) == 'console') { + $found['console'] = 1; + fwrite($fd, $tty . "\n"); } else { fwrite($fd, $tty . "\n"); } } unset($on_off, $console_type, $serial_type); + + /* Detect missing main lines on original file and try to rebuild it */ + $items = array( + 'console', + 'ttyv0', + 'ttyu0', + 'ttyu1', + 'ttyu2', + 'ttyu3' + ); + + foreach ($items as $item) { + if (isset($found[$item])) { + continue; + } + + if ($item == 'console') { + fwrite($fd, $console_line); + } elseif ($item == 'ttyv0') { + fwrite($fd, $ttyv0_line); + } else { + fwrite($fd, "{$item} {$ttyu_line}"); + } + } + fclose($fd); if ($when != "upgrade") { reload_ttys(); -- cgit v1.1