diff options
author | Renato Botelho <renato@netgate.com> | 2016-10-14 07:27:00 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-10-14 08:49:43 -0300 |
commit | 7fa3bcae122080188742b037d70e2f087ccbdb89 (patch) | |
tree | 4b489b3925a1d553b2af21d3b5357c93b723f708 /src/etc/inc/pfsense-utils.inc | |
parent | a4cd0c5ff74ed2e6de5213dd06f05de18300a441 (diff) | |
download | pfsense-7fa3bcae122080188742b037d70e2f087ccbdb89.zip pfsense-7fa3bcae122080188742b037d70e2f087ccbdb89.tar.gz |
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
Diffstat (limited to 'src/etc/inc/pfsense-utils.inc')
-rw-r--r-- | src/etc/inc/pfsense-utils.inc | 43 |
1 files changed, 40 insertions, 3 deletions
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(); |