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-2017, 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 void _PG_init(void);
24 
25 /* GUC Variables */
27 
28 /* Original Hook */
30 
31 /*
32  * Check authentication
33  */
34 static void
36 {
37  /*
38  * Any other plugins which use ClientAuthentication_hook.
39  */
41  original_client_auth_hook(port, status);
42 
43  /*
44  * Inject a short delay if authentication failed.
45  */
46  if (status != STATUS_OK)
47  {
49  }
50 }
51 
52 /*
53  * Module Load Callback
54  */
55 void
56 _PG_init(void)
57 {
58  /* Define custom GUC variables */
59  DefineCustomIntVariable("auth_delay.milliseconds",
60  "Milliseconds to delay before reporting authentication failure",
61  NULL,
63  0,
64  0, INT_MAX / 1000,
65  PGC_SIGHUP,
67  NULL,
68  NULL,
69  NULL);
70  /* Install Hooks */
73 }
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:7782
Definition: libpq-be.h:116
void _PG_init(void)
Definition: auth_delay.c:56
void pg_usleep(long microsec)
Definition: signal.c:53
PG_MODULE_MAGIC
Definition: auth_delay.c:21
ClientAuthentication_hook_type ClientAuthentication_hook
Definition: auth.c:242
static ClientAuthentication_hook_type original_client_auth_hook
Definition: auth_delay.c:29
void(* ClientAuthentication_hook_type)(Port *, int)
Definition: auth.h:26
#define STATUS_OK
Definition: c.h:953
static int port
Definition: pg_regress.c:90
Definition: guc.h:72
static void auth_delay_checks(Port *port, int status)
Definition: auth_delay.c:35
static int auth_delay_milliseconds
Definition: auth_delay.c:26
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:225
#define GUC_UNIT_MS
Definition: guc.h:225