/*********************************************************/
/* toksvc: a framework-native token broker service */
/* Copyright (C) 2020 Z. Gilboa */
/* Released under GPLv2 and GPLv3; see COPYING.TOKSVC. */
/*********************************************************/
#include <psxtypes/psxtypes.h>
#include <ntapi/ntapi.h>
#include <toksvc/toksvc.h>
#include "toksvc_driver_impl.h"
int32_t toks_client_connect(struct toks_driver_ctx * dctx)
{
int32_t status;
void * hsvclink;
void * hservice;
nt_unicode_string name;
nt_guid_str_utf16 guid;
nt_oa oa;
nt_sqos sqos = {
sizeof(sqos),
NT_SECURITY_ANONYMOUS,
NT_SECURITY_TRACKING_STATIC,
1};
ntapi->tt_guid_to_string_utf16(
toks_get_driver_uuid(dctx),
&guid);
name.strlen = sizeof(guid);
name.maxlen = 0;
name.buffer = &guid.lbrace;
oa.len = sizeof(oa);
oa.root_dir = toks_get_driver_hsvcdir(dctx);
oa.obj_name = &name;
oa.obj_attr = NT_OBJ_INHERIT;
oa.sec_desc = 0;
oa.sec_qos = &sqos;
if ((status = ntapi->zw_open_symbolic_link_object(
&hsvclink,
NT_SYMBOLIC_LINK_QUERY,
&oa)))
return status;
toks_set_driver_hsvclink(
dctx,hsvclink);
if ((status = ntapi->ipc_connect_by_symlink(&hservice,hsvclink)))
return status;
toks_set_driver_hservice(
dctx,hservice);
return NT_STATUS_SUCCESS;
}