Skip to content

Commit b2a3d70

Browse files
committed
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
1 parent 07b3908 commit b2a3d70

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

contrib/passwordcheck/passwordcheck.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@
2626

2727
PG_MODULE_MAGIC;
2828

29+
/* Saved hook value in case of unload */
30+
static check_password_hook_type prev_check_password_hook = NULL;
31+
2932
/* passwords shorter than this will be rejected */
3033
#define MIN_PWD_LENGTH 8
3134

3235
extern void _PG_init(void);
36+
extern void _PG_fini(void);
3337

3438
/*
3539
* check_password
@@ -55,6 +59,11 @@ check_password(const char *username,
5559
Datum validuntil_time,
5660
bool validuntil_null)
5761
{
62+
if (prev_check_password_hook)
63+
prev_check_password_hook(username, shadow_pass,
64+
password_type, validuntil_time,
65+
validuntil_null);
66+
5867
if (password_type != PASSWORD_TYPE_PLAINTEXT)
5968
{
6069
/*
@@ -133,5 +142,16 @@ void
133142
_PG_init(void)
134143
{
135144
/* activate password checks when the module is loaded */
145+
prev_check_password_hook = check_password_hook;
136146
check_password_hook = check_password;
137147
}
148+
149+
/*
150+
* Module unload function
151+
*/
152+
void
153+
_PG_fini(void)
154+
{
155+
/* uninstall hook */
156+
check_password_hook = prev_check_password_hook;
157+
}

0 commit comments

Comments
 (0)