Commit 11f063b0 authored by Michael Paquier's avatar Michael Paquier

Remove some dead code in contrib/adminpack/

Since its introduction in fe59e566, the code in charge of validating and
converting a file path includes some extra handling for absolute paths
pointing to an external log_directory, but this has never been used.

Author: Antonin Houska
Reviewed-by: Julien Rouhaud, Michael Paquier
Discussion: https://postgr.es/m/32663.1581592539@antos
parent eb67623c
...@@ -69,10 +69,10 @@ typedef struct ...@@ -69,10 +69,10 @@ typedef struct
* Convert a "text" filename argument to C string, and check it's allowable. * Convert a "text" filename argument to C string, and check it's allowable.
* *
* Filename may be absolute or relative to the DataDir, but we only allow * Filename may be absolute or relative to the DataDir, but we only allow
* absolute paths that match DataDir or Log_directory. * absolute paths that match DataDir.
*/ */
static char * static char *
convert_and_check_filename(text *arg, bool logAllowed) convert_and_check_filename(text *arg)
{ {
char *filename = text_to_cstring(arg); char *filename = text_to_cstring(arg);
...@@ -95,13 +95,8 @@ convert_and_check_filename(text *arg, bool logAllowed) ...@@ -95,13 +95,8 @@ convert_and_check_filename(text *arg, bool logAllowed)
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("reference to parent directory (\"..\") not allowed"))); errmsg("reference to parent directory (\"..\") not allowed")));
/* /* Allow absolute paths if within DataDir */
* Allow absolute paths if within DataDir or Log_directory, even if (!path_is_prefix_of_path(DataDir, filename))
* though Log_directory might be outside DataDir.
*/
if (!path_is_prefix_of_path(DataDir, filename) &&
(!logAllowed || !is_absolute_path(Log_directory) ||
!path_is_prefix_of_path(Log_directory, filename)))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("absolute path not allowed"))); errmsg("absolute path not allowed")));
...@@ -185,7 +180,7 @@ pg_file_write_internal(text *file, text *data, bool replace) ...@@ -185,7 +180,7 @@ pg_file_write_internal(text *file, text *data, bool replace)
char *filename; char *filename;
int64 count = 0; int64 count = 0;
filename = convert_and_check_filename(file, false); filename = convert_and_check_filename(file);
if (!replace) if (!replace)
{ {
...@@ -228,7 +223,7 @@ pg_file_sync(PG_FUNCTION_ARGS) ...@@ -228,7 +223,7 @@ pg_file_sync(PG_FUNCTION_ARGS)
char *filename; char *filename;
struct stat fst; struct stat fst;
filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0), false); filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));
if (stat(filename, &fst) < 0) if (stat(filename, &fst) < 0)
ereport(ERROR, ereport(ERROR,
...@@ -319,13 +314,13 @@ pg_file_rename_internal(text *file1, text *file2, text *file3) ...@@ -319,13 +314,13 @@ pg_file_rename_internal(text *file1, text *file2, text *file3)
*fn3; *fn3;
int rc; int rc;
fn1 = convert_and_check_filename(file1, false); fn1 = convert_and_check_filename(file1);
fn2 = convert_and_check_filename(file2, false); fn2 = convert_and_check_filename(file2);
if (file3 == NULL) if (file3 == NULL)
fn3 = NULL; fn3 = NULL;
else else
fn3 = convert_and_check_filename(file3, false); fn3 = convert_and_check_filename(file3);
if (access(fn1, W_OK) < 0) if (access(fn1, W_OK) < 0)
{ {
...@@ -411,7 +406,7 @@ pg_file_unlink(PG_FUNCTION_ARGS) ...@@ -411,7 +406,7 @@ pg_file_unlink(PG_FUNCTION_ARGS)
requireSuperuser(); requireSuperuser();
filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0), false); filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));
if (access(filename, W_OK) < 0) if (access(filename, W_OK) < 0)
{ {
...@@ -449,7 +444,7 @@ pg_file_unlink_v1_1(PG_FUNCTION_ARGS) ...@@ -449,7 +444,7 @@ pg_file_unlink_v1_1(PG_FUNCTION_ARGS)
{ {
char *filename; char *filename;
filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0), false); filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0));
if (access(filename, W_OK) < 0) if (access(filename, W_OK) < 0)
{ {
......
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