Re: Pasword expiration warning

From: Gilles Darold <gilles(at)darold(dot)net>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Pasword expiration warning
Date: 2026-01-29 15:39:54
Message-ID: fe15d2b8-729f-4783-9d72-fdc3c9da0c2f@darold.net
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Le 28/01/2026 à 13:44, Euler Taveira a écrit :
> On Fri, Jan 9, 2026, at 8:27 AM, Gilles Darold wrote:
>> Here is a v11 version of the patch.
>>
> + if (result <= (TimestampTz) password_expire_warning)
> + {
> + MyClientConnectionInfo.warning_message =
> + psprintf(_("your password will expire in %d day(s)"),
> + (int) (result / SECS_PER_DAY));
> + }
>
> You should use ngettext() for plural forms.

Is it a use we must do now or a wish?

$ grep -r "ngettext(" src/backend/ | wc -l
9
$ grep -r "(s)" src/backend/ | wc -l
831

If this is not a must do now, I prefer to use the old way because we
don't have to repeat 2 times the constant.

> I don't think you need a string into ClientConnectionInfo. Instead, you could store only the number of days.
>
> + /*
> + * Emit a warning message to the client when set, for example
> + * to warn the user that the password will expire.
> + */
> + if (MyClientConnectionInfo.warning_message)
> + ereport(WARNING, (errmsg("%s", MyClientConnectionInfo.warning_message)));
> +
>
> ... and you construct the message directly in the ereport().

I have explained this choice in my first message:

"I have chosen to add a new field, const char *warning_message, to
struct ClientConnectionInfo so that it can be used to send other
messages to the client at end of connection (
src/backend/utils/init/postinit.c: InitPostgres() ). Not sure sure that
this is the best way to do that but as it is a message dedicated to the
connection I've though it could be the right place. If we don't expect
other warning message sent to the client at connection time, just using
an integer for the number of days remaining will be enough. We could use
notice but it is not logged by default and also I think that warning is
the good level for this message. "

--
Gilles Darold
http://hexacluster.ai/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2026-01-29 15:41:20 Re: Improvements and refactoring in shmem.c
Previous Message Ilia Evdokimov 2026-01-29 15:25:12 Re: Optional skipping of unchanged relations during ANALYZE?