From 093128a956d72d05a0c3dd5c6d20f144826b9e32 Mon Sep 17 00:00:00 2001 From: midipix Date: Jul 06 2020 06:00:15 +0000 Subject: daemon: toks_daemon_ioctl_get_token_info(): return pending requests info. --- diff --git a/src/daemon/toks_daemon_acquire.c b/src/daemon/toks_daemon_acquire.c index df606dd..5d6fc9d 100644 --- a/src/daemon/toks_daemon_acquire.c +++ b/src/daemon/toks_daemon_acquire.c @@ -149,7 +149,7 @@ static int32_t toks_daemon_token_instance( return NT_STATUS_SUCCESS; } -static int32_t toks_daemon_queue(struct toks_daemon_ctx * dctx, void * hcaller, void * hprocess) +static int32_t toks_daemon_queue(struct toks_daemon_ctx * dctx, const struct toks_client_ctx * client) { int nwaiters; struct toks_waiter * waiter; @@ -165,7 +165,7 @@ static int32_t toks_daemon_queue(struct toks_daemon_ctx * dctx, void * hcaller, status = ntapi->zw_duplicate_object( - hcaller, + client->hcaller, msg->syncinfo.hevent, NT_CURRENT_PROCESS_HANDLE, &hevent, @@ -173,12 +173,12 @@ static int32_t toks_daemon_queue(struct toks_daemon_ctx * dctx, void * hcaller, 0,0); if (status) { - ntapi->zw_close(hprocess); + ntapi->zw_close(client->hprocess); return status; } if ((status = ntapi->zw_reset_event(hevent,&(int){0}))) { - ntapi->zw_close(hprocess); + ntapi->zw_close(client->hprocess); ntapi->zw_close(hevent); return status; } @@ -186,10 +186,13 @@ static int32_t toks_daemon_queue(struct toks_daemon_ctx * dctx, void * hcaller, waiter = dctx->waiter_next; - waiter->client.hprocess = hprocess; - waiter->client.hcaller = hcaller; + waiter->client.hprocess = client->hprocess; + waiter->client.hcaller = client->hcaller; waiter->client.hevent = hevent; + waiter->client.tokpid = client->tokpid; + waiter->client.cid.process_id = client->cid.process_id; + toks_set_driver_nwaiters( dctx->driver_ctx, ++nwaiters); @@ -300,9 +303,7 @@ int32_t __stdcall toks_daemon_acquire(struct toks_daemon_ctx * dctx) msg->header.msg_id, dctx,sizeof(*dctx)); - return toks_daemon_queue( - dctx,client.hcaller, - client.hprocess); + return toks_daemon_queue(dctx,&client); } token = toks_get_driver_tokens(dctx->driver_ctx); diff --git a/src/daemon/toks_daemon_ioctl.c b/src/daemon/toks_daemon_ioctl.c index fa5eec1..7993a7d 100644 --- a/src/daemon/toks_daemon_ioctl.c +++ b/src/daemon/toks_daemon_ioctl.c @@ -128,6 +128,7 @@ static int32_t toks_daemon_ioctl_get_token_info(struct toks_daemon_ctx * dctx) nt_unicode_string path; nt_large_integer asize; struct toks_token * token; + struct toks_waiter * waiter; struct toks_token_ctx * tctx; struct toks_token_info * tinfo; struct toks_token_sctx stctx; @@ -136,6 +137,7 @@ static int32_t toks_daemon_ioctl_get_token_info(struct toks_daemon_ctx * dctx) uint32_t access_group; uint32_t access_other; uint32_t access_admin; + int32_t nwaiters; uint32_t keys[4]; wchar16_t name[37]; @@ -225,8 +227,11 @@ static int32_t toks_daemon_ioctl_get_token_info(struct toks_daemon_ctx * dctx) access |= NT_FILE_WRITE_DATA | NT_FILE_WRITE_ATTRIBUTES; /* alloc_size */ + nwaiters = toks_get_driver_nwaiters(dctx->driver_ctx); + asize.quad = __offsetof(struct toks_token_ctx,tokens); asize.quad += sizeof(struct toks_token_info) * dctx->utokens; + asize.quad += sizeof(struct toks_token_info) * nwaiters; /* create temporary file */ status = ntapi->zw_create_file( @@ -245,7 +250,7 @@ static int32_t toks_daemon_ioctl_get_token_info(struct toks_daemon_ctx * dctx) } /* buffer */ - if (dctx->utokens <= 512) { + if ((dctx->utokens + nwaiters) <= 512) { tctx = 0; addr = &stctx; size = asize.quad; @@ -253,7 +258,7 @@ static int32_t toks_daemon_ioctl_get_token_info(struct toks_daemon_ctx * dctx) stctx.allocated = toks_get_driver_atokens(dctx->driver_ctx); stctx.available = toks_get_driver_ntokens(dctx->driver_ctx); - stctx.pending = toks_get_driver_nwaiters(dctx->driver_ctx); + stctx.pending = nwaiters; stctx.tused = dctx->utokens; stctx.tfree = dctx->ftokens; } else { @@ -271,7 +276,7 @@ static int32_t toks_daemon_ioctl_get_token_info(struct toks_daemon_ctx * dctx) tctx->allocated = toks_get_driver_atokens(dctx->driver_ctx); tctx->available = toks_get_driver_ntokens(dctx->driver_ctx); - tctx->pending = toks_get_driver_nwaiters(dctx->driver_ctx); + tctx->pending = nwaiters; tctx->tused = dctx->utokens; tctx->tfree = dctx->ftokens; } @@ -304,6 +309,38 @@ static int32_t toks_daemon_ioctl_get_token_info(struct toks_daemon_ctx * dctx) } } + /* waiter info */ + idx = 0; + waiter = dctx->waiter_first; + + for (; idxmsg.header.msg_id) { + tinfo->tokpid = waiter->client.tokpid; + tinfo->tsyspid = waiter->client.cid.process_id; + tinfo->pad = 0; + + tinfo->keys[0] = waiter->msg.syncinfo.ipckeys[0]; + tinfo->keys[1] = waiter->msg.syncinfo.ipckeys[1]; + tinfo->keys[2] = waiter->msg.syncinfo.ipckeys[2]; + tinfo->keys[3] = waiter->msg.syncinfo.ipckeys[3]; + tinfo->keys[4] = waiter->msg.syncinfo.ipckeys[4]; + tinfo->keys[5] = waiter->msg.syncinfo.ipckeys[5]; + + tinfo->meta[0] = waiter->msg.syncinfo.ipcsvc.keys.key[0]; + tinfo->meta[1] = waiter->msg.syncinfo.ipcsvc.keys.key[1]; + tinfo->meta[2] = waiter->msg.syncinfo.ipcsvc.keys.key[2]; + tinfo->meta[3] = waiter->msg.syncinfo.ipcsvc.keys.key[3]; + tinfo->meta[4] = waiter->msg.syncinfo.ipcsvc.keys.key[4]; + tinfo->meta[5] = waiter->msg.syncinfo.ipcsvc.keys.key[5]; + + idx++; + tinfo++; + } + + if (++waiter == dctx->waiter_cap) + waiter = dctx->waiter_base; + } + /* write */ for (mark=addr; size; size-=iosb.info) { status = ntapi->zw_write_file(