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

Commit3e32e94

Browse files
committed
Patch that makes quoting "sameuser", "samegroup", and "all" remove
special meaning of these terms in pg_hba.conf.Also changes ugly pg_hba.conf IPv6 netmask offfff:ffff:ffff:ffff:ffff:ffff:ffff:ffff to ::1/128.Andrew Dunstan
1 parent1c757c4 commit3e32e94

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

‎src/backend/libpq/hba.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.118 2003/12/05 15:50:31 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.119 2003/12/25 03:44:04 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -87,16 +87,19 @@ pg_isblank(const char c)
8787
* token or EOF, whichever comes first. If no more tokens on line,
8888
* return null string as *buf and position file to beginning of
8989
* next line or EOF, whichever comes first. Allow spaces in quoted
90-
* strings. Terminate on unquoted commas. Handle comments.
90+
* strings. Terminate on unquoted commas. Handle comments. Treat
91+
* unquoted keywords that might be user names or database names
92+
* specially, by appending a newline to them.
9193
*/
9294
void
9395
next_token(FILE*fp,char*buf,constintbufsz)
9496
{
9597
intc;
9698
char*start_buf=buf;
97-
char*end_buf=buf+ (bufsz-1);
99+
char*end_buf=buf+ (bufsz-2);
98100
boolin_quote= false;
99101
boolwas_quote= false;
102+
boolsaw_quote= false;
100103

101104
/* Move over initial whitespace and commas */
102105
while ((c=getc(fp))!=EOF&& (pg_isblank(c)||c==','))
@@ -149,7 +152,10 @@ next_token(FILE *fp, char *buf, const int bufsz)
149152
was_quote= false;
150153

151154
if (c=='"')
155+
{
152156
in_quote= !in_quote;
157+
saw_quote= true;
158+
}
153159

154160
c=getc(fp);
155161
}
@@ -161,7 +167,22 @@ next_token(FILE *fp, char *buf, const int bufsz)
161167
if (c!=EOF)
162168
ungetc(c,fp);
163169
}
170+
171+
172+
if ( !saw_quote&&
173+
(
174+
strncmp(start_buf,"all",3)==0||
175+
strncmp(start_buf,"sameuser",8)==0||
176+
strncmp(start_buf,"samegroup",9)==0
177+
)
178+
)
179+
{
180+
/* append newline to a magical keyword */
181+
*buf++='\n';
182+
}
183+
164184
*buf='\0';
185+
165186
}
166187

167188
/*
@@ -446,7 +467,7 @@ check_user(char *user, char *param_str)
446467
return true;
447468
}
448469
elseif (strcmp(tok,user)==0||
449-
strcmp(tok,"all")==0)
470+
strcmp(tok,"all\n")==0)
450471
return true;
451472
}
452473

@@ -463,14 +484,14 @@ check_db(char *dbname, char *user, char *param_str)
463484

464485
for (tok=strtok(param_str,MULTI_VALUE_SEP);tok!=NULL;tok=strtok(NULL,MULTI_VALUE_SEP))
465486
{
466-
if (strcmp(tok,"all")==0)
487+
if (strcmp(tok,"all\n")==0)
467488
return true;
468-
elseif (strcmp(tok,"sameuser")==0)
489+
elseif (strcmp(tok,"sameuser\n")==0)
469490
{
470491
if (strcmp(dbname,user)==0)
471492
return true;
472493
}
473-
elseif (strcmp(tok,"samegroup")==0)
494+
elseif (strcmp(tok,"samegroup\n")==0)
474495
{
475496
if (check_group(dbname,user))
476497
return true;
@@ -1068,7 +1089,7 @@ check_ident_usermap(const char *usermap_name,
10681089
errmsg("cannot use Ident authentication without usermap field")));
10691090
found_entry= false;
10701091
}
1071-
elseif (strcmp(usermap_name,"sameuser")==0)
1092+
elseif (strcmp(usermap_name,"sameuser\n")==0)
10721093
{
10731094
if (strcmp(pg_user,ident_user)==0)
10741095
found_entry= true;

‎src/backend/libpq/pg_hba.conf.sample

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
# encrypted passwords. OPTION is the ident map or the name of the PAM
3636
# service.
3737
#
38+
# Database and user names containing spaces, commas, quotes and other special
39+
# characters can be quoted. Quoting one of the keywords "all", "sameuser" or
40+
# "samegroup" makes the name lose its special character, and just match a
41+
# database or username with that name.
42+
#
3843
# This file is read on server startup and when the postmaster receives
3944
# a SIGHUP signal. If you edit the file on a running system, you have
4045
# to SIGHUP the postmaster for the changes to take effect, or use
@@ -59,4 +64,4 @@ local all all trust
5964
# IPv4-style local connections:
6065
host all all 127.0.0.1 255.255.255.255 trust
6166
# IPv6-style local connections:
62-
host all all ::1ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff trust
67+
host all all ::1/128 trust

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp