From 78c962da76efe644b8d485265f1ecdda84b45d27 Mon Sep 17 00:00:00 2001 From: Eamon Walsh Date: Mon, 19 Mar 2007 17:04:51 -0400 Subject: [PATCH] xselinux: use the new ResourceStateCallback instead of the XACE_WINDOW_INIT hook. --- Xext/xselinux.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Xext/xselinux.c b/Xext/xselinux.c index 74d4c6067..4056d9e92 100644 --- a/Xext/xselinux.c +++ b/Xext/xselinux.c @@ -1217,26 +1217,34 @@ XSELinuxClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata) /* Labeling callbacks */ static void -XSELinuxWindowInit(CallbackListPtr *pcbl, pointer unused, pointer calldata) +XSELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata) { - XaceWindowRec *rec = (XaceWindowRec*)calldata; + ResourceStateInfoRec *rec = (ResourceStateInfoRec *)calldata; + WindowPtr pWin; + ClientPtr client; security_context_t ctx; int rc; - if (HAVESTATE(rec->client)) { - rc = avc_sid_to_context(SID(rec->client), &ctx); + if (rec->type != RT_WINDOW) + return; + + pWin = (WindowPtr)rec->value; + client = wClient(pWin); + + if (HAVESTATE(client)) { + rc = avc_sid_to_context(SID(client), &ctx); if (rc < 0) FatalError("XSELinux: Failed to get security context!\n"); - rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8, + rc = ChangeWindowProperty(pWin, atom_client_ctx, XA_STRING, 8, PropModeReplace, strlen(ctx), ctx, FALSE); freecon(ctx); } else - rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8, + rc = ChangeWindowProperty(pWin, atom_client_ctx, XA_STRING, 8, PropModeReplace, 10, "UNLABELED!", FALSE); if (rc != Success) FatalError("XSELinux: Failed to set context property on window!\n"); -} /* XSELinuxWindowInit */ +} /* XSELinuxResourceState */ static char *XSELinuxKeywords[] = { #define XSELinuxKeywordComment 0 @@ -1836,6 +1844,8 @@ XSELinuxExtensionInit(INITARGS) if (!AddCallback(&ClientStateCallback, XSELinuxClientState, NULL)) return; + if (!AddCallback(&ResourceStateCallback, XSELinuxResourceState, NULL)) + return; /* Create atoms for doing window labeling */ atom_ctx = MakeAtom("_SELINUX_CONTEXT", 16, 1); @@ -1870,7 +1880,6 @@ XSELinuxExtensionInit(INITARGS) XaceRegisterCallback(XACE_BACKGRND_ACCESS, XSELinuxBackgrnd, NULL); XaceRegisterCallback(XACE_DRAWABLE_ACCESS, XSELinuxDrawable, NULL); XaceRegisterCallback(XACE_PROPERTY_ACCESS, XSELinuxProperty, NULL); - XaceRegisterCallback(XACE_WINDOW_INIT, XSELinuxWindowInit, NULL); /* XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, XSELinuxDeclare, NULL); XaceRegisterCallback(XACE_DEVICE_ACCESS, XSELinuxDevice, NULL); */