Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

PostgreSQL plug-in hook mechanism

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Internal_load_library postgresql- > PG_init = (PG_init_t) pg_dlsym (file_scanner- > handle, "_ PG_init"); if (PG_init) (* PG_init) (); internal_unload_library (const char * libname)-> PG_fini = (PG_fini_t) pg_dlsym (file_scanner- > handle, "_ PG_fini") If (PG_fini) (* PG_fini) (); take ClientAuthentication_hook_type as an example auth.h:// declares the function used by the plug-in extern void ClientAuthentication (Port * port); / * Hook for plugins to get control in ClientAuthentication () * / typedef void (* ClientAuthentication_hook_type) (Port *, int); extern PGDLLIMPORT ClientAuthentication_hook_type ClientAuthentication_hook The auth.c:// global variable is initialized to NULL, and the initialization assignment is made in the _ PG_init function. If the plug-in is loaded, ClientAuthentication_hook is ClientAuthentication_hook_type ClientAuthentication_hook = NULL;//. If ClientAuthentication_hook is assigned, execute the implanted code InitPostgres- > PerformAuthentication- > ClientAuthentication- > if (ClientAuthentication_hook) (* ClientAuthentication_hook) (port, status); auth_delay.c:static ClientAuthentication_hook_type original_client_auth_hook = NULL / * * 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) / * Install Hooks * / original_client_auth_hook = ClientAuthentication_hook; ClientAuthentication_hook= auth_delay_checks;} / * this function is called if uninstalled, which actually assigns ClientAuthentication_hook back to the original value * / void_PG_fini (void) {ClientAuthentication_hook=original_client_auth_hook } / * * / static void auth_delay_checks (Port * port, int status) {if (original_client_auth_hook) original_client_auth_hook (port, status); if (status! = STATUS_OK) {pg_usleep (1000L * auth_delay_milliseconds);}}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report