aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-08-01 09:37:28 +0900
committerMichael Paquier <michael@paquier.xyz>2019-08-01 09:37:28 +0900
commitb2a3d706b8d76b9d65e953942fc1ccafe892f692 (patch)
tree1fd53a8bfcd1f8b58ebd459c117dbdce200bea19
parent07b39083c2aca003c4b1f289d7dc2368b5e2297a (diff)
downloadpostgresql-b2a3d706b8d76b9d65e953942fc1ccafe892f692.tar.gz
postgresql-b2a3d706b8d76b9d65e953942fc1ccafe892f692.zip
Fix handling of previous password hooks in passwordcheck
When piling up loading of modules using check_password_hook_type, loading passwordcheck would remove any trace of a previously-loaded hook. Unloading the module would also cause previous hooks to be entirely gone. Reported-by: Rafael Castro Author: Michael Paquier Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/15932-78f48f9ef166778c@postgresql.org Backpatch-through: 9.4
-rw-r--r--contrib/passwordcheck/passwordcheck.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/contrib/passwordcheck/passwordcheck.c b/contrib/passwordcheck/passwordcheck.c
index b161e0f1460..c3fb5a9c085 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,16 @@ 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)
+{
+ /* uninstall hook */
+ check_password_hook = prev_check_password_hook;
+}