From cda006236763babb7e68ae0755c2ecff7834e855 Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Thu, 6 Aug 2020 03:23:55 +0200 Subject: [PATCH] Cedar/Proto: add ProtoLog(), write message to log on session creation/deletion Example: [OpenVPN] 192.168.122.100:47390 -> 0.0.0.0:1194 (UDP): Session created. [OpenVPN] 192.168.122.100:47390 -> 0.0.0.0:1194 (UDP): Session deleted. [OpenVPN] 192.168.122.100:49866 -> 192.168.122.1:1194 (TCP): Session created. [OpenVPN] 192.168.122.100:49866 -> 192.168.122.1:1194 (TCP): Session deleted. --- src/Cedar/Proto.c | 55 ++++++++++++++++++++++++++++++ src/Cedar/Proto.h | 2 ++ src/bin/hamcore/strtable_cn.stb | 6 ++++ src/bin/hamcore/strtable_en.stb | 7 ++++ src/bin/hamcore/strtable_ja.stb | 5 +++ src/bin/hamcore/strtable_ko.stb | 6 ++++ src/bin/hamcore/strtable_pt_br.stb | 6 ++++ src/bin/hamcore/strtable_ru.stb | 6 ++++ src/bin/hamcore/strtable_tw.stb | 8 ++++- 9 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/Cedar/Proto.c b/src/Cedar/Proto.c index c4b63e33..33896d0a 100644 --- a/src/Cedar/Proto.c +++ b/src/Cedar/Proto.c @@ -2,6 +2,46 @@ #include "Proto_OpenVPN.h" +void ProtoLog(const PROTO *proto, const PROTO_SESSION *session, const char *name, ...) +{ + wchar_t message[MAX_SIZE * 2]; + + if (proto == NULL) + { + return; + } + + if (session != NULL) + { + wchar_t *proto_name; + UINT current_len; + va_list args; + + proto_name = CopyStrToUni(session->Impl->Name()); + UniFormat(message, sizeof(message), _UU("LP_PREFIX_SESSION"), proto_name, &session->SrcIp, session->SrcPort, &session->DstIp, session->DstPort, L"UDP"); + Free(proto_name); + + current_len = UniStrLen(message); + + va_start(args, name); + UniFormatArgs(message + current_len, sizeof(message) - current_len, _UU(name), args); + va_end(args); + } + else + { + va_list args; + + UniStrCpy(message, sizeof(message), _UU("LP_PREFIX_SESSION")); + UniStrCat(message, sizeof(message), _UU(name)); + + va_start(args, name); + UniFormatArgs(message, sizeof(message), message, args); + va_end(args); + } + + WriteServerLog(proto->Cedar, message); +} + int ProtoOptionCompare(void *p1, void *p2) { PROTO_OPTION *option_1, *option_2; @@ -373,6 +413,8 @@ PROTO_SESSION *ProtoSessionNew(const PROTO *proto, const PROTO_CONTAINER *contai session->Lock = NewLock(); session->Thread = NewThread(ProtoSessionThread, session); + ProtoLog(proto, session, "LP_SESSION_CREATED"); + return session; } @@ -399,6 +441,8 @@ void ProtoSessionDelete(PROTO_SESSION *session) DeleteLock(session->Lock); + ProtoLog(session->Proto, session, "LP_SESSION_DELETED"); + Free(session); } @@ -455,6 +499,7 @@ bool ProtoHandleConnection(PROTO *proto, SOCK *sock, const char *protocol) { const PROTO_CONTAINER *container = NULL; + wchar_t *proto_name; LIST *options; if (protocol != NULL) @@ -507,6 +552,10 @@ bool ProtoHandleConnection(PROTO *proto, SOCK *sock, const char *protocol) } UnlockList(options); + + proto_name = CopyStrToUni(container->Name); + ProtoLog(proto, NULL, "LP_SESSION_CREATED", proto_name, &sock->RemoteIP, sock->RemotePort, &sock->LocalIP, sock->LocalPort, L"TCP"); + Free(proto_name); } SetTimeout(sock, TIMEOUT_INFINITE); @@ -596,6 +645,12 @@ bool ProtoHandleConnection(PROTO *proto, SOCK *sock, const char *protocol) ReleaseFifo(send_fifo); Free(buf); + { + wchar_t *proto_name = CopyStrToUni(impl->Name()); + ProtoLog(proto, NULL, "LP_SESSION_DELETED", proto_name, &sock->RemoteIP, sock->RemotePort, &sock->LocalIP, sock->LocalPort, L"TCP"); + Free(proto_name); + } + return true; } diff --git a/src/Cedar/Proto.h b/src/Cedar/Proto.h index 92bf641a..63f1b360 100644 --- a/src/Cedar/Proto.h +++ b/src/Cedar/Proto.h @@ -78,6 +78,8 @@ typedef struct PROTO_SESSION volatile bool Halt; } PROTO_SESSION; +void ProtoLog(const PROTO *proto, const PROTO_SESSION *session, const char *name, ...); + int ProtoOptionCompare(void *p1, void *p2); int ProtoContainerCompare(void *p1, void *p2); int ProtoSessionCompare(void *p1, void *p2); diff --git a/src/bin/hamcore/strtable_cn.stb b/src/bin/hamcore/strtable_cn.stb index 1c2e1efd..25ff2d6c 100644 --- a/src/bin/hamcore/strtable_cn.stb +++ b/src/bin/hamcore/strtable_cn.stb @@ -1810,6 +1810,12 @@ LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" +# (Proto log) +LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s): +LP_SESSION_CREATED Session created. +LP_SESSION_DELETED Session deleted. + + # (OpenVPN Logs) LO_PREFIX_RAW OpenVPN 模块: LO_PREFIX_SESSION OpenVPN 会话%u (%r:%u -> %r:%u): diff --git a/src/bin/hamcore/strtable_en.stb b/src/bin/hamcore/strtable_en.stb index baf2d564..75aff5af 100644 --- a/src/bin/hamcore/strtable_en.stb +++ b/src/bin/hamcore/strtable_en.stb @@ -1792,6 +1792,13 @@ LS_API_AUTH_OK HTTPS API client "%r:%u" (%S): Administration mode: "%S": The e LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server refused a login attempt. Username: "%S", Method: "%S", Path: "%S" LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" + +# (Proto log) +LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s): +LP_SESSION_CREATED Session created. +LP_SESSION_DELETED Session deleted. + + # (OpenVPN Logs) LO_PREFIX_RAW OpenVPN Module: LO_PREFIX_SESSION OpenVPN Session %u (%r:%u -> %r:%u): diff --git a/src/bin/hamcore/strtable_ja.stb b/src/bin/hamcore/strtable_ja.stb index 4db2ae51..27d13780 100644 --- a/src/bin/hamcore/strtable_ja.stb +++ b/src/bin/hamcore/strtable_ja.stb @@ -1796,6 +1796,11 @@ LS_API_AUTH_OK HTTPS API クライアント "%r:%u" (%S): 管理モード: "%S LS_API_AUTH_ERROR HTTPS API クライアント "%r:%u" (%S): 組み込み HTTPS Web サーバーを用いてログインに失敗しました。使用されたユーザー名: "%S", メソッド: "%S", パス: "%S" LS_API_RPC_CALL HTTPS API クライアント "%r:%u" (%S): JSON-API を呼び出しました。メソッド名: "%S", 結果エラーコード: %u (0 = 成功), 結果エラーメッセージ: "%s" +# (Proto ログ) +LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s): +LP_SESSION_CREATED Session created. +LP_SESSION_DELETED Session deleted. + # (OpenVPN ログ) LO_PREFIX_RAW OpenVPN モジュール: LO_PREFIX_SESSION OpenVPN セッション %u (%r:%u -> %r:%u): diff --git a/src/bin/hamcore/strtable_ko.stb b/src/bin/hamcore/strtable_ko.stb index b9405fed..26acf5d9 100644 --- a/src/bin/hamcore/strtable_ko.stb +++ b/src/bin/hamcore/strtable_ko.stb @@ -1778,6 +1778,12 @@ LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" +# (Proto 로그) +LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s): +LP_SESSION_CREATED Session created. +LP_SESSION_DELETED Session deleted. + + # (OpenVPN 로그) LO_PREFIX_RAW OpenVPN 모듈: LO_PREFIX_SESSION OpenVPN 세션 %u (%r:%u -> %r:%u): diff --git a/src/bin/hamcore/strtable_pt_br.stb b/src/bin/hamcore/strtable_pt_br.stb index 323f7d0f..1f6d2483 100644 --- a/src/bin/hamcore/strtable_pt_br.stb +++ b/src/bin/hamcore/strtable_pt_br.stb @@ -1793,6 +1793,12 @@ LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server r LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" +# (Proto log) +LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s): +LP_SESSION_CREATED Session created. +LP_SESSION_DELETED Session deleted. + + # (OpenVPN Logs) LO_PREFIX_RAW OpenVPN Module: LO_PREFIX_SESSION OpenVPN Session %u (%r:%u -> %r:%u): diff --git a/src/bin/hamcore/strtable_ru.stb b/src/bin/hamcore/strtable_ru.stb index 6e65f049..24708012 100644 --- a/src/bin/hamcore/strtable_ru.stb +++ b/src/bin/hamcore/strtable_ru.stb @@ -1793,6 +1793,12 @@ LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" +# (Proto log) +LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s): +LP_SESSION_CREATED Session created. +LP_SESSION_DELETED Session deleted. + + # (OpenVPN Logs) LO_PREFIX_RAW OpenVPN Module: LO_PREFIX_SESSION OpenVPN Session %u (%r:%u -> %r:%u): diff --git a/src/bin/hamcore/strtable_tw.stb b/src/bin/hamcore/strtable_tw.stb index 6610fdc1..ce3cb572 100644 --- a/src/bin/hamcore/strtable_tw.stb +++ b/src/bin/hamcore/strtable_tw.stb @@ -1813,7 +1813,13 @@ LS_API_AUTH_ERROR HTTPS API client "%r:%u" (%S): The embedded HTTPS web server LS_API_RPC_CALL HTTPS API client "%r:%u" (%S): The client called a JSON-API. Method: "%S", Returned error code: %u (0 = success), Returned error message: "%s" -# (OpenVPN Logs) +# (Proto 日誌) +LP_PREFIX_SESSION [%s] %r:%u -> %r:%u (%s): +LP_SESSION_CREATED Session created. +LP_SESSION_DELETED Session deleted. + + +# (OpenVPN 日誌) LO_PREFIX_RAW OpenVPN 模組: LO_PREFIX_SESSION OpenVPN 會話%u (%r:%u -> %r:%u): LO_PREFIX_CHANNEL OpenVPN 會話%u (%r:%u -> %r:%u) 通道 %u: