Commit 5c03d131 authored by Eamon Walsh's avatar Eamon Walsh Committed by Eamon Walsh

xace: add new hooks + access controls: XInput extension.

Introduces new dix API to lookup a device, dixLookupDevice(), which
replaces LookupDeviceIntRec and LookupDevice.
parent 27612748
......@@ -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)
{
......
......@@ -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) {
......
......@@ -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 client)
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;
......
......@@ -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 client)
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:
......
......@@ -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 client)
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,
......
......@@ -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(ClientPtr client)
stuff->count)
return BadLength;
rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
if (rc != Success)
return rc;
......
......@@ -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"
......
......@@ -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 dev, WindowPtr p1, ClientPtr client)
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 */
......
......@@ -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) {
......
......@@ -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, DeviceIntPtr dev, BYTE this_device_mode,
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, DeviceIntPtr dev, BYTE this_device_mode,
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 dev, BYTE this_device_mode,
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 dev, BYTE this_device_mode,
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 d, Window dest, Bool propagate,
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(deviceKeyButtonPointer * pEvents, Mask mask)
{
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 pWin, int type,
{
DeviceIntPtr dev;
dev = LookupDeviceIntRec(xE->deviceid & DEVICE_BITS);
dixLookupDevice(&dev, xE->deviceid & DEVICE_BITS, serverClient,
DixReadAccess);
if (!dev)
return;
......
......@@ -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
......
......@@ -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 client)
DeviceIntPtr dev;
xGetDeviceButtonMappingReply rep;
ButtonClassPtr b;
int rc;
REQUEST(xGetDeviceButtonMappingReq);
REQUEST_SIZE_MATCH(xGetDeviceButtonMappingReq);
......@@ -102,9 +102,9 @@ ProcXGetDeviceButtonMapping(ClientPtr client)
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)
......
......@@ -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 size, xGetDeviceControlReply * rep)
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;
......
......@@ -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 size,
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;
......
......@@ -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;
......
......@@ -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 client)
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;
......
......@@ -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 client)
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)
......
......@@ -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(ClientPtr client)
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;
......
......@@ -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(ClientPtr client)
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;
......
......@@ -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"
......
......@@ -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, XEventClass * list, int count,
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++)
......
......@@ -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
......
......@@ -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);