Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6bbd8b7

Browse files
committed
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
1 parent f05a5e0 commit 6bbd8b7

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

src/backend/libpq/hba.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "storage/fd.h"
4242
#include "utils/acl.h"
4343
#include "utils/builtins.h"
44+
#include "utils/conffiles.h"
4445
#include "utils/guc.h"
4546
#include "utils/lsyscache.h"
4647
#include "utils/memutils.h"
@@ -466,21 +467,7 @@ tokenize_inc_file(List *tokens,
466467
ListCell *inc_line;
467468
MemoryContext linecxt;
468469

469-
if (is_absolute_path(inc_filename))
470-
{
471-
/* absolute path is taken as-is */
472-
inc_fullname = pstrdup(inc_filename);
473-
}
474-
else
475-
{
476-
/* relative path is relative to dir of calling file */
477-
inc_fullname = (char *) palloc(strlen(outer_filename) + 1 +
478-
strlen(inc_filename) + 1);
479-
strcpy(inc_fullname, outer_filename);
480-
get_parent_directory(inc_fullname);
481-
join_path_components(inc_fullname, inc_fullname, inc_filename);
482-
canonicalize_path(inc_fullname);
483-
}
470+
inc_fullname = AbsoluteConfigLocation(inc_filename, outer_filename);
484471

485472
inc_file = AllocateFile(inc_fullname, "r");
486473
if (inc_file == NULL)

src/backend/utils/misc/conffiles.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
char *
3636
AbsoluteConfigLocation(const char *location, const char *calling_file)
3737
{
38-
char abs_path[MAXPGPATH];
39-
4038
if (is_absolute_path(location))
4139
return pstrdup(location);
4240
else
4341
{
42+
char abs_path[MAXPGPATH];
43+
4444
if (calling_file != NULL)
4545
{
4646
strlcpy(abs_path, calling_file, sizeof(abs_path));

0 commit comments

Comments
 (0)