*
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.200 2010/03/03 20:31:08 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.201 2010/03/06 00:45:49 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
  * double quotes (this allows the inclusion of blanks, but not newlines).
  *
  * The token, if any, is returned at *buf (a buffer of size bufsz).
+ * Also, we set *initial_quote to indicate whether there was quoting before
+ * the first character.  (We use that to prevent "@x" from being treated
+ * as a file inclusion request.  Note that @"x" should be so treated;
+ * we want to allow that to support embedded spaces in file paths.)
  *
  * If successful: store null-terminated token at *buf and return TRUE.
  * If no more tokens on line: set *buf = '\0' and return FALSE.
  * token.
  */
 static bool
-next_token(FILE *fp, char *buf, int bufsz)
+next_token(FILE *fp, char *buf, int bufsz, bool *initial_quote)
 {
        int                     c;
        char       *start_buf = buf;
        bool            was_quote = false;
        bool            saw_quote = false;
 
+       /* end_buf reserves two bytes to ensure we can append \n and \0 */
        Assert(end_buf > start_buf);
 
+       *initial_quote = false;
+
        /* Move over initial whitespace and commas */
        while ((c = getc(fp)) != EOF && (pg_isblank(c) || c == ','))
                ;
                {
                        in_quote = !in_quote;
                        saw_quote = true;
+                       if (buf == start_buf)
+                               *initial_quote = true;
                }
 
                c = getc(fp);
        char       *comma_str = pstrdup("");
        bool            got_something = false;
        bool            trailing_comma;
+       bool            initial_quote;
        char       *incbuf;
        int                     needed;
 
        do
        {
-               if (!next_token(file, buf, sizeof(buf)))
+               if (!next_token(file, buf, sizeof(buf), &initial_quote))
                        break;
 
                got_something = true;
                        trailing_comma = false;
 
                /* Is this referencing a file? */
-               if (buf[0] == '@')
+               if (!initial_quote && buf[0] == '@' && buf[1] != '\0')
                        incbuf = tokenize_inc_file(filename, buf + 1);
                else
                        incbuf = pstrdup(buf);