Re: pg_hba_lookup function to get all matching pg_hba.conf entries

Поиск
Список
Период
Сортировка
От Shulgin, Oleksandr
Тема Re: pg_hba_lookup function to get all matching pg_hba.conf entries
Дата
Msg-id CACACo5Th0PuHvJVE_TOoSAqOkrPaJvmtySGwFJ-bk=azDOQcnw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: pg_hba_lookup function to get all matching pg_hba.conf entries  (Haribabu Kommi <kommi.haribabu@gmail.com>)
Ответы Re: pg_hba_lookup function to get all matching pg_hba.conf entries  (Haribabu Kommi <kommi.haribabu@gmail.com>)
Список pgsql-hackers
On Tue, Dec 29, 2015 at 4:15 AM, Haribabu Kommi <kommi.haribabu@gmail.com> wrote:
On Mon, Dec 28, 2015 at 9:09 PM, Shulgin, Oleksandr
<oleksandr.shulgin@zalando.de> wrote:
>
> Still this requires a revert of the memory context handling commit for
> load_hba() and load_ident().  I think you can get around the problem by
> changing these functions to work with CurrentMemoryContext and set it
> explicitly to the newly allocated PostmasterContext in
> PerformAuthentication().  In your function you could then create a temporary
> context to be discarded before leaving the function.

Thanks for the review. I didn't understand your point clearly.

In the attached patch, load_hba uses PostmasterContext if it is present,
otherwise CurretMemoryContext. PostmasterContext is present only
in the backend start phase.

> I still think you should not try to re-implement check_hba(), but extend
> this function with means to report line skip reasons as per your
> requirements.  Having an optional callback function might be a good fit (a
> possible use case is logging the reasons line by line).

check_hba function is enhanced to fill the hba line details with
reason for mismatch.
In check_hba function whenever a mismatch is found, the fill_hbaline function is
called to frame the tuple and inserted into tuple store.

This is close enough, but what I actually mean by "a callback" is more or less like the attached version.

While at it, I've also added some trivial code to preserve keyword quoting in database and user fields, as well as added netmask output parameter; also documentation is extended a little.

The biggest question for me is the proper handling of memory contexts for HBA and ident files data.  I think it makes sense to release them explicitly because with the current state of affairs, we have dangling pointers in parsed_{hba,ident}_{context,lines} after release of PostmasterContext.  The detailed comment in postgres.c around MemoryContextDelete(PostmasterContext); suggests that it's not easy already to keep track of the all things that might be affected by this cleanup step:

/*
* If the PostmasterContext is still around, recycle the space; we don't
* need it anymore after InitPostgres completes.  Note this does not trash
* *MyProcPort, because ConnCreate() allocated that space with malloc()
* ... else we'd need to copy the Port data first.  Also, subsidiary data
* such as the username isn't lost either; see ProcessStartupPacket().
*/

Not sure if we need any advanced machinery here like some sort of cleanup hooks list?  For now I've added discard_{hba,ident}() functions and call them explicitly where appropriate.

--
Alex

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Stephen Frost
Дата:
Сообщение: Re: Additional role attributes && superuser review
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: Making tab-complete.c easier to maintain