PG_init = (PG_init_t) pg_dlsym(file_scanner->handle, _PG_init ); if (PG_init) (*PG_init) (); ..."/>
您好,登錄后才能下訂單哦!
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) ();
以ClientAuthentication_hook_type為例
auth.h:
//聲明插件使用的函數(shù)
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;
auth.c:
//全局變量初始化為NULL,在_PG_init函數(shù)中進(jìn)行初始化賦值,如果該插件加載,則ClientAuthentication_hook為
ClientAuthentication_hook_type ClientAuthentication_hook = NULL;
//如果ClientAuthentication_hook被賦值則執(zhí)行植入的代碼
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;
}
/*
如果卸載則調(diào)用該函數(shù),實(shí)際上是將ClientAuthentication_hook賦回原值
*/
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);
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。