/*********************************************************/
/* 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"
void toks_log_token_info(struct toks_daemon_ctx * dctx)
{
struct toks_driver_ctx * drvctx = dctx->driver_ctx;
TOKS_LOG_LEVEL(drvctx,1);
int idx;
int nwaiters;
char path[2048];
char tokstr[64];
struct toks_token * token;
struct toks_waiter * waiter;
toks_log_service_info(dctx);
token = toks_get_driver_tokens(dctx->driver_ctx);
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_1,
"\n",0);
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"%-11s%-55s%-12s%-14s%s\n",
"token no.",
"token id.",
"token pid",
"token syspid",
"token refstr",
0);
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"%-11s%-55s%-12s%-14s%s\n",
"=========",
"=========",
"=========",
"============",
"============",
0);
for (idx=0; idx<dctx->utokens; token++) {
if (token->self) {
toks_log_get_process_name(
token->client.hprocess,
path,sizeof(path));
ntapi->sprintf(
tokstr,
"%08X-%08X-%08X-%08X-%08X-%08X",
token->keys.key[0],
token->keys.key[1],
token->keys.key[2],
token->keys.key[3],
token->keys.key[4],
token->keys.key[5]);
if (token->client.tokpid) {
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"#%-10d%-55s%-12d%-14d%s\n",
++idx,tokstr,
token->client.tokpid,
token->client.cid.process_id,
token->meta.key);
} else {
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"#%-10d%-55s%-12s%-14d%s\n",
++idx,tokstr,"N/A",
token->client.cid.process_id,
token->meta.key);
}
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"%-11s%s.\n",(char[]){0},path);
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_1,
"\n",0);
}
}
if ((nwaiters = toks_get_driver_nwaiters(dctx->driver_ctx)) == 0)
return;
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_1,
"\n",0);
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"%-11s%-55s%-12s%-14s%s\n",
"waiter no.",
"token id.",
"token pid",
"token syspid",
"token refstr",
0);
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"%-11s%-55s%-12s%-14s%s\n",
"==========",
"=========",
"=========",
"============",
"============",
0);
idx = 0;
waiter = dctx->waiter_first;
for (; idx<nwaiters; ) {
if (waiter->msg.header.msg_id) {
toks_log_get_process_name(
waiter->client.hprocess,
path,sizeof(path));
ntapi->sprintf(
tokstr,
"%08X-%08X-%08X-%08X-%08X-%08X",
waiter->msg.syncinfo.ipckeys[0],
waiter->msg.syncinfo.ipckeys[1],
waiter->msg.syncinfo.ipckeys[2],
waiter->msg.syncinfo.ipckeys[3],
waiter->msg.syncinfo.ipckeys[4],
waiter->msg.syncinfo.ipckeys[5]);
if (waiter->client.tokpid) {
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"*%-10d%-55s%-12d%-14d%s\n",
++idx,tokstr,
waiter->client.tokpid,
waiter->client.cid.process_id,
waiter->msg.syncinfo.ipcsvc.keys.key);
} else {
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"*%-10d%-55s%-12s%-14d%s\n",
++idx,tokstr,"N/A",
waiter->client.cid.process_id,
waiter->msg.syncinfo.ipcsvc.keys.key);
}
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_2,
"%-11s%s.\n",(char[]){0},path);
toks_log_write(
drvctx,
TOKS_LOG_ENTRY_SUB_LEVEL_1,
"\n",0);
}
if (++waiter == dctx->waiter_cap)
waiter = dctx->waiter_base;
}
}