- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- ソース を表示
- PostgreSQL/開発/フック/libpq/auth へ行く。
- 1 (2017-08-16 (水) 21:25:58)
- 2 (2017-08-16 (水) 21:37:14)
フック †
Hookインターフェース | 説明 |
---|---|
ClientAuthentication_hook(Port *port, int status) | 認証時に呼ばれる。具体的には、認証後にフックポイントがありログインイベントの記録などに利用される。 |
参考 libpq/auth.c - on doxygen.postgresql.org
サンプル †
サンプル
myext.c
#include "postgres.h" #include "fmgr.h" #include "libpq/auth.h" #include "lib/stringinfo.h" PG_MODULE_MAGIC; extern void _PG_init(void); extern ClientAuthentication_hook_type ClientAuthentication_hook; static const char *logfile = "/tmp/postgresql-auth.log"; static void my_ClientAuthentication_hook(Port *port, int status); void _PG_init(void) { ClientAuthentication_hook = my_ClientAuthentication_hook; } static void my_ClientAuthentication_hook(Port *port, int status) { FILE *fp; StringInfo strinfo = makeStringInfo(); if ((fp = fopen(logfile, "ab")) == NULL) { elog(ERROR, "failed to open %s", logfile); return; } appendStringInfo(strinfo, "{\"username\":\"%s\",\"status\":\"%d\"}\n", port->user_name, status); fputs(strinfo->data, fp); fclose(fp); }
postgresql.conf
shared_preload_libraries = 'myext'
実行例
$ psql -U guest -d postgres -c "\d" $ cat /tmp/postgresql-auth.log {"username":"guest","status":"0"}