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
This commit is contained in:
Michael Paquier 2022-11-09 08:47:02 +09:00
parent f05a5e0003
commit 6bbd8b7385
2 changed files with 4 additions and 17 deletions

View File

@ -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)

View File

@ -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));