PostgreSQL Source Code  git master
auth_delay.c
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  *
3  * auth_delay.c
4  *
5  * Copyright (c) 2010-2024, PostgreSQL Global Development Group
6  *
7  * IDENTIFICATION
8  * contrib/auth_delay/auth_delay.c
9  *
10  * -------------------------------------------------------------------------
11  */
12 #include "postgres.h"
13 
14 #include <limits.h>
15 
16 #include "libpq/auth.h"
17 #include "utils/guc.h"
18 
20 
21 /* GUC Variables */
22 static int auth_delay_milliseconds = 0;
23 
24 /* Original Hook */
26 
27 /*
28  * Check authentication
29  */
30 static void
32 {
33  /*
34  * Any other plugins which use ClientAuthentication_hook.
35  */
38 
39  /*
40  * Inject a short delay if authentication failed.
41  */
42  if (status != STATUS_OK)
43  {
45  }
46 }
47 
48 /*
49  * Module Load Callback
50  */
51 void
52 _PG_init(void)
53 {
54  /* Define custom GUC variables */
55  DefineCustomIntVariable("auth_delay.milliseconds",
56  "Milliseconds to delay before reporting authentication failure",
57  NULL,
59  0,
60  0, INT_MAX / 1000,
61  PGC_SIGHUP,
63  NULL,
64  NULL,
65  NULL);
66 
67  MarkGUCPrefixReserved("auth_delay");
68 
69  /* Install Hooks */
72 }
ClientAuthentication_hook_type ClientAuthentication_hook
Definition: auth.c:230
void(* ClientAuthentication_hook_type)(Port *, int)
Definition: auth.h:28
static void auth_delay_checks(Port *port, int status)
Definition: auth_delay.c:31
void _PG_init(void)
Definition: auth_delay.c:52
PG_MODULE_MAGIC
Definition: auth_delay.c:19
static int auth_delay_milliseconds
Definition: auth_delay.c:22
static ClientAuthentication_hook_type original_client_auth_hook
Definition: auth_delay.c:25
#define STATUS_OK
Definition: c.h:1123
void MarkGUCPrefixReserved(const char *className)
Definition: guc.c:5279
void DefineCustomIntVariable(const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, GucIntAssignHook assign_hook, GucShowHook show_hook)
Definition: guc.c:5158
#define GUC_UNIT_MS
Definition: guc.h:235
@ PGC_SIGHUP
Definition: guc.h:71
static int port
Definition: pg_regress.c:115
void pg_usleep(long microsec)
Definition: signal.c:53
Definition: libpq-be.h:133