From 83e502a94a672e214668fb4152d0c44af4447710 Mon Sep 17 00:00:00 2001 From: midipix Date: Jun 17 2020 23:03:24 +0000 Subject: client: toks_client_connect(): obtain the server's syspid its daemon's systid. --- diff --git a/src/client/toks_client_connect.c b/src/client/toks_client_connect.c index 055c106..07ad311 100644 --- a/src/client/toks_client_connect.c +++ b/src/client/toks_client_connect.c @@ -9,12 +9,15 @@ #include #include "toksvc_driver_impl.h" +#include "toksvc_daemon_impl.h" int32_t toks_client_connect(struct toks_driver_ctx * dctx) { int32_t status; void * hsvclink; void * hservice; + void * hserver; + struct _nt_tty_sync_msg msg; nt_unicode_string name; nt_guid_str_utf16 guid; nt_oa oa; @@ -51,8 +54,42 @@ int32_t toks_client_connect(struct toks_driver_ctx * dctx) if ((status = ntapi->ipc_connect_by_symlink(&hservice,hsvclink))) return status; + 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_CIDQUERY; + + if ((status = ntapi->zw_request_wait_reply_port(hservice,&msg,&msg))) { + ntapi->zw_close(hservice); + return status; + + } else if (msg.data.ttyinfo.status) { + ntapi->zw_close(hservice); + return msg.data.ttyinfo.status; + } + + oa.len = sizeof(oa); + oa.root_dir = 0; + oa.obj_name = 0; + oa.obj_attr = 0; + oa.sec_desc = 0; + oa.sec_qos = &sqos; + + if ((status = ntapi->zw_open_process( + &hserver,NT_PROCESS_SYNCHRONIZE, + &oa,&msg.data.syncinfo.cid))) { + ntapi->zw_close(hservice); + return status; + } + toks_set_driver_hservice( dctx,hservice); + toks_set_driver_hserver( + dctx,hserver); + return NT_STATUS_SUCCESS; } diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index dc3df1f..0567be9 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -617,6 +617,9 @@ static void toks_free_driver_ctx_impl(struct toks_driver_ctx_alloc * ictx) if (ictx->ctx.hservice) ntapi->zw_close(ictx->ctx.hservice); + if (ictx->ctx.hserver) + ntapi->zw_close(ictx->ctx.hserver); + if (ictx->ctx.tokens) toks_free(ictx->ctx.tokens); diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index c4350d7..6ef8a6c 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -61,6 +61,7 @@ struct toks_driver_ctx_impl { void * hpiddir; void * hsvclink; void * hservice; + void * hserver; int nwaiters; int ntokens; int tokpid; @@ -164,6 +165,20 @@ static inline void toks_set_driver_hservice(const struct toks_driver_ctx * dctx, ictx->hservice = hservice; } +static inline void * toks_get_driver_hserver(const struct toks_driver_ctx * dctx) +{ + struct toks_driver_ctx_impl * ictx; + ictx = toks_get_driver_ictx(dctx); + return ictx->hserver; +} + +static inline void toks_set_driver_hserver(const struct toks_driver_ctx * dctx, void * hserver) +{ + struct toks_driver_ctx_impl * ictx; + ictx = toks_get_driver_ictx(dctx); + ictx->hserver = hserver; +} + static inline struct _nt_port_keys * toks_get_driver_keys(const struct toks_driver_ctx * dctx) { struct toks_driver_ctx_impl * ictx;