Blame src/log/toks_log_token_info.c

5ce44d
/*********************************************************/
5ce44d
/*  toksvc: a framework-native token broker service      */
5ce44d
/*  Copyright (C) 2020  Z. Gilboa                        */
5ce44d
/*  Released under GPLv2 and GPLv3; see COPYING.TOKSVC.  */
5ce44d
/*********************************************************/
5ce44d
5ce44d
#include <psxtypes/psxtypes.h>
5ce44d
#include <ntapi/nt_tty.h>
5ce44d
5ce44d
#include <toksvc/toksvc.h>
5ce44d
#include "toksvc_driver_impl.h"
5ce44d
#include "toksvc_daemon_impl.h"
5ce44d
#include "toksvc_log_impl.h"
5ce44d
5ce44d
void toks_log_token_info(struct toks_daemon_ctx * dctx)
5ce44d
{
5ce44d
	struct toks_driver_ctx * drvctx = dctx->driver_ctx;
5ce44d
5ce44d
	TOKS_LOG_LEVEL(drvctx,1);
5ce44d
5ce44d
	int                   idx;
37de4b
	int                   nwaiters;
5ce44d
	char                  path[2048];
5ce44d
	char                  tokstr[64];
5ce44d
	struct toks_token *   token;
37de4b
	struct toks_waiter *  waiter;
5ce44d
5ce44d
	toks_log_service_info(dctx);
5ce44d
5ce44d
	token = toks_get_driver_tokens(dctx->driver_ctx);
5ce44d
5ce44d
	toks_log_write(
5ce44d
		drvctx,
5ce44d
		TOKS_LOG_ENTRY_SUB_LEVEL_1,
5ce44d
		"\n",0);
5ce44d
5ce44d
	toks_log_write(
5ce44d
		drvctx,
5ce44d
		TOKS_LOG_ENTRY_SUB_LEVEL_2,
5ce44d
		"%-11s%-55s%-12s%-14s%s\n",
5ce44d
		"token no.",
5ce44d
		"token id.",
5ce44d
		"token pid",
5ce44d
		"token syspid",
5ce44d
		"token refstr",
5ce44d
		0);
5ce44d
5ce44d
	toks_log_write(
5ce44d
		drvctx,
5ce44d
		TOKS_LOG_ENTRY_SUB_LEVEL_2,
5ce44d
		"%-11s%-55s%-12s%-14s%s\n",
5ce44d
		"=========",
5ce44d
		"=========",
5ce44d
		"=========",
5ce44d
		"============",
5ce44d
		"============",
5ce44d
		0);
5ce44d
5ce44d
	for (idx=0; idx<dctx->utokens; token++) {
5ce44d
		if (token->self) {
5ce44d
			toks_log_get_process_name(
5ce44d
				token->client.hprocess,
5ce44d
				path,sizeof(path));
5ce44d
5ce44d
			ntapi->sprintf(
5ce44d
				tokstr,
0410ab
				"%08X-%08X-%08X-%08X-%08X-%08X",
5ce44d
				token->keys.key[0],
5ce44d
				token->keys.key[1],
5ce44d
				token->keys.key[2],
5ce44d
				token->keys.key[3],
5ce44d
				token->keys.key[4],
5ce44d
				token->keys.key[5]);
5ce44d
5ce44d
			if (token->client.tokpid) {
5ce44d
				toks_log_write(
5ce44d
					drvctx,
5ce44d
					TOKS_LOG_ENTRY_SUB_LEVEL_2,
5ce44d
					"#%-10d%-55s%-12d%-14d%s\n",
5ce44d
					++idx,tokstr,
5ce44d
					token->client.tokpid,
5ce44d
					token->client.cid.process_id,
5ce44d
					token->meta.key);
5ce44d
			} else {
5ce44d
				toks_log_write(
5ce44d
					drvctx,
5ce44d
					TOKS_LOG_ENTRY_SUB_LEVEL_2,
5ce44d
					"#%-10d%-55s%-12s%-14d%s\n",
5ce44d
					++idx,tokstr,"N/A",
5ce44d
					token->client.cid.process_id,
5ce44d
					token->meta.key);
5ce44d
			}
5ce44d
5ce44d
			toks_log_write(
5ce44d
				drvctx,
5ce44d
				TOKS_LOG_ENTRY_SUB_LEVEL_2,
5ce44d
				"%-11s%s.\n",(char[]){0},path);
5ce44d
5ce44d
			toks_log_write(
5ce44d
				drvctx,
5ce44d
				TOKS_LOG_ENTRY_SUB_LEVEL_1,
5ce44d
				"\n",0);
5ce44d
		}
5ce44d
	}
37de4b
37de4b
	if ((nwaiters = toks_get_driver_nwaiters(dctx->driver_ctx)) == 0)
37de4b
		return;
37de4b
37de4b
	toks_log_write(
37de4b
		drvctx,
37de4b
		TOKS_LOG_ENTRY_SUB_LEVEL_1,
37de4b
		"\n",0);
37de4b
37de4b
	toks_log_write(
37de4b
		drvctx,
37de4b
		TOKS_LOG_ENTRY_SUB_LEVEL_2,
37de4b
		"%-11s%-55s%-12s%-14s%s\n",
37de4b
		"waiter no.",
37de4b
		"token id.",
37de4b
		"token pid",
37de4b
		"token syspid",
37de4b
		"token refstr",
37de4b
		0);
37de4b
37de4b
	toks_log_write(
37de4b
		drvctx,
37de4b
		TOKS_LOG_ENTRY_SUB_LEVEL_2,
37de4b
		"%-11s%-55s%-12s%-14s%s\n",
37de4b
		"==========",
37de4b
		"=========",
37de4b
		"=========",
37de4b
		"============",
37de4b
		"============",
37de4b
		0);
37de4b
37de4b
	idx    = 0;
37de4b
	waiter = dctx->waiter_first;
37de4b
37de4b
	for (; idx
37de4b
		if (waiter->msg.header.msg_id) {
37de4b
			toks_log_get_process_name(
37de4b
				waiter->client.hprocess,
37de4b
				path,sizeof(path));
37de4b
37de4b
			ntapi->sprintf(
37de4b
				tokstr,
0410ab
				"%08X-%08X-%08X-%08X-%08X-%08X",
37de4b
				waiter->msg.syncinfo.ipckeys[0],
37de4b
				waiter->msg.syncinfo.ipckeys[1],
37de4b
				waiter->msg.syncinfo.ipckeys[2],
37de4b
				waiter->msg.syncinfo.ipckeys[3],
37de4b
				waiter->msg.syncinfo.ipckeys[4],
37de4b
				waiter->msg.syncinfo.ipckeys[5]);
37de4b
37de4b
			if (waiter->client.tokpid) {
37de4b
				toks_log_write(
37de4b
					drvctx,
37de4b
					TOKS_LOG_ENTRY_SUB_LEVEL_2,
37de4b
					"*%-10d%-55s%-12d%-14d%s\n",
37de4b
					++idx,tokstr,
37de4b
					waiter->client.tokpid,
37de4b
					waiter->client.cid.process_id,
37de4b
					waiter->msg.syncinfo.ipcsvc.keys.key);
37de4b
			} else {
37de4b
				toks_log_write(
37de4b
					drvctx,
37de4b
					TOKS_LOG_ENTRY_SUB_LEVEL_2,
37de4b
					"*%-10d%-55s%-12s%-14d%s\n",
37de4b
					++idx,tokstr,"N/A",
37de4b
					waiter->client.cid.process_id,
37de4b
					waiter->msg.syncinfo.ipcsvc.keys.key);
37de4b
			}
37de4b
37de4b
			toks_log_write(
37de4b
				drvctx,
37de4b
				TOKS_LOG_ENTRY_SUB_LEVEL_2,
37de4b
				"%-11s%s.\n",(char[]){0},path);
37de4b
37de4b
			toks_log_write(
37de4b
				drvctx,
37de4b
				TOKS_LOG_ENTRY_SUB_LEVEL_1,
37de4b
				"\n",0);
37de4b
		}
37de4b
37de4b
		if (++waiter == dctx->waiter_cap)
37de4b
			waiter = dctx->waiter_base;
37de4b
	}
5ce44d
}