1 /* -------------------------------------------------------------------------
5 * Copyright (c) 2010-2024, PostgreSQL Global Development Group
8 * contrib/auth_delay/auth_delay.c
10 * -------------------------------------------------------------------------
16 #include "libpq/auth.h"
18 #include "utils/guc.h"
19 #include "utils/timestamp.h"
24 static int auth_delay_milliseconds
= 0;
27 static ClientAuthentication_hook_type original_client_auth_hook
= NULL
;
30 * Check authentication
33 auth_delay_checks(Port
*port
, int status
)
36 * Any other plugins which use ClientAuthentication_hook.
38 if (original_client_auth_hook
)
39 original_client_auth_hook(port
, status
);
42 * Inject a short delay if authentication failed.
44 if (status
!= STATUS_OK
)
46 pg_usleep(1000L * auth_delay_milliseconds
);
51 * Module Load Callback
56 /* Define custom GUC variables */
57 DefineCustomIntVariable("auth_delay.milliseconds",
58 "Milliseconds to delay before reporting authentication failure",
60 &auth_delay_milliseconds
,
69 MarkGUCPrefixReserved("auth_delay");
72 original_client_auth_hook
= ClientAuthentication_hook
;
73 ClientAuthentication_hook
= auth_delay_checks
;