Blame src/client/toks_client_query.c

d64f31
/*********************************************************/
d64f31
/*  toksvc: a framework-native token broker service      */
d91fa0
/*  Copyright (C) 2020  SysDeer Technologies, LLC        */
d64f31
/*  Released under GPLv2 and GPLv3; see COPYING.TOKSVC.  */
d64f31
/*********************************************************/
d64f31
d64f31
#include <psxtypes/psxtypes.h>
d64f31
#include <ntapi/ntapi.h>
d64f31
d64f31
#include <toksvc/toksvc.h>
d64f31
#include "toksvc_driver_impl.h"
d64f31
#include "toksvc_daemon_impl.h"
d64f31
d64f31
int32_t toks_client_query_service(
d64f31
	struct toks_driver_ctx *    dctx,
d64f31
	struct toks_service_info *  svcinfo)
d64f31
{
d64f31
	int32_t			status;
d64f31
	void *			hport;
d64f31
	struct _nt_tty_port_msg	msg;
d64f31
d64f31
	hport  = toks_get_driver_hservice(dctx);
d64f31
d64f31
	ntapi->tt_aligned_block_memset(
d64f31
		&msg,0,sizeof(msg));
d64f31
d64f31
	msg.header.msg_type  = NT_LPC_NEW_MESSAGE;
d64f31
	msg.header.data_size = sizeof(msg.ttyinfo) + sizeof(msg.svcdata);
d64f31
	msg.header.msg_size  = sizeof(msg);
d64f31
	msg.ttyinfo.opcode   = TOKS_DAEMON_IOCTL;
d64f31
	msg.ttyinfo.opdata   = TOKS_IOCTL_GET_SERVICE_INFO;
d64f31
d64f31
	if ((status = ntapi->zw_request_wait_reply_port(hport,&msg,&msg)))
d64f31
		return status;
d64f31
d64f31
	else if (msg.ttyinfo.status)
d64f31
		return msg.ttyinfo.status;
d64f31
d64f31
	/* uuid */
d64f31
	svcinfo->uuid.data1    = (msg.svcdata.meta[0]);
d64f31
d64f31
	svcinfo->uuid.data2    = (msg.svcdata.meta[1]  & 0xffff);
d64f31
	svcinfo->uuid.data3    = (msg.svcdata.meta[1] >> 16);
d64f31
d64f31
	svcinfo->uuid.data4[0] = (msg.svcdata.meta[2] & 0xff);
d64f31
	svcinfo->uuid.data4[1] = (msg.svcdata.meta[2] & 0xff00) >> 8;
d64f31
	svcinfo->uuid.data4[2] = (msg.svcdata.meta[2] & 0xff0000) >> 16;
d64f31
	svcinfo->uuid.data4[3] = (msg.svcdata.meta[2] & 0xff000000) >> 24;
d64f31
d64f31
	svcinfo->uuid.data4[4] = (msg.svcdata.meta[3] & 0xff);
d64f31
	svcinfo->uuid.data4[5] = (msg.svcdata.meta[3] & 0xff00) >> 8;
d64f31
	svcinfo->uuid.data4[6] = (msg.svcdata.meta[3] & 0xff0000) >> 16;
d64f31
	svcinfo->uuid.data4[7] = (msg.svcdata.meta[3] & 0xff000000) >> 24;
d64f31
d64f31
	/* syspid, systid */
d64f31
	svcinfo->syspid        = msg.svcdata.data[0];
d64f31
	svcinfo->systid        = msg.svcdata.data[1];
d64f31
d64f31
	/* ctrlpid, csyspid */
d64f31
	svcinfo->ctrlpid       = msg.svcdata.data[2];
d64f31
	svcinfo->csyspid       = msg.svcdata.data[3];
d64f31
91a57a
	/* allocated, available, pending */
d64f31
	svcinfo->allocated     = msg.svcdata.data[4];
d64f31
	svcinfo->available     = msg.svcdata.data[5];
91a57a
	svcinfo->pending       = msg.svcdata.data[6];
d64f31
d64f31
	/* used, free */
91a57a
	svcinfo->tused         = msg.svcdata.data[7];
91a57a
	svcinfo->tfree         = msg.svcdata.data[8];
d64f31
d64f31
	return NT_STATUS_SUCCESS;
d64f31
}