Blob Blame History Raw
/*********************************************************/
/*  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;
	char                  path[2048];
	char                  tokstr[64];
	struct toks_token *   token;

	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);
		}
	}
}