Fix nbtree "deduce NOT NULL" scan key comment.
[pgsql.git] / contrib / auth_delay / auth_delay.c
blobff0e1fd461bb3320d942b3d114dea55ea1616ce5
1 /* -------------------------------------------------------------------------
3 * auth_delay.c
5 * Copyright (c) 2010-2024, 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 "port.h"
18 #include "utils/guc.h"
19 #include "utils/timestamp.h"
21 PG_MODULE_MAGIC;
23 /* GUC Variables */
24 static int auth_delay_milliseconds = 0;
26 /* Original Hook */
27 static ClientAuthentication_hook_type original_client_auth_hook = NULL;
30 * Check authentication
32 static void
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
53 void
54 _PG_init(void)
56 /* Define custom GUC variables */
57 DefineCustomIntVariable("auth_delay.milliseconds",
58 "Milliseconds to delay before reporting authentication failure",
59 NULL,
60 &auth_delay_milliseconds,
62 0, INT_MAX / 1000,
63 PGC_SIGHUP,
64 GUC_UNIT_MS,
65 NULL,
66 NULL,
67 NULL);
69 MarkGUCPrefixReserved("auth_delay");
71 /* Install Hooks */
72 original_client_auth_hook = ClientAuthentication_hook;
73 ClientAuthentication_hook = auth_delay_checks;