From 94fc59c2920fd4e677c24995794917308122a3f5 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 16 Sep 2025 15:08:53 +0200 Subject: [PATCH] xselinux: inline SProc*()'s No need to have a hole bunch of extra functions, if we can just easily inline the few relevant lines. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/xselinux_ext.c | 228 +++++++++++--------------------------------- 1 file changed, 58 insertions(+), 170 deletions(-) diff --git a/Xext/xselinux_ext.c b/Xext/xselinux_ext.c index 3b30008e71..ba864d4613 100644 --- a/Xext/xselinux_ext.c +++ b/Xext/xselinux_ext.c @@ -108,15 +108,20 @@ SELinuxSendContextReply(ClientPtr client, security_id_t sid) static int ProcSELinuxSetCreateContext(ClientPtr client, unsigned offset) { + REQUEST(SELinuxSetCreateContextReq); + REQUEST_AT_LEAST_SIZE(SELinuxSetCreateContextReq); + + if (client->swapped) + swapl(&stuff->context_len); + + REQUEST_FIXED_SIZE(SELinuxSetCreateContextReq, stuff->context_len); + PrivateRec **privPtr = &client->devPrivates; security_id_t *pSid; char *ctx = NULL; char *ptr; int rc; - REQUEST(SELinuxSetCreateContextReq); - REQUEST_FIXED_SIZE(SELinuxSetCreateContextReq, stuff->context_len); - if (stuff->context_len > 0) { ctx = SELinuxCopyContext((char *) (stuff + 1), stuff->context_len); if (!ctx) @@ -158,6 +163,16 @@ ProcSELinuxGetCreateContext(ClientPtr client, unsigned offset) static int ProcSELinuxSetDeviceContext(ClientPtr client) { + REQUEST(SELinuxSetContextReq); + REQUEST_AT_LEAST_SIZE(SELinuxSetContextReq); + + if (client->swapped) { + swapl(&stuff->id); + swapl(&stuff->context_len); + } + + REQUEST_FIXED_SIZE(SELinuxSetContextReq, stuff->context_len); + char *ctx; security_id_t sid; DeviceIntPtr dev; @@ -165,9 +180,6 @@ ProcSELinuxSetDeviceContext(ClientPtr client) SELinuxObjectRec *obj; int rc; - REQUEST(SELinuxSetContextReq); - REQUEST_FIXED_SIZE(SELinuxSetContextReq, stuff->context_len); - if (stuff->context_len < 1) return BadLength; ctx = SELinuxCopyContext((char *) (stuff + 1), stuff->context_len); @@ -198,13 +210,17 @@ ProcSELinuxSetDeviceContext(ClientPtr client) static int ProcSELinuxGetDeviceContext(ClientPtr client) { + REQUEST(SELinuxGetContextReq); + REQUEST_SIZE_MATCH(SELinuxGetContextReq); + + if (client->swapped) { + swapl(&stuff->id); + } + DeviceIntPtr dev; SELinuxSubjectRec *subj; int rc; - REQUEST(SELinuxGetContextReq); - REQUEST_SIZE_MATCH(SELinuxGetContextReq); - rc = dixLookupDevice(&dev, stuff->id, client, DixGetAttrAccess); if (rc != Success) return rc; @@ -216,14 +232,17 @@ ProcSELinuxGetDeviceContext(ClientPtr client) static int ProcSELinuxGetDrawableContext(ClientPtr client) { + REQUEST(SELinuxGetContextReq); + REQUEST_SIZE_MATCH(SELinuxGetContextReq); + + if (client->swapped) + swapl(&stuff->id); + DrawablePtr pDraw; PrivateRec **privatePtr; SELinuxObjectRec *obj; int rc; - REQUEST(SELinuxGetContextReq); - REQUEST_SIZE_MATCH(SELinuxGetContextReq); - rc = dixLookupDrawable(&pDraw, stuff->id, client, 0, DixGetAttrAccess); if (rc != Success) return rc; @@ -240,14 +259,19 @@ ProcSELinuxGetDrawableContext(ClientPtr client) static int ProcSELinuxGetPropertyContext(ClientPtr client, void *privKey) { + REQUEST(SELinuxGetPropertyContextReq); + REQUEST_SIZE_MATCH(SELinuxGetPropertyContextReq); + + if (client->swapped) { + swapl(&stuff->window); + swapl(&stuff->property); + } + WindowPtr pWin; PropertyPtr pProp; SELinuxObjectRec *obj; int rc; - REQUEST(SELinuxGetPropertyContextReq); - REQUEST_SIZE_MATCH(SELinuxGetPropertyContextReq); - rc = dixLookupWindow(&pWin, stuff->window, client, DixGetPropAccess); if (rc != Success) return rc; @@ -264,13 +288,16 @@ ProcSELinuxGetPropertyContext(ClientPtr client, void *privKey) static int ProcSELinuxGetSelectionContext(ClientPtr client, void *privKey) { + REQUEST(SELinuxGetContextReq); + REQUEST_SIZE_MATCH(SELinuxGetContextReq); + + if (client->swapped) + swapl(&stuff->id); + Selection *pSel; SELinuxObjectRec *obj; int rc; - REQUEST(SELinuxGetContextReq); - REQUEST_SIZE_MATCH(SELinuxGetContextReq); - rc = dixLookupSelection(&pSel, stuff->id, client, DixGetAttrAccess); if (rc != Success) return rc; @@ -282,13 +309,16 @@ ProcSELinuxGetSelectionContext(ClientPtr client, void *privKey) static int ProcSELinuxGetClientContext(ClientPtr client) { + REQUEST(SELinuxGetContextReq); + REQUEST_SIZE_MATCH(SELinuxGetContextReq); + + if (client->swapped) + swapl(&stuff->id); + ClientPtr target; SELinuxSubjectRec *subj; int rc; - REQUEST(SELinuxGetContextReq); - REQUEST_SIZE_MATCH(SELinuxGetContextReq); - rc = dixLookupResourceOwner(&target, stuff->id, client, DixGetAttrAccess); if (rc != Success) return rc; @@ -365,15 +395,18 @@ SELinuxSendItemsToClient(ClientPtr client, SELinuxListItemRec * items, static int ProcSELinuxListProperties(ClientPtr client) { + REQUEST(SELinuxGetContextReq); + REQUEST_SIZE_MATCH(SELinuxGetContextReq); + + if (client->swapped) + swapl(&stuff->id); + WindowPtr pWin; PropertyPtr pProp; SELinuxListItemRec *items; int rc, count, size, i; CARD32 id; - REQUEST(SELinuxGetContextReq); - REQUEST_SIZE_MATCH(SELinuxGetContextReq); - rc = dixLookupWindow(&pWin, stuff->id, client, DixListPropAccess); if (rc != Success) return rc; @@ -492,151 +525,6 @@ ProcSELinuxDispatch(ClientPtr client) } } -static int _X_COLD -SProcSELinuxQueryVersion(ClientPtr client) -{ - return ProcSELinuxQueryVersion(client); -} - -static int _X_COLD -SProcSELinuxSetCreateContext(ClientPtr client, unsigned offset) -{ - REQUEST(SELinuxSetCreateContextReq); - - REQUEST_AT_LEAST_SIZE(SELinuxSetCreateContextReq); - swapl(&stuff->context_len); - return ProcSELinuxSetCreateContext(client, offset); -} - -static int _X_COLD -SProcSELinuxSetDeviceContext(ClientPtr client) -{ - REQUEST(SELinuxSetContextReq); - - REQUEST_AT_LEAST_SIZE(SELinuxSetContextReq); - swapl(&stuff->id); - swapl(&stuff->context_len); - return ProcSELinuxSetDeviceContext(client); -} - -static int _X_COLD -SProcSELinuxGetDeviceContext(ClientPtr client) -{ - REQUEST(SELinuxGetContextReq); - - REQUEST_SIZE_MATCH(SELinuxGetContextReq); - swapl(&stuff->id); - return ProcSELinuxGetDeviceContext(client); -} - -static int _X_COLD -SProcSELinuxGetDrawableContext(ClientPtr client) -{ - REQUEST(SELinuxGetContextReq); - - REQUEST_SIZE_MATCH(SELinuxGetContextReq); - swapl(&stuff->id); - return ProcSELinuxGetDrawableContext(client); -} - -static int _X_COLD -SProcSELinuxGetPropertyContext(ClientPtr client, void *privKey) -{ - REQUEST(SELinuxGetPropertyContextReq); - - REQUEST_SIZE_MATCH(SELinuxGetPropertyContextReq); - swapl(&stuff->window); - swapl(&stuff->property); - return ProcSELinuxGetPropertyContext(client, privKey); -} - -static int _X_COLD -SProcSELinuxGetSelectionContext(ClientPtr client, void *privKey) -{ - REQUEST(SELinuxGetContextReq); - - REQUEST_SIZE_MATCH(SELinuxGetContextReq); - swapl(&stuff->id); - return ProcSELinuxGetSelectionContext(client, privKey); -} - -static int _X_COLD -SProcSELinuxListProperties(ClientPtr client) -{ - REQUEST(SELinuxGetContextReq); - - REQUEST_SIZE_MATCH(SELinuxGetContextReq); - swapl(&stuff->id); - return ProcSELinuxListProperties(client); -} - -static int _X_COLD -SProcSELinuxGetClientContext(ClientPtr client) -{ - REQUEST(SELinuxGetContextReq); - - REQUEST_SIZE_MATCH(SELinuxGetContextReq); - swapl(&stuff->id); - return ProcSELinuxGetClientContext(client); -} - -static int _X_COLD -SProcSELinuxDispatch(ClientPtr client) -{ - REQUEST(xReq); - - switch (stuff->data) { - case X_SELinuxQueryVersion: - return SProcSELinuxQueryVersion(client); - case X_SELinuxSetDeviceCreateContext: - return SProcSELinuxSetCreateContext(client, CTX_DEV); - case X_SELinuxGetDeviceCreateContext: - return ProcSELinuxGetCreateContext(client, CTX_DEV); - case X_SELinuxSetDeviceContext: - return SProcSELinuxSetDeviceContext(client); - case X_SELinuxGetDeviceContext: - return SProcSELinuxGetDeviceContext(client); - case X_SELinuxSetDrawableCreateContext: - return SProcSELinuxSetCreateContext(client, CTX_WIN); - case X_SELinuxGetDrawableCreateContext: - return ProcSELinuxGetCreateContext(client, CTX_WIN); - case X_SELinuxGetDrawableContext: - return SProcSELinuxGetDrawableContext(client); - case X_SELinuxSetPropertyCreateContext: - return SProcSELinuxSetCreateContext(client, CTX_PRP); - case X_SELinuxGetPropertyCreateContext: - return ProcSELinuxGetCreateContext(client, CTX_PRP); - case X_SELinuxSetPropertyUseContext: - return SProcSELinuxSetCreateContext(client, USE_PRP); - case X_SELinuxGetPropertyUseContext: - return ProcSELinuxGetCreateContext(client, USE_PRP); - case X_SELinuxGetPropertyContext: - return SProcSELinuxGetPropertyContext(client, objectKey); - case X_SELinuxGetPropertyDataContext: - return SProcSELinuxGetPropertyContext(client, dataKey); - case X_SELinuxListProperties: - return SProcSELinuxListProperties(client); - case X_SELinuxSetSelectionCreateContext: - return SProcSELinuxSetCreateContext(client, CTX_SEL); - case X_SELinuxGetSelectionCreateContext: - return ProcSELinuxGetCreateContext(client, CTX_SEL); - case X_SELinuxSetSelectionUseContext: - return SProcSELinuxSetCreateContext(client, USE_SEL); - case X_SELinuxGetSelectionUseContext: - return ProcSELinuxGetCreateContext(client, USE_SEL); - case X_SELinuxGetSelectionContext: - return SProcSELinuxGetSelectionContext(client, objectKey); - case X_SELinuxGetSelectionDataContext: - return SProcSELinuxGetSelectionContext(client, dataKey); - case X_SELinuxListSelections: - return ProcSELinuxListSelections(client); - case X_SELinuxGetClientContext: - return SProcSELinuxGetClientContext(client); - default: - return BadRequest; - } -} - /* * Extension Setup / Teardown */ @@ -672,5 +560,5 @@ SELinuxExtensionInit(void) /* Add extension to server */ AddExtension(SELINUX_EXTENSION_NAME, SELinuxNumberEvents, SELinuxNumberErrors, ProcSELinuxDispatch, - SProcSELinuxDispatch, SELinuxResetProc, StandardMinorOpcode); + ProcSELinuxDispatch, SELinuxResetProc, StandardMinorOpcode); }