From 867b3050ad5e8f74aee83d6fe3e59341e15c4b5f Mon Sep 17 00:00:00 2001 From: midipix Date: Jun 08 2020 01:01:24 +0000 Subject: driver: added --release support. --- diff --git a/include/toksvc/toksvc.h b/include/toksvc/toksvc.h index 51ec884..b1eb2b8 100644 --- a/include/toksvc/toksvc.h +++ b/include/toksvc/toksvc.h @@ -52,6 +52,7 @@ extern "C" { #define TOKS_DRIVER_MODE_CLIENT 0X20000 #define TOKS_DRIVER_ACTION_ACQUIRE 0X100000 +#define TOKS_DRIVER_ACTION_RELEASE 0X200000 /* error flags */ #define TOKS_ERROR_TOP_LEVEL 0x0001 @@ -128,6 +129,7 @@ toks_api void toks_free_driver_ctx (struct toks_driver_ctx *); /* client api */ toks_api int toks_client_connect (struct toks_driver_ctx *); toks_api int toks_client_acquire (struct toks_driver_ctx *); +toks_api int toks_client_release (struct toks_driver_ctx *); toks_api int toks_client_token_to_str (struct toks_driver_ctx *, struct toks_token_string *); toks_api int toks_client_str_to_token (struct toks_driver_ctx *, const struct toks_token_string *); diff --git a/src/driver/toks_amain.c b/src/driver/toks_amain.c index c02e19e..e14f579 100644 --- a/src/driver/toks_amain.c +++ b/src/driver/toks_amain.c @@ -85,6 +85,20 @@ int toks_main(char ** argv, char ** envp) } } + if (dctx->cctx->drvflags & TOKS_DRIVER_ACTION_RELEASE) { + ret = toks_client_release(dctx) + ? 2 : 0; + + if (ret == 0) { + toks_client_token_to_str(dctx,&toks); + toks_dprintf(STDOUT_FILENO,"token %s has been released\n",toks.token); + } + + if (ret == 2) { + toks_dprintf(STDERR_FILENO,"error: invalid token"); + } + } + return (dctx->cctx->drvflags & TOKS_DRIVER_MODE_SERVER) ? NT_STATUS_SERVICE_NOTIFICATION : toks_exit(dctx,ret); diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index 2c3aa85..3a1a359 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -182,6 +182,8 @@ int toks_get_driver_ctx( struct argv_entry * entry; struct argv_entry * uuid; struct argv_entry * pid; + struct toks_token_string key; + size_t keylen; nt_guid svcguid; const char * program; const char * ch; @@ -214,6 +216,7 @@ int toks_get_driver_ctx( uuid = 0; tokpid = 0; + keylen = 0; ntokens = 0; program = argv_program_name(argv[0]); @@ -282,6 +285,22 @@ int toks_get_driver_ctx( cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; cctx.drvflags |= TOKS_DRIVER_ACTION_ACQUIRE; break; + + case TAG_RELEASE: + cctx.drvflags &= ~(uint64_t)TOKS_DRIVER_MODE_SERVER; + cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; + cctx.drvflags |= TOKS_DRIVER_ACTION_RELEASE; + + keylen = toks_strlen(entry->arg); + + ntapi->tt_generic_memset( + &key,0,sizeof(key)); + + if (keylen < sizeof(key.token)) + ntapi->tt_generic_memcpy( + &key.token,entry->arg, + keylen); + break; } } else /* strict */ @@ -324,6 +343,16 @@ int toks_get_driver_ctx( if (!(ctx = toks_driver_ctx_alloc(meta,&cctx))) return toks_get_driver_ctx_fail(meta); + if ((cctx.drvflags & TOKS_DRIVER_ACTION_RELEASE)) { + if (toks_client_str_to_token(&ctx->ctx,&key)) { + if (flags & TOKS_DRIVER_VERBOSITY_ERRORS) + toks_dprintf(STDERR_FILENO, + "%s: error: [%s] is not a valid token.", + program,key.token); + return toks_get_driver_ctx_fail(meta); + } + } + ntapi->tt_guid_copy( &ctx->uuid, uuid ? &svcguid : &ctx->rtdata->srv_guid); diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index a92f8dd..7908a41 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -27,6 +27,7 @@ enum app_tags { TAG_CONNECT, TAG_TOKENS, TAG_ACQUIRE, + TAG_RELEASE, TAG_PID, }; diff --git a/src/skin/toks_skin_default.c b/src/skin/toks_skin_default.c index cd5c2be..9acd139 100644 --- a/src/skin/toks_skin_default.c +++ b/src/skin/toks_skin_default.c @@ -36,5 +36,8 @@ const struct argv_option toks_default_options[] = { "assign the token to the framework process " "identified by %s"}, + {"release", 'r',TAG_RELEASE,ARGV_OPTARG_REQUIRED,0,0,"", + "release the key specified by %s."}, + {0,0,0,0,0,0,0,0} };