From 34469256688ddb77f3ddce4a98e3d5c2e646217d Mon Sep 17 00:00:00 2001 From: midipix Date: Jun 11 2020 08:54:09 +0000 Subject: daemon: save the (alternate) token pid in the client's and daemon's contexts. --- diff --git a/src/client/toks_client_acquire.c b/src/client/toks_client_acquire.c index 56cb89f..81c3415 100644 --- a/src/client/toks_client_acquire.c +++ b/src/client/toks_client_acquire.c @@ -50,7 +50,7 @@ int32_t toks_client_acquire(struct toks_driver_ctx * dctx) msg.header.msg_size = sizeof(msg); msg.data.ttyinfo.opcode = TOKS_DAEMON_ACQUIRE; - msg.data.ipcinfo.ctrlsvc.keys.key[0] = toks_get_driver_tokpid(dctx); + msg.data.ipcinfo.ctrlsvc.keys.reserved = toks_get_driver_tokpid(dctx); msg.data.ipcinfo.hevent = toks_get_driver_hevent(dctx); if (!(millisecs = toks_get_driver_timeout(dctx))) { diff --git a/src/daemon/toks_daemon_acquire.c b/src/daemon/toks_daemon_acquire.c index 8373fba..5612d11 100644 --- a/src/daemon/toks_daemon_acquire.c +++ b/src/daemon/toks_daemon_acquire.c @@ -225,6 +225,7 @@ int32_t __stdcall toks_daemon_acquire(struct toks_daemon_ctx * dctx) client.hdaemon = dctx->hport_internal_client; client.cid.process_id = msg->header.client_id.process_id; client.cid.thread_id = 0; + client.tokpid = 0; oa.len = sizeof(oa); oa.root_dir = 0; @@ -234,11 +235,12 @@ int32_t __stdcall toks_daemon_acquire(struct toks_daemon_ctx * dctx) oa.sec_qos = 0; if (dctx->opcode == TOKS_DAEMON_ACQUIRE) { - if (msg->ipcinfo.ctrlsvc.keys.key[0]) { + if ((dctx->reqtokpid = msg->ipcinfo.ctrlsvc.keys.reserved)) { if ((status = toks_daemon_pidopen(dctx))) return status; - client.cid.process_id = msg->ipcinfo.ctrlsvc.keys.key[1]; + client.tokpid = dctx->reqtokpid; + client.cid.process_id = dctx->reqsyspid; } if ((status = ntapi->zw_open_process( diff --git a/src/daemon/toks_daemon_pidopen.c b/src/daemon/toks_daemon_pidopen.c index 2c816fe..3ff385a 100644 --- a/src/daemon/toks_daemon_pidopen.c +++ b/src/daemon/toks_daemon_pidopen.c @@ -17,8 +17,8 @@ static const nt_guid g_pidany = NT_PROCESS_GUID_PIDANY; static const wchar16_t p_pidany[6] = NT_PROCESS_OBJDIR_PREFIX_PIDANY; static int32_t toks_daemon_pid_connect( - struct toks_driver_ctx * dctx, - int32_t pid, void ** hipc) + struct toks_daemon_ctx * dctx, + void ** hipc) { int32_t status; void * hpidany; @@ -28,7 +28,7 @@ static int32_t toks_daemon_pid_connect( wchar16_t pidnamebuf[8]; /* hpiddir */ - if (!(hpiddir = toks_get_driver_hpiddir(dctx))) { + if (!(hpiddir = toks_get_driver_hpiddir(dctx->driver_ctx))) { if ((status = ntapi->tt_open_ipc_object_directory( &hpiddir, NT_SEC_READ_CONTROL @@ -39,12 +39,12 @@ static int32_t toks_daemon_pid_connect( p_pidany,&g_pidany))) return status; - toks_set_driver_hpiddir(dctx,hpiddir); + toks_set_driver_hpiddir(dctx->driver_ctx,hpiddir); } /* pid entry name */ ntapi->tt_uint32_to_hex_utf16( - pid,pidnamebuf); + dctx->reqtokpid,pidnamebuf); pidname.strlen = sizeof(pidnamebuf); pidname.maxlen = sizeof(pidnamebuf);; @@ -77,11 +77,8 @@ int32_t toks_daemon_pidopen(struct toks_daemon_ctx * dctx) int32_t status; nt_tty_session_msg msg; void * hipc; - int32_t pid; - pid = dctx->reply.ipcinfo.ctrlsvc.keys.key[0]; - - if ((status = toks_daemon_pid_connect(dctx->driver_ctx,pid,&hipc))) + if ((status = toks_daemon_pid_connect(dctx,&hipc))) return status; ntapi->tt_aligned_block_memset( @@ -97,7 +94,7 @@ int32_t toks_daemon_pidopen(struct toks_daemon_ctx * dctx) else if (msg.data.ttyinfo.status) return msg.data.ttyinfo.status; - dctx->reply.ipcinfo.ctrlsvc.keys.key[1] = msg.data.sessioninfo.syspid; + dctx->reqsyspid = msg.data.sessioninfo.syspid; return NT_STATUS_SUCCESS; } diff --git a/src/internal/toksvc_daemon_impl.h b/src/internal/toksvc_daemon_impl.h index 5e46deb..22b166b 100644 --- a/src/internal/toksvc_daemon_impl.h +++ b/src/internal/toksvc_daemon_impl.h @@ -30,6 +30,7 @@ struct toks_client_ctx { void * halert; void * hevent; void * hdaemon; + int32_t tokpid; nt_cid cid; }; @@ -68,6 +69,9 @@ struct toks_daemon_ctx { nt_tty_port_msg request; nt_tty_port_msg reply; + + intptr_t reqtokpid; + intptr_t reqsyspid; }; int32_t __stdcall toks_daemon_init(struct toks_daemon_ctx *, const nt_guid *);