Repair memory leaks in plpython.
[pgsql.git] / contrib / auth_delay / auth_delay.c
blobf611da2158bea80d87bfbc72ecde4d91cc714150
1 /* -------------------------------------------------------------------------
3 * auth_delay.c
5 * Copyright (c) 2010-2025, PostgreSQL Global Development Group
7 * IDENTIFICATION
8 * contrib/auth_delay/auth_delay.c
10 * -------------------------------------------------------------------------
12 #include "postgres.h"
14 #include <limits.h>
16 #include "libpq/auth.h"
17 #include "utils/guc.h"
19 PG_MODULE_MAGIC;
21 /* GUC Variables */
22 static int auth_delay_milliseconds = 0;
24 /* Original Hook */
25 static ClientAuthentication_hook_type original_client_auth_hook = NULL;
28 * Check authentication
30 static void
31 auth_delay_checks(Port *port, int status)
34 * Any other plugins which use ClientAuthentication_hook.
36 if (original_client_auth_hook)
37 original_client_auth_hook(port, status);
40 * Inject a short delay if authentication failed.
42 if (status != STATUS_OK)
44 pg_usleep(1000L * auth_delay_milliseconds);
49 * Module Load Callback
51 void
52 _PG_init(void)
54 /* Define custom GUC variables */
55 DefineCustomIntVariable("auth_delay.milliseconds",
56 "Milliseconds to delay before reporting authentication failure",
57 NULL,
58 &auth_delay_milliseconds,
60 0, INT_MAX / 1000,
61 PGC_SIGHUP,
62 GUC_UNIT_MS,
63 NULL,
64 NULL,
65 NULL);
67 MarkGUCPrefixReserved("auth_delay");
69 /* Install Hooks */
70 original_client_auth_hook = ClientAuthentication_hook;
71 ClientAuthentication_hook = auth_delay_checks;