From 0f6bb23bc22e7111f64f3adf5f1c3d0c4b672f1e Mon Sep 17 00:00:00 2001
From: "Enrico Weigelt, metux IT consult" <info@metux.net>
Date: Fri, 17 May 2024 15:06:19 +0200
Subject: [PATCH] xace: typesafe hook function for XACE_EXT_ACCESS

he 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>
---
 Xext/xace.c     | 16 +++++++---------
 Xext/xace.h     |  2 ++
 dix/extension.c |  2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/Xext/xace.c b/Xext/xace.c
index 82cc6d2b536..f0c70553e40 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -101,13 +101,19 @@ int XaceHookClientAccess(ClientPtr client, ClientPtr target, Mask access_mode)
     return rec.status;
 }
 
+int XaceHookExtAccess(ClientPtr client, ExtensionEntry *ext)
+{
+    XaceExtAccessRec rec = { client, ext, DixGetAttrAccess, Success };
+    CallCallbacks(&XaceHooks[XACE_EXT_ACCESS], &rec);
+    return rec.status;
+}
+
 /* Entry point for hook functions.  Called by Xserver.
  */
 int
 XaceHook(int hook, ...)
 {
     union {
-        XaceExtAccessRec ext;
         XaceServerAccessRec server;
         XaceScreenAccessRec screen;
         XaceAuthAvailRec auth;
@@ -127,14 +133,6 @@ XaceHook(int hook, ...)
      * sets calldata directly to a single argument (with no return result)
      */
     switch (hook) {
-    case XACE_EXT_ACCESS:
-        u.ext.client = va_arg(ap, ClientPtr);
-
-        u.ext.ext = va_arg(ap, ExtensionEntry *);
-        u.ext.access_mode = DixGetAttrAccess;
-        u.ext.status = Success; /* default allow */
-        prv = &u.ext.status;
-        break;
     case XACE_SERVER_ACCESS:
         u.server.client = va_arg(ap, ClientPtr);
         u.server.access_mode = va_arg(ap, Mask);
diff --git a/Xext/xace.h b/Xext/xace.h
index 9227794a01d..1a88cab92da 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XACE_MAJOR_VERSION		2
 #define XACE_MINOR_VERSION		0
 
+#include "extnsionst.h"
 #include "pixmap.h"
 #include "region.h"
 #include "window.h"
@@ -88,6 +89,7 @@ int XaceHookSendAccess(ClientPtr client, DeviceIntPtr dev, WindowPtr win,
                        xEventPtr ev, int count);
 int XaceHookReceiveAccess(ClientPtr client, WindowPtr win, xEventPtr ev, int count);
 int XaceHookClientAccess(ClientPtr client, ClientPtr target, Mask access_mode);
+int XaceHookExtAccess(ClientPtr client, ExtensionEntry *ext);
 
 
 /* Register a callback for a given hook.
diff --git a/dix/extension.c b/dix/extension.c
index dbe6c0a9717..e8a373de3aa 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -215,7 +215,7 @@ CloseDownExtensions(void)
 static Bool
 ExtensionAvailable(ClientPtr client, ExtensionEntry *ext)
 {
-    if (XaceHook(XACE_EXT_ACCESS, client, ext) != Success)
+    if (XaceHookExtAccess(client, ext) != Success)
         return FALSE;
     if (!ext->base)
         return FALSE;
-- 
GitLab