/*********************************************************/
/* toksvc: a framework-native token broker service */
/* Copyright (C) 2020 Z. Gilboa */
/* Released under GPLv2 and GPLv3; see COPYING.TOKSVC. */
/*********************************************************/
#include <psxtypes/psxtypes.h>
#include <ntapi/nt_tty.h>
#include <toksvc/toksvc.h>
#include "toksvc_driver_impl.h"
#include "toksvc_daemon_impl.h"
#include "toksvc_log_impl.h"
static const char toks_error_str[] = "#ERROR";
static const char * toks_lpc_msg_str[] = {
[NT_LPC_NEW_MESSAGE] = "NT_LPC_NEW_MESSAGE",
[NT_LPC_REQUEST] = "NT_LPC_REQUEST",
[NT_LPC_REPLY] = "NT_LPC_REPLY",
[NT_LPC_DATAGRAM] = "NT_LPC_DATAGRAM",
[NT_LPC_LOST_REPLY] = "NT_LPC_LOST_REPLY",
[NT_LPC_PORT_CLOSED] = "NT_LPC_PORT_CLOSED",
[NT_LPC_CLIENT_DIED] = "NT_LPC_CLIENT_DIED",
[NT_LPC_EXCEPTION] = "NT_LPC_EXCEPTION",
[NT_LPC_DEBUG_EVENT] = "NT_LPC_DEBUG_EVENT",
[NT_LPC_ERROR_EVENT] = "NT_LPC_ERROR_EVENT",
[NT_LPC_CONNECTION_REQUEST] = "NT_LPC_CONNECTION_REQUEST",
};
static const char * toks_alpc_msg_str[] = {
[NT_ALPC_REQUEST ^ 0x2000] = "NT_ALPC_REQUEST",
[NT_ALPC_CONNECTION_REQUEST ^ 0x2000] = "NT_ALPC_CONNECTION_REQUEST",
};
static const char * toks_lpc_msg_type_desc(unsigned msgtype)
{
if (msgtype <= NT_LPC_CONNECTION_REQUEST)
return toks_lpc_msg_str[msgtype];
else if (msgtype == NT_ALPC_REQUEST)
return toks_alpc_msg_str[msgtype ^ 0x2000];
else if (msgtype == NT_ALPC_CONNECTION_REQUEST)
return toks_alpc_msg_str[msgtype ^ 0x2000];
else
return toks_error_str;
}
void toks_log_lpc_request(
struct toks_daemon_ctx * dctx,
const nt_tty_port_msg * msg)
{
struct toks_driver_ctx * drvctx = dctx->driver_ctx;
TOKS_LOG_LEVEL(drvctx,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(
drvctx,
TOKS_LOG_ENTRY_SERVER_INFO,
"LPC message from %s (syspid %d, systid %d), "
"data_size=%u, msg_size=%u, "
"msg_type=%u (%s), 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,
toks_lpc_msg_type_desc(msg->header.msg_type),
msg->header.msg_id);
if (cid.process_id)
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"%s.\n",path);
}