Blame src/daemon/toks_daemon_cancel.c

3034d1
/*********************************************************/
3034d1
/*  toksvc: a framework-native token broker service      */
d91fa0
/*  Copyright (C) 2020  SysDeer Technologies, LLC        */
3034d1
/*  Released under GPLv2 and GPLv3; see COPYING.TOKSVC.  */
3034d1
/*********************************************************/
3034d1
3034d1
#include <psxtypes/psxtypes.h>
3034d1
#include <ntapi/ntapi.h>
3034d1
3034d1
#include <toksvc/toksvc.h>
3034d1
#include "toksvc_daemon_impl.h"
3034d1
#include "toksvc_driver_impl.h"
3034d1
3034d1
int32_t __stdcall toks_daemon_cancel(struct toks_daemon_ctx * dctx)
3034d1
{
3034d1
	nt_tty_port_msg *           msg;
3034d1
	nt_cid *                    cid;
3034d1
	struct toks_waiter *        waiter;
3034d1
	int                         nwaiters;
55176c
	int                         idx;
3034d1
55176c
	if ((nwaiters = toks_get_driver_nwaiters(dctx->driver_ctx)) == 0)
3034d1
		return NT_STATUS_NOT_FOUND;
3034d1
55176c
	idx     = 0;
55176c
	msg     = &dctx->reply;
55176c
	cid     = &msg->header.client_id;
3034d1
	waiter  = dctx->waiter_first;
3034d1
55176c
	for (; idx
3034d1
		if (waiter->msg.header.client_id.process_id == cid->process_id) {
3034d1
			if (waiter->msg.header.client_id.thread_id == cid->thread_id) {
55176c
				if (waiter->msg.header.msg_id) {
55176c
					waiter->msg.header.msg_id = 0;
55176c
					toks_set_driver_nwaiters(dctx->driver_ctx,--nwaiters);
55176c
					return NT_STATUS_CANCELLED;
55176c
				}
3034d1
			}
3034d1
		}
3034d1
55176c
		if (++waiter == dctx->waiter_cap)
55176c
			waiter = dctx->waiter_base;
3034d1
	}
3034d1
3034d1
	return NT_STATUS_NOT_FOUND;
3034d1
}