Skip to content

Commit eea28a3

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 4e10b6f commit eea28a3

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
@@ -27,10 +27,14 @@
2727

2828
PG_MODULE_MAGIC;
2929

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

3336
extern void _PG_init(void);
37+
extern void _PG_fini(void);
3438

3539
/*
3640
* check_password
@@ -63,6 +67,11 @@ check_password(const char *username,
6367
bool pwd_has_letter,
6468
pwd_has_nonletter;
6569

70+
if (prev_check_password_hook)
71+
prev_check_password_hook(username, password,
72+
password_type, validuntil_time,
73+
validuntil_null);
74+
6675
switch (password_type)
6776
{
6877
case PASSWORD_TYPE_MD5:
@@ -144,5 +153,16 @@ void
144153
_PG_init(void)
145154
{
146155
/* activate password checks when the module is loaded */
156+
prev_check_password_hook = check_password_hook;
147157
check_password_hook = check_password;
148158
}
159+
160+
/*
161+
* Module unload function
162+
*/
163+
void
164+
_PG_fini(void)
165+
{
166+
/* uninstall hook */
167+
check_password_hook = prev_check_password_hook;
168+
}

0 commit comments

Comments
 (0)