diff options
Diffstat (limited to 'src/backend/libpq/be-secure-common.c')
-rw-r--r-- | src/backend/libpq/be-secure-common.c | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/src/backend/libpq/be-secure-common.c b/src/backend/libpq/be-secure-common.c index f6078c91c34..ab5e2dfa2bf 100644 --- a/src/backend/libpq/be-secure-common.c +++ b/src/backend/libpq/be-secure-common.c @@ -22,6 +22,7 @@ #include <sys/stat.h> #include <unistd.h> +#include "common/percentrepl.h" #include "common/string.h" #include "libpq/libpq.h" #include "storage/fd.h" @@ -39,8 +40,7 @@ int run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf, int size) { int loglevel = is_server_start ? ERROR : LOG; - StringInfoData command; - char *p; + char *command; FILE *fh; int pclose_rc; size_t len = 0; @@ -49,37 +49,15 @@ run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf, Assert(size > 0); buf[0] = '\0'; - initStringInfo(&command); + command = replace_percent_placeholders(ssl_passphrase_command, "ssl_passphrase_command", "p", prompt); - for (p = ssl_passphrase_command; *p; p++) - { - if (p[0] == '%') - { - switch (p[1]) - { - case 'p': - appendStringInfoString(&command, prompt); - p++; - break; - case '%': - appendStringInfoChar(&command, '%'); - p++; - break; - default: - appendStringInfoChar(&command, p[0]); - } - } - else - appendStringInfoChar(&command, p[0]); - } - - fh = OpenPipeStream(command.data, "r"); + fh = OpenPipeStream(command, "r"); if (fh == NULL) { ereport(loglevel, (errcode_for_file_access(), errmsg("could not execute command \"%s\": %m", - command.data))); + command))); goto error; } @@ -91,7 +69,7 @@ run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf, ereport(loglevel, (errcode_for_file_access(), errmsg("could not read from command \"%s\": %m", - command.data))); + command))); goto error; } } @@ -111,7 +89,7 @@ run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf, ereport(loglevel, (errcode_for_file_access(), errmsg("command \"%s\" failed", - command.data), + command), errdetail_internal("%s", wait_result_to_str(pclose_rc)))); goto error; } @@ -120,7 +98,7 @@ run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf, len = pg_strip_crlf(buf); error: - pfree(command.data); + pfree(command); return len; } |