1 /* -------------------------------------------------------------------------
5 * Copyright (c) 2010-2022, 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"
26 static int auth_delay_milliseconds
;
29 static ClientAuthentication_hook_type original_client_auth_hook
= NULL
;
32 * Check authentication
35 auth_delay_checks(Port
*port
, int status
)
38 * Any other plugins which use ClientAuthentication_hook.
40 if (original_client_auth_hook
)
41 original_client_auth_hook(port
, status
);
44 * Inject a short delay if authentication failed.
46 if (status
!= STATUS_OK
)
48 pg_usleep(1000L * auth_delay_milliseconds
);
53 * Module Load Callback
58 /* Define custom GUC variables */
59 DefineCustomIntVariable("auth_delay.milliseconds",
60 "Milliseconds to delay before reporting authentication failure",
62 &auth_delay_milliseconds
,
71 EmitWarningsOnPlaceholders("auth_delay");
74 original_client_auth_hook
= ClientAuthentication_hook
;
75 ClientAuthentication_hook
= auth_delay_checks
;