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-2022, 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 "port.h"
18 #include "utils/guc.h"
19 #include "utils/timestamp.h"
20 
22 
23 /* GUC Variables */
24 static int auth_delay_milliseconds = 0;
25 
26 /* Original Hook */
28 
29 /*
30  * Check authentication
31  */
32 static void
34 {
35  /*
36  * Any other plugins which use ClientAuthentication_hook.
37  */
40 
41  /*
42  * Inject a short delay if authentication failed.
43  */
44  if (status != STATUS_OK)
45  {
47  }
48 }
49 
50 /*
51  * Module Load Callback
52  */
53 void
54 _PG_init(void)
55 {
56  /* Define custom GUC variables */
57  DefineCustomIntVariable("auth_delay.milliseconds",
58  "Milliseconds to delay before reporting authentication failure",
59  NULL,
61  0,
62  0, INT_MAX / 1000,
63  PGC_SIGHUP,
65  NULL,
66  NULL,
67  NULL);
68 
69  MarkGUCPrefixReserved("auth_delay");
70 
71  /* Install Hooks */
74 }
ClientAuthentication_hook_type ClientAuthentication_hook
Definition: auth.c:227
void(* ClientAuthentication_hook_type)(Port *, int)
Definition: auth.h:28
static void auth_delay_checks(Port *port, int status)
Definition: auth_delay.c:33
void _PG_init(void)
Definition: auth_delay.c:54
PG_MODULE_MAGIC
Definition: auth_delay.c:21
static int auth_delay_milliseconds
Definition: auth_delay.c:24
static ClientAuthentication_hook_type original_client_auth_hook
Definition: auth_delay.c:27
#define STATUS_OK
Definition: c.h:1108
void MarkGUCPrefixReserved(const char *className)
Definition: guc.c:5087
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:4966
#define GUC_UNIT_MS
Definition: guc.h:232
@ PGC_SIGHUP
Definition: guc.h:71
static int port
Definition: pg_regress.c:90
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:225
void pg_usleep(long microsec)
Definition: signal.c:53
Definition: libpq-be.h:146