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 */
9294void
9395next_token (FILE * fp ,char * buf ,const int bufsz )
9496{
9597int c ;
9698char * start_buf = buf ;
97- char * end_buf = buf + (bufsz - 1 );
99+ char * end_buf = buf + (bufsz - 2 );
98100bool in_quote = false;
99101bool was_quote = false;
102+ bool saw_quote = false;
100103
101104/* Move over initial whitespace and commas */
102105while ((c = getc (fp ))!= EOF && (pg_isblank (c )|| c == ',' ))
@@ -149,7 +152,10 @@ next_token(FILE *fp, char *buf, const int bufsz)
149152was_quote = false;
150153
151154if (c == '"' )
155+ {
152156in_quote = !in_quote ;
157+ saw_quote = true;
158+ }
153159
154160c = getc (fp );
155161}
@@ -161,7 +167,22 @@ next_token(FILE *fp, char *buf, const int bufsz)
161167if (c != EOF )
162168ungetc (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)
446467return true;
447468}
448469else if (strcmp (tok ,user )== 0 ||
449- strcmp (tok ,"all" )== 0 )
470+ strcmp (tok ,"all\n " )== 0 )
450471return true;
451472}
452473
@@ -463,14 +484,14 @@ check_db(char *dbname, char *user, char *param_str)
463484
464485for (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 )
467488return true;
468- else if (strcmp (tok ,"sameuser" )== 0 )
489+ else if (strcmp (tok ,"sameuser\n " )== 0 )
469490{
470491if (strcmp (dbname ,user )== 0 )
471492return true;
472493}
473- else if (strcmp (tok ,"samegroup" )== 0 )
494+ else if (strcmp (tok ,"samegroup\n " )== 0 )
474495{
475496if (check_group (dbname ,user ))
476497return true;
@@ -1068,7 +1089,7 @@ check_ident_usermap(const char *usermap_name,
10681089errmsg ("cannot use Ident authentication without usermap field" )));
10691090found_entry = false;
10701091}
1071- else if (strcmp (usermap_name ,"sameuser" )== 0 )
1092+ else if (strcmp (usermap_name ,"sameuser\n " )== 0 )
10721093{
10731094if (strcmp (pg_user ,ident_user )== 0 )
10741095found_entry = true;