aboutsummaryrefslogtreecommitdiff
path: root/contrib/basebackup_to_shell
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-05-12 15:17:30 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2022-05-12 15:17:30 -0400
commit23e7b38bfe396f919fdb66057174d29e17086418 (patch)
tree335c3962ef8afe0f6193d0413dbc51642276b147 /contrib/basebackup_to_shell
parent93909599cdba64c8759d646983c0a4ef93de1e50 (diff)
downloadpostgresql-23e7b38bfe396f919fdb66057174d29e17086418.tar.gz
postgresql-23e7b38bfe396f919fdb66057174d29e17086418.zip
Pre-beta mechanical code beautification.
Run pgindent, pgperltidy, and reformat-dat-files. I manually fixed a couple of comments that pgindent uglified.
Diffstat (limited to 'contrib/basebackup_to_shell')
-rw-r--r--contrib/basebackup_to_shell/basebackup_to_shell.c27
-rw-r--r--contrib/basebackup_to_shell/t/001_basic.pl71
2 files changed, 51 insertions, 47 deletions
diff --git a/contrib/basebackup_to_shell/basebackup_to_shell.c b/contrib/basebackup_to_shell/basebackup_to_shell.c
index a279219966d..bc754b177af 100644
--- a/contrib/basebackup_to_shell/basebackup_to_shell.c
+++ b/contrib/basebackup_to_shell/basebackup_to_shell.c
@@ -37,13 +37,13 @@ typedef struct bbsink_shell
FILE *pipe;
} bbsink_shell;
-void _PG_init(void);
+void _PG_init(void);
static void *shell_check_detail(char *target, char *target_detail);
static bbsink *shell_get_sink(bbsink *next_sink, void *detail_arg);
static void bbsink_shell_begin_archive(bbsink *sink,
- const char *archive_name);
+ const char *archive_name);
static void bbsink_shell_archive_contents(bbsink *sink, size_t len);
static void bbsink_shell_end_archive(bbsink *sink);
static void bbsink_shell_begin_manifest(bbsink *sink);
@@ -101,7 +101,7 @@ shell_check_detail(char *target, char *target_detail)
{
if (shell_required_role[0] != '\0')
{
- Oid roleid;
+ Oid roleid;
StartTransactionCommand();
roleid = get_role_oid(shell_required_role, true);
@@ -125,8 +125,8 @@ static bbsink *
shell_get_sink(bbsink *next_sink, void *detail_arg)
{
bbsink_shell *sink;
- bool has_detail_escape = false;
- char *c;
+ bool has_detail_escape = false;
+ char *c;
/*
* Set up the bbsink.
@@ -171,15 +171,15 @@ shell_get_sink(bbsink *next_sink, void *detail_arg)
/*
* Since we're passing the string provided by the user to popen(), it will
* be interpreted by the shell, which is a potential security
- * vulnerability, since the user invoking this module is not necessarily
- * a superuser. To stay out of trouble, we must disallow any shell
+ * vulnerability, since the user invoking this module is not necessarily a
+ * superuser. To stay out of trouble, we must disallow any shell
* metacharacters here; to be conservative and keep things simple, we
* allow only alphanumerics.
*/
if (sink->target_detail != NULL)
{
- char *d;
- bool scary = false;
+ char *d;
+ bool scary = false;
for (d = sink->target_detail; *d != '\0'; ++d)
{
@@ -210,7 +210,7 @@ static char *
shell_construct_command(char *base_command, const char *filename,
char *target_detail)
{
- StringInfoData buf;
+ StringInfoData buf;
char *c;
initStringInfo(&buf);
@@ -271,7 +271,7 @@ shell_construct_command(char *base_command, const char *filename,
static void
shell_finish_command(bbsink_shell *sink)
{
- int pclose_rc;
+ int pclose_rc;
/* There should be a command running. */
Assert(sink->current_command != NULL);
@@ -335,9 +335,8 @@ shell_send_data(bbsink_shell *sink, size_t len)
{
/*
* The error we're about to throw would shut down the command
- * anyway, but we may get a more meaningful error message by
- * doing this. If not, we'll fall through to the generic error
- * below.
+ * anyway, but we may get a more meaningful error message by doing
+ * this. If not, we'll fall through to the generic error below.
*/
shell_finish_command(sink);
errno = EPIPE;
diff --git a/contrib/basebackup_to_shell/t/001_basic.pl b/contrib/basebackup_to_shell/t/001_basic.pl
index 350d42079a7..acb66eb9a84 100644
--- a/contrib/basebackup_to_shell/t/001_basic.pl
+++ b/contrib/basebackup_to_shell/t/001_basic.pl
@@ -20,11 +20,12 @@ my $node = PostgreSQL::Test::Cluster->new('primary');
# Make sure pg_hba.conf is set up to allow connections from backupuser.
# This is only needed on Windows machines that don't use UNIX sockets.
-$node->init('allows_streaming' => 1,
- 'auth_extra' => [ '--create-role', 'backupuser' ]);
+$node->init(
+ 'allows_streaming' => 1,
+ 'auth_extra' => [ '--create-role', 'backupuser' ]);
$node->append_conf('postgresql.conf',
- "shared_preload_libraries = 'basebackup_to_shell'");
+ "shared_preload_libraries = 'basebackup_to_shell'");
$node->start;
$node->safe_psql('postgres', 'CREATE USER backupuser REPLICATION');
$node->safe_psql('postgres', 'CREATE ROLE trustworthy');
@@ -41,61 +42,61 @@ my @pg_basebackup_cmd = (@pg_basebackup_defs, '-U', 'backupuser', '-Xfetch');
# Can't use this module without setting basebackup_to_shell.command.
$node->command_fails_like(
- [ @pg_basebackup_cmd, '--target', 'shell' ],
+ [ @pg_basebackup_cmd, '--target', 'shell' ],
qr/shell command for backup is not configured/,
'fails if basebackup_to_shell.command is not set');
# Configure basebackup_to_shell.command and reload the configuation file.
-my $backup_path = PostgreSQL::Test::Utils::tempdir;
+my $backup_path = PostgreSQL::Test::Utils::tempdir;
my $escaped_backup_path = $backup_path;
-$escaped_backup_path =~ s{\\}{\\\\}g if ($PostgreSQL::Test::Utils::windows_os);
+$escaped_backup_path =~ s{\\}{\\\\}g
+ if ($PostgreSQL::Test::Utils::windows_os);
my $shell_command =
- $PostgreSQL::Test::Utils::windows_os
- ? qq{$gzip --fast > "$escaped_backup_path\\\\%f.gz"}
- : qq{$gzip --fast > "$escaped_backup_path/%f.gz"};
+ $PostgreSQL::Test::Utils::windows_os
+ ? qq{$gzip --fast > "$escaped_backup_path\\\\%f.gz"}
+ : qq{$gzip --fast > "$escaped_backup_path/%f.gz"};
$node->append_conf('postgresql.conf',
- "basebackup_to_shell.command='$shell_command'");
+ "basebackup_to_shell.command='$shell_command'");
$node->reload();
# Should work now.
$node->command_ok(
- [ @pg_basebackup_cmd, '--target', 'shell' ],
+ [ @pg_basebackup_cmd, '--target', 'shell' ],
'backup with no detail: pg_basebackup');
verify_backup('', $backup_path, "backup with no detail");
# Should fail with a detail.
$node->command_fails_like(
- [ @pg_basebackup_cmd, '--target', 'shell:foo' ],
+ [ @pg_basebackup_cmd, '--target', 'shell:foo' ],
qr/a target detail is not permitted because the configured command does not include %d/,
'fails if detail provided without %d');
# Reconfigure to restrict access and require a detail.
$shell_command =
- $PostgreSQL::Test::Utils::windows_os
- ? qq{$gzip --fast > "$escaped_backup_path\\\\%d.%f.gz"}
- : qq{$gzip --fast > "$escaped_backup_path/%d.%f.gz"};
+ $PostgreSQL::Test::Utils::windows_os
+ ? qq{$gzip --fast > "$escaped_backup_path\\\\%d.%f.gz"}
+ : qq{$gzip --fast > "$escaped_backup_path/%d.%f.gz"};
$node->append_conf('postgresql.conf',
- "basebackup_to_shell.command='$shell_command'");
+ "basebackup_to_shell.command='$shell_command'");
$node->append_conf('postgresql.conf',
- "basebackup_to_shell.required_role='trustworthy'");
+ "basebackup_to_shell.required_role='trustworthy'");
$node->reload();
# Should fail due to lack of permission.
$node->command_fails_like(
- [ @pg_basebackup_cmd, '--target', 'shell' ],
+ [ @pg_basebackup_cmd, '--target', 'shell' ],
qr/permission denied to use basebackup_to_shell/,
'fails if required_role not granted');
# Should fail due to lack of a detail.
$node->safe_psql('postgres', 'GRANT trustworthy TO backupuser');
$node->command_fails_like(
- [ @pg_basebackup_cmd, '--target', 'shell' ],
+ [ @pg_basebackup_cmd, '--target', 'shell' ],
qr/a target detail is required because the configured command includes %d/,
'fails if %d is present and detail not given');
# Should work.
-$node->command_ok(
- [ @pg_basebackup_cmd, '--target', 'shell:bar' ],
+$node->command_ok([ @pg_basebackup_cmd, '--target', 'shell:bar' ],
'backup with detail: pg_basebackup');
verify_backup('bar.', $backup_path, "backup with detail");
@@ -105,30 +106,34 @@ sub verify_backup
{
my ($prefix, $backup_dir, $test_name) = @_;
- ok(-f "$backup_dir/${prefix}backup_manifest.gz",
- "$test_name: backup_manifest.gz was created");
- ok(-f "$backup_dir/${prefix}base.tar.gz",
- "$test_name: base.tar.gz was created");
+ ok( -f "$backup_dir/${prefix}backup_manifest.gz",
+ "$test_name: backup_manifest.gz was created");
+ ok( -f "$backup_dir/${prefix}base.tar.gz",
+ "$test_name: base.tar.gz was created");
- SKIP: {
+ SKIP:
+ {
my $tar = $ENV{TAR};
skip "no tar program available", 1 if (!defined $tar || $tar eq '');
# Decompress.
system_or_bail($gzip, '-d',
- $backup_dir . '/' . $prefix . 'backup_manifest.gz');
+ $backup_dir . '/' . $prefix . 'backup_manifest.gz');
system_or_bail($gzip, '-d',
- $backup_dir . '/' . $prefix . 'base.tar.gz');
+ $backup_dir . '/' . $prefix . 'base.tar.gz');
# Untar.
my $extract_path = PostgreSQL::Test::Utils::tempdir;
system_or_bail($tar, 'xf', $backup_dir . '/' . $prefix . 'base.tar',
- '-C', $extract_path);
+ '-C', $extract_path);
# Verify.
- $node->command_ok([ 'pg_verifybackup', '-n',
- '-m', "${backup_dir}/${prefix}backup_manifest",
- '-e', $extract_path ],
- "$test_name: backup verifies ok");
+ $node->command_ok(
+ [
+ 'pg_verifybackup', '-n',
+ '-m', "${backup_dir}/${prefix}backup_manifest",
+ '-e', $extract_path
+ ],
+ "$test_name: backup verifies ok");
}
}