pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: rafaelthca@gmail.com
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15932: Module passwordcheck doesn't reference previous hooks
Date: Tue, 30 Jul 2019 11:24:20 +0900
Message-ID: <20190730022420.GC1742@paquier.xyz> (raw)
In-Reply-To: <15932-78f48f9ef166778c@postgresql.org>
References: <15932-78f48f9ef166778c@postgresql.org>

On Mon, Jul 29, 2019 at 03:56:35PM +0000, PG Bug reporting form wrote:
> Module passwordcheck doesn't reference (thus, doesn't call) previous
> hooks:
> 
> https://github.com/postgres/postgres/blob/master/contrib/passwordcheck/passwordcheck.c#L133
> 
> As a result, if passwordcheck is used hook check_password_hook becomes
> useless.

So, it would erase the trace of previous hooks if loaded last.
passwordcheck holds value as an example of use for some hooks, and
examples should be a good students, so I agree to do better and fix
that.  The attached patch does the work, what do you think about it?
--
Michael

Attachments:

  [text/x-diff] passwordcheck-prev-hook-v1.patch (1.1K, ../20190730022420.GC1742@paquier.xyz/2-passwordcheck-prev-hook-v1.patch)
  download | inline diff:
diff --git a/contrib/passwordcheck/passwordcheck.c b/contrib/passwordcheck/passwordcheck.c
index b161e0f146..0cc51d1489 100644
--- a/contrib/passwordcheck/passwordcheck.c
+++ b/contrib/passwordcheck/passwordcheck.c
@@ -26,10 +26,14 @@
 
 PG_MODULE_MAGIC;
 
+/* Saved hook value in case of unload */
+static check_password_hook_type prev_check_password_hook = NULL;
+
 /* passwords shorter than this will be rejected */
 #define MIN_PWD_LENGTH 8
 
 extern void _PG_init(void);
+extern void _PG_fini(void);
 
 /*
  * check_password
@@ -55,6 +59,11 @@ check_password(const char *username,
 			   Datum validuntil_time,
 			   bool validuntil_null)
 {
+	if (prev_check_password_hook)
+		prev_check_password_hook(username, shadow_pass,
+								 password_type, validuntil_time,
+								 validuntil_null);
+
 	if (password_type != PASSWORD_TYPE_PLAINTEXT)
 	{
 		/*
@@ -133,5 +142,15 @@ void
 _PG_init(void)
 {
 	/* activate password checks when the module is loaded */
+	prev_check_password_hook = check_password_hook;
 	check_password_hook = check_password;
 }
+
+/*
+ * Module unload function
+ */
+void
+_PG_fini(void)
+{
+	check_password_hook = prev_check_password_hook;
+}

  [application/pgp-signature] signature.asc (832B, ../20190730022420.GC1742@paquier.xyz/3-signature.asc)
  download

view thread (7+ messages)  latest in thread

Message-ID: <20190730022420.GC1742@paquier.xyz>
Permalink:  ../20190730022420.GC1742@paquier.xyz/
Also on:    postgresql.org/message-id/20190730022420.GC1742@paquier.xyz

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: michael@paquier.xyz, rafaelthca@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #15932: Module passwordcheck doesn't reference previous hooks
  In-Reply-To: <20190730022420.GC1742@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox