xace: typesafe hook function for XACE_SEND_ACCESS

The generic XaceHook() call isn't typesafe (und unnecessarily slow).
Better add an explicit function, just like we already have for others.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1556>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-05-16 20:34:50 +02:00 committed by Marge Bot
parent 9524ffee89
commit 67e468c8bd
4 changed files with 18 additions and 21 deletions

View File

@ -78,13 +78,20 @@ int XaceHookDeviceAccess(ClientPtr client, DeviceIntPtr dev, Mask access_mode)
return rec.status; return rec.status;
} }
int XaceHookSendAccess(ClientPtr client, DeviceIntPtr dev, WindowPtr win,
xEventPtr ev, int count)
{
XaceSendAccessRec rec = { client, dev, win, ev, count, Success };
CallCallbacks(&XaceHooks[XACE_SEND_ACCESS], &rec);
return rec.status;
}
/* Entry point for hook functions. Called by Xserver. /* Entry point for hook functions. Called by Xserver.
*/ */
int int
XaceHook(int hook, ...) XaceHook(int hook, ...)
{ {
union { union {
XaceSendAccessRec send;
XaceReceiveAccessRec recv; XaceReceiveAccessRec recv;
XaceClientAccessRec client; XaceClientAccessRec client;
XaceExtAccessRec ext; XaceExtAccessRec ext;
@ -107,17 +114,6 @@ XaceHook(int hook, ...)
* sets calldata directly to a single argument (with no return result) * sets calldata directly to a single argument (with no return result)
*/ */
switch (hook) { switch (hook) {
case XACE_SEND_ACCESS:
u.send.client = va_arg(ap, ClientPtr);
u.send.dev = va_arg(ap, DeviceIntPtr);
u.send.pWin = va_arg(ap, WindowPtr);
u.send.events = va_arg(ap, xEventPtr);
u.send.count = va_arg(ap, int);
u.send.status = Success; /* default allow */
prv = &u.send.status;
break;
case XACE_RECEIVE_ACCESS: case XACE_RECEIVE_ACCESS:
u.recv.client = va_arg(ap, ClientPtr); u.recv.client = va_arg(ap, ClientPtr);
u.recv.pWin = va_arg(ap, WindowPtr); u.recv.pWin = va_arg(ap, WindowPtr);

View File

@ -84,6 +84,9 @@ _X_EXPORT int XaceHookResourceAccess(ClientPtr client, XID id, RESTYPE rtype, vo
int XaceHookDeviceAccess(ClientPtr client, DeviceIntPtr dev, Mask access_mode); int XaceHookDeviceAccess(ClientPtr client, DeviceIntPtr dev, Mask access_mode);
int XaceHookSendAccess(ClientPtr client, DeviceIntPtr dev, WindowPtr win,
xEventPtr ev, int count);
/* Register a callback for a given hook. /* Register a callback for a given hook.
*/ */
#define XaceRegisterCallback(hook,callback,data) \ #define XaceRegisterCallback(hook,callback,data) \

View File

@ -2957,7 +2957,7 @@ SendEvent(ClientPtr client, DeviceIntPtr d, Window dest, Bool propagate,
break; break;
} }
} }
else if (!XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, ev, count)) else if (!XaceHookSendAccess(client, NULL, pWin, ev, count))
DeliverEventsToWindow(d, pWin, ev, count, mask, NullGrab); DeliverEventsToWindow(d, pWin, ev, count, mask, NullGrab);
return Success; return Success;
} }

View File

@ -2789,7 +2789,7 @@ DeliverEvent(DeviceIntPtr dev, xEvent *xE, int count,
Mask filter; Mask filter;
int deliveries = 0; int deliveries = 0;
if (XaceHook(XACE_SEND_ACCESS, NULL, dev, win, xE, count) == Success) { if (XaceHookSendAccess(NULL, dev, win, xE, count) == Success) {
filter = GetEventFilter(dev, xE); filter = GetEventFilter(dev, xE);
FixUpEventFromWindow(pSprite, xE, win, child, FALSE); FixUpEventFromWindow(pSprite, xE, win, child, FALSE);
deliveries = DeliverEventsToWindow(dev, win, xE, count, filter, grab); deliveries = DeliverEventsToWindow(dev, win, xE, count, filter, grab);
@ -4213,7 +4213,7 @@ DeliverFocusedEvent(DeviceIntPtr keybd, InternalEvent *event, WindowPtr window)
rc = EventToXI(event, &xE, &count); rc = EventToXI(event, &xE, &count);
if (rc == Success && if (rc == Success &&
XaceHook(XACE_SEND_ACCESS, NULL, keybd, focus, xE, count) == Success) { XaceHookSendAccess(NULL, keybd, focus, xE, count) == Success) {
FixUpEventFromWindow(ptr->spriteInfo->sprite, xE, focus, None, FALSE); FixUpEventFromWindow(ptr->spriteInfo->sprite, xE, focus, None, FALSE);
deliveries = DeliverEventsToWindow(keybd, focus, xE, count, deliveries = DeliverEventsToWindow(keybd, focus, xE, count,
GetEventFilter(keybd, xE), NullGrab); GetEventFilter(keybd, xE), NullGrab);
@ -4229,7 +4229,7 @@ DeliverFocusedEvent(DeviceIntPtr keybd, InternalEvent *event, WindowPtr window)
if (sendCore) { if (sendCore) {
rc = EventToCore(event, &core, &count); rc = EventToCore(event, &core, &count);
if (rc == Success) { if (rc == Success) {
if (XaceHook(XACE_SEND_ACCESS, NULL, keybd, focus, core, count) == if (XaceHookSendAccess(NULL, keybd, focus, core, count) ==
Success) { Success) {
FixUpEventFromWindow(keybd->spriteInfo->sprite, core, focus, FixUpEventFromWindow(keybd->spriteInfo->sprite, core, focus,
None, FALSE); None, FALSE);
@ -4302,8 +4302,7 @@ DeliverOneGrabbedEvent(InternalEvent *event, DeviceIntPtr dev,
if (rc == Success) { if (rc == Success) {
FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE); FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
if (XaceHook(XACE_SEND_ACCESS, 0, dev, if (XaceHookSendAccess(0, dev, grab->window, xE, count) ||
grab->window, xE, count) ||
XaceHook(XACE_RECEIVE_ACCESS, rClient(grab), XaceHook(XACE_RECEIVE_ACCESS, rClient(grab),
grab->window, xE, count)) grab->window, xE, count))
deliveries = 1; /* don't send, but pretend we did */ deliveries = 1; /* don't send, but pretend we did */
@ -5532,8 +5531,7 @@ ProcSendEvent(ClientPtr client)
stuff->event.u.u.type |= SEND_EVENT_BIT; stuff->event.u.u.type |= SEND_EVENT_BIT;
if (stuff->propagate) { if (stuff->propagate) {
for (; pWin; pWin = pWin->parent) { for (; pWin; pWin = pWin->parent) {
if (XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, if (XaceHookSendAccess(client, NULL, pWin, &stuff->event, 1))
&stuff->event, 1))
return Success; return Success;
if (DeliverEventsToWindow(dev, pWin, if (DeliverEventsToWindow(dev, pWin,
&stuff->event, 1, stuff->eventMask, &stuff->event, 1, stuff->eventMask,
@ -5546,7 +5544,7 @@ ProcSendEvent(ClientPtr client)
break; break;
} }
} }
else if (!XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, &stuff->event, 1)) else if (!XaceHookSendAccess(client, NULL, pWin, &stuff->event, 1))
DeliverEventsToWindow(dev, pWin, &stuff->event, DeliverEventsToWindow(dev, pWin, &stuff->event,
1, stuff->eventMask, NullGrab); 1, stuff->eventMask, NullGrab);
return Success; return Success;