diff --git a/include/toksvc/toksvc.h b/include/toksvc/toksvc.h index 06fcbd2..dd1b8a0 100644 --- a/include/toksvc/toksvc.h +++ b/include/toksvc/toksvc.h @@ -53,6 +53,7 @@ extern "C" { #define TOKS_DRIVER_ACTION_ACQUIRE 0X100000 #define TOKS_DRIVER_ACTION_RELEASE 0X200000 +#define TOKS_DRIVER_ACTION_ABORT 0X400000 /* error flags */ #define TOKS_ERROR_TOP_LEVEL 0x0001 @@ -128,6 +129,7 @@ toks_api void toks_driver_set_timeout (struct toks_driver_ctx *, int64_t milli toks_api void toks_driver_unset_timeout (struct toks_driver_ctx *); /* core api */ +toks_api int toks_service_abort (struct toks_driver_ctx *); /* client api */ toks_api int toks_client_connect (struct toks_driver_ctx *); diff --git a/project/common.mk b/project/common.mk index 699f2a3..0879f14 100644 --- a/project/common.mk +++ b/project/common.mk @@ -24,6 +24,7 @@ INTERNAL_SRCS = \ src/internal/toksvc_ntaio_impl.c \ src/internal/toksvc_open_impl.c \ src/log/toks_log_lpc_request.c \ + src/service/toks_service_abort.c \ src/skin/toks_skin_default.c \ APP_SRCS = \ diff --git a/project/tree.mk b/project/tree.mk index d95637b..e1154e5 100644 --- a/project/tree.mk +++ b/project/tree.mk @@ -5,6 +5,7 @@ TREE_DIRS = bin src lib \ src/internal \ src/internal/nolibc \ src/log \ + src/service \ src/skin \ tree.tag: diff --git a/src/driver/toks_amain.c b/src/driver/toks_amain.c index 2b6bdaa..f989b3b 100644 --- a/src/driver/toks_amain.c +++ b/src/driver/toks_amain.c @@ -117,6 +117,31 @@ int toks_main(char ** argv, char ** envp) } } + if (dctx->cctx->drvflags & TOKS_DRIVER_ACTION_ABORT) { + ret = (status = toks_service_abort(dctx)) + ? 2 : 0; + + switch (status) { + case NT_STATUS_SUCCESS: + toks_dprintf(STDERR_FILENO, + "%s: the server responded with no error.\n", + toks_log_basename(argv[0]),status); + break; + + case NT_STATUS_ACCESS_DENIED: + toks_dprintf(STDERR_FILENO, + "%s: the abort operataion timed (access denied) [0x%x].\n", + toks_log_basename(argv[0]),status); + break; + + default: + toks_dprintf(STDERR_FILENO, + "%s: the abort operataion failed ", + "(check the system's documentation) [0x%x].", + toks_log_basename(argv[0]),status); + } + } + 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 eb3738f..9da2c37 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -297,6 +297,12 @@ int toks_get_driver_ctx( cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; break; + case TAG_ABORT: + cctx.drvflags &= ~(uint64_t)TOKS_DRIVER_MODE_SERVER; + cctx.drvflags |= TOKS_DRIVER_MODE_CLIENT; + cctx.drvflags |= TOKS_DRIVER_ACTION_ABORT; + break; + case TAG_ACQUIRE: 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 cf047b9..6fc7471 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -26,6 +26,7 @@ enum app_tags { TAG_UUID, TAG_CONNECT, TAG_TOKENS, + TAG_ABORT, TAG_ACQUIRE, TAG_RELEASE, TAG_TIMEOUT, diff --git a/src/service/toks_service_abort.c b/src/service/toks_service_abort.c new file mode 100644 index 0000000..dc06583 --- /dev/null +++ b/src/service/toks_service_abort.c @@ -0,0 +1,36 @@ +/*********************************************************/ +/* toksvc: a framework-native token broker service */ +/* Copyright (C) 2020 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.TOKSVC. */ +/*********************************************************/ + +#include +#include + +#include +#include "toksvc_driver_impl.h" +#include "toksvc_daemon_impl.h" + +int32_t toks_service_abort(struct toks_driver_ctx * dctx) +{ + int32_t status; + void * hport; + struct _nt_tty_ipc_msg msg; + + hport = toks_get_driver_hservice(dctx); + + ntapi->tt_aligned_block_memset( + &msg,0,sizeof(msg)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = TOKS_DAEMON_ABORT; + + if ((status = ntapi->zw_request_wait_reply_port(hport,&msg,&msg))) + return status; + + return (msg.data.ttyinfo.status) + ? msg.data.ttyinfo.status + : NT_STATUS_SUCCESS; +} diff --git a/src/skin/toks_skin_default.c b/src/skin/toks_skin_default.c index ab625a1..36d29ff 100644 --- a/src/skin/toks_skin_default.c +++ b/src/skin/toks_skin_default.c @@ -29,6 +29,9 @@ const struct argv_option toks_default_options[] = { {"connect", 'c',TAG_CONNECT,ARGV_OPTARG_NONE,0,0,0, "connect to the server without placing any request"}, + {"abort", 'k',TAG_ABORT,ARGV_OPTARG_NONE,0,0,0, + "ask the token service to terminate"}, + {"acquire", 'a',TAG_ACQUIRE,ARGV_OPTARG_NONE,0,0,0, "acquire the next available token"},