Thread: pg_hba.conf additional comment re local line

pg_hba.conf additional comment re local line

From
Andrew Dunstan
Date:
The attached tiny patch will possibly help to avoid some confusion by
Windows users about the "local" line in pg_hba.conf (and thus help
reduce queries to us ;-) ). It also removes an essentially content-free
suffix in 2 nearby comment lines.

cheers

andrew
Index: src/backend/libpq/pg_hba.conf.sample
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/pg_hba.conf.sample,v
retrieving revision 1.53
diff -c -w -r1.53 pg_hba.conf.sample
*** src/backend/libpq/pg_hba.conf.sample    26 Aug 2004 16:50:05 -0000    1.53
--- src/backend/libpq/pg_hba.conf.sample    21 Sep 2004 16:41:30 -0000
***************
*** 60,67 ****

  # TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

  local   all         all                               @authmethod@
! # IPv4-style local connections:
  host    all         all         127.0.0.1/32          @authmethod@
! # IPv6-style local connections:
  host    all         all         ::1/128               @authmethod@
--- 60,68 ----

  # TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

+ # "local" is for Unix domain socket connections, and does not apply to Windows
  local   all         all                               @authmethod@
! # IPv4 local connections:
  host    all         all         127.0.0.1/32          @authmethod@
! # IPv6 local connections:
  host    all         all         ::1/128               @authmethod@

Re: pg_hba.conf additional comment re local line

From
Peter Eisentraut
Date:
Andrew Dunstan wrote:
> The attached tiny patch will possibly help to avoid some confusion by
> Windows users about the "local" line in pg_hba.conf (and thus help
> reduce queries to us ;-) ). It also removes an essentially
> content-free suffix in 2 nearby comment lines.

Maybe initdb should just remove those lines on Windows.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


Re: pg_hba.conf additional comment re local line

From
Andrew Dunstan
Date:

Peter Eisentraut wrote:

>Andrew Dunstan wrote:
>
>
>>The attached tiny patch will possibly help to avoid some confusion by
>>Windows users about the "local" line in pg_hba.conf (and thus help
>>reduce queries to us ;-) ). It also removes an essentially
>>content-free suffix in 2 nearby comment lines.
>>
>>
>
>Maybe initdb should just remove those lines on Windows.
>
>
>

You are probably right. initdb's filtering capabilities are (by design)
rather primitive - I didn't want to clutter it up with regex code - so
it's a bit less easy than it might otherwise be.

This patch was done as a "quick fix".

If someone doesn't beat me to it I will try to look at initdb in the
next week or so.

cheers

andrew

Re: pg_hba.conf additional comment re local line

From
Tom Lane
Date:
Andrew Dunstan <andrew@dunslane.net> writes:
> The attached tiny patch will possibly help to avoid some confusion by
> Windows users about the "local" line in pg_hba.conf (and thus help
> reduce queries to us ;-) ).

I was wondering if we could teach initdb to remove that line altogether
in Windows installations.

            regards, tom lane

Re: pg_hba.conf additional comment re local line

From
Andrew Dunstan
Date:

Tom Lane wrote:

>Andrew Dunstan <andrew@dunslane.net> writes:
>
>
>>The attached tiny patch will possibly help to avoid some confusion by
>>Windows users about the "local" line in pg_hba.conf (and thus help
>>reduce queries to us ;-) ).
>>
>>
>
>I was wondering if we could teach initdb to remove that line altogether
>in Windows installations.
>
>
>

See later email.

Of course it can be done. Probably the simplest way is a new small
routine called, say filter_token, which would remove lines containing a
given token:

  static char **filter_token(char **lines, char *token);

Then we could have something like:

#ifdef WIN32 (orwhatever we are calling it now)
    conflines = filter_token(conflines,"@remove-line-for-win32@");
#else
    conflines = replace_token(conflines, "@remove-line-for-win32@","");
#endif

Incidentally, even Unix users frequently get confused about the "local"
line - one of the commonest newbie mistakes is to think it means
localhost. So marking it clearly as being for Unix domain sockets would
still be a Good Thing (tm).

cheers

andrew

>            regards, tom lane
>
>---------------------------(end of broadcast)---------------------------
>TIP 7: don't forget to increase your free space map settings
>
>
>

Re: pg_hba.conf additional comment re local line

From
Andrew Dunstan
Date:
The original of this seems to have gotten lost in the ether somewhere.
It might turn up some day ...

andrew

Tom Lane wrote:

>Andrew Dunstan <andrew@dunslane.net> writes:
>
>
>>The attached tiny patch will possibly help to avoid some confusion by
>>Windows users about the "local" line in pg_hba.conf (and thus help
>>reduce queries to us ;-) ).
>>
>>
>
>I was wondering if we could teach initdb to remove that line altogether
>in Windows installations.
>
>
>
>

I think this does what Tom and Peter suggested. I don't have a Windows
box to test it on, though.

cheers

andrew


Index: src/backend/libpq/pg_hba.conf.sample
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/pg_hba.conf.sample,v
retrieving revision 1.53
diff -c -w -r1.53 pg_hba.conf.sample
*** src/backend/libpq/pg_hba.conf.sample    26 Aug 2004 16:50:05 -0000    1.53
--- src/backend/libpq/pg_hba.conf.sample    22 Sep 2004 14:17:41 -0000
***************
*** 60,67 ****

  # TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

! local   all         all                               @authmethod@
! # IPv4-style local connections:
  host    all         all         127.0.0.1/32          @authmethod@
! # IPv6-style local connections:
  host    all         all         ::1/128               @authmethod@
--- 60,68 ----

  # TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

! @remove-line-for-win32@# "local" is for Unix domain socket connections only
! @remove-line-for-win32@local   all         all                               @authmethod@
! # IPv4 local connections:
  host    all         all         127.0.0.1/32          @authmethod@
! # IPv6 local connections:
  host    all         all         ::1/128               @authmethod@
Index: src/bin/initdb/initdb.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/initdb/initdb.c,v
retrieving revision 1.54
diff -c -w -r1.54 initdb.c
*** src/bin/initdb/initdb.c    2 Sep 2004 17:58:41 -0000    1.54
--- src/bin/initdb/initdb.c    22 Sep 2004 14:17:42 -0000
***************
*** 147,152 ****
--- 147,153 ----
  static void *xmalloc(size_t size);
  static char *xstrdup(const char *s);
  static char **replace_token(char **lines, char *token, char *replacement);
+ static char **filter_lines_with_token(char **lines, char *token);
  static char **readfile(char *path);
  static void writefile(char *path, char **lines);
  static int    mkdir_p(char *path, mode_t omode);
***************
*** 311,316 ****
--- 312,348 ----
  }

  /*
+  * make a copy of lines without any that contain the token
+  * a sort of poor man's grep -v
+  *
+  */
+
+ static char **
+ filter_lines_with_token(char **lines, char *token)
+ {
+     int            numlines = 1;
+     int            i, src, dst;
+     char      **result;
+
+     for (i = 0; lines[i]; i++)
+         numlines++;
+
+     result = (char **) xmalloc(numlines * sizeof(char *));
+
+     for (src = 0, dst = 0; src < numlines; src++)
+     {
+
+         if (lines[src] == NULL || strstr(lines[src], token) == NULL)
+         {
+             result[dst++] = lines[src];
+         }
+
+     }
+
+     return result;
+ }
+
+ /*
   * get the lines from a text file
   */
  static char **
***************
*** 1093,1098 ****
--- 1125,1136 ----

      conflines = readfile(hba_file);

+ #ifdef WIN32
+     conflines = filter_lines_with_token(conflines,"@remove-line-for-win32@");
+ #else
+     conflines = replace_token(conflines,"@remove-line-for-win32@","");
+ #endif
+
  #ifndef HAVE_IPV6
      conflines = replace_token(conflines,
                                "host    all         all         ::1",


Re: pg_hba.conf additional comment re local line

From
Bruce Momjian
Date:
Patch applied.  Thanks.

I adjusted the code slightly and I tested !HAVE_UNIX_SOCKETS rather than
Win32.

---------------------------------------------------------------------------


Andrew Dunstan wrote:
>
> The original of this seems to have gotten lost in the ether somewhere.
> It might turn up some day ...
>
> andrew
>
> Tom Lane wrote:
>
> >Andrew Dunstan <andrew@dunslane.net> writes:
> >
> >
> >>The attached tiny patch will possibly help to avoid some confusion by
> >>Windows users about the "local" line in pg_hba.conf (and thus help
> >>reduce queries to us ;-) ).
> >>
> >>
> >
> >I was wondering if we could teach initdb to remove that line altogether
> >in Windows installations.
> >
> >
> >
> >
>
> I think this does what Tom and Peter suggested. I don't have a Windows
> box to test it on, though.
>
> cheers
>
> andrew
>
>


>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073