From 6bbd8b73857a337e3aba2f6cdcaca6355b4c2b51 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 9 Nov 2022 08:47:02 +0900 Subject: [PATCH] Use AbsoluteConfigLocation() when building an included path in hba.c The code building an absolute path to a file included, as prefixed by '@' in authentication files, for user and database lists uses the same logic as for GUCs, except that it has no need to know about DataDir as there is always a calling file to rely to build the base directory path. The refactoring done in a1a7bb8 makes this move straight-forward, and unifies the code used for GUCs and authentication files, and the intention is to rely also on that for the upcoming patch to be able to include full files from HBA or ident files. Note that this gets rid of an inconsistency introduced in 370f909, that copied the logic coming from GUCs but applied it for files included in authentication files, where the result buffer given to join_path_components() must have a size of MAXPGPATH. Based on a double-check of the existing code, all the other callers of join_path_components() already do that, except the code path changed here. Discussion: https://postgr.es/m/Y2igk7q8OMpg+Yta@paquier.xyz --- src/backend/libpq/hba.c | 17 ++--------------- src/backend/utils/misc/conffiles.c | 4 ++-- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c index e9fc0af7c9..a9f87ab5bf 100644 --- a/src/backend/libpq/hba.c +++ b/src/backend/libpq/hba.c @@ -41,6 +41,7 @@ #include "storage/fd.h" #include "utils/acl.h" #include "utils/builtins.h" +#include "utils/conffiles.h" #include "utils/guc.h" #include "utils/lsyscache.h" #include "utils/memutils.h" @@ -466,21 +467,7 @@ tokenize_inc_file(List *tokens, ListCell *inc_line; MemoryContext linecxt; - if (is_absolute_path(inc_filename)) - { - /* absolute path is taken as-is */ - inc_fullname = pstrdup(inc_filename); - } - else - { - /* relative path is relative to dir of calling file */ - inc_fullname = (char *) palloc(strlen(outer_filename) + 1 + - strlen(inc_filename) + 1); - strcpy(inc_fullname, outer_filename); - get_parent_directory(inc_fullname); - join_path_components(inc_fullname, inc_fullname, inc_filename); - canonicalize_path(inc_fullname); - } + inc_fullname = AbsoluteConfigLocation(inc_filename, outer_filename); inc_file = AllocateFile(inc_fullname, "r"); if (inc_file == NULL) diff --git a/src/backend/utils/misc/conffiles.c b/src/backend/utils/misc/conffiles.c index 4a99a1961e..027d481df8 100644 --- a/src/backend/utils/misc/conffiles.c +++ b/src/backend/utils/misc/conffiles.c @@ -35,12 +35,12 @@ char * AbsoluteConfigLocation(const char *location, const char *calling_file) { - char abs_path[MAXPGPATH]; - if (is_absolute_path(location)) return pstrdup(location); else { + char abs_path[MAXPGPATH]; + if (calling_file != NULL) { strlcpy(abs_path, calling_file, sizeof(abs_path));