diff --git a/Xext/security.c b/Xext/security.c index cfa52d701..74abfc1d9 100644 --- a/Xext/security.c +++ b/Xext/security.c @@ -32,6 +32,7 @@ in this Software without prior written authorization from The Open Group. #include "dix/dix_priv.h" #include "dix/registry_priv.h" +#include "dix/resource_priv.h" #include "include/extinit_priv.h" #include "os/audit.h" #include "os/auth.h" @@ -856,13 +857,13 @@ SecurityProperty(CallbackListPtr *pcbl, void *unused, void *calldata) Mask allowed = SecurityResourceMask | DixReadAccess; subj = dixLookupPrivate(&rec->client->devPrivates, stateKey); - obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey); + obj = dixLookupPrivate(&dixClientForWindow(rec->pWin)->devPrivates, stateKey); if (SecurityDoCheck(subj, obj, requested, allowed) != Success) { SecurityAudit("Security: denied client %d access to property %s " "(atom 0x%x) window 0x%lx of client %d on request %s\n", rec->client->index, NameForAtom(name), name, - (unsigned long)rec->pWin->drawable.id, wClient(rec->pWin)->index, + (unsigned long)rec->pWin->drawable.id, dixClientForWindow(rec->pWin)->index, SecurityLookupRequestName(rec->client)); rec->status = BadAccess; } @@ -878,7 +879,7 @@ SecuritySend(CallbackListPtr *pcbl, void *unused, void *calldata) int i; subj = dixLookupPrivate(&rec->client->devPrivates, stateKey); - obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey); + obj = dixLookupPrivate(&dixClientForWindow(rec->pWin)->devPrivates, stateKey); if (SecurityDoCheck(subj, obj, DixSendAccess, 0) == Success) return; @@ -893,7 +894,7 @@ SecuritySend(CallbackListPtr *pcbl, void *unused, void *calldata) rec->client->index, LookupEventName(rec->events[i].u.u.type), (unsigned long)rec->pWin->drawable.id, - wClient(rec->pWin)->index); + dixClientForWindow(rec->pWin)->index); rec->status = BadAccess; return; } @@ -907,7 +908,7 @@ SecurityReceive(CallbackListPtr *pcbl, void *unused, void *calldata) SecurityStateRec *subj, *obj; subj = dixLookupPrivate(&rec->client->devPrivates, stateKey); - obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey); + obj = dixLookupPrivate(&dixClientForWindow(rec->pWin)->devPrivates, stateKey); if (SecurityDoCheck(subj, obj, DixReceiveAccess, 0) == Success) return; @@ -915,7 +916,7 @@ SecurityReceive(CallbackListPtr *pcbl, void *unused, void *calldata) SecurityAudit("Security: denied client %d from receiving an event " "sent to window 0x%lx of client %d\n", rec->client->index, (unsigned long)rec->pWin->drawable.id, - wClient(rec->pWin)->index); + dixClientForWindow(rec->pWin)->index); rec->status = BadAccess; } diff --git a/Xext/xselinux_hooks.c b/Xext/xselinux_hooks.c index 11fcc491f..100e0d708 100644 --- a/Xext/xselinux_hooks.c +++ b/Xext/xselinux_hooks.c @@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "dix/input_priv.h" #include "dix/registry_priv.h" +#include "dix/resource_priv.h" #include "os/client_priv.h" #include "selection.h" @@ -772,7 +773,7 @@ SELinuxResourceState(CallbackListPtr *pcbl, void *unused, void *calldata) return; pWin = (WindowPtr) rec->value; - subj = dixLookupPrivate(&wClient(pWin)->devPrivates, subjectKey); + subj = dixLookupPrivate(&dixClientForWindow(pWin)->devPrivates, subjectKey); if (subj->sid) { char *ctx; diff --git a/Xi/exevents.c b/Xi/exevents.c index a8e2336a5..2b837e1a9 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -96,6 +96,7 @@ SOFTWARE. #include "dix/eventconvert.h" #include "dix/exevents_priv.h" #include "dix/input_priv.h" +#include "dix/resource_priv.h" #include "mi/mi_priv.h" #include "inputstr.h" @@ -1427,7 +1428,7 @@ RetrieveTouchDeliveryData(DeviceIntPtr dev, TouchPointInfoPtr ti, break; /* if owner selected, oclients is NULL */ - *client = oclients ? rClient(oclients) : wClient(*win); + *client = oclients ? rClient(oclients) : dixClientForWindow(*win); } *grab = NULL; diff --git a/composite/compwindow.c b/composite/compwindow.c index 42959bc21..ed6bb5899 100644 --- a/composite/compwindow.c +++ b/composite/compwindow.c @@ -44,6 +44,7 @@ #include #include "dix/dix_priv.h" +#include "dix/resource_priv.h" #include "os/osdep.h" #include "compint.h" @@ -216,7 +217,7 @@ updateOverlayWindow(ScreenPtr pScreen) /* Let's resize the overlay window. */ vlist[0] = w; vlist[1] = h; - return ConfigureWindow(pWin, CWWidth | CWHeight, vlist, wClient(pWin)); + return ConfigureWindow(pWin, CWWidth | CWHeight, vlist, dixClientForWindow(pWin)); } /* Let's be on the safe side and not assume an overlay window is diff --git a/dix/events.c b/dix/events.c index a59b97126..d75aab757 100644 --- a/dix/events.c +++ b/dix/events.c @@ -125,6 +125,7 @@ Equipment Corporation. #include "dix/eventconvert.h" #include "dix/exevents_priv.h" #include "dix/reqhandlers_priv.h" +#include "dix/resource_priv.h" #include "os/bug_priv.h" #include "os/client_priv.h" #include "os/fmt.h" @@ -2199,11 +2200,11 @@ DeliverToWindowOwner(DeviceIntPtr dev, WindowPtr win, !((wOtherEventMasks(win) | win->eventMask) & filter)) return EVENT_SKIP; - if (IsInterferingGrab(wClient(win), dev, events)) + if (IsInterferingGrab(dixClientForWindow(win), dev, events)) return EVENT_SKIP; - if (!XaceHookReceiveAccess(wClient(win), win, events, count)) { - int attempt = TryClientEvents(wClient(win), dev, events, + if (!XaceHookReceiveAccess(dixClientForWindow(win), win, events, count)) { + int attempt = TryClientEvents(dixClientForWindow(win), dev, events, count, win->eventMask, filter, grab); @@ -2377,7 +2378,7 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent case EVENT_DELIVERED: /* We delivered to the owner, with our event mask */ deliveries++; - client = wClient(pWin); + client = dixClientForWindow(pWin); deliveryMask = pWin->eventMask; break; case EVENT_NOT_DELIVERED: @@ -2551,16 +2552,16 @@ Bool MaybeDeliverEventToClient(WindowPtr pWin, xEvent *pEvents, OtherClients *other; if (pWin->eventMask & filter) { - if (wClient(pWin) == dontClient) + if (dixClientForWindow(pWin) == dontClient) return FALSE; #ifdef XINERAMA if (!noPanoramiXExtension && pWin->drawable.pScreen->myNum) - return XineramaTryClientEventsResult(wClient(pWin), NullGrab, + return XineramaTryClientEventsResult(dixClientForWindow(pWin), NullGrab, pWin->eventMask, filter); #endif /* XINERAMA */ - if (XaceHookReceiveAccess(wClient(pWin), pWin, pEvents, 1)) + if (XaceHookReceiveAccess(dixClientForWindow(pWin), pWin, pEvents, 1)) return TRUE; /* don't send, but pretend we did */ - return TryClientEvents(wClient(pWin), NULL, pEvents, 1, + return TryClientEvents(dixClientForWindow(pWin), NULL, pEvents, 1, pWin->eventMask, filter, NullGrab) == 1; } for (other = wOtherClients(pWin); other; other = other->next) { @@ -4560,14 +4561,14 @@ XRetCode EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask) /* It is illegal for two different clients to select on any of the events for AtMostOneClient. However, it is OK, for some client to continue selecting on one of those events. */ - if ((wClient(pWin) != client) && (check & pWin->eventMask)) + if ((dixClientForWindow(pWin) != client) && (check & pWin->eventMask)) return BadAccess; for (others = wOtherClients(pWin); others; others = others->next) { if (!SameClient(others, client) && (check & others->mask)) return BadAccess; } } - if (wClient(pWin) == client) { + if (dixClientForWindow(pWin) == client) { check = pWin->eventMask; pWin->eventMask = mask; } @@ -4721,7 +4722,7 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse, xKeymapEvent ke = { .type = KeymapNotify }; - ClientPtr client = grab ? rClient(grab) : wClient(pWin); + ClientPtr client = grab ? rClient(grab) : dixClientForWindow(pWin); int rc; rc = XaceHookDeviceAccess(client, keybd, DixReadAccess); @@ -4834,7 +4835,7 @@ CoreFocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin) xKeymapEvent ke = { .type = KeymapNotify }; - ClientPtr client = wClient(pWin); + ClientPtr client = dixClientForWindow(pWin); int rc; rc = XaceHookDeviceAccess(client, dev, DixReadAccess); @@ -5895,7 +5896,7 @@ DeleteWindowFromAnyEvents(WindowPtr pWin, Bool freeResources) of ending up reverting to a dying window and thence to None */ #ifdef NOTDEF - || wClient(parent)->clientGone + || dixClientForWindow(parent)->clientGone #endif ); if (!ActivateFocusInGrab(keybd, pWin, parent)) @@ -5967,7 +5968,7 @@ EventMaskForClient(WindowPtr pWin, ClientPtr client) { OtherClientsPtr other; - if (wClient(pWin) == client) + if (dixClientForWindow(pWin) == client) return pWin->eventMask; for (other = wOtherClients(pWin); other; other = other->next) { if (SameClient(other, client)) diff --git a/dix/lookup.c b/dix/lookup.c new file mode 100644 index 000000000..7a14711d1 --- /dev/null +++ b/dix/lookup.c @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + * + * @brief DIX lookup functions + */ +#include + +#include "dix/dix_priv.h" +#include "include/windowstr.h" + +ClientPtr dixClientForWindow(WindowPtr pWin) { + if (!pWin) + return NullClient; + + return clients[CLIENT_ID(pWin->drawable.id)]; +} diff --git a/dix/meson.build b/dix/meson.build index 190972101..7d02841a7 100644 --- a/dix/meson.build +++ b/dix/meson.build @@ -20,6 +20,7 @@ srcs_dix = [ 'glyphcurs.c', 'grabs.c', 'inpututils.c', + 'lookup.c', 'pixmap.c', 'privates.c', 'property.c', diff --git a/dix/resource_priv.h b/dix/resource_priv.h new file mode 100644 index 000000000..8d1969710 --- /dev/null +++ b/dix/resource_priv.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + */ +#ifndef _XSERVER_DIX_RESOURCE_PRIV_H +#define _XSERVER_DIX_RESOURCE_PRIV_H + +#include "include/dix.h" + +/* + * @brief retrieve client that owns given window + * + * XIDs carry the ID of the client who created/owns the resource in upper bits. + * (every client so is assigned a range of XIDs it may use for resource creation) + * + * @param WindowPtr to the window whose client shall be retrieved + * @return pointer to ClientRec structure or NullClient (NULL) + */ +ClientPtr dixClientForWindow(WindowPtr pWin); + +#endif /* _XSERVER_DIX_RESOURCE_PRIV_H */ diff --git a/dix/window.c b/dix/window.c index 51b616c25..3f09bc05f 100644 --- a/dix/window.c +++ b/dix/window.c @@ -104,6 +104,7 @@ Equipment Corporation. #include "dix/exevents_priv.h" #include "dix/input_priv.h" #include "dix/property_priv.h" +#include "dix/resource_priv.h" #include "mi/mi_priv.h" /* miPaintWindow */ #include "os/auth.h" #include "os/client_priv.h" @@ -921,7 +922,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w, RecalculateDeliverableEvents(pWin); if (vmask) - *error = ChangeWindowAttributes(pWin, vmask, vlist, wClient(pWin)); + *error = ChangeWindowAttributes(pWin, vmask, vlist, dixClientForWindow(pWin)); else *error = Success; @@ -2940,7 +2941,7 @@ HandleSaveSet(ClientPtr client) else { pParent = pWin->parent; - while (pParent && (wClient(pParent) == client)) + while (pParent && (dixClientForWindow(pParent) == client)) pParent = pParent->parent; } if (pParent) { diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c index 2b901431b..8350279a3 100644 --- a/hw/xwayland/xwayland-output.c +++ b/hw/xwayland/xwayland-output.c @@ -31,6 +31,7 @@ #include "dix/dix_priv.h" #include "dix/input_priv.h" +#include "dix/resource_priv.h" #include "randr/randrstr_priv.h" #include "xwayland-cvt.h" @@ -574,7 +575,7 @@ xwl_output_set_window_randr_emu_props(struct xwl_screen *xwl_screen, { struct xwl_output_randr_emu_prop prop = {}; - xwl_output_randr_emu_prop(xwl_screen, wClient(window), &prop); + xwl_output_randr_emu_prop(xwl_screen, dixClientForWindow(window), &prop); xwl_output_set_randr_emu_prop(window, &prop); } diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c index a501d8585..2ce2ed045 100644 --- a/hw/xwayland/xwayland-window.c +++ b/hw/xwayland/xwayland-window.c @@ -34,6 +34,7 @@ #include "dix/dix_priv.h" #include "dix/property_priv.h" +#include "dix/resource_priv.h" #include "compositeext.h" #include "compint.h" @@ -570,7 +571,7 @@ xwl_window_should_enable_viewport(struct xwl_window *xwl_window, if (!window) return FALSE; - owner = wClient(window); + owner = dixClientForWindow(window); drawable = &window->drawable; /* 1. Test if the window matches the emulated mode on one of the outputs diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c index e50a93a9b..616cf118e 100644 --- a/hw/xwin/winmultiwindowwindow.c +++ b/hw/xwin/winmultiwindowwindow.c @@ -36,6 +36,7 @@ #include #endif +#include "dix/resource_priv.h" #include "mi/mi_priv.h" #include "win.h" @@ -662,7 +663,7 @@ XID winGetWindowID(WindowPtr pWin) { WindowIDPairRec wi = { pWin, 0 }; - ClientPtr c = wClient(pWin); + ClientPtr c = dixClientForWindow(pWin); /* */ FindClientResourcesByType(c, X11_RESTYPE_WINDOW, winFindWindow, &wi); @@ -732,14 +733,14 @@ winReorderWindowsMultiWindow(void) if (!pWinSib) { /* 1st window - raise to the top */ vlist[0] = Above; - ConfigureWindow(pWin, CWStackMode, vlist, wClient(pWin)); + ConfigureWindow(pWin, CWStackMode, vlist, dixClientForWindow(pWin)); } else { /* 2nd or deeper windows - just below the previous one */ vlist[0] = winGetWindowID(pWinSib); vlist[1] = Below; ConfigureWindow(pWin, CWSibling | CWStackMode, - vlist, wClient(pWin)); + vlist, dixClientForWindow(pWin)); } } } @@ -798,7 +799,7 @@ winAdjustXWindow(WindowPtr pWin, HWND hwnd) */ vlist[0] = 0; vlist[1] = 0; - return ConfigureWindow(pWin, CWX | CWY, vlist, wClient(pWin)); + return ConfigureWindow(pWin, CWX | CWY, vlist, dixClientForWindow(pWin)); } pDraw = &pWin->drawable; @@ -860,7 +861,7 @@ winAdjustXWindow(WindowPtr pWin, HWND hwnd) (unsigned int)vlist[2], (unsigned int)vlist[3]); #endif return ConfigureWindow(pWin, CWX | CWY | CWWidth | CWHeight, - vlist, wClient(pWin)); + vlist, dixClientForWindow(pWin)); #undef WIDTH #undef HEIGHT diff --git a/include/windowstr.h b/include/windowstr.h index 8c3e2ffbd..d640ee7e4 100644 --- a/include/windowstr.h +++ b/include/windowstr.h @@ -193,7 +193,6 @@ extern _X_EXPORT Mask DontPropagateMasks[]; #define wBoundingShape(w) wUseDefault(w, boundingShape, NULL) #define wClipShape(w) wUseDefault(w, clipShape, NULL) #define wInputShape(w) wUseDefault(w, inputShape, NULL) -#define wClient(w) (clients[CLIENT_ID((w)->drawable.id)]) #define wBorderWidth(w) ((int) (w)->borderWidth) static inline PropertyPtr wUserProps(WindowPtr pWin) { return pWin->properties; }