Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad6c528

Browse files
committed
Add error context callback when tokenizing authentication files
The parsing of the authentication files for HBA and ident entrieshappens in two phases:- Tokenization of the files, creating a list of TokenizedAuthLines.- Validation of the HBA and ident entries, building a set of HbaLines orIdentLines.The second phase doing the validation provides already some errorcontext about the configuration file and the line where a problemhappens, but there is no such information in the first phase whentokenizing the files. This commit adds an ErrorContextCallback intokenize_auth_file(), with a context made of the line number and theconfiguration file name involved in a problem. This is useful for filesincluded in an HBA file for user and database lists, and it will becomemuch more handy to track problems for files included via a potential@include[_dir,_if_exists].The error context is registered so as the full chain of events isreported when using cascaded inclusions when for exampletokenize_auth_file() recurses over itself on new files, displaying onecontext line for each file gone through when tokenizing things.Author: Michael PaquierReviewed-by: Julien RouhaudDiscussion:https://postgr.es/m/Y2xUBJ+S+Z0zbxRW@paquier.xyz
1 parent783e8c6 commitad6c528

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

‎src/backend/libpq/hba.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ typedef struct check_network_data
6666
boolresult;/* set to true if match */
6767
}check_network_data;
6868

69+
typedefstruct
70+
{
71+
constchar*filename;
72+
intlinenum;
73+
}tokenize_error_callback_arg;
6974

7075
#definetoken_has_regexp(t)(t->regex != NULL)
7176
#definetoken_is_keyword(t,k)(!t->quoted && strcmp(t->string, k) == 0)
@@ -125,6 +130,7 @@ static intregcomp_auth_token(AuthToken *token, char *filename, int line_num,
125130
char**err_msg,intelevel);
126131
staticintregexec_auth_token(constchar*match,AuthToken*token,
127132
size_tnmatch,regmatch_tpmatch[]);
133+
staticvoidtokenize_error_callback(void*arg);
128134

129135

130136
/*
@@ -570,6 +576,18 @@ open_auth_file(const char *filename, int elevel, int depth,
570576
returnfile;
571577
}
572578

579+
/*
580+
* error context callback for tokenize_auth_file()
581+
*/
582+
staticvoid
583+
tokenize_error_callback(void*arg)
584+
{
585+
tokenize_error_callback_arg*callback_arg= (tokenize_error_callback_arg*)arg;
586+
587+
errcontext("line %d of configuration file \"%s\"",
588+
callback_arg->linenum,callback_arg->filename);
589+
}
590+
573591
/*
574592
* tokenize_auth_file
575593
*Tokenize the given file.
@@ -598,6 +616,16 @@ tokenize_auth_file(const char *filename, FILE *file, List **tok_lines,
598616
StringInfoDatabuf;
599617
MemoryContextlinecxt;
600618
MemoryContextoldcxt;
619+
ErrorContextCallbacktokenerrcontext;
620+
tokenize_error_callback_argcallback_arg;
621+
622+
callback_arg.filename=filename;
623+
callback_arg.linenum=line_number;
624+
625+
tokenerrcontext.callback=tokenize_error_callback;
626+
tokenerrcontext.arg= (void*)&callback_arg;
627+
tokenerrcontext.previous=error_context_stack;
628+
error_context_stack=&tokenerrcontext;
601629

602630
linecxt=AllocSetContextCreate(CurrentMemoryContext,
603631
"tokenize_auth_file",
@@ -686,10 +714,13 @@ tokenize_auth_file(const char *filename, FILE *file, List **tok_lines,
686714
}
687715

688716
line_number+=continuations+1;
717+
callback_arg.linenum=line_number;
689718
}
690719

691720
MemoryContextSwitchTo(oldcxt);
692721

722+
error_context_stack=tokenerrcontext.previous;
723+
693724
returnlinecxt;
694725
}
695726

‎src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,6 +3723,7 @@ timeout_params
37233723
timerCA
37243724
tlist_vinfo
37253725
toast_compress_header
3726+
tokenize_error_callback_arg
37263727
transferMode
37273728
transfer_thread_arg
37283729
trgm

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp