1 /* -------------------------------------------------------------------------
5 * Copyright (C) 2010-2011, PostgreSQL Global Development Group
8 * contrib/auth_delay/auth_delay.c
10 * -------------------------------------------------------------------------
14 #include "libpq/auth.h"
16 #include "utils/guc.h"
17 #include "utils/timestamp.h"
24 static int auth_delay_milliseconds;
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 original_client_auth_hook = ClientAuthentication_hook;
70 ClientAuthentication_hook = auth_delay_checks;