diff options
author | Peter Hutterer <peter.hutterer@redhat.com> | 2008-10-31 16:40:41 +1030 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@redhat.com> | 2008-11-04 16:04:15 +1030 |
commit | d97239956667f8181f30271759573b75bf455fbb (patch) | |
tree | 9d39488c657248ef68eee1afd8b925f8f3c64fee /dix | |
parent | cbc6f983959595aa21c9dd72fac6a7070a650ef7 (diff) |
Purge device-based WindowAccess code.
Really, this was a bad idea. It's not security, the UI features that would
have been cool (e.g. clicking through windows) aren't implemented anyway, and
there's nothing you can't achieve just by using plain XI anyway.
Requires inputproto 1.9.99.6.
Diffstat (limited to 'dix')
-rw-r--r-- | dix/Makefile.am | 1 | ||||
-rw-r--r-- | dix/access.c | 315 | ||||
-rw-r--r-- | dix/dispatch.c | 1 | ||||
-rw-r--r-- | dix/events.c | 132 |
4 files changed, 61 insertions, 388 deletions
diff --git a/dix/Makefile.am b/dix/Makefile.am index bdc2d4570..a4b48c82e 100644 --- a/dix/Makefile.am +++ b/dix/Makefile.am @@ -5,7 +5,6 @@ AM_CFLAGS = $(DIX_CFLAGS) \ -DVENDOR_RELEASE="@VENDOR_RELEASE@" libdix_la_SOURCES = \ - access.c \ atom.c \ colormap.c \ cursor.c \ diff --git a/dix/access.c b/dix/access.c deleted file mode 100644 index f71b3cc8b..000000000 --- a/dix/access.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Copyright 2007-2008 Peter Hutterer - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Peter Hutterer, University of South Australia, NICTA - */ - -/* This file controls the access control lists for each window. - * Each device can be explicitely allowed or denied access to a given window. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include <X11/Xlib.h> -#include <X11/extensions/XI.h> -#include "exglobals.h" - -#include "input.h" -#include "inputstr.h" -#include "windowstr.h" - - -/* Only one single client can be responsible for window access control. */ -static ClientPtr ACClient = NULL; - - -/* Forward declarations */ -static void acReplaceList(DeviceIntPtr** list, - int* count, - DeviceIntPtr* devices, - int ndevices); - -/* Register global window access control client - * Return True on success or False otherwise. - */ - -Bool -ACRegisterClient(ClientPtr client) -{ - if (ACClient && ACClient != client) - return False; - - ACClient = client; - return True; -} - - -/* Unregister global client. If client is not the registered client, nothing - * happens and False is returned. If no client is registered, return True. - * Returns True if client was registred and is now unregistered. - */ - -Bool -ACUnregisterClient(ClientPtr client) -{ - if (ACClient && ACClient != client) - return False; - - ACClient = NULL; - return True; -} - -/* Clears all access control for the window and remove the default rule, - * depending on what is set. */ -int ACClearWindowAccess(ClientPtr client, - WindowPtr win, - int what) -{ - if (client != ACClient && client != wClient(win)) - return BadAccess; - - if (!win->optional) - { - /* we shouldn't get here if programmers know what they're doing. - * A client should not request to clear a window's access controls - * if they've never been set before anyway. If they do, do nothing and - * let the client figure out what to do next. - */ - return Success; - } - - if (what & WindowAccessClearPerm) - { - xfree(win->optional->access.perm); - win->optional->access.perm = NULL; - win->optional->access.nperm = 0; - } - - if (what & WindowAccessClearDeny) - { - xfree(win->optional->access.deny); - win->optional->access.deny = NULL; - win->optional->access.ndeny = 0; - } - - if (what & WindowAccessClearRule) - win->optional->access.defaultRule = WindowAccessNoRule; - - return Success; -} - -/* - * Changes window access control. - * - * Returns Success or BadAccess if the client is not allowed to change - * anything. - */ - -int -ACChangeWindowAccess(ClientPtr client, - WindowPtr win, - int defaultRule, - DeviceIntPtr* perm_devices, - int nperm, - DeviceIntPtr* deny_devices, - int ndeny) -{ - if (client != ACClient && client != wClient(win)) - return BadAccess; - - if (!win->optional && !MakeWindowOptional(win)) - { - ErrorF("[dix] ACChangeWindowAcccess: Failed to make window optional.\n"); - return BadImplementation; - } - - if (defaultRule != WindowAccessKeepRule) - win->optional->access.defaultRule = defaultRule; - - if (nperm) - { - acReplaceList(&win->optional->access.perm, - &win->optional->access.nperm, - perm_devices, nperm); - } - - if (ndeny) - { - acReplaceList(&win->optional->access.deny, - &win->optional->access.ndeny, - deny_devices, ndeny); - } - - return Success; -} - -static void -acReplaceList(DeviceIntPtr** list, - int* count, - DeviceIntPtr* devices, - int ndevices) -{ - xfree(*list); - *list = NULL; - *count = 0; - - if (ndevices) - { - *list = - xalloc(ndevices * sizeof(DeviceIntPtr*)); - if (!*list) - { - ErrorF("[dix] ACChangeWindowAccess: out of memory\n"); - return; - } - memcpy(*list, - devices, - ndevices * sizeof(DeviceIntPtr)); - *count = ndevices; - } - return; -} - -/* - * Query the given window for the devices allowed to access a window. - * The caller is responsible for freeing perm and deny. - */ -void -ACQueryWindowAccess(WindowPtr win, - int* defaultRule, - DeviceIntPtr** perm, - int* nperm, - DeviceIntPtr** deny, - int* ndeny) -{ - *defaultRule = WindowAccessNoRule; - *perm = NULL; - *nperm = 0; - *deny = NULL; - *ndeny = 0; - - if (!win->optional) - return; - - *defaultRule = win->optional->access.defaultRule; - - if (win->optional->access.nperm) - { - *nperm = win->optional->access.nperm; - *perm = (DeviceIntPtr*)xalloc(*nperm * sizeof(DeviceIntPtr)); - if (!*perm) - { - ErrorF("[dix] ACQuerywinAccess: xalloc failure\n"); - return; - } - memcpy(*perm, - win->optional->access.perm, - *nperm * sizeof(DeviceIntPtr)); - } - - if (win->optional->access.ndeny) - { - *ndeny = win->optional->access.ndeny; - *deny = (DeviceIntPtr*)xalloc(*ndeny * sizeof(DeviceIntPtr)); - if (!*deny) - { - ErrorF("[dix] ACQuerywinAccess: xalloc failure\n"); - return; - } - memcpy(*deny, - win->optional->access.deny, - *ndeny * sizeof(DeviceIntPtr)); - } -} - -/* - * Check if the given device is allowed to send events to the window. Returns - * true if device is allowed or false otherwise. - * - * Checks are done in the following order until a result is found: - * If the device is explicitely permitted, allow. - * If the window has a default of DenyAll, do not allow. - * If the device is explicitely denied, do not allow. - * If the window has a default of AllowAll, allow. - * Check parent window. Rinse, wash, repeat. - * If no rule could be found, allow. - */ -Bool -ACDeviceAllowed(WindowPtr win, DeviceIntPtr dev, xEvent* xE) -{ - int i; - - if (!win) /* happens for parent of RootWindow */ - return True; - - /* there's a number of events we don't care about */ - switch (xE->u.u.type) - { - case ButtonPress: - case ButtonRelease: - case MotionNotify: - case EnterNotify: - case LeaveNotify: - case KeyPress: - case KeyRelease: - break; - default: - if (xE->u.u.type == DeviceMotionNotify || - xE->u.u.type == DeviceButtonPress || - xE->u.u.type == DeviceButtonRelease || - xE->u.u.type == DeviceKeyPress || - xE->u.u.type == DeviceKeyRelease || - xE->u.u.type == DeviceEnterNotify || - xE->u.u.type == DeviceLeaveNotify) - { - break; - } - return True; - } - - - if (!win->optional) /* no list, check parent */ - return ACDeviceAllowed(win->parent, dev, xE); - - for (i = 0; i < win->optional->access.nperm; i++) - { - if (win->optional->access.perm[i]->id == dev->id) - return True; - } - - if (win->optional->access.defaultRule == WindowAccessDenyAll) - return False; - - for (i = 0; i < win->optional->access.ndeny; i++) - { - if (win->optional->access.deny[i]->id == dev->id) - return False; - } - - if (win->optional->access.defaultRule == WindowAccessAllowAll) - return True; - - return ACDeviceAllowed(win->parent, dev, xE); -} - diff --git a/dix/dispatch.c b/dix/dispatch.c index c4a6a9cf8..66f8f79ff 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -3375,7 +3375,6 @@ CloseDownClient(ClientPtr client) DeleteClientFromAnySelections(client); ReleaseActiveGrabs(client); DeleteClientFontStuff(client); - ACUnregisterClient(client); if (!really_close_down) { /* This frees resources that should never be retained diff --git a/dix/events.c b/dix/events.c index 35c1bface..dad786dd6 100644 --- a/dix/events.c +++ b/dix/events.c @@ -2030,13 +2030,6 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent this mask is the mask of the grab. */ int type = pEvents->u.u.type; - /* if a is denied, we return 0. This could cause the caller to - * traverse the parent. May be bad! (whot) */ - if (!ACDeviceAllowed(pWin, pDev, pEvents)) - { - return 0; - } - /* CantBeFiltered means only window owner gets the event */ if ((filter == CantBeFiltered) || (!(type & EXTENSION_EVENT_BASE) && type != GenericEvent)) @@ -3633,83 +3626,80 @@ DeliverGrabbedEvent(xEvent *xE, DeviceIntPtr thisDev, } if (!deliveries) { - if (ACDeviceAllowed(grab->window, thisDev, xE)) + if (xE->u.u.type == GenericEvent) { - if (xE->u.u.type == GenericEvent) - { - /* find evmask for event's extension */ - xGenericEvent* ge = ((xGenericEvent*)xE); - GenericMaskPtr gemask = grab->genericMasks; - - if (!gemask || !gemask->eventMask[GEEXTIDX(ge)]) - return; - - if (GEEventFill(xE)) - GEEventFill(xE)(ge, thisDev, grab->window, grab); - deliveries = TryClientEvents(rClient(grab), thisDev, xE, - count, gemask->eventMask[GEEXTIDX(ge)], - generic_filters[GEEXTIDX(ge)][ge->evtype], - grab); - } else - { - Mask mask = grab->eventMask; + /* find evmask for event's extension */ + xGenericEvent* ge = ((xGenericEvent*)xE); + GenericMaskPtr gemask = grab->genericMasks; - sendCore = (thisDev->isMaster && thisDev->coreEvents); - /* try core event */ - if (sendCore && grab->coreGrab) - { - core = *xE; - core.u.u.type = XItoCoreType(xE->u.u.type); - if(core.u.u.type) { - FixUpEventFromWindow(thisDev, &core, grab->window, - None, TRUE); - if (XaceHook(XACE_SEND_ACCESS, 0, thisDev, - grab->window, &core, 1) || - XaceHook(XACE_RECEIVE_ACCESS, rClient(grab), - grab->window, &core, 1)) - deliveries = 1; /* don't send, but pretend we did */ - else if (!IsInterferingGrab(rClient(grab), thisDev, - &core)) - { - deliveries = TryClientEvents(rClient(grab), thisDev, - &core, 1, mask, - filters[thisDev->id][core.u.u.type], - grab); - } - } - } + if (!gemask || !gemask->eventMask[GEEXTIDX(ge)]) + return; - if (!deliveries) - { - /* try XI event */ - if (grabinfo->fromPassiveGrab && - grabinfo->implicitGrab && - (xE->u.u.type & EXTENSION_EVENT_BASE)) - mask = grab->deviceMask; - FixUpEventFromWindow(thisDev, xE, grab->window, - None, TRUE); + if (GEEventFill(xE)) + GEEventFill(xE)(ge, thisDev, grab->window, grab); + deliveries = TryClientEvents(rClient(grab), thisDev, xE, + count, gemask->eventMask[GEEXTIDX(ge)], + generic_filters[GEEXTIDX(ge)][ge->evtype], + grab); + } else + { + Mask mask = grab->eventMask; + sendCore = (thisDev->isMaster && thisDev->coreEvents); + /* try core event */ + if (sendCore && grab->coreGrab) + { + core = *xE; + core.u.u.type = XItoCoreType(xE->u.u.type); + if(core.u.u.type) { + FixUpEventFromWindow(thisDev, &core, grab->window, + None, TRUE); if (XaceHook(XACE_SEND_ACCESS, 0, thisDev, - grab->window, xE, count) || + grab->window, &core, 1) || XaceHook(XACE_RECEIVE_ACCESS, rClient(grab), - grab->window, xE, count)) + grab->window, &core, 1)) deliveries = 1; /* don't send, but pretend we did */ - else + else if (!IsInterferingGrab(rClient(grab), thisDev, + &core)) { - deliveries = - TryClientEvents(rClient(grab), thisDev, - xE, count, - mask, - filters[thisDev->id][xE->u.u.type], - grab); + deliveries = TryClientEvents(rClient(grab), thisDev, + &core, 1, mask, + filters[thisDev->id][core.u.u.type], + grab); } + } + } + if (!deliveries) + { + /* try XI event */ + if (grabinfo->fromPassiveGrab && + grabinfo->implicitGrab && + (xE->u.u.type & EXTENSION_EVENT_BASE)) + mask = grab->deviceMask; + FixUpEventFromWindow(thisDev, xE, grab->window, + None, TRUE); + + if (XaceHook(XACE_SEND_ACCESS, 0, thisDev, + grab->window, xE, count) || + XaceHook(XACE_RECEIVE_ACCESS, rClient(grab), + grab->window, xE, count)) + deliveries = 1; /* don't send, but pretend we did */ + else + { + deliveries = + TryClientEvents(rClient(grab), thisDev, + xE, count, + mask, + filters[thisDev->id][xE->u.u.type], + grab); } + } - if (deliveries && (xE->u.u.type == MotionNotify - || xE->u.u.type == DeviceMotionNotify)) - thisDev->valuator->motionHintWindow = grab->window; } + if (deliveries && (xE->u.u.type == MotionNotify + || xE->u.u.type == DeviceMotionNotify)) + thisDev->valuator->motionHintWindow = grab->window; } if (deliveries && !deactivateGrab && (xE->u.u.type != MotionNotify && xE->u.u.type != DeviceMotionNotify)) |