Skip to content

Commit

Permalink
fix bug #2605601 Doesn't check if pg_dump_path is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
ioguix committed Mar 11, 2009
1 parent 15413db commit a68d3ca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
33 changes: 21 additions & 12 deletions dbexport.php
Expand Up @@ -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']){
Expand All @@ -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'];
Expand All @@ -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";

Expand All @@ -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 ) {
Expand Down
2 changes: 2 additions & 0 deletions lang/english.php
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions lang/recoded/english.php
Expand Up @@ -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';
Expand Down

0 comments on commit a68d3ca

Please sign in to comment.