From a68d3ca4a09e1c8c487a242a3c68e2bd41713f33 Mon Sep 17 00:00:00 2001 From: "Guillaume (ioguix) de Rorthais" Date: Tue, 10 Mar 2009 22:01:37 -0400 Subject: [PATCH] fix bug #2605601 Doesn't check if pg_dump_path is valid --- dbexport.php | 33 +++++++++++++++++++++------------ lang/english.php | 2 ++ lang/recoded/english.php | 2 ++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/dbexport.php b/dbexport.php index c4630bb29..aba52ca56 100644 --- a/dbexport.php +++ b/dbexport.php @@ -13,8 +13,28 @@ $_no_output = true; include_once('./libraries/lib.inc.php'); + // Are we doing a cluster-wide dump or just a per-database dump + $dumpall = ($_REQUEST['subject'] == 'server'); + // Check that database dumps are enabled. - if ($misc->isDumpEnabled()) { + if ($misc->isDumpEnabled($dumpall)) { + + $server_info = $misc->getServerInfo(); + + // Get the path of the pg_dump/pg_dumpall executable + $exe = $misc->escapeShellCmd($server_info[$dumpall ? 'pg_dumpall_path' : 'pg_dump_path']); + + // Obtain the pg_dump version number and check if the path is good + $version = array(); + preg_match("/(\d+(?:\.\d+)?)(?:\.\d+)?.*$/", exec($exe . " --version"), $version); + + if (empty($version)) { + if ($dumpall) + printf($lang['strbadpgdumpallpath'], $server_info['pg_dumpall_path']); + else + printf($lang['strbadpgdumppath'], $server_info['pg_dump_path']); + exit; + } // Make it do a download, if necessary switch($_REQUEST['output']){ @@ -40,7 +60,6 @@ } // Set environmental variables that pg_dump uses - $server_info = $misc->getServerInfo(); putenv('PGPASSWORD=' . $server_info['password']); putenv('PGUSER=' . $server_info['username']); $hostname = $server_info['host']; @@ -52,12 +71,6 @@ putenv('PGPORT=' . $port); } - // Are we doing a cluster-wide dump or just a per-database dump - $dumpall = ($_REQUEST['subject'] == 'server'); - - // Get the path og the pg_dump/pg_dumpall executable - $exe = $misc->escapeShellCmd($server_info[$dumpall ? 'pg_dumpall_path' : 'pg_dump_path']); - // Build command for executing pg_dump. '-i' means ignore version differences. $cmd = $exe . " -i"; @@ -66,10 +79,6 @@ switch ($_REQUEST['subject']) { case 'table': case 'view': - // Obtain the pg_dump version number - $version = array(); - preg_match("/(\d+(?:\.\d+)?)(?:\.\d+)?.*$/", exec($exe . " --version"), $version); - // Starting in 8.2, -n and -t are orthagonal, so we now schema qualify // the table name in the -t argument and quote both identifiers if ( ((float) $version[1]) >= 8.2 ) { diff --git a/lang/english.php b/lang/english.php index ca4bcdc67..6ddb60e24 100644 --- a/lang/english.php +++ b/lang/english.php @@ -180,6 +180,8 @@ $lang['strcannotdumponwindows'] = 'Dumping of complex table and schema names on Windows is not supported.'; $lang['strinvalidserverparam'] = 'Attempt to connect with invalid server parameter, possibly someone is trying to hack your system.'; $lang['strnoserversupplied'] = 'No server supplied!'; + $lang['strbadpgdumppath'] = 'Export error: Failed to execute pg_dump (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.'; + $lang['strbadpgdumpallpath'] = 'Export error: Failed to execute pg_dumpall (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.'; // Tables $lang['strtable'] = 'Table'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index 37c10bd9d..139c90afc 100644 --- a/lang/recoded/english.php +++ b/lang/recoded/english.php @@ -180,6 +180,8 @@ $lang['strcannotdumponwindows'] = 'Dumping of complex table and schema names on Windows is not supported.'; $lang['strinvalidserverparam'] = 'Attempt to connect with invalid server parameter, possibly someone is trying to hack your system.'; $lang['strnoserversupplied'] = 'No server supplied!'; + $lang['strbadpgdumppath'] = 'Export error: Failed to execute pg_dump (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.'; + $lang['strbadpgdumpallpath'] = 'Export error: Failed to execute pg_dumpall (given path in your conf/config.inc.php : %s). Please, fix this path in your configuration and relog.'; // Tables $lang['strtable'] = 'Table';