From eb3ecd3f2733690188ed11c729d580516572e7c6 Mon Sep 17 00:00:00 2001 From: midipix Date: Jul 04 2020 18:47:54 +0000 Subject: driver: added --get-token-info support. --- diff --git a/include/toksvc/toksvc.h b/include/toksvc/toksvc.h index 42662e7..f22934b 100644 --- a/include/toksvc/toksvc.h +++ b/include/toksvc/toksvc.h @@ -64,6 +64,7 @@ extern "C" { #define TOKS_DRIVER_ACTION_SVCINFO_GET 0X10000000 #define TOKS_DRIVER_ACTION_SVCINFO_LOG 0X20000000 +#define TOKS_DRIVER_ACTION_TOKINFO_GET 0X40000000 #define TOKS_DRIVER_ACTION_TOKINFO_LOG 0X80000000 /* message options */ diff --git a/src/driver/toks_amain.c b/src/driver/toks_amain.c index 35a8092..4022149 100644 --- a/src/driver/toks_amain.c +++ b/src/driver/toks_amain.c @@ -53,7 +53,7 @@ static ssize_t toks_version(struct toks_driver_ctx * dctx) verclr[4],verinfo->commit,verclr[5]); } -static ssize_t toks_output_service_info(struct toks_service_info * svcinfo) +static ssize_t toks_output_service_info(const struct toks_service_info * svcinfo) { char guidstr[40]; @@ -84,6 +84,44 @@ static ssize_t toks_output_service_info(struct toks_service_info * svcinfo) svcinfo->loglevel); } +static void toks_output_token_info(const struct toks_token_ctx * tokctx) +{ + int idx; + const struct toks_token_info * tinfo; + char path[2048]; + + toks_dprintf(STDOUT_FILENO,"toks_tokens:{\n"); + + for (idx=0,tinfo=tokctx->tokens; idxtused; tinfo++) { + toks_log_get_arbitrary_process_name( + &(nt_cid){.process_id=tinfo->tsyspid,.thread_id=0}, + path,sizeof(path)); + + toks_dprintf(STDOUT_FILENO, + "\t{" + ".token_no=%d, " + ".token_id=%08X-%08X-%08X-%08X-%08X-%08X, " + ".token_pid=%d, " + ".token_syspid=%d, " + ".token_refstr=``%s''}\n" + "\t\t" + ".client_image=%s\n", + ++idx, + tinfo->keys[0], + tinfo->keys[1], + tinfo->keys[2], + tinfo->keys[3], + tinfo->keys[4], + tinfo->keys[5], + tinfo->tokpid, + tinfo->tsyspid, + tinfo->meta, + path); + } + + toks_dprintf(STDOUT_FILENO,"}\n"); +} + static int toks_exit(struct toks_driver_ctx * dctx, int nerrors) { toks_free_driver_ctx(dctx); @@ -97,6 +135,7 @@ int toks_main(char ** argv, char ** envp) struct toks_driver_ctx * dctx; struct toks_token_string toks; struct toks_service_info svcinfo; + struct toks_server_snapshot * snapshot; if ((ret = toks_init())) return ret; @@ -253,6 +292,26 @@ int toks_main(char ** argv, char ** envp) } } + if (dctx->cctx->drvflags & TOKS_DRIVER_ACTION_TOKINFO_GET) { + status = toks_get_server_snapshot(dctx,&snapshot); + ret = status ? 2 : 0; + + switch (status) { + case NT_STATUS_SUCCESS: + toks_output_service_info(&snapshot->svcinfo); + toks_output_token_info(snapshot->tokctx); + toks_free_server_snapshot(snapshot); + break; + + default: + toks_dprintf(STDERR_FILENO, + "%s: the TOKS_IOCTL_GET_TOKEN_INFO " + "ioctl operataion has failed " + "(check the system's documentation) [0x%x].", + toks_log_basename(argv[0]),status); + } + } + if (dctx->cctx->drvflags & TOKS_DRIVER_ACTION_TOKINFO_LOG) { status = toks_service_ioctl(dctx,TOKS_IOCTL_LOG_TOKEN_INFO,0,0); ret = status ? 2 : 0; diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index 87cce27..3b00216 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -659,6 +659,12 @@ int toks_get_driver_ctx( cctx.drvflags |= TOKS_DRIVER_ACTION_SVCINFO_LOG; break; + case TAG_GETTOKINFO: + cctx.drvflags &= ~(uint64_t)TOKS_DRIVER_MODE_SERVER; + cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; + cctx.drvflags |= TOKS_DRIVER_ACTION_TOKINFO_GET; + break; + case TAG_LOGTOKINFO: cctx.drvflags &= ~(uint64_t)TOKS_DRIVER_MODE_SERVER; cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index 4a55b21..a7b135a 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -50,6 +50,7 @@ enum app_tags { TAG_LOGLEVELSET, TAG_GETSVCINFO, TAG_LOGSVCINFO, + TAG_GETTOKINFO, TAG_LOGTOKINFO, }; diff --git a/src/skin/toks_skin_default.c b/src/skin/toks_skin_default.c index ffac44a..1e4c172 100644 --- a/src/skin/toks_skin_default.c +++ b/src/skin/toks_skin_default.c @@ -93,6 +93,11 @@ const struct argv_option toks_default_options[] = { "connect to the server and request that the current " "service information be sent to its log"}, + {"get-token-info", 's',TAG_GETTOKINFO,ARGV_OPTARG_NONE,0,0,0, + "connect to the server and output the current " + "service information, along with information about all " + "currently allocated tokens"}, + {"log-token-info", 'S',TAG_LOGTOKINFO,ARGV_OPTARG_NONE,0,0,0, "connect to the server and request that the current " "service information, along with information about all "