Blame src/client/toks_client_connect.c

486fcd
/*********************************************************/
486fcd
/*  toksvc: a framework-native token broker service      */
486fcd
/*  Copyright (C) 2020  Z. Gilboa                        */
486fcd
/*  Released under GPLv2 and GPLv3; see COPYING.TOKSVC.  */
486fcd
/*********************************************************/
486fcd
486fcd
#include <psxtypes/psxtypes.h>
486fcd
#include <ntapi/ntapi.h>
486fcd
486fcd
#include <toksvc/toksvc.h>
486fcd
#include "toksvc_driver_impl.h"
83e502
#include "toksvc_daemon_impl.h"
486fcd
486fcd
int32_t toks_client_connect(struct toks_driver_ctx * dctx)
486fcd
{
486fcd
	int32_t			status;
486fcd
	void *			hsvclink;
486fcd
	void *			hservice;
83e502
	void *			hserver;
83e502
	struct _nt_tty_sync_msg msg;
486fcd
	nt_unicode_string	name;
486fcd
	nt_guid_str_utf16	guid;
486fcd
	nt_oa			oa;
486fcd
	nt_sqos			sqos = {
486fcd
					sizeof(sqos),
486fcd
					NT_SECURITY_ANONYMOUS,
486fcd
					NT_SECURITY_TRACKING_STATIC,
486fcd
					1};
486fcd
486fcd
	ntapi->tt_guid_to_string_utf16(
486fcd
		toks_get_driver_uuid(dctx),
486fcd
		&guid);
486fcd
486fcd
	name.strlen = sizeof(guid);
486fcd
	name.maxlen = 0;
486fcd
	name.buffer = &guid.lbrace;
486fcd
486fcd
	oa.len		= sizeof(oa);
486fcd
	oa.root_dir	= toks_get_driver_hsvcdir(dctx);
486fcd
	oa.obj_name	= &nam;;
486fcd
	oa.obj_attr	= NT_OBJ_INHERIT;
486fcd
	oa.sec_desc	= 0;
486fcd
	oa.sec_qos	= &sqo;;
486fcd
486fcd
	if ((status = ntapi->zw_open_symbolic_link_object(
486fcd
			&hsvclink,
486fcd
			NT_SYMBOLIC_LINK_QUERY,
486fcd
			&oa)))
486fcd
		return status;
486fcd
486fcd
	toks_set_driver_hsvclink(
486fcd
		dctx,hsvclink);
486fcd
d90cbf
	if ((status = ntapi->ipc_connect_by_symlink(&hservice,hsvclink)))
486fcd
		return status;
486fcd
83e502
	ntapi->tt_aligned_block_memset(
83e502
		&msg,0,sizeof(msg));
83e502
83e502
	msg.header.msg_type	= NT_LPC_NEW_MESSAGE;
83e502
	msg.header.data_size	= sizeof(msg.data);
83e502
	msg.header.msg_size	= sizeof(msg);
83e502
	msg.data.ttyinfo.opcode	= TOKS_DAEMON_CIDQUERY;
83e502
83e502
	if ((status = ntapi->zw_request_wait_reply_port(hservice,&msg,&msg))) {
83e502
		ntapi->zw_close(hservice);
83e502
		return status;
83e502
83e502
	} else if (msg.data.ttyinfo.status) {
83e502
		ntapi->zw_close(hservice);
83e502
		return msg.data.ttyinfo.status;
83e502
	}
83e502
83e502
	oa.len		= sizeof(oa);
83e502
	oa.root_dir	= 0;
83e502
	oa.obj_name	= 0;
83e502
	oa.obj_attr	= 0;
83e502
	oa.sec_desc	= 0;
83e502
	oa.sec_qos	= &sqo;;
83e502
83e502
	if ((status = ntapi->zw_open_process(
83e502
			&hserver,NT_PROCESS_SYNCHRONIZE,
83e502
			&oa,&msg.data.syncinfo.cid))) {
83e502
		ntapi->zw_close(hservice);
83e502
		return status;
83e502
	}
83e502
486fcd
	toks_set_driver_hservice(
486fcd
		dctx,hservice);
486fcd
83e502
	toks_set_driver_hserver(
83e502
		dctx,hserver);
83e502
486fcd
	return NT_STATUS_SUCCESS;
486fcd
}