Re: [PATCHES] distinguish between all and "all" in pg_hba.conf

2003-12-24 Thread Bruce Momjian

Patch applied.  Thanks.

---


Andrew Dunstan wrote:
> I wrote:
> 
> > Tom Lane wrote:
> >
> >> Andrew Dunstan <[EMAIL PROTECTED]> writes:
> >>  
> >>
> >>> The minimal disturbance change might be to teach the parser to 
> >>> distinguish between a quoted 'all' and an unquoted 'all', and forget 
> >>> the '*' idea.
> >>>   
> >>
> >>
> >> Probably we ought to go with that, on backwards-compatibility grounds.
> >>
> >>  
> >>
> >
> > OK, here's the patch. Should we also do this for "sameuser" and 
> > "samegroup" for the sake of completness?
> 
> 
> 
> Revised patch for this as suggested by Tom.
> 
> cheers
> 
> andrew
> 

> Index: hba.c
> ===
> RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/hba.c,v
> retrieving revision 1.118
> diff -c -w -r1.118 hba.c
> *** hba.c 5 Dec 2003 15:50:31 -   1.118
> --- hba.c 19 Dec 2003 17:42:20 -
> ***
> *** 87,102 
>*   token or EOF, whichever comes first. If no more tokens on line,
>*   return null string as *buf and position file to beginning of
>*   next line or EOF, whichever comes first. Allow spaces in quoted
> !  *   strings. Terminate on unquoted commas. Handle comments.
>*/
>   void
>   next_token(FILE *fp, char *buf, const int bufsz)
>   {
>   int c;
>   char   *start_buf = buf;
> ! char   *end_buf = buf + (bufsz - 1);
>   boolin_quote = false;
>   boolwas_quote = false;
>   
>   /* Move over initial whitespace and commas */
>   while ((c = getc(fp)) != EOF && (pg_isblank(c) || c == ','))
> --- 87,105 
>*   token or EOF, whichever comes first. If no more tokens on line,
>*   return null string as *buf and position file to beginning of
>*   next line or EOF, whichever comes first. Allow spaces in quoted
> !  *   strings. Terminate on unquoted commas. Handle comments. Treat
> !  *   unquoted keywords that might be user names or database names 
> !  *   specially, by appending a newline to them.
>*/
>   void
>   next_token(FILE *fp, char *buf, const int bufsz)
>   {
>   int c;
>   char   *start_buf = buf;
> ! char   *end_buf = buf + (bufsz - 2);
>   boolin_quote = false;
>   boolwas_quote = false;
> + boolsaw_quote = false;
>   
>   /* Move over initial whitespace and commas */
>   while ((c = getc(fp)) != EOF && (pg_isblank(c) || c == ','))
> ***
> *** 149,155 
> --- 152,161 
>   was_quote = false;
>   
>   if (c == '"')
> + {
>   in_quote = !in_quote;
> + saw_quote = true;
> + }
>   
>   c = getc(fp);
>   }
> ***
> *** 161,167 
> --- 167,188 
>   if (c != EOF)
>   ungetc(c, fp);
>   }
> + 
> + 
> + if ( !saw_quote && 
> +  (
> +  strncmp(start_buf,"all",3) == 0  ||
> +  strncmp(start_buf,"sameuser",8) == 0  ||
> +  strncmp(start_buf,"samegroup",9) == 0 
> +  )
> + )
> + {
> + /* append newline to a magical keyword */
> + *buf++ = '\n';
> + }
> + 
>   *buf = '\0';
> + 
>   }
>   
>   /*
> ***
> *** 446,452 
>   return true;
>   }
>   else if (strcmp(tok, user) == 0 ||
> !  strcmp(tok, "all") == 0)
>   return true;
>   }
>   
> --- 467,473 
>   return true;
>   }
>   else if (strcmp(tok, user) == 0 ||
> !  strcmp(tok, "all\n") == 0)
>   return true;
>   }
>   
> ***
> *** 463,476 
>   
>   for (tok = strtok(param_str, MULTI_VALUE_SEP); tok != NULL; tok = strtok(NULL, 
> MULTI_VALUE_SEP))
>   {
> ! if (strcmp(tok, "all") == 0)
>   return true;
> ! else if (strcmp(tok, "sameuser") == 0)
>   {
>   if (strcmp(dbname, user) == 0)
>   return true;
>   }
> ! else if (strcmp(tok, "samegroup") == 0)
>   {
>   if (check_group(dbname, user))
>   return true;
> --- 484,497 
>   
>   for (tok = strtok(param_str, MULTI_VALUE_SEP); tok != NULL; tok = strtok(NULL, 
> MULTI_VALUE_SEP))
>   {
> ! if (strcmp(tok, "all\n") == 0)
>   return true;
> ! else if (strcmp(tok, "sameuser\n") == 0)
>   {
>   if (str

Re: [PATCHES] distinguish between all and "all" in pg_hba.conf

2003-12-19 Thread Bruce Momjian

That IPv6 cleanup is major!

> ! hostall all ::1   
> :::::::trust

> ! hostall all ::1/128 trust

Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---


Andrew Dunstan wrote:
> I wrote:
> 
> > Tom Lane wrote:
> >
> >> Andrew Dunstan <[EMAIL PROTECTED]> writes:
> >>  
> >>
> >>> The minimal disturbance change might be to teach the parser to 
> >>> distinguish between a quoted 'all' and an unquoted 'all', and forget 
> >>> the '*' idea.
> >>>   
> >>
> >>
> >> Probably we ought to go with that, on backwards-compatibility grounds.
> >>
> >>  
> >>
> >
> > OK, here's the patch. Should we also do this for "sameuser" and 
> > "samegroup" for the sake of completness?
> 
> 
> 
> Revised patch for this as suggested by Tom.
> 
> cheers
> 
> andrew
> 

> Index: hba.c
> ===
> RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/hba.c,v
> retrieving revision 1.118
> diff -c -w -r1.118 hba.c
> *** hba.c 5 Dec 2003 15:50:31 -   1.118
> --- hba.c 19 Dec 2003 17:42:20 -
> ***
> *** 87,102 
>*   token or EOF, whichever comes first. If no more tokens on line,
>*   return null string as *buf and position file to beginning of
>*   next line or EOF, whichever comes first. Allow spaces in quoted
> !  *   strings. Terminate on unquoted commas. Handle comments.
>*/
>   void
>   next_token(FILE *fp, char *buf, const int bufsz)
>   {
>   int c;
>   char   *start_buf = buf;
> ! char   *end_buf = buf + (bufsz - 1);
>   boolin_quote = false;
>   boolwas_quote = false;
>   
>   /* Move over initial whitespace and commas */
>   while ((c = getc(fp)) != EOF && (pg_isblank(c) || c == ','))
> --- 87,105 
>*   token or EOF, whichever comes first. If no more tokens on line,
>*   return null string as *buf and position file to beginning of
>*   next line or EOF, whichever comes first. Allow spaces in quoted
> !  *   strings. Terminate on unquoted commas. Handle comments. Treat
> !  *   unquoted keywords that might be user names or database names 
> !  *   specially, by appending a newline to them.
>*/
>   void
>   next_token(FILE *fp, char *buf, const int bufsz)
>   {
>   int c;
>   char   *start_buf = buf;
> ! char   *end_buf = buf + (bufsz - 2);
>   boolin_quote = false;
>   boolwas_quote = false;
> + boolsaw_quote = false;
>   
>   /* Move over initial whitespace and commas */
>   while ((c = getc(fp)) != EOF && (pg_isblank(c) || c == ','))
> ***
> *** 149,155 
> --- 152,161 
>   was_quote = false;
>   
>   if (c == '"')
> + {
>   in_quote = !in_quote;
> + saw_quote = true;
> + }
>   
>   c = getc(fp);
>   }
> ***
> *** 161,167 
> --- 167,188 
>   if (c != EOF)
>   ungetc(c, fp);
>   }
> + 
> + 
> + if ( !saw_quote && 
> +  (
> +  strncmp(start_buf,"all",3) == 0  ||
> +  strncmp(start_buf,"sameuser",8) == 0  ||
> +  strncmp(start_buf,"samegroup",9) == 0 
> +  )
> + )
> + {
> + /* append newline to a magical keyword */
> + *buf++ = '\n';
> + }
> + 
>   *buf = '\0';
> + 
>   }
>   
>   /*
> ***
> *** 446,452 
>   return true;
>   }
>   else if (strcmp(tok, user) == 0 ||
> !  strcmp(tok, "all") == 0)
>   return true;
>   }
>   
> --- 467,473 
>   return true;
>   }
>   else if (strcmp(tok, user) == 0 ||
> !  strcmp(tok, "all\n") == 0)
>   return true;
>   }
>   
> ***
> *** 463,476 
>   
>   for (tok = strtok(param_str, MULTI_VALUE_SEP); tok != NULL; tok = strtok(NULL, 
> MULTI_VALUE_SEP))
>   {
> ! if (strcmp(tok, "all") == 0)
>   return true;
> ! else if (strcmp(tok, "sameuser") == 0)
>   {
>   if (strcmp(dbname, user) == 0)
>   return true;
>   }
> ! else if (strcmp(tok, "samegroup") == 0)
>   {
>   if (check_group(dbname, user))
>   

Re: [PATCHES] distinguish between all and "all" in pg_hba.conf

2003-12-19 Thread Andrew Dunstan
I wrote:

Tom Lane wrote:

Andrew Dunstan <[EMAIL PROTECTED]> writes:
 

The minimal disturbance change might be to teach the parser to 
distinguish between a quoted 'all' and an unquoted 'all', and forget 
the '*' idea.
  


Probably we ought to go with that, on backwards-compatibility grounds.

 

OK, here's the patch. Should we also do this for "sameuser" and 
"samegroup" for the sake of completness?


Revised patch for this as suggested by Tom.

cheers

andrew

Index: hba.c
===
RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/hba.c,v
retrieving revision 1.118
diff -c -w -r1.118 hba.c
*** hba.c   5 Dec 2003 15:50:31 -   1.118
--- hba.c   19 Dec 2003 17:42:20 -
***
*** 87,102 
   * token or EOF, whichever comes first. If no more tokens on line,
   * return null string as *buf and position file to beginning of
   * next line or EOF, whichever comes first. Allow spaces in quoted
!  * strings. Terminate on unquoted commas. Handle comments.
   */
  void
  next_token(FILE *fp, char *buf, const int bufsz)
  {
int c;
char   *start_buf = buf;
!   char   *end_buf = buf + (bufsz - 1);
boolin_quote = false;
boolwas_quote = false;
  
/* Move over initial whitespace and commas */
while ((c = getc(fp)) != EOF && (pg_isblank(c) || c == ','))
--- 87,105 
   * token or EOF, whichever comes first. If no more tokens on line,
   * return null string as *buf and position file to beginning of
   * next line or EOF, whichever comes first. Allow spaces in quoted
!  * strings. Terminate on unquoted commas. Handle comments. Treat
!  *   unquoted keywords that might be user names or database names 
!  *   specially, by appending a newline to them.
   */
  void
  next_token(FILE *fp, char *buf, const int bufsz)
  {
int c;
char   *start_buf = buf;
!   char   *end_buf = buf + (bufsz - 2);
boolin_quote = false;
boolwas_quote = false;
+   boolsaw_quote = false;
  
/* Move over initial whitespace and commas */
while ((c = getc(fp)) != EOF && (pg_isblank(c) || c == ','))
***
*** 149,155 
--- 152,161 
was_quote = false;
  
if (c == '"')
+   {
in_quote = !in_quote;
+   saw_quote = true;
+   }
  
c = getc(fp);
}
***
*** 161,167 
--- 167,188 
if (c != EOF)
ungetc(c, fp);
}
+ 
+ 
+   if ( !saw_quote && 
+(
+strncmp(start_buf,"all",3) == 0  ||
+strncmp(start_buf,"sameuser",8) == 0  ||
+strncmp(start_buf,"samegroup",9) == 0 
+)
+   )
+   {
+   /* append newline to a magical keyword */
+   *buf++ = '\n';
+   }
+ 
*buf = '\0';
+ 
  }
  
  /*
***
*** 446,452 
return true;
}
else if (strcmp(tok, user) == 0 ||
!strcmp(tok, "all") == 0)
return true;
}
  
--- 467,473 
return true;
}
else if (strcmp(tok, user) == 0 ||
!strcmp(tok, "all\n") == 0)
return true;
}
  
***
*** 463,476 
  
for (tok = strtok(param_str, MULTI_VALUE_SEP); tok != NULL; tok = strtok(NULL, 
MULTI_VALUE_SEP))
{
!   if (strcmp(tok, "all") == 0)
return true;
!   else if (strcmp(tok, "sameuser") == 0)
{
if (strcmp(dbname, user) == 0)
return true;
}
!   else if (strcmp(tok, "samegroup") == 0)
{
if (check_group(dbname, user))
return true;
--- 484,497 
  
for (tok = strtok(param_str, MULTI_VALUE_SEP); tok != NULL; tok = strtok(NULL, 
MULTI_VALUE_SEP))
{
!   if (strcmp(tok, "all\n") == 0)
return true;
!   else if (strcmp(tok, "sameuser\n") == 0)
{
if (strcmp(dbname, user) == 0)
return true;
}
!   else if (strcmp(tok, "samegroup\n") == 0)
{
if (check_group(dbname, user))
return true;
***
*** 1068,1074 
errmsg("canno