pwdcheck-hook.patch
application/octet-stream
Filename: pwdcheck-hook.patch
Type: application/octet-stream
Part: 0
Message:
Re: Rejecting weak passwords
Patch
Format: context
| File | + | − |
|---|---|---|
| src/backend/commands/user.c | 25 | 0 |
| src/include/commands/user.h | 3 | 0 |
diff --new-file -c -r postgresql-8.5.orig/src/backend/commands/user.c postgresql-8.5/src/backend/commands/user.c
*** postgresql-8.5.orig/src/backend/commands/user.c 2009-11-16 11:31:15.000000000 +0100
--- postgresql-8.5/src/backend/commands/user.c 2009-11-16 11:33:37.000000000 +0100
***************
*** 35,40 ****
--- 35,43 ----
#include "utils/tqual.h"
+ /* Hook for plugins to check passwords in CreateRole() and AlterRole() */
+ PGDLLIMPORT check_password_hook_type check_password_hook = NULL;
+
extern bool Password_encryption;
static List *roleNamesToIds(List *memberNames);
***************
*** 299,304 ****
--- 302,318 ----
stmt->role)));
/*
+ * Call the password checking function if there is one defined
+ */
+ if (check_password_hook && password)
+ {
+ if (! (*check_password_hook)(stmt->role, password))
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("password rejected as insecure")));
+ }
+
+ /*
* Build a tuple to insert
*/
MemSet(new_record, 0, sizeof(new_record));
***************
*** 588,593 ****
--- 602,618 ----
}
/*
+ * Call the password checking function if there is one defined
+ */
+ if (check_password_hook && password)
+ {
+ if (! (*check_password_hook)(stmt->role, password))
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("password rejected as insecure")));
+ }
+
+ /*
* Build an updated tuple, perusing the information just obtained
*/
MemSet(new_record, 0, sizeof(new_record));
diff --new-file -c -r postgresql-8.5.orig/src/include/commands/user.h postgresql-8.5/src/include/commands/user.h
*** postgresql-8.5.orig/src/include/commands/user.h 2009-11-16 11:31:19.000000000 +0100
--- postgresql-8.5/src/include/commands/user.h 2009-11-16 11:44:33.000000000 +0100
***************
*** 13,18 ****
--- 13,21 ----
#include "nodes/parsenodes.h"
+ /* Hook for plugins to check passwords in CreateRole() and AlterRole() */
+ typedef bool(*check_password_hook_type)(const char * username, const char * password);
+ extern PGDLLIMPORT check_password_hook_type check_password_hook;
extern void CreateRole(CreateRoleStmt *stmt);
extern void AlterRole(AlterRoleStmt *stmt);