LCOV - code coverage report
Current view: top level - contrib/auth_delay - auth_delay.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 0 12 0.0 %
Date: 2019-11-21 13:06:38 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -------------------------------------------------------------------------
       2             :  *
       3             :  * auth_delay.c
       4             :  *
       5             :  * Copyright (c) 2010-2019, 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             : 
      21           0 : PG_MODULE_MAGIC;
      22             : 
      23             : void        _PG_init(void);
      24             : 
      25             : /* GUC Variables */
      26             : static int  auth_delay_milliseconds;
      27             : 
      28             : /* Original Hook */
      29             : static ClientAuthentication_hook_type original_client_auth_hook = NULL;
      30             : 
      31             : /*
      32             :  * Check authentication
      33             :  */
      34             : static void
      35           0 : auth_delay_checks(Port *port, int status)
      36             : {
      37             :     /*
      38             :      * Any other plugins which use ClientAuthentication_hook.
      39             :      */
      40           0 :     if (original_client_auth_hook)
      41           0 :         original_client_auth_hook(port, status);
      42             : 
      43             :     /*
      44             :      * Inject a short delay if authentication failed.
      45             :      */
      46           0 :     if (status != STATUS_OK)
      47             :     {
      48           0 :         pg_usleep(1000L * auth_delay_milliseconds);
      49             :     }
      50           0 : }
      51             : 
      52             : /*
      53             :  * Module Load Callback
      54             :  */
      55             : void
      56           0 : _PG_init(void)
      57             : {
      58             :     /* Define custom GUC variables */
      59           0 :     DefineCustomIntVariable("auth_delay.milliseconds",
      60             :                             "Milliseconds to delay before reporting authentication failure",
      61             :                             NULL,
      62             :                             &auth_delay_milliseconds,
      63             :                             0,
      64             :                             0, INT_MAX / 1000,
      65             :                             PGC_SIGHUP,
      66             :                             GUC_UNIT_MS,
      67             :                             NULL,
      68             :                             NULL,
      69             :                             NULL);
      70             :     /* Install Hooks */
      71           0 :     original_client_auth_hook = ClientAuthentication_hook;
      72           0 :     ClientAuthentication_hook = auth_delay_checks;
      73           0 : }

Generated by: LCOV version 1.13