mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 00:03:57 -04:00 
			
		
		
		
	It seems potentially useful to label our shared libraries with version information, now that a facility exists for retrieving that. This patch labels them with the PG_VERSION string. There was some discussion about using semantic versioning conventions, but that doesn't seem terribly helpful for modules with no SQL-level presence; and for those that do have SQL objects, we typically expect them to support multiple revisions of the SQL definitions, so it'd still not be very helpful. I did not label any of src/test/modules/. It seems unnecessary since we don't install those, and besides there ought to be someplace that still provides test coverage for the original PG_MODULE_MAGIC macro. Author: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/dd4d1b59-d0fe-49d5-b28f-1e463b68fa32@gmail.com
		
			
				
	
	
		
			76 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /* -------------------------------------------------------------------------
 | |
|  *
 | |
|  * auth_delay.c
 | |
|  *
 | |
|  * Copyright (c) 2010-2025, PostgreSQL Global Development Group
 | |
|  *
 | |
|  * IDENTIFICATION
 | |
|  *		contrib/auth_delay/auth_delay.c
 | |
|  *
 | |
|  * -------------------------------------------------------------------------
 | |
|  */
 | |
| #include "postgres.h"
 | |
| 
 | |
| #include <limits.h>
 | |
| 
 | |
| #include "libpq/auth.h"
 | |
| #include "utils/guc.h"
 | |
| 
 | |
| PG_MODULE_MAGIC_EXT(
 | |
| 					.name = "auth_delay",
 | |
| 					.version = PG_VERSION
 | |
| );
 | |
| 
 | |
| /* GUC Variables */
 | |
| static int	auth_delay_milliseconds = 0;
 | |
| 
 | |
| /* Original Hook */
 | |
| static ClientAuthentication_hook_type original_client_auth_hook = NULL;
 | |
| 
 | |
| /*
 | |
|  * Check authentication
 | |
|  */
 | |
| static void
 | |
| auth_delay_checks(Port *port, int status)
 | |
| {
 | |
| 	/*
 | |
| 	 * Any other plugins which use ClientAuthentication_hook.
 | |
| 	 */
 | |
| 	if (original_client_auth_hook)
 | |
| 		original_client_auth_hook(port, status);
 | |
| 
 | |
| 	/*
 | |
| 	 * Inject a short delay if authentication failed.
 | |
| 	 */
 | |
| 	if (status != STATUS_OK)
 | |
| 	{
 | |
| 		pg_usleep(1000L * auth_delay_milliseconds);
 | |
| 	}
 | |
| }
 | |
| 
 | |
| /*
 | |
|  * Module Load Callback
 | |
|  */
 | |
| void
 | |
| _PG_init(void)
 | |
| {
 | |
| 	/* Define custom GUC variables */
 | |
| 	DefineCustomIntVariable("auth_delay.milliseconds",
 | |
| 							"Milliseconds to delay before reporting authentication failure",
 | |
| 							NULL,
 | |
| 							&auth_delay_milliseconds,
 | |
| 							0,
 | |
| 							0, INT_MAX / 1000,
 | |
| 							PGC_SIGHUP,
 | |
| 							GUC_UNIT_MS,
 | |
| 							NULL,
 | |
| 							NULL,
 | |
| 							NULL);
 | |
| 
 | |
| 	MarkGUCPrefixReserved("auth_delay");
 | |
| 
 | |
| 	/* Install Hooks */
 | |
| 	original_client_auth_hook = ClientAuthentication_hook;
 | |
| 	ClientAuthentication_hook = auth_delay_checks;
 | |
| }
 |