Commit b49df3a3 authored by Martin Pitt's avatar Martin Pitt

* t/030_errors.t, t/130_nonroot_admin.t: Check pg_dropcluster/

  pg_createcluster error message when being called with insufficient
  privileges.
* pg_createcluster, pg_dropcluster: Point out that program needs to be run
  as root when creating/removing config or data directory fails.
  (Closes: #460576)
parent aadcdb27
......@@ -13,8 +13,14 @@ postgresql-common (84) UNRELEASED; urgency=low
* PgCommon.pm, get_cluster_locales(): Print proper error message when server
package is removed, but not purged, and a cluster still exists.
(Closes: #463070)
-- Martin Pitt <mpitt@debian.org> Sun, 03 Feb 2008 13:34:47 +0100
* t/030_errors.t, t/130_nonroot_admin.t: Check pg_dropcluster/
pg_createcluster error message when being called with insufficient
privileges.
* pg_createcluster, pg_dropcluster: Point out that program needs to be run
as root when creating/removing config or data directory fails.
(Closes: #460576)
-- Martin Pitt <mpitt@debian.org> Sun, 03 Feb 2008 18:01:48 +0100
postgresql-common (83) unstable; urgency=low
......
......@@ -51,7 +51,7 @@ sub init_db {
$datadir = (-l $_[1]) ? readlink $_[1] : $_[1];
if (system 'install', '-d', '-o', $_[2], '-g', $_[3], $datadir) {
error 'could not create data directory';
error 'could not create data directory; you might need to run this program with root privileges';
}
@initdb = ((get_program_path 'initdb', $_[0]), '-D', $datadir);
......@@ -302,7 +302,8 @@ if (defined $port) {
}
# create configuration directory
error 'could not create data directory' if system ('install', '-d', $confdir);
error 'could not create configuration directory; you might ' .
'need to run this program with root privileges' if system ('install', '-d', $confdir);
# check whether we have an already existing cluster; check version and
# determine owner in this case
......@@ -374,7 +375,7 @@ set_cluster_port $version, $cluster, $port;
# create log file
system 'mkdir', '-m', '0755', '-p', '/var/log/postgresql' and
error "could not create log directory";
error "could not create log directory; you might need to run this program with root privileges";
$real_logfile = $custom_logfile || "/var/log/postgresql/postgresql-$version-$cluster.log";
if (! -e $real_logfile) {
open L, ">>$real_logfile" or error "could not create log file $real_logfile";
......
......@@ -55,7 +55,12 @@ if (cluster_exists $version, $cluster) {
if ($info{'pgdata'} && -d $info{'pgdata'}) {
$result = system '/bin/rm', '-r', $info{'pgdata'};
exit $result if $result;
if ($result) {
if (! -w ($info{'pgdata'} . '/..')) {
error 'you might need to run this program with root privileges';
}
exit $result;
}
} else {
print STDERR "warning: corrupted cluster: data directory does not exist\n";
}
......
......@@ -6,7 +6,7 @@ require File::Temp;
use lib 't';
use TestLib;
use Test::More tests => 132;
use Test::More tests => 134;
use lib '/usr/share/postgresql-common';
use PgCommon;
......@@ -187,6 +187,10 @@ is_deeply (\@c, ['main'],
'leftover /etc/postgresql/postgresql.conf is not regarded as a cluster');
unlink '/etc/postgresql/postgresql.conf';
# fails by default due to access restrictions
like_program_out 'postgres', "pg_dropcluster $version main", 1,
qr/root privileges/, "pg_dropcluster fails as user postgres by default";
# remove cluster and directory
ok ((system "pg_dropcluster $version main") == 0,
'pg_dropcluster');
......
......@@ -9,7 +9,7 @@ use TestLib;
my $ownver = $MAJORS[-1];
my $grpver = $MAJORS[0];
use Test::More tests => 37;
use Test::More tests => 38;
use lib '/usr/share/postgresql-common';
use PgCommon;
......@@ -18,8 +18,8 @@ my $testuser = 'postgres';
my ($uid, $gid) = (getpwnam $testuser)[2,3];
# fails by default due to access restrictions
is ((exec_as 'postgres', "pg_createcluster $ownver fail --start"), 1,
"pg_createcluster fails as user $testuser by default");
like_program_out $testuser, "pg_createcluster $ownver fail --start", 1,
qr/root privileges/, "pg_createcluster fails as user $testuser by default";
# and does not leave any garbage behind
check_clean;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment