10
10
*
11
11
*
12
12
* 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 $
14
14
*
15
15
*-------------------------------------------------------------------------
16
16
*/
@@ -87,16 +87,19 @@ pg_isblank(const char c)
87
87
* token or EOF, whichever comes first. If no more tokens on line,
88
88
* return null string as *buf and position file to beginning of
89
89
* 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.
91
93
*/
92
94
void
93
95
next_token (FILE * fp , char * buf , const int bufsz )
94
96
{
95
97
int c ;
96
98
char * start_buf = buf ;
97
- char * end_buf = buf + (bufsz - 1 );
99
+ char * end_buf = buf + (bufsz - 2 );
98
100
bool in_quote = false;
99
101
bool was_quote = false;
102
+ bool saw_quote = false;
100
103
101
104
/* Move over initial whitespace and commas */
102
105
while ((c = getc (fp )) != EOF && (pg_isblank (c ) || c == ',' ))
@@ -149,7 +152,10 @@ next_token(FILE *fp, char *buf, const int bufsz)
149
152
was_quote = false;
150
153
151
154
if (c == '"' )
155
+ {
152
156
in_quote = !in_quote ;
157
+ saw_quote = true;
158
+ }
153
159
154
160
c = getc (fp );
155
161
}
@@ -161,7 +167,22 @@ next_token(FILE *fp, char *buf, const int bufsz)
161
167
if (c != EOF )
162
168
ungetc (c , fp );
163
169
}
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
+
164
184
* buf = '\0' ;
185
+
165
186
}
166
187
167
188
/*
@@ -446,7 +467,7 @@ check_user(char *user, char *param_str)
446
467
return true;
447
468
}
448
469
else if (strcmp (tok , user ) == 0 ||
449
- strcmp (tok , "all" ) == 0 )
470
+ strcmp (tok , "all\n " ) == 0 )
450
471
return true;
451
472
}
452
473
@@ -463,14 +484,14 @@ check_db(char *dbname, char *user, char *param_str)
463
484
464
485
for (tok = strtok (param_str , MULTI_VALUE_SEP ); tok != NULL ; tok = strtok (NULL , MULTI_VALUE_SEP ))
465
486
{
466
- if (strcmp (tok , "all" ) == 0 )
487
+ if (strcmp (tok , "all\n " ) == 0 )
467
488
return true;
468
- else if (strcmp (tok , "sameuser" ) == 0 )
489
+ else if (strcmp (tok , "sameuser\n " ) == 0 )
469
490
{
470
491
if (strcmp (dbname , user ) == 0 )
471
492
return true;
472
493
}
473
- else if (strcmp (tok , "samegroup" ) == 0 )
494
+ else if (strcmp (tok , "samegroup\n " ) == 0 )
474
495
{
475
496
if (check_group (dbname , user ))
476
497
return true;
@@ -1068,7 +1089,7 @@ check_ident_usermap(const char *usermap_name,
1068
1089
errmsg ("cannot use Ident authentication without usermap field" )));
1069
1090
found_entry = false;
1070
1091
}
1071
- else if (strcmp (usermap_name , "sameuser" ) == 0 )
1092
+ else if (strcmp (usermap_name , "sameuser\n " ) == 0 )
1072
1093
{
1073
1094
if (strcmp (pg_user , ident_user ) == 0 )
1074
1095
found_entry = true;
0 commit comments