From 82e6d1b388dd670346ff732423f71132d554c383 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Sun, 3 Jan 2016 12:18:43 +0545 Subject: Redmine #5727 TFTP protect against empty stuff 1) If the user presses Save when there was no interface selected, and the user has still not selected an interface, then do not attempt to unset() tftpdinterface in the config when it is already unset. 2) If the user does backup/restore or other similar stuff when the tftpboot directory has no files in it, then do not do chmod of the (non-existent) files. This avoids a "No such file or directory" message being logged. --- config/tftp2/tftp.inc | 17 ++++++++++++++++- config/tftp2/tftp.xml | 2 +- config/tftp2/tftp_files.php | 12 +++++++++--- pkg_config.10.xml | 2 +- pkg_config.8.xml | 2 +- pkg_config.8.xml.amd64 | 2 +- 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/config/tftp2/tftp.inc b/config/tftp2/tftp.inc index baf753c9..7ad4ab1b 100644 --- a/config/tftp2/tftp.inc +++ b/config/tftp2/tftp.inc @@ -41,6 +41,19 @@ function tftp_byte_convert($bytes) { return round($bytes/pow($convention, $e), 2) . ' ' . $s[$e]; } +function tftp_dir_contains_files($dir) { + if (!is_readable($dir)) { + return NULL; + } + $handle = opendir($dir); + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + return TRUE; + } + } + return FALSE; +} + function tftp_install_command() { global $config; @@ -54,7 +67,9 @@ function tftp_install_command() { // Restore backup if it exists if (file_exists($tftpbackup)) { mwexec("/usr/bin/tar xvpfz {$tftpbackup} -C /"); - mwexec("/bin/chmod -R 0744 {$tftpdir}/*"); + if (tftp_dir_contains_files($tftpdir)) { + mwexec("/bin/chmod -R 0744 {$tftpdir}/*"); + } } unset($tftpdir, $tftpbackup); } diff --git a/config/tftp2/tftp.xml b/config/tftp2/tftp.xml index 350999dd..7e5b9746 100644 --- a/config/tftp2/tftp.xml +++ b/config/tftp2/tftp.xml @@ -43,7 +43,7 @@ ]]> tftpsettings - 2.2.4 + 2.2.5 TFTP: Settings /usr/local/pkg/tftp.inc diff --git a/config/tftp2/tftp_files.php b/config/tftp2/tftp_files.php index 0cc08233..cc2947bc 100644 --- a/config/tftp2/tftp_files.php +++ b/config/tftp2/tftp_files.php @@ -76,7 +76,9 @@ if ($_GET['a'] == "other") { //echo "The file $filename exists"; conf_mount_rw(); mwexec("/usr/bin/tar -xpzC / -f {$backup_path}"); - mwexec("/bin/chmod -R 744 {$files_dir}/*"); + if (tftp_dir_contains_files($files_dir)) { + mwexec("/bin/chmod -R 744 {$files_dir}/*"); + } header( 'Location: tftp_files.php?savemsg=Backup+has+been+restored.' ) ; conf_mount_ro(); } else { @@ -92,7 +94,9 @@ if ($_POST['submit'] == "Save") { write_config(); send_event("filter reload"); } else { - unset($config['installedpackages']['tftpd']['config'][0]['tftpdinterface']); + if (isset($config['installedpackages']['tftpd']['config'][0]['tftpdinterface'])) { + unset($config['installedpackages']['tftpd']['config'][0]['tftpdinterface']); + } write_config(); send_event("filter reload"); } @@ -102,7 +106,9 @@ if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_na conf_mount_rw(); move_uploaded_file($_FILES['ulfile']['tmp_name'], "{$files_dir}/{$_FILES['ulfile']['name']}"); $savemsg = "Uploaded file to {$files_dir}/" . htmlentities($_FILES['ulfile']['name']); - mwexec('/bin/chmod -R 744 {$files_dir}/*'); + if (tftp_dir_contains_files($files_dir)) { + mwexec('/bin/chmod -R 744 {$files_dir}/*'); + } unset($_POST['txtCommand']); conf_mount_ro(); } diff --git a/pkg_config.10.xml b/pkg_config.10.xml index 980a529d..c49c0233 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -337,7 +337,7 @@ ftp https://packages.pfsense.org/packages/config/tftp2/tftp.xml - 2.2.4 + 2.2.5 RELEASE 2.2 tftp.xml diff --git a/pkg_config.8.xml b/pkg_config.8.xml index 398d172b..f3cc21d8 100644 --- a/pkg_config.8.xml +++ b/pkg_config.8.xml @@ -383,7 +383,7 @@ https://packages.pfsense.org/packages/config/tftp2/tftp.xml https://files.pfsense.org/packages/8/All/ - 2.2.4 + 2.2.5 Stable 2.0 tftp.xml diff --git a/pkg_config.8.xml.amd64 b/pkg_config.8.xml.amd64 index 80d9d879..e3b1347c 100644 --- a/pkg_config.8.xml.amd64 +++ b/pkg_config.8.xml.amd64 @@ -383,7 +383,7 @@ https://packages.pfsense.org/packages/config/tftp2/tftp.xml https://files.pfsense.org/packages/amd64/8/All/ - 2.2.4 + 2.2.5 Stable 2.0 tftp.xml -- cgit v1.2.3