|
|
e6c547 |
/*********************************************************/
|
|
|
e6c547 |
/* toksvc: a framework-native token broker service */
|
|
|
e6c547 |
/* Copyright (C) 2020 Z. Gilboa */
|
|
|
e6c547 |
/* Released under GPLv2 and GPLv3; see COPYING.TOKSVC. */
|
|
|
e6c547 |
/*********************************************************/
|
|
|
e6c547 |
|
|
|
e6c547 |
#include <psxtypes/psxtypes.h>
|
|
|
e6c547 |
#include <ntapi/ntapi.h>
|
|
|
e6c547 |
#include <ntapi/nt_termios.h>
|
|
|
e6c547 |
|
|
|
e6c547 |
#include "toksvc_daemon_impl.h"
|
|
|
e6c547 |
#include "toksvc_driver_impl.h"
|
|
|
ca08aa |
#include "toksvc_log_impl.h"
|
|
|
e6c547 |
|
|
|
e6c547 |
static int32_t toks_daemon_ioctl_get_token_count(struct toks_daemon_ctx * dctx)
|
|
|
e6c547 |
{
|
|
|
e6c547 |
nt_tty_port_msg * msg = &dctx->reply;
|
|
|
e6c547 |
msg->ttyinfo.exarg = (void *)(intptr_t)toks_get_driver_ntokens(dctx->driver_ctx);
|
|
|
e6c547 |
return NT_STATUS_SUCCESS;
|
|
|
e6c547 |
}
|
|
|
e6c547 |
|
|
|
8f6a66 |
static int32_t toks_daemon_ioctl_set_token_count(struct toks_daemon_ctx * dctx)
|
|
|
8f6a66 |
{
|
|
|
8f6a66 |
nt_tty_port_msg * msg;
|
|
|
8f6a66 |
int ntokens;
|
|
|
8f6a66 |
|
|
|
8f6a66 |
msg = &dctx->reply;
|
|
|
8f6a66 |
ntokens = (int)(intptr_t)msg->ttyinfo.exarg;
|
|
|
8f6a66 |
|
|
|
dc482a |
if (ntokens < 0)
|
|
|
dc482a |
return NT_STATUS_INVALID_PARAMETER;
|
|
|
dc482a |
|
|
|
dc482a |
else if (ntokens > toks_get_driver_atokens(dctx->driver_ctx))
|
|
|
8f6a66 |
return NT_STATUS_BUFFER_TOO_SMALL;
|
|
|
8f6a66 |
|
|
|
8f6a66 |
toks_set_driver_ntokens(dctx->driver_ctx,ntokens);
|
|
|
8f6a66 |
|
|
|
971724 |
dctx->ftokens = (dctx->utokens < ntokens)
|
|
|
971724 |
? ntokens - dctx->utokens : 0;
|
|
|
971724 |
|
|
|
8f6a66 |
return toks_daemon_release(dctx);
|
|
|
8f6a66 |
}
|
|
|
8f6a66 |
|
|
|
a644fe |
static int32_t toks_daemon_ioctl_get_log_level(struct toks_daemon_ctx * dctx)
|
|
|
a644fe |
{
|
|
|
a644fe |
nt_tty_port_msg * msg = &dctx->reply;
|
|
|
a644fe |
msg->ttyinfo.exarg = (void *)(intptr_t)dctx->driver_ctx->cctx->loglevel;
|
|
|
a644fe |
return NT_STATUS_SUCCESS;
|
|
|
a644fe |
}
|
|
|
a644fe |
|
|
|
a644fe |
static int32_t toks_daemon_ioctl_set_log_level(struct toks_daemon_ctx * dctx)
|
|
|
a644fe |
{
|
|
|
a644fe |
nt_tty_port_msg * msg;
|
|
|
a644fe |
int loglevel;
|
|
|
a644fe |
|
|
|
a644fe |
msg = &dctx->reply;
|
|
|
a644fe |
loglevel = (int)(intptr_t)msg->ttyinfo.exarg;
|
|
|
a644fe |
|
|
|
a644fe |
if ((loglevel < 0) || (loglevel > 9))
|
|
|
a644fe |
return NT_STATUS_INVALID_PARAMETER;
|
|
|
a644fe |
|
|
|
a644fe |
toks_set_driver_log_level(dctx->driver_ctx,loglevel);
|
|
|
a644fe |
|
|
|
a644fe |
toks_log_service_info(dctx);
|
|
|
a644fe |
|
|
|
a644fe |
return NT_STATUS_SUCCESS;
|
|
|
a644fe |
}
|
|
|
a644fe |
|
|
|
ca08aa |
static int32_t toks_daemon_ioctl_get_service_info(struct toks_daemon_ctx * dctx)
|
|
|
ca08aa |
{
|
|
|
ca08aa |
nt_tty_port_msg * msg = &dctx->reply;
|
|
|
ca08aa |
|
|
|
ca08aa |
/* uuid */
|
|
|
ca08aa |
msg->svcdata.meta[0] = (dctx->driver_ctx->cctx->uuid->data1);
|
|
|
ca08aa |
|
|
|
ca08aa |
msg->svcdata.meta[1] = (dctx->driver_ctx->cctx->uuid->data2);
|
|
|
ca08aa |
msg->svcdata.meta[1] |= (dctx->driver_ctx->cctx->uuid->data3 << 16);
|
|
|
ca08aa |
|
|
|
ca08aa |
msg->svcdata.meta[2] = (dctx->driver_ctx->cctx->uuid->data4[0]);
|
|
|
ca08aa |
msg->svcdata.meta[2] |= (dctx->driver_ctx->cctx->uuid->data4[1] << 8);
|
|
|
ca08aa |
msg->svcdata.meta[2] |= (dctx->driver_ctx->cctx->uuid->data4[2] << 16);
|
|
|
ca08aa |
msg->svcdata.meta[2] |= (dctx->driver_ctx->cctx->uuid->data4[3] << 24);
|
|
|
ca08aa |
|
|
|
ca08aa |
msg->svcdata.meta[3] = (dctx->driver_ctx->cctx->uuid->data4[4]);
|
|
|
ca08aa |
msg->svcdata.meta[3] |= (dctx->driver_ctx->cctx->uuid->data4[5] << 8);
|
|
|
ca08aa |
msg->svcdata.meta[3] |= (dctx->driver_ctx->cctx->uuid->data4[6] << 16);
|
|
|
ca08aa |
msg->svcdata.meta[3] |= (dctx->driver_ctx->cctx->uuid->data4[7] << 24);
|
|
|
ca08aa |
|
|
|
ca08aa |
/* syspid, systid */
|
|
|
ca08aa |
msg->svcdata.data[0] = pe_get_current_process_id();
|
|
|
ca08aa |
msg->svcdata.data[1] = pe_get_current_thread_id();
|
|
|
ca08aa |
|
|
|
ca08aa |
/* ctrlpid, csyspid */
|
|
|
ca08aa |
msg->svcdata.data[2] = dctx->ctrlpid;
|
|
|
ca08aa |
msg->svcdata.data[3] = dctx->csyspid;
|
|
|
ca08aa |
|
|
|
ca08aa |
/* allocated, available */
|
|
|
ca08aa |
msg->svcdata.data[4] = toks_get_driver_atokens(dctx->driver_ctx);
|
|
|
ca08aa |
msg->svcdata.data[5] = toks_get_driver_ntokens(dctx->driver_ctx);
|
|
|
ca08aa |
|
|
|
ca08aa |
/* used, free */
|
|
|
ca08aa |
msg->svcdata.data[6] = dctx->utokens;
|
|
|
ca08aa |
msg->svcdata.data[7] = dctx->ftokens;
|
|
|
ca08aa |
|
|
|
ca08aa |
return NT_STATUS_SUCCESS;
|
|
|
ca08aa |
}
|
|
|
ca08aa |
|
|
|
ca08aa |
static int32_t toks_daemon_ioctl_log_service_info(struct toks_daemon_ctx * dctx)
|
|
|
ca08aa |
{
|
|
|
ca08aa |
toks_log_service_info(dctx);
|
|
|
ca08aa |
return NT_STATUS_SUCCESS;
|
|
|
ca08aa |
}
|
|
|
ca08aa |
|
|
|
e6c547 |
int32_t __stdcall toks_daemon_ioctl(struct toks_daemon_ctx * dctx)
|
|
|
e6c547 |
{
|
|
|
e6c547 |
nt_tty_port_msg * msg;
|
|
|
e6c547 |
uint32_t ctlcode;
|
|
|
e6c547 |
|
|
|
e6c547 |
msg = &dctx->reply;
|
|
|
e6c547 |
ctlcode = msg->ttyinfo.opdata;
|
|
|
e6c547 |
|
|
|
e6c547 |
switch (ctlcode) {
|
|
|
e6c547 |
case TOKS_IOCTL_GET_TOKEN_COUNT:
|
|
|
e6c547 |
return toks_daemon_ioctl_get_token_count(dctx);
|
|
|
e6c547 |
|
|
|
8f6a66 |
case TOKS_IOCTL_SET_TOKEN_COUNT:
|
|
|
8f6a66 |
return toks_daemon_ioctl_set_token_count(dctx);
|
|
|
8f6a66 |
|
|
|
ca08aa |
case TOKS_IOCTL_GET_SERVICE_INFO:
|
|
|
ca08aa |
return toks_daemon_ioctl_get_service_info(dctx);
|
|
|
ca08aa |
|
|
|
ca08aa |
case TOKS_IOCTL_LOG_SERVICE_INFO:
|
|
|
ca08aa |
return toks_daemon_ioctl_log_service_info(dctx);
|
|
|
ca08aa |
|
|
|
a644fe |
case TOKS_IOCTL_GET_LOG_LEVEL:
|
|
|
a644fe |
return toks_daemon_ioctl_get_log_level(dctx);
|
|
|
a644fe |
|
|
|
a644fe |
case TOKS_IOCTL_SET_LOG_LEVEL:
|
|
|
a644fe |
return toks_daemon_ioctl_set_log_level(dctx);
|
|
|
a644fe |
|
|
|
e6c547 |
default:
|
|
|
e6c547 |
return NT_STATUS_NOT_IMPLEMENTED;
|
|
|
e6c547 |
}
|
|
|
e6c547 |
}
|