xserver: Branch 'XACE-SELINUX'

Eamon Walsh ewalsh at kemper.freedesktop.org
Fri Sep 28 10:15:58 PDT 2007


 Xext/xtest.c                   |    8 ++++----
 Xi/allowev.c                   |    8 ++++----
 Xi/chgdctl.c                   |    7 ++-----
 Xi/chgfctl.c                   |    8 ++++----
 Xi/chgkmap.c                   |    7 +++----
 Xi/chgprop.c                   |    3 +--
 Xi/chgptr.c                    |    2 --
 Xi/closedev.c                  |    9 ++++-----
 Xi/devbell.c                   |    9 ++++-----
 Xi/exevents.c                  |   37 +++++++++++++++++++++++++++----------
 Xi/extinit.c                   |   23 -----------------------
 Xi/getbmap.c                   |    8 ++++----
 Xi/getdctl.c                   |    9 ++++-----
 Xi/getfctl.c                   |    9 ++++-----
 Xi/getfocus.c                  |    8 +++++---
 Xi/getkmap.c                   |    8 ++++----
 Xi/getmmap.c                   |    8 ++++----
 Xi/getprop.c                   |    3 +--
 Xi/getselev.c                  |    3 +--
 Xi/getvers.c                   |    1 -
 Xi/grabdev.c                   |   15 ++++++++-------
 Xi/grabdevb.c                  |   14 +++++++-------
 Xi/grabdevk.c                  |   14 +++++++-------
 Xi/gtmotion.c                  |    9 ++++-----
 Xi/listdev.c                   |   10 ++++++++--
 Xi/opendev.c                   |    7 ++++---
 Xi/queryst.c                   |    9 ++++-----
 Xi/selectev.c                  |    3 +--
 Xi/sendexev.c                  |    8 ++++----
 Xi/setbmap.c                   |    7 +++----
 Xi/setdval.c                   |    8 ++++----
 Xi/setfocus.c                  |    7 ++++---
 Xi/setmmap.c                   |    7 +++----
 Xi/setmode.c                   |    8 ++++----
 Xi/stubs.c                     |    2 ++
 Xi/ungrdev.c                   |    8 ++++----
 Xi/ungrdevb.c                  |   14 +++++++-------
 Xi/ungrdevk.c                  |   14 +++++++-------
 config/dbus.c                  |    2 +-
 dix/devices.c                  |   18 +++++++++++++-----
 hw/dmx/input/dmxeq.c           |    4 ++--
 hw/xfree86/common/xf86Xinput.c |    1 -
 include/extinit.h              |    5 -----
 include/input.h                |   10 +++++-----
 xkb/xkbUtils.c                 |    2 +-
 45 files changed, 187 insertions(+), 197 deletions(-)

New commits:
diff-tree 5c03d131815cfe2f78792277ab8352e69e830196 (from 27612748e0ec20f3a23839f0a12e39f598dd722c)
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 28 08:02:00 2007 -0400

    xace: add new hooks + access controls: XInput extension.
    
    Introduces new dix API to lookup a device, dixLookupDevice(), which
    replaces LookupDeviceIntRec and LookupDevice.

diff --git a/Xext/xtest.c b/Xext/xtest.c
index 8d879c7..42cf817 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -49,7 +49,6 @@ from The Open Group.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #define EXTENSION_EVENT_BASE	64
-#include "extinit.h"		/* LookupDeviceIntRec */
 #endif /* XINPUT */
 
 #include "modinit.h"
@@ -286,11 +285,12 @@ ProcXTestFakeInput(client)
 #ifdef XINPUT
     if (extension)
     {
-	dev = LookupDeviceIntRec(stuff->deviceid & 0177);
-	if (!dev)
+	rc = dixLookupDevice(&dev, stuff->deviceid & 0177, client,
+			     DixWriteAccess);
+	if (rc != Success)
 	{
 	    client->errorValue = stuff->deviceid & 0177;
-	    return BadValue;
+	    return rc;
 	}
 	if (nev > 1)
 	{
diff --git a/Xi/allowev.c b/Xi/allowev.c
index cf075e1..0043cb1 100644
--- a/Xi/allowev.c
+++ b/Xi/allowev.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "allowev.h"
@@ -95,13 +94,14 @@ ProcXAllowDeviceEvents(ClientPtr client)
 {
     TimeStamp time;
     DeviceIntPtr thisdev;
+    int rc;
 
     REQUEST(xAllowDeviceEventsReq);
     REQUEST_SIZE_MATCH(xAllowDeviceEventsReq);
 
-    thisdev = LookupDeviceIntRec(stuff->deviceid);
-    if (thisdev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&thisdev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
     time = ClientTimeToServerTime(stuff->time);
 
     switch (stuff->mode) {
diff --git a/Xi/chgdctl.c b/Xi/chgdctl.c
index 055f459..e7d04a7 100644
--- a/Xi/chgdctl.c
+++ b/Xi/chgdctl.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>	/* control constants */
 #include "XIstubs.h"
 
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "exevents.h"
 
@@ -112,11 +111,9 @@ ProcXChangeDeviceControl(ClientPtr clien
     REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq);
 
     len = stuff->length - (sizeof(xChangeDeviceControlReq) >> 2);
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL) {
-        ret = BadDevice;
+    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (ret != Success)
         goto out;
-    }
 
     rep.repType = X_Reply;
     rep.RepType = X_ChangeDeviceControl;
diff --git a/Xi/chgfctl.c b/Xi/chgfctl.c
index 46bb8e7..8fc24d5 100644
--- a/Xi/chgfctl.c
+++ b/Xi/chgfctl.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>	/* control constants */
 
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "chgfctl.h"
@@ -444,14 +443,15 @@ ProcXChangeFeedbackControl(ClientPtr cli
     StringFeedbackPtr s;
     BellFeedbackPtr b;
     LedFeedbackPtr l;
+    int rc;
 
     REQUEST(xChangeFeedbackControlReq);
     REQUEST_AT_LEAST_SIZE(xChangeFeedbackControlReq);
 
     len = stuff->length - (sizeof(xChangeFeedbackControlReq) >> 2);
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     switch (stuff->feedbackid) {
     case KbdFeedbackClass:
diff --git a/Xi/chgkmap.c b/Xi/chgkmap.c
index bfdc1ce..3361e98 100644
--- a/Xi/chgkmap.c
+++ b/Xi/chgkmap.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exevents.h"
 #include "exglobals.h"
 
@@ -107,9 +106,9 @@ ProcXChangeDeviceKeyMapping(ClientPtr cl
     REQUEST(xChangeDeviceKeyMappingReq);
     REQUEST_AT_LEAST_SIZE(xChangeDeviceKeyMappingReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (ret != Success)
+	return ret;
     len = stuff->length - (sizeof(xChangeDeviceKeyMappingReq) >> 2);
 
     ret = ChangeKeyMapping(client, dev, len, DeviceMappingNotify,
diff --git a/Xi/chgprop.c b/Xi/chgprop.c
index 13463dd..58db886 100644
--- a/Xi/chgprop.c
+++ b/Xi/chgprop.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "windowstr.h"
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 
 #include "exevents.h"
 #include "exglobals.h"
@@ -115,7 +114,7 @@ ProcXChangeDeviceDontPropagateList(Clien
 	stuff->count)
 	return BadLength;
 
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/Xi/chgptr.c b/Xi/chgptr.c
index 2ce81d1..2895091 100644
--- a/Xi/chgptr.c
+++ b/Xi/chgptr.c
@@ -63,8 +63,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structure  */
 #include "scrnintstr.h"	/* screen structure  */
 
-#include "extinit.h"	/* LookupDeviceIntRec */
-
 #include "dixevents.h"
 #include "exevents.h"
 #include "exglobals.h"
diff --git a/Xi/closedev.c b/Xi/closedev.c
index 1ec3fa1..b2b5f69 100644
--- a/Xi/closedev.c
+++ b/Xi/closedev.c
@@ -62,7 +62,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "closedev.h"
@@ -140,16 +139,16 @@ DeleteEventsFromChildren(DeviceIntPtr de
 int
 ProcXCloseDevice(ClientPtr client)
 {
-    int i;
+    int rc, i;
     WindowPtr pWin, p1;
     DeviceIntPtr d;
 
     REQUEST(xCloseDeviceReq);
     REQUEST_SIZE_MATCH(xCloseDeviceReq);
 
-    d = LookupDeviceIntRec(stuff->deviceid);
-    if (d == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&d, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     if (d->grab && SameClient(d->grab, client))
 	(*d->DeactivateGrab) (d);	/* release active grab */
diff --git a/Xi/devbell.c b/Xi/devbell.c
index 83e844d..264f648 100644
--- a/Xi/devbell.c
+++ b/Xi/devbell.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "devbell.h"
@@ -93,7 +92,7 @@ ProcXDeviceBell(ClientPtr client)
     DeviceIntPtr dev;
     KbdFeedbackPtr k;
     BellFeedbackPtr b;
-    int base;
+    int rc, base;
     int newpercent;
     CARD8 class;
     pointer ctrl;
@@ -102,10 +101,10 @@ ProcXDeviceBell(ClientPtr client)
     REQUEST(xDeviceBellReq);
     REQUEST_SIZE_MATCH(xDeviceBellReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL) {
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixBellAccess);
+    if (rc != Success) {
 	client->errorValue = stuff->deviceid;
-	return BadDevice;
+	return rc;
     }
 
     if (stuff->percent < -100 || stuff->percent > 100) {
diff --git a/Xi/exevents.c b/Xi/exevents.c
index 377311e..9a17950 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -67,11 +67,11 @@ SOFTWARE.
 #include "region.h"
 #include "exevents.h"
 #include "extnsionst.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "dixevents.h"	/* DeliverFocusedEvent */
 #include "dixgrabs.h"	/* CreateGrab() */
 #include "scrnintstr.h"
+#include "xace.h"
 
 #ifdef XKB
 #include "xkbsrv.h"
@@ -511,6 +511,7 @@ GrabButton(ClientPtr client, DeviceIntPt
     WindowPtr pWin, confineTo;
     CursorPtr cursor;
     GrabPtr grab;
+    Mask access_mode = DixGrabAccess;
     int rc;
 
     if ((this_device_mode != GrabModeSync) &&
@@ -531,25 +532,33 @@ GrabButton(ClientPtr client, DeviceIntPt
 	client->errorValue = ownerEvents;
 	return BadValue;
     }
-    rc = dixLookupWindow(&pWin, grabWindow, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
     if (rconfineTo == None)
 	confineTo = NullWindow;
     else {
-	rc = dixLookupWindow(&confineTo, rconfineTo, client, DixUnknownAccess);
+	rc = dixLookupWindow(&confineTo, rconfineTo, client, DixSetAttrAccess);
 	if (rc != Success)
 	    return rc;
     }
     if (rcursor == None)
 	cursor = NullCursor;
     else {
-	cursor = (CursorPtr) LookupIDByType(rcursor, RT_CURSOR);
-	if (!cursor) {
+	rc = dixLookupResource((pointer *)&cursor, rcursor, RT_CURSOR,
+			       client, DixUseAccess);
+	if (rc != Success)
+	{
 	    client->errorValue = rcursor;
-	    return BadCursor;
+	    return (rc == BadValue) ? BadCursor : rc;
 	}
+	access_mode |= DixForceAccess;
     }
+    if (this_device_mode == GrabModeSync || other_devices_mode == GrabModeSync)
+	access_mode |= DixFreezeAccess;
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
+    if (rc != Success)
+	return rc;
 
     grab = CreateGrab(client->index, dev, pWin, eventMask,
 		      (Bool) ownerEvents, (Bool) this_device_mode,
@@ -569,6 +578,7 @@ GrabKey(ClientPtr client, DeviceIntPtr d
     WindowPtr pWin;
     GrabPtr grab;
     KeyClassPtr k = dev->key;
+    Mask access_mode = DixGrabAccess;
     int rc;
 
     if (k == NULL)
@@ -596,7 +606,12 @@ GrabKey(ClientPtr client, DeviceIntPtr d
 	client->errorValue = ownerEvents;
 	return BadValue;
     }
-    rc = dixLookupWindow(&pWin, grabWindow, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, grabWindow, client, DixSetAttrAccess);
+    if (rc != Success)
+	return rc;
+    if (this_device_mode == GrabModeSync || other_devices_mode == GrabModeSync)
+	access_mode |= DixFreezeAccess;
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
     if (rc != Success)
 	return rc;
 
@@ -837,7 +852,7 @@ SendEvent(ClientPtr client, DeviceIntPtr
 	    if (!mask)
 		break;
 	}
-    } else
+    } else if (!XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, ev, count))
 	(void)(DeliverEventsToWindow(pWin, ev, count, mask, NullGrab, d->id));
     return Success;
 }
@@ -1101,7 +1116,8 @@ MaybeSendDeviceMotionNotifyHint(deviceKe
 {
     DeviceIntPtr dev;
 
-    dev = LookupDeviceIntRec(pEvents->deviceid & DEVICE_BITS);
+    dixLookupDevice(&dev, pEvents->deviceid & DEVICE_BITS, serverClient,
+		    DixReadAccess);
     if (!dev)
         return 0;
 
@@ -1125,7 +1141,8 @@ CheckDeviceGrabAndHintWindow(WindowPtr p
 {
     DeviceIntPtr dev;
 
-    dev = LookupDeviceIntRec(xE->deviceid & DEVICE_BITS);
+    dixLookupDevice(&dev, xE->deviceid & DEVICE_BITS, serverClient,
+		    DixReadAccess);
     if (!dev)
         return;
 
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 73bae5e..1a435ed 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -856,29 +856,6 @@ MakeDeviceTypeAtoms(void)
 	    MakeAtom(dev_type[i].name, strlen(dev_type[i].name), 1);
 }
 
-/**************************************************************************
- * Return a DeviceIntPtr corresponding to a specified device id.
- *
- */
-
-DeviceIntPtr
-LookupDeviceIntRec(CARD8 id)
-{
-    DeviceIntPtr dev;
-
-    for (dev = inputInfo.devices; dev; dev = dev->next) {
-	if (dev->id == id)
-	    return dev;
-    }
-
-    for (dev = inputInfo.off_devices; dev; dev = dev->next) {
-	if (dev->id == id)
-	    return dev;
-    }
-
-    return NULL;
-}
-
 /*****************************************************************************
  *
  *	SEventIDispatch
diff --git a/Xi/getbmap.c b/Xi/getbmap.c
index ebb0613..9f93b06 100644
--- a/Xi/getbmap.c
+++ b/Xi/getbmap.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getbmap.h"
@@ -92,6 +91,7 @@ ProcXGetDeviceButtonMapping(ClientPtr cl
     DeviceIntPtr dev;
     xGetDeviceButtonMappingReply rep;
     ButtonClassPtr b;
+    int rc;
 
     REQUEST(xGetDeviceButtonMappingReq);
     REQUEST_SIZE_MATCH(xGetDeviceButtonMappingReq);
@@ -102,9 +102,9 @@ ProcXGetDeviceButtonMapping(ClientPtr cl
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     b = dev->button;
     if (b == NULL)
diff --git a/Xi/getdctl.c b/Xi/getdctl.c
index 8a84e91..3f2bb29 100644
--- a/Xi/getdctl.c
+++ b/Xi/getdctl.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getdctl.h"
@@ -238,7 +237,7 @@ SRepXGetDeviceControl(ClientPtr client, 
 int
 ProcXGetDeviceControl(ClientPtr client)
 {
-    int total_length = 0;
+    int rc, total_length = 0;
     char *buf, *savbuf;
     DeviceIntPtr dev;
     xGetDeviceControlReply rep;
@@ -246,9 +245,9 @@ ProcXGetDeviceControl(ClientPtr client)
     REQUEST(xGetDeviceControlReq);
     REQUEST_SIZE_MATCH(xGetDeviceControlReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     rep.repType = X_Reply;
     rep.RepType = X_GetDeviceControl;
diff --git a/Xi/getfctl.c b/Xi/getfctl.c
index 7dff32f..1b1e594 100644
--- a/Xi/getfctl.c
+++ b/Xi/getfctl.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getfctl.h"
@@ -290,7 +289,7 @@ SRepXGetFeedbackControl(ClientPtr client
 int
 ProcXGetFeedbackControl(ClientPtr client)
 {
-    int total_length = 0;
+    int rc, total_length = 0;
     char *buf, *savbuf;
     DeviceIntPtr dev;
     KbdFeedbackPtr k;
@@ -304,9 +303,9 @@ ProcXGetFeedbackControl(ClientPtr client
     REQUEST(xGetFeedbackControlReq);
     REQUEST_SIZE_MATCH(xGetFeedbackControlReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     rep.repType = X_Reply;
     rep.RepType = X_GetFeedbackControl;
diff --git a/Xi/getfocus.c b/Xi/getfocus.c
index 073913b..dfef22f 100644
--- a/Xi/getfocus.c
+++ b/Xi/getfocus.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getfocus.h"
@@ -93,12 +92,15 @@ ProcXGetDeviceFocus(ClientPtr client)
     DeviceIntPtr dev;
     FocusClassPtr focus;
     xGetDeviceFocusReply rep;
+    int rc;
 
     REQUEST(xGetDeviceFocusReq);
     REQUEST_SIZE_MATCH(xGetDeviceFocusReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL || !dev->focus)
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetFocusAccess);
+    if (rc != Success)
+	return rc;
+    if (!dev->focus)
 	return BadDevice;
 
     rep.repType = X_Reply;
diff --git a/Xi/getkmap.c b/Xi/getkmap.c
index eaa0cff..0eec1d8 100644
--- a/Xi/getkmap.c
+++ b/Xi/getkmap.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "swaprep.h"
 
@@ -94,13 +93,14 @@ ProcXGetDeviceKeyMapping(ClientPtr clien
     xGetDeviceKeyMappingReply rep;
     DeviceIntPtr dev;
     KeySymsPtr k;
+    int rc;
 
     REQUEST(xGetDeviceKeyMappingReq);
     REQUEST_SIZE_MATCH(xGetDeviceKeyMappingReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
     if (dev->key == NULL)
 	return BadMatch;
     k = &dev->key->curKeySyms;
diff --git a/Xi/getmmap.c b/Xi/getmmap.c
index 8a99d63..c6c9c33 100644
--- a/Xi/getmmap.c
+++ b/Xi/getmmap.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>	/* Request macro     */
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getmmap.h"
@@ -94,13 +93,14 @@ ProcXGetDeviceModifierMapping(ClientPtr 
     DeviceIntPtr dev;
     xGetDeviceModifierMappingReply rep;
     KeyClassPtr kp;
+    int rc;
 
     REQUEST(xGetDeviceModifierMappingReq);
     REQUEST_SIZE_MATCH(xGetDeviceModifierMappingReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     kp = dev->key;
     if (kp == NULL)
diff --git a/Xi/getprop.c b/Xi/getprop.c
index 531e65f..188f549 100644
--- a/Xi/getprop.c
+++ b/Xi/getprop.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structs    */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "swaprep.h"
 
@@ -112,7 +111,7 @@ ProcXGetDeviceDontPropagateList(ClientPt
     rep.length = 0;
     rep.count = 0;
 
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/Xi/getselev.c b/Xi/getselev.c
index 819b2db..caa376f 100644
--- a/Xi/getselev.c
+++ b/Xi/getselev.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include "windowstr.h"	/* window struct     */
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "swaprep.h"
 
@@ -114,7 +113,7 @@ ProcXGetSelectedExtensionEvents(ClientPt
     rep.this_client_count = 0;
     rep.all_clients_count = 0;
 
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/Xi/getvers.c b/Xi/getvers.c
index a223a5d..a4afe80 100644
--- a/Xi/getvers.c
+++ b/Xi/getvers.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getvers.h"
diff --git a/Xi/grabdev.c b/Xi/grabdev.c
index b303695..110fc6b 100644
--- a/Xi/grabdev.c
+++ b/Xi/grabdev.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "dixevents.h"	/* GrabDevice */
 
@@ -122,9 +121,9 @@ ProcXGrabDevice(ClientPtr client)
     rep.sequenceNumber = client->sequence;
     rep.length = 0;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
+    if (rc != Success)
+	return rc;
 
     if ((rc = CreateMaskFromList(client, (XEventClass *) & stuff[1],
 				 stuff->event_count, tmp, dev,
@@ -153,7 +152,7 @@ int
 CreateMaskFromList(ClientPtr client, XEventClass * list, int count,
 		   struct tmask *mask, DeviceIntPtr dev, int req)
 {
-    int i, j;
+    int rc, i, j;
     int device;
     DeviceIntPtr tdev;
 
@@ -167,8 +166,10 @@ CreateMaskFromList(ClientPtr client, XEv
 	if (device > 255)
 	    return BadClass;
 
-	tdev = LookupDeviceIntRec(device);
-	if (tdev == NULL || (dev != NULL && tdev != dev))
+	rc = dixLookupDevice(&tdev, device, client, DixReadAccess);
+	if (rc != BadDevice && rc != Success)
+	    return rc;
+	if (rc == BadDevice || (dev != NULL && tdev != dev))
 	    return BadClass;
 
 	for (j = 0; j < ExtEventIndex; j++)
diff --git a/Xi/grabdevb.c b/Xi/grabdevb.c
index 21e46fc..7eb5422 100644
--- a/Xi/grabdevb.c
+++ b/Xi/grabdevb.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "exevents.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "grabdev.h"
@@ -117,14 +116,15 @@ ProcXGrabDeviceButton(ClientPtr client)
 	(sizeof(xGrabDeviceButtonReq) >> 2) + stuff->event_count)
 	return BadLength;
 
-    dev = LookupDeviceIntRec(stuff->grabbed_device);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess);
+    if (ret != Success)
+	return ret;
 
     if (stuff->modifier_device != UseXKeyboard) {
-	mdev = LookupDeviceIntRec(stuff->modifier_device);
-	if (mdev == NULL)
-	    return BadDevice;
+	ret = dixLookupDevice(&mdev, stuff->modifier_device, client,
+			      DixReadAccess);
+	if (ret != Success)
+	    return ret;
 	if (mdev->key == NULL)
 	    return BadMatch;
     } else
diff --git a/Xi/grabdevk.c b/Xi/grabdevk.c
index 8da36ba..e187a4f 100644
--- a/Xi/grabdevk.c
+++ b/Xi/grabdevk.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "exevents.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "grabdev.h"
@@ -115,14 +114,15 @@ ProcXGrabDeviceKey(ClientPtr client)
     if (stuff->length != (sizeof(xGrabDeviceKeyReq) >> 2) + stuff->event_count)
 	return BadLength;
 
-    dev = LookupDeviceIntRec(stuff->grabbed_device);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess);
+    if (ret != Success)
+	return ret;
 
     if (stuff->modifier_device != UseXKeyboard) {
-	mdev = LookupDeviceIntRec(stuff->modifier_device);
-	if (mdev == NULL)
-	    return BadDevice;
+	ret = dixLookupDevice(&mdev, stuff->modifier_device, client,
+			      DixReadAccess);
+	if (ret != Success)
+	    return ret;
 	if (mdev->key == NULL)
 	    return BadMatch;
     } else
diff --git a/Xi/gtmotion.c b/Xi/gtmotion.c
index 51d4248..de22d04 100644
--- a/Xi/gtmotion.c
+++ b/Xi/gtmotion.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exevents.h"
 #include "exglobals.h"
 
@@ -96,7 +95,7 @@ ProcXGetDeviceMotionEvents(ClientPtr cli
     INT32 *coords = NULL, *bufptr;
     xGetDeviceMotionEventsReply rep;
     unsigned long i;
-    int num_events, axes, size = 0, tsize;
+    int rc, num_events, axes, size = 0, tsize;
     unsigned long nEvents;
     DeviceIntPtr dev;
     TimeStamp start, stop;
@@ -106,9 +105,9 @@ ProcXGetDeviceMotionEvents(ClientPtr cli
     REQUEST(xGetDeviceMotionEventsReq);
 
     REQUEST_SIZE_MATCH(xGetDeviceMotionEventsReq);
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixReadAccess);
+    if (rc != Success)
+	return rc;
     v = dev->valuator;
     if (v == NULL || v->numAxes == 0)
 	return BadMatch;
diff --git a/Xi/listdev.c b/Xi/listdev.c
index 160ad02..041de76 100644
--- a/Xi/listdev.c
+++ b/Xi/listdev.c
@@ -63,8 +63,8 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
 #include "extnsionst.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"	/* FIXME */
+#include "xace.h"
 
 #include "listdev.h"
 
@@ -310,7 +310,7 @@ ProcXListInputDevices(ClientPtr client)
     xListInputDevicesReply rep;
     int numdevs = 0;
     int namesize = 1;	/* need 1 extra byte for strcpy */
-    int size = 0;
+    int rc, size = 0;
     int total_length;
     char *devbuf;
     char *classbuf;
@@ -329,10 +329,16 @@ ProcXListInputDevices(ClientPtr client)
     AddOtherInputDevices();
 
     for (d = inputInfo.devices; d; d = d->next) {
+	rc = XaceHook(XACE_DEVICE_ACCESS, client, d, DixGetAttrAccess);
+	if (rc != Success)
+	    return rc;
 	SizeDeviceInfo(d, &namesize, &size);
         numdevs++;
     }
     for (d = inputInfo.off_devices; d; d = d->next) {
+	rc = XaceHook(XACE_DEVICE_ACCESS, client, d, DixGetAttrAccess);
+	if (rc != Success)
+	    return rc;
 	SizeDeviceInfo(d, &namesize, &size);
         numdevs++;
     }
diff --git a/Xi/opendev.c b/Xi/opendev.c
index dfefe05..128b1bd 100644
--- a/Xi/opendev.c
+++ b/Xi/opendev.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
 #include "windowstr.h"	/* window structure  */
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "opendev.h"
@@ -107,13 +106,15 @@ ProcXOpenDevice(ClientPtr client)
 	stuff->deviceid == inputInfo.keyboard->id)
 	return BadDevice;
 
-    if ((dev = LookupDeviceIntRec(stuff->deviceid)) == NULL) {	/* not open */
+    status = dixLookupDevice(&dev, stuff->deviceid, client, DixReadAccess);
+    if (status == BadDevice) {  /* not open */
 	for (dev = inputInfo.off_devices; dev; dev = dev->next)
 	    if (dev->id == stuff->deviceid)
 		break;
 	if (dev == NULL)
 	    return BadDevice;
-    }
+    } else if (status != Success)
+	return status;
 
     OpenInputDevice(dev, client, &status);
     if (status != Success)
diff --git a/Xi/queryst.c b/Xi/queryst.c
index 2b66b7e..71ab79b 100644
--- a/Xi/queryst.c
+++ b/Xi/queryst.c
@@ -42,7 +42,6 @@ from The Open Group.
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exevents.h"
 #include "exglobals.h"
 
@@ -74,7 +73,7 @@ int
 ProcXQueryDeviceState(ClientPtr client)
 {
     char n;
-    int i;
+    int rc, i;
     int num_classes = 0;
     int total_length = 0;
     char *buf, *savbuf;
@@ -96,9 +95,9 @@ ProcXQueryDeviceState(ClientPtr client)
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixReadAccess);
+    if (rc != Success)
+	return rc;
 
     v = dev->valuator;
     if (v != NULL && v->motionHintWindow != NULL)
diff --git a/Xi/selectev.c b/Xi/selectev.c
index a5cf567..b93618a 100644
--- a/Xi/selectev.c
+++ b/Xi/selectev.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exevents.h"
 #include "exglobals.h"
 
@@ -164,7 +163,7 @@ ProcXSelectExtensionEvent(ClientPtr clie
     if (stuff->length != (sizeof(xSelectExtensionEventReq) >> 2) + stuff->count)
 	return BadLength;
 
-    ret = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    ret = dixLookupWindow(&pWin, stuff->window, client, DixReceiveAccess);
     if (ret != Success)
 	return ret;
 
diff --git a/Xi/sendexev.c b/Xi/sendexev.c
index 20b415a..e4e38d7 100644
--- a/Xi/sendexev.c
+++ b/Xi/sendexev.c
@@ -59,9 +59,9 @@ SOFTWARE.
 
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include "windowstr.h"	/* Window            */
+#include "extnsionst.h" /* EventSwapPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exevents.h"
 #include "exglobals.h"
 
@@ -131,9 +131,9 @@ ProcXSendExtensionEvent(ClientPtr client
 	(stuff->num_events * (sizeof(xEvent) >> 2)))
 	return BadLength;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixWriteAccess);
+    if (ret != Success)
+	return ret;
 
     /* The client's event type must be one defined by an extension. */
 
diff --git a/Xi/setbmap.c b/Xi/setbmap.c
index 40f0f9a..3035c64 100644
--- a/Xi/setbmap.c
+++ b/Xi/setbmap.c
@@ -63,7 +63,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "exevents.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "setbmap.h"
@@ -110,9 +109,9 @@ ProcXSetDeviceButtonMapping(ClientPtr cl
     rep.sequenceNumber = client->sequence;
     rep.status = MappingSuccess;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (ret != Success)
+	return ret;
 
     ret = SetButtonMapping(client, dev, stuff->map_length, (BYTE *) & stuff[1]);
 
diff --git a/Xi/setdval.c b/Xi/setdval.c
index cb35b91..b1e22fc 100644
--- a/Xi/setdval.c
+++ b/Xi/setdval.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "setdval.h"
@@ -92,6 +91,7 @@ ProcXSetDeviceValuators(ClientPtr client
 {
     DeviceIntPtr dev;
     xSetDeviceValuatorsReply rep;
+    int rc;
 
     REQUEST(xSetDeviceValuatorsReq);
     REQUEST_AT_LEAST_SIZE(xSetDeviceValuatorsReq);
@@ -106,9 +106,9 @@ ProcXSetDeviceValuators(ClientPtr client
 	stuff->num_valuators)
 	return BadLength;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (rc != Success)
+	return rc;
     if (dev->valuator == NULL)
 	return BadMatch;
 
diff --git a/Xi/setfocus.c b/Xi/setfocus.c
index 74de17e..c6edbc2 100644
--- a/Xi/setfocus.c
+++ b/Xi/setfocus.c
@@ -63,7 +63,6 @@ SOFTWARE.
 
 #include "dixevents.h"
 
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "setfocus.h"
@@ -102,8 +101,10 @@ ProcXSetDeviceFocus(ClientPtr client)
     REQUEST(xSetDeviceFocusReq);
     REQUEST_SIZE_MATCH(xSetDeviceFocusReq);
 
-    dev = LookupDeviceIntRec(stuff->device);
-    if (dev == NULL || !dev->focus)
+    ret = dixLookupDevice(&dev, stuff->device, client, DixSetFocusAccess);
+    if (ret != Success)
+	return ret;
+    if (!dev->focus)
 	return BadDevice;
 
     ret = SetInputFocus(client, dev, stuff->focus, stuff->revertTo,
diff --git a/Xi/setmmap.c b/Xi/setmmap.c
index 19ec71b..be3d3cb 100644
--- a/Xi/setmmap.c
+++ b/Xi/setmmap.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "exevents.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "setmmap.h"
@@ -99,9 +98,9 @@ ProcXSetDeviceModifierMapping(ClientPtr 
     REQUEST(xSetDeviceModifierMappingReq);
     REQUEST_AT_LEAST_SIZE(xSetDeviceModifierMappingReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (ret != Success)
+	return ret;
 
     rep.repType = X_Reply;
     rep.RepType = X_SetDeviceModifierMapping;
diff --git a/Xi/setmode.c b/Xi/setmode.c
index 957721c..8b6003a 100644
--- a/Xi/setmode.c
+++ b/Xi/setmode.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "setmode.h"
@@ -92,6 +91,7 @@ ProcXSetDeviceMode(ClientPtr client)
 {
     DeviceIntPtr dev;
     xSetDeviceModeReply rep;
+    int rc;
 
     REQUEST(xSetDeviceModeReq);
     REQUEST_SIZE_MATCH(xSetDeviceModeReq);
@@ -101,9 +101,9 @@ ProcXSetDeviceMode(ClientPtr client)
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (rc != Success)
+	return rc;
     if (dev->valuator == NULL)
 	return BadMatch;
     if ((dev->grab) && !SameClient(dev->grab, client))
diff --git a/Xi/stubs.c b/Xi/stubs.c
index 40cd02f..80ddd73 100644
--- a/Xi/stubs.c
+++ b/Xi/stubs.c
@@ -65,6 +65,7 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
+#include "xace.h"
 
 /***********************************************************************
  *
@@ -153,6 +154,7 @@ AddOtherInputDevices(void)
 void
 OpenInputDevice(DeviceIntPtr dev, ClientPtr client, int *status)
 {
+    *status = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess);
 }
 
 /****************************************************************************
diff --git a/Xi/ungrdev.c b/Xi/ungrdev.c
index 505d669..7abb1d0 100644
--- a/Xi/ungrdev.c
+++ b/Xi/ungrdev.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "ungrdev.h"
@@ -94,13 +93,14 @@ ProcXUngrabDevice(ClientPtr client)
     DeviceIntPtr dev;
     GrabPtr grab;
     TimeStamp time;
+    int rc;
 
     REQUEST(xUngrabDeviceReq);
     REQUEST_SIZE_MATCH(xUngrabDeviceReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
     grab = dev->grab;
 
     time = ClientTimeToServerTime(stuff->time);
diff --git a/Xi/ungrdevb.c b/Xi/ungrdevb.c
index 0dfe805..85ca5c6 100644
--- a/Xi/ungrdevb.c
+++ b/Xi/ungrdevb.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "dixgrabs.h"
 
@@ -107,22 +106,23 @@ ProcXUngrabDeviceButton(ClientPtr client
     REQUEST(xUngrabDeviceButtonReq);
     REQUEST_SIZE_MATCH(xUngrabDeviceButtonReq);
 
-    dev = LookupDeviceIntRec(stuff->grabbed_device);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess);
+    if (rc != Success)
+	return rc;
     if (dev->button == NULL)
 	return BadMatch;
 
     if (stuff->modifier_device != UseXKeyboard) {
-	mdev = LookupDeviceIntRec(stuff->modifier_device);
-	if (mdev == NULL)
+	rc = dixLookupDevice(&mdev, stuff->modifier_device, client,
+			     DixReadAccess);
+	if (rc != Success)
 	    return BadDevice;
 	if (mdev->key == NULL)
 	    return BadMatch;
     } else
 	mdev = (DeviceIntPtr) LookupKeyboardDevice();
 
-    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/Xi/ungrdevk.c b/Xi/ungrdevk.c
index e6307af..ac40035 100644
--- a/Xi/ungrdevk.c
+++ b/Xi/ungrdevk.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "dixgrabs.h"
 
@@ -107,22 +106,23 @@ ProcXUngrabDeviceKey(ClientPtr client)
     REQUEST(xUngrabDeviceKeyReq);
     REQUEST_SIZE_MATCH(xUngrabDeviceKeyReq);
 
-    dev = LookupDeviceIntRec(stuff->grabbed_device);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess);
+    if (rc != Success)
+	return rc;
     if (dev->key == NULL)
 	return BadMatch;
 
     if (stuff->modifier_device != UseXKeyboard) {
-	mdev = LookupDeviceIntRec(stuff->modifier_device);
-	if (mdev == NULL)
+	rc = dixLookupDevice(&mdev, stuff->modifier_device, client,
+			     DixReadAccess);
+	if (rc != Success)
 	    return BadDevice;
 	if (mdev->key == NULL)
 	    return BadMatch;
     } else
 	mdev = (DeviceIntPtr) LookupKeyboardDevice();
 
-    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/config/dbus.c b/config/dbus.c
index c867512..e564c90 100644
--- a/config/dbus.c
+++ b/config/dbus.c
@@ -213,7 +213,7 @@ remove_device(DBusMessage *message, DBus
         MALFORMED_MESSAGE_ERROR();
     }
 
-    dev = LookupDeviceIntRec(deviceid);
+    dixLookupDevice(&dev, deviceid, serverClient, DixUnknownAccess);
     if (!dev) {
         DebugF("[config/dbus] bogus device id %d given\n", deviceid);
         ret = BadMatch;
diff --git a/dix/devices.c b/dix/devices.c
index 3f4a33d..bd1bef7 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -717,20 +717,28 @@ LookupPointerDevice(void)
     return inputInfo.pointer ? &inputInfo.pointer->public : NULL;
 }
 
-DevicePtr
-LookupDevice(int id)
+int
+dixLookupDevice(DeviceIntPtr *pDev, int id, ClientPtr client, Mask access_mode)
 {
     DeviceIntPtr dev;
+    int rc;
+    *pDev = NULL;
 
     for (dev=inputInfo.devices; dev; dev=dev->next) {
         if (dev->id == (CARD8)id)
-            return (DevicePtr)dev;
+            goto found;
     }
     for (dev=inputInfo.off_devices; dev; dev=dev->next) {
         if (dev->id == (CARD8)id)
-            return (DevicePtr)dev;
+	    goto found;
     }
-    return NULL;
+    return BadDevice;
+
+found:
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
+    if (rc == Success)
+	*pDev = dev;
+    return rc;
 }
 
 void
diff --git a/hw/dmx/input/dmxeq.c b/hw/dmx/input/dmxeq.c
index 3e98fb7..dff0b44 100644
--- a/hw/dmx/input/dmxeq.c
+++ b/hw/dmx/input/dmxeq.c
@@ -82,7 +82,6 @@
 #ifdef XINPUT
 #include <X11/extensions/XIproto.h>
 #define EXTENSION_PROC_ARGS void *
-#include "extinit.h"            /* For LookupDeviceIntRec */
 #endif
 
 #if DMX_EQ_DEBUG
@@ -217,8 +216,9 @@ static void dmxeqProcessXInputEvent(xEve
 {
     deviceKeyButtonPointer *ev     = (deviceKeyButtonPointer *)xe;
     int                    id      = ev->deviceid & DEVICE_BITS;
-    DeviceIntPtr           pDevice = LookupDeviceIntRec(id);
+    DeviceIntPtr           pDevice;
     
+    dixLookupDevice(&pDevice, id, serverClient, DixUnknownAccess);
     if (!pDevice) {
         dmxLog(dmxError, "dmxeqProcessInputEvents: id %d not found\n", id);
         return;
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index e45d44c..b694b73 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -77,7 +77,6 @@
 
 #define EXTENSION_PROC_ARGS void *
 #include "extnsionst.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 
 #include "windowstr.h"	/* screenIsSaved */
 
diff --git a/include/extinit.h b/include/extinit.h
index e616b6d..df9773c 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -44,9 +44,4 @@ AssignTypeAndName (
 	char *                 /* name */
 	);
 
-DeviceIntPtr
-LookupDeviceIntRec (
-	CARD8                  /* id */
-	);
-
 #endif /* EXTINIT_H */
diff --git a/include/input.h b/include/input.h
index 4f9164a..d8a9fe8 100644
--- a/include/input.h
+++ b/include/input.h
@@ -201,8 +201,11 @@ extern DevicePtr LookupKeyboardDevice(vo
 
 extern DevicePtr LookupPointerDevice(void);
 
-extern DevicePtr LookupDevice(
-    int /* id */);
+extern int dixLookupDevice(
+    DeviceIntPtr *         /* dev */,
+    int                    /* id */,
+    ClientPtr              /* client */,
+    Mask                   /* access_mode */);
 
 extern void QueryMinMaxKeyCodes(
     KeyCode* /*minCode*/,
@@ -436,9 +439,6 @@ extern int GetMotionHistory(
 extern void SwitchCoreKeyboard(DeviceIntPtr pDev);
 extern void SwitchCorePointer(DeviceIntPtr pDev);
 
-extern DeviceIntPtr LookupDeviceIntRec(
-    CARD8 deviceid);
-
 /* Implemented by the DDX. */
 extern int NewInputDeviceRequest(
     InputOption *options,
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index c7f9a26..877d4d2 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -65,7 +65,7 @@ DeviceIntPtr dev = NULL;
     if (id&(~0xff))
 	 dev = NULL;
 
-    dev= (DeviceIntPtr)LookupDevice(id);
+    dixLookupDevice(&dev, id, serverClient, DixUnknownAccess);
     if (dev!=NULL) 
 	return dev;
     if ((!dev)&&(why_rtrn))


More information about the xorg-commit mailing list