From 57551db4b0812e364c5825c9013232b90ca119e4 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 5 Mar 2025 16:18:31 +0100 Subject: [PATCH] dix: add dixResouceIsServerOwned() Little helper function for checking whether a resource XID belongs to the server itself. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/security.c | 2 +- dix/colormap.c | 4 +--- dix/resource_priv.h | 10 ++++++++++ hw/xwayland/xwayland-pixmap.h | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Xext/security.c b/Xext/security.c index 41afd4ffc..c4486e2f6 100644 --- a/Xext/security.c +++ b/Xext/security.c @@ -764,7 +764,7 @@ SecurityResource(CallbackListPtr *pcbl, void *unused, void *calldata) goto denied; /* special checks for server-owned resources */ - if (owner == serverClient) { + if (dixResouceIsServerOwned(rec->id)) { if (rec->rtype & RC_DRAWABLE) /* additional operations allowed on root windows */ allowed |= SecurityRootWindowExtraMask; diff --git a/dix/colormap.c b/dix/colormap.c index 13b4ffcb4..d3e0f7d61 100644 --- a/dix/colormap.c +++ b/dix/colormap.c @@ -224,8 +224,6 @@ static void FindColorInRootCmap(ColormapPtr /* pmap */ , (bits) += (base); \ while((bits) & ~(mask)) \ (bits) += ((bits) & ~(mask)); -/* ID of server as client */ -#define SERVER_ID 0 typedef struct _colorResource { Colormap mid; @@ -422,7 +420,7 @@ FreeColormap(void *value, XID mid) EntryPtr pent; ColormapPtr pmap = (ColormapPtr) value; - if (dixClientIdForXID(mid) != SERVER_ID) { + if (!dixResouceIsServerOwned(mid)) { (*pmap->pScreen->UninstallColormap) (pmap); WalkTree(pmap->pScreen, (VisitWindowProcPtr) TellNoMap, (void *) &mid); } diff --git a/dix/resource_priv.h b/dix/resource_priv.h index f7d4e4e36..cdbb377c4 100644 --- a/dix/resource_priv.h +++ b/dix/resource_priv.h @@ -82,4 +82,14 @@ static inline ClientPtr dixClientForXID(XID xid) { return NullClient; } +/* + * @brief check whether resource is owned by server + * + * @param XID the ID of the resource to check + * @return TRUE if resource is server owned + */ +static inline Bool dixResouceIsServerOwned(XID xid) { + return (dixClientForXID(xid) == serverClient); +} + #endif /* _XSERVER_DIX_RESOURCE_PRIV_H */ diff --git a/hw/xwayland/xwayland-pixmap.h b/hw/xwayland/xwayland-pixmap.h index 840e8e5ea..8d9388766 100644 --- a/hw/xwayland/xwayland-pixmap.h +++ b/hw/xwayland/xwayland-pixmap.h @@ -50,7 +50,7 @@ Bool xwl_pixmap_init(void); static inline Bool xwl_is_client_pixmap(PixmapPtr pixmap) { - return dixClientForXID(pixmap->drawable.id) != serverClient; + return (!dixResouceIsServerOwned(pixmap->drawable.id)); } #endif /* XWAYLAND_PIXMAP_H */