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

Commita903971

Browse files
committed
Refactor more logic for compilation of regular expressions in hba.c
It happens that the parts of hba.conf that are planned to be extendedto support regular expressions would finish by using the same errormessage as the one used currently for pg_ident.conf when a regularexpression cannot be compiled, as long as the routine centralizing thelogic, regcomp_auth_token(), knows from which file the regexp comes fromand its line location in the so-said file.This change makes the follow-up patches slightly simpler, and the logicremains the same. I suspect that this makes the proposal to add supportfor file inclusions in pg_ident.conf and pg_hba.conf slightly simpler,as well.Extracted from a larger patch by the same author. This is similar tothe refactoring done in fc579e1.Author: Bertrand DrouvotDiscussion:https://postgr.es/m/fff0d7c1-8ad4-76a1-9db3-0ab6ec338bf7@amazon.com
1 parent42d01f5 commita903971

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

‎src/backend/libpq/hba.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ static List *tokenize_inc_file(List *tokens, const char *outer_filename,
119119
constchar*inc_filename,intelevel,char**err_msg);
120120
staticboolparse_hba_auth_opt(char*name,char*val,HbaLine*hbaline,
121121
intelevel,char**err_msg);
122-
staticintregcomp_auth_token(AuthToken*token);
122+
staticintregcomp_auth_token(AuthToken*token,char*filename,intline_num,
123+
char**err_msg,intelevel);
123124
staticintregexec_auth_token(constchar*match,AuthToken*token,
124125
size_tnmatch,regmatch_tpmatch[]);
125126

@@ -305,10 +306,12 @@ copy_auth_token(AuthToken *in)
305306

306307
/*
307308
* Compile the regular expression and store it in the AuthToken given in
308-
* input. Returns the result of pg_regcomp().
309+
* input. Returns the result of pg_regcomp(). On error, the details are
310+
* stored in "err_msg".
309311
*/
310312
staticint
311-
regcomp_auth_token(AuthToken*token)
313+
regcomp_auth_token(AuthToken*token,char*filename,intline_num,
314+
char**err_msg,intelevel)
312315
{
313316
pg_wchar*wstr;
314317
intwlen;
@@ -326,6 +329,22 @@ regcomp_auth_token(AuthToken *token)
326329

327330
rc=pg_regcomp(token->regex,wstr,wlen,REG_ADVANCED,C_COLLATION_OID);
328331

332+
if (rc)
333+
{
334+
charerrstr[100];
335+
336+
pg_regerror(rc,token->regex,errstr,sizeof(errstr));
337+
ereport(elevel,
338+
(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
339+
errmsg("invalid regular expression \"%s\": %s",
340+
token->string+1,errstr),
341+
errcontext("line %d of configuration file \"%s\"",
342+
line_num,filename)));
343+
344+
*err_msg=psprintf("invalid regular expression \"%s\": %s",
345+
token->string+1,errstr);
346+
}
347+
329348
pfree(wstr);
330349
returnrc;
331350
}
@@ -2374,7 +2393,6 @@ parse_ident_line(TokenizedAuthLine *tok_line, int elevel)
23742393
List*tokens;
23752394
AuthToken*token;
23762395
IdentLine*parsedline;
2377-
intrc;
23782396

23792397
Assert(tok_line->fields!=NIL);
23802398
field=list_head(tok_line->fields);
@@ -2410,22 +2428,10 @@ parse_ident_line(TokenizedAuthLine *tok_line, int elevel)
24102428
* Now that the field validation is done, compile a regex from the user
24112429
* token, if necessary.
24122430
*/
2413-
rc=regcomp_auth_token(parsedline->token);
2414-
if (rc)
2431+
if (regcomp_auth_token(parsedline->token,IdentFileName,line_num,
2432+
err_msg,elevel))
24152433
{
2416-
charerrstr[100];
2417-
2418-
pg_regerror(rc,parsedline->token->regex,errstr,sizeof(errstr));
2419-
ereport(elevel,
2420-
(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
2421-
errmsg("invalid regular expression \"%s\": %s",
2422-
parsedline->token->string+1,errstr),
2423-
errcontext("line %d of configuration file \"%s\"",
2424-
line_num,IdentFileName)));
2425-
2426-
*err_msg=psprintf("invalid regular expression \"%s\": %s",
2427-
parsedline->token->string+1,errstr);
2428-
2434+
/* err_msg includes the error to report */
24292435
returnNULL;
24302436
}
24312437

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp