diff --git a/project/common.mk b/project/common.mk index 0309811..c3c85c4 100644 --- a/project/common.mk +++ b/project/common.mk @@ -14,6 +14,7 @@ INTERNAL_SRCS = \ src/internal/toksvc_nolibc_impl.c \ src/internal/toksvc_ntaio_impl.c \ src/internal/toksvc_open_impl.c \ + src/log/toks_log_lpc_request.c \ src/skin/toks_skin_default.c \ APP_SRCS = \ diff --git a/project/tree.mk b/project/tree.mk index aa3220c..801a85e 100644 --- a/project/tree.mk +++ b/project/tree.mk @@ -3,6 +3,7 @@ TREE_DIRS = bin src lib \ src/driver \ src/internal \ src/internal/nolibc \ + src/log \ src/skin \ tree.tag: diff --git a/src/daemon/toks_daemon_loop.c b/src/daemon/toks_daemon_loop.c index fb151ec..557d27c 100644 --- a/src/daemon/toks_daemon_loop.c +++ b/src/daemon/toks_daemon_loop.c @@ -10,6 +10,7 @@ #include #include "toksvc_daemon_impl.h" #include "toksvc_driver_impl.h" +#include "toksvc_log_impl.h" #define TOKS_VTBL_ELEMENTS TOKS_DAEMON_OPCODE_CAP - TOKS_DAEMON_OPCODE_BASE @@ -54,6 +55,8 @@ int32_t __stdcall toks_daemon_loop(void * ctx) /* message loop */ do { + toks_log_lpc_request(dctx->driver_ctx,request); + switch (request->header.msg_type) { case NT_LPC_REQUEST: case NT_LPC_DATAGRAM: diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index a9aba7c..b6a3c65 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -274,10 +274,6 @@ int toks_get_driver_ctx( &ctx->uuid, uuid ? &svcguid : &ctx->rtdata->srv_guid); - if (cctx.drvflags & TOKS_DRIVER_MODE_SERVER) - if (toks_daemon_init(&toks_daemon_ctx,&ctx->uuid)) - return toks_get_driver_ctx_fail(meta); - if ((toks_ntapi->tt_create_private_event( &ctx->hevent, NT_NOTIFICATION_EVENT, @@ -295,6 +291,12 @@ int toks_get_driver_ctx( ctx->ctx.cctx = &ctx->cctx; ctx->cctx.uuid = &ctx->uuid; + toks_daemon_ctx.driver_ctx = &ctx->ctx; + + if (cctx.drvflags & TOKS_DRIVER_MODE_SERVER) + if (toks_daemon_init(&toks_daemon_ctx,&ctx->uuid)) + return toks_get_driver_ctx_fail(meta); + *pctx = &ctx->ctx; return TOKS_OK; } diff --git a/src/internal/toksvc_daemon_impl.h b/src/internal/toksvc_daemon_impl.h index 07c43a4..a97e327 100644 --- a/src/internal/toksvc_daemon_impl.h +++ b/src/internal/toksvc_daemon_impl.h @@ -17,7 +17,11 @@ enum toks_daemon_opcodes { typedef int32_t __stdcall toks_daemon_routine(nt_tty_port_msg *); +struct toks_driver_ctx; + struct toks_daemon_ctx { + struct toks_driver_ctx *driver_ctx; + nt_port_keys daemon_keys; nt_port_attr daemon_attr; nt_port_name daemon_name; diff --git a/src/internal/toksvc_log_impl.h b/src/internal/toksvc_log_impl.h index 74b15ab..38b0492 100644 --- a/src/internal/toksvc_log_impl.h +++ b/src/internal/toksvc_log_impl.h @@ -2,6 +2,7 @@ #define TOKSVC_LOG_IMPL_H #include +#include #define TOKS_LOG_LEVEL(dctx,x) \ if (dctx->cctx->loglevel < x) \ @@ -45,4 +46,8 @@ void toks_log_get_process_name( void toks_log_get_arbitrary_process_name( nt_cid *, char *, size_t); +void toks_log_lpc_request( + const struct toks_driver_ctx *, + const nt_tty_port_msg *); + #endif diff --git a/src/log/toks_log_lpc_request.c b/src/log/toks_log_lpc_request.c new file mode 100644 index 0000000..d4508e6 --- /dev/null +++ b/src/log/toks_log_lpc_request.c @@ -0,0 +1,48 @@ +/*********************************************************/ +/* toksvc: a framework-native token broker service */ +/* Copyright (C) 2020 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.TOKSVC. */ +/*********************************************************/ + +#include +#include + +#include +#include "toksvc_driver_impl.h" +#include "toksvc_log_impl.h" + +void toks_log_lpc_request( + const struct toks_driver_ctx * dctx, + const nt_tty_port_msg * msg) +{ + TOKS_LOG_LEVEL(dctx,0); + + nt_cid cid; + char path[2048]; + + cid.process_id = msg->header.client_id.process_id; + cid.thread_id = msg->header.client_id.thread_id; + + toks_log_get_arbitrary_process_name( + &cid,path,sizeof(path)); + + toks_log_header( + dctx, + TOKS_LOG_ENTRY_SERVER_INFO, + "LPC request from %s (syspid %d, systid %d), " + "data_size=%u, msg_size=%u, " + "msg_type=%u, msg_id=%u\n", + toks_log_basename(path), + cid.process_id, + cid.thread_id, + msg->header.data_size, + msg->header.msg_size, + msg->header.msg_type, + msg->header.msg_id); + + if (cid.process_id) + toks_log_write( + dctx, + TOKS_LOG_ENTRY_SUB_LEVEL_2, + "%s.\n",path); +}