Xi: disallow changing core keyboard and pointer

Just short-circuit the change core keyboard/pointer requests.
This commit is contained in:
Daniel Stone 2006-10-29 03:43:34 +03:00 committed by Daniel Stone
parent 68f595ca6c
commit 96e32805d1
8 changed files with 11 additions and 435 deletions

View File

@ -64,7 +64,6 @@ SOFTWARE.
#include "XIstubs.h"
#include "globals.h"
#include "extnsionst.h"
#include "extinit.h" /* LookupDeviceIntRec */
#include "exevents.h"
#include "exglobals.h"
@ -99,107 +98,10 @@ SProcXChangeKeyboardDevice(register ClientPtr client)
int
ProcXChangeKeyboardDevice(register ClientPtr client)
{
int i;
DeviceIntPtr xkbd = inputInfo.keyboard;
DeviceIntPtr dev;
FocusClassPtr xf = xkbd->focus;
FocusClassPtr df;
KeyClassPtr k;
xChangeKeyboardDeviceReply rep;
changeDeviceNotify ev;
REQUEST(xChangeKeyboardDeviceReq);
REQUEST_SIZE_MATCH(xChangeKeyboardDeviceReq);
rep.repType = X_Reply;
rep.RepType = X_ChangeKeyboardDevice;
rep.length = 0;
rep.sequenceNumber = client->sequence;
dev = LookupDeviceIntRec(stuff->deviceid);
if (dev == NULL) {
rep.status = -1;
SendErrorToClient(client, IReqCode, X_ChangeKeyboardDevice, 0,
BadDevice);
return Success;
}
k = dev->key;
if (k == NULL) {
rep.status = -1;
SendErrorToClient(client, IReqCode, X_ChangeKeyboardDevice, 0,
BadMatch);
return Success;
}
if (((dev->grab) && !SameClient(dev->grab, client)) ||
((xkbd->grab) && !SameClient(xkbd->grab, client)))
rep.status = AlreadyGrabbed;
else if ((dev->sync.frozen &&
dev->sync.other && !SameClient(dev->sync.other, client)) ||
(xkbd->sync.frozen &&
xkbd->sync.other && !SameClient(xkbd->sync.other, client)))
rep.status = GrabFrozen;
else {
if (ChangeKeyboardDevice(xkbd, dev) != Success) {
SendErrorToClient(client, IReqCode, X_ChangeKeyboardDevice, 0,
BadDevice);
return Success;
}
if (!dev->focus)
InitFocusClassDeviceStruct(dev);
if (!dev->kbdfeed)
InitKbdFeedbackClassDeviceStruct(dev, (BellProcPtr) NoopDDA,
(KbdCtrlProcPtr) NoopDDA);
df = dev->focus;
df->win = xf->win;
df->revert = xf->revert;
df->time = xf->time;
df->traceGood = xf->traceGood;
if (df->traceSize != xf->traceSize) {
Must_have_memory = TRUE; /* XXX */
df->trace = (WindowPtr *) xrealloc(df->trace,
xf->traceSize *
sizeof(WindowPtr));
Must_have_memory = FALSE; /* XXX */
}
df->traceSize = xf->traceSize;
for (i = 0; i < df->traceSize; i++)
df->trace[i] = xf->trace[i];
RegisterOtherDevice(xkbd);
RegisterKeyboardDevice(dev);
ev.type = ChangeDeviceNotify;
ev.deviceid = stuff->deviceid;
ev.time = currentTime.milliseconds;
ev.request = NewKeyboard;
SendEventToAllWindows(dev, ChangeDeviceNotifyMask, (xEvent *) & ev, 1);
SendMappingNotify(MappingKeyboard, k->curKeySyms.minKeyCode,
k->curKeySyms.maxKeyCode - k->curKeySyms.minKeyCode +
1, client);
rep.status = 0;
}
WriteReplyToClient(client, sizeof(xChangeKeyboardDeviceReply), &rep);
SendErrorToClient(client, IReqCode, X_ChangeKeyboardDevice, 0,
BadDevice);
return Success;
}
/***********************************************************************
*
* This procedure writes the reply for the XChangeKeyboardDevice
* function, if the client and server have a different byte ordering.
*
*/
void
SRepXChangeKeyboardDevice(ClientPtr client, int size,
xChangeKeyboardDeviceReply * rep)
{
register char n;
swaps(&rep->sequenceNumber, n);
swapl(&rep->length, n);
WriteToClient(client, size, (char *)rep);
}

View File

@ -36,9 +36,4 @@ int SProcXChangeKeyboardDevice(ClientPtr /* client */
int ProcXChangeKeyboardDevice(ClientPtr /* client */
);
void SRepXChangeKeyboardDevice(ClientPtr /* client */ ,
int /* size */ ,
xChangeKeyboardDeviceReply * /* rep */
);
#endif /* CHGKBD_H */

View File

@ -101,97 +101,10 @@ SProcXChangePointerDevice(register ClientPtr client)
int
ProcXChangePointerDevice(register ClientPtr client)
{
DeviceIntPtr xptr = inputInfo.pointer;
DeviceIntPtr dev;
ValuatorClassPtr v;
xChangePointerDeviceReply rep;
changeDeviceNotify ev;
REQUEST(xChangePointerDeviceReq);
REQUEST_SIZE_MATCH(xChangePointerDeviceReq);
rep.repType = X_Reply;
rep.RepType = X_ChangePointerDevice;
rep.length = 0;
rep.sequenceNumber = client->sequence;
dev = LookupDeviceIntRec(stuff->deviceid);
if (dev == NULL) {
rep.status = -1;
SendErrorToClient(client, IReqCode, X_ChangePointerDevice, 0,
BadDevice);
return Success;
}
v = dev->valuator;
if (v == NULL || v->numAxes < 2 ||
stuff->xaxis >= v->numAxes || stuff->yaxis >= v->numAxes) {
rep.status = -1;
SendErrorToClient(client, IReqCode, X_ChangePointerDevice, 0, BadMatch);
return Success;
}
if (((dev->grab) && !SameClient(dev->grab, client)) ||
((xptr->grab) && !SameClient(xptr->grab, client)))
rep.status = AlreadyGrabbed;
else if ((dev->sync.frozen &&
dev->sync.other && !SameClient(dev->sync.other, client)) ||
(xptr->sync.frozen &&
xptr->sync.other && !SameClient(xptr->sync.other, client)))
rep.status = GrabFrozen;
else {
if (ChangePointerDevice(xptr, dev, stuff->xaxis, stuff->yaxis) !=
Success) {
SendErrorToClient(client, IReqCode, X_ChangePointerDevice, 0,
BadDevice);
return Success;
}
if (dev->focus)
DeleteFocusClassDeviceStruct(dev);
if (!dev->button)
InitButtonClassDeviceStruct(dev, 0, NULL);
if (!dev->ptrfeed)
InitPtrFeedbackClassDeviceStruct(dev, (PtrCtrlProcPtr) NoopDDA);
RegisterOtherDevice(xptr);
RegisterPointerDevice(dev);
ev.type = ChangeDeviceNotify;
ev.deviceid = stuff->deviceid;
ev.time = currentTime.milliseconds;
ev.request = NewPointer;
SendEventToAllWindows(dev, ChangeDeviceNotifyMask, (xEvent *) & ev, 1);
SendMappingNotify(MappingPointer, 0, 0, client);
rep.status = 0;
}
WriteReplyToClient(client, sizeof(xChangePointerDeviceReply), &rep);
SendErrorToClient(client, IReqCode, X_ChangePointerDevice, 0,
BadDevice);
return Success;
}
void
DeleteFocusClassDeviceStruct(DeviceIntPtr dev)
{
xfree(dev->focus->trace);
xfree(dev->focus);
dev->focus = NULL;
}
/***********************************************************************
*
* This procedure writes the reply for the XChangePointerDevice
* function, if the client and server have a different byte ordering.
*
*/
void
SRepXChangePointerDevice(ClientPtr client, int size,
xChangePointerDeviceReply * rep)
{
register char n;
swaps(&rep->sequenceNumber, n);
swapl(&rep->length, n);
WriteToClient(client, size, (char *)rep);
}

View File

@ -53,9 +53,4 @@ void FindInterestedChildren( /* FIXME: could be static? */
int /* count */
);
void SRepXChangePointerDevice(ClientPtr /* client */ ,
int /* size */ ,
xChangePointerDeviceReply * /* rep */
);
#endif /* CHGPTR_H */

View File

@ -465,12 +465,6 @@ SReplyIDispatch(ClientPtr client, int len, xGrabDeviceReply * rep)
else if (rep->RepType == X_GetDeviceMotionEvents)
SRepXGetDeviceMotionEvents(client, len,
(xGetDeviceMotionEventsReply *) rep);
else if (rep->RepType == X_ChangeKeyboardDevice)
SRepXChangeKeyboardDevice(client, len,
(xChangeKeyboardDeviceReply *) rep);
else if (rep->RepType == X_ChangePointerDevice)
SRepXChangePointerDevice(client, len,
(xChangePointerDeviceReply *) rep);
else if (rep->RepType == X_GrabDevice)
SRepXGrabDevice(client, len, (xGrabDeviceReply *) rep);
else if (rep->RepType == X_GetDeviceFocus)

View File

@ -66,86 +66,6 @@ SOFTWARE.
#include <X11/extensions/XIproto.h>
#include "XIstubs.h"
/***********************************************************************
*
* Caller: ProcXChangeKeyboardDevice
*
* This procedure does the implementation-dependent portion of the work
* needed to change the keyboard device.
*
* The X keyboard device has a FocusRec. If the device that has been
* made into the new X keyboard did not have a FocusRec,
* ProcXChangeKeyboardDevice will allocate one for it.
*
* If you do not want clients to be able to focus the old X keyboard
* device, call DeleteFocusClassDeviceStruct to free the FocusRec.
*
* If you support input devices with keys that you do not want to be
* used as the X keyboard, you need to check for them here and return
* a BadDevice error.
*
* The default implementation is to do nothing (assume you do want
* clients to be able to focus the old X keyboard). The commented-out
* sample code shows what you might do if you don't want the default.
*
*/
int
ChangeKeyboardDevice(DeviceIntPtr old_dev, DeviceIntPtr new_dev)
{
/***********************************************************************
DeleteFocusClassDeviceStruct(old_dev); * defined in xchgptr.c *
**********************************************************************/
return BadMatch;
}
/***********************************************************************
*
* Caller: ProcXChangePointerDevice
*
* This procedure does the implementation-dependent portion of the work
* needed to change the pointer device.
*
* The X pointer device does not have a FocusRec. If the device that
* has been made into the new X pointer had a FocusRec,
* ProcXChangePointerDevice will free it.
*
* If you want clients to be able to focus the old pointer device that
* has now become accessible through the input extension, you need to
* add a FocusRec to it here.
*
* The XChangePointerDevice protocol request also allows the client
* to choose which axes of the new pointer device are used to move
* the X cursor in the X- and Y- directions. If the axes are different
* than the default ones, you need to keep track of that here.
*
* If you support input devices with valuators that you do not want to be
* used as the X pointer, you need to check for them here and return a
* BadDevice error.
*
* The default implementation is to do nothing (assume you don't want
* clients to be able to focus the old X pointer). The commented-out
* sample code shows what you might do if you don't want the default.
*
*/
int
ChangePointerDevice(DeviceIntPtr old_dev,
DeviceIntPtr new_dev, unsigned char x, unsigned char y)
{
/***********************************************************************
InitFocusClassDeviceStruct(old_dev); * allow focusing old ptr*
x_axis = x; * keep track of new x-axis*
y_axis = y; * keep track of new y-axis*
if (x_axis != 0 || y_axis != 1)
axes_changed = TRUE; * remember axes have changed*
else
axes_changed = FALSE;
*************************************************************************/
return BadMatch;
}
/***********************************************************************
*
* Caller: ProcXCloseDevice

View File

@ -251,148 +251,12 @@ OpenInputDevice(DeviceIntPtr dev,
*status = Success;
}
/***********************************************************************
*
* Caller: ProcXChangeKeyboardDevice
*
* This procedure does the implementation-dependent portion of the work
* needed to change the keyboard device.
*
* The X keyboard device has a FocusRec. If the device that has been
* made into the new X keyboard did not have a FocusRec,
* ProcXChangeKeyboardDevice will allocate one for it.
*
* If you do not want clients to be able to focus the old X keyboard
* device, call DeleteFocusClassDeviceStruct to free the FocusRec.
*
* If you support input devices with keys that you do not want to be
* used as the X keyboard, you need to check for them here and return
* a BadDevice error.
*
* The default implementation is to do nothing (assume you do want
* clients to be able to focus the old X keyboard). The commented-out
* sample code shows what you might do if you don't want the default.
*
***********************************************************************
*/
int
ChangeKeyboardDevice (DeviceIntPtr old_dev, DeviceIntPtr new_dev)
{
/**********************************************************************
* DeleteFocusClassDeviceStruct(old_dev); * defined in xchgptr.c *
**********************************************************************/
return !Success;
}
/***********************************************************************
*
* Caller: ProcXChangePointerDevice
*
* This procedure does the implementation-dependent portion of the work
* needed to change the pointer device.
*
* The X pointer device does not have a FocusRec. If the device that
* has been made into the new X pointer had a FocusRec,
* ProcXChangePointerDevice will free it.
*
* If you want clients to be able to focus the old pointer device that
* has now become accessible through the input extension, you need to
* add a FocusRec to it here.
*
* The XChangePointerDevice protocol request also allows the client
* to choose which axes of the new pointer device are used to move
* the X cursor in the X- and Y- directions. If the axes are different
* than the default ones, you need to keep track of that here.
*
* If you support input devices with valuators that you do not want to be
* used as the X pointer, you need to check for them here and return a
* BadDevice error.
*
* The default implementation is to do nothing (assume you don't want
* clients to be able to focus the old X pointer). The commented-out
* sample code shows what you might do if you don't want the default.
*
***********************************************************************
*/
int
ChangePointerDevice (
DeviceIntPtr old_dev,
DeviceIntPtr new_dev,
unsigned char x,
unsigned char y)
{
/************************************************************************
InitFocusClassDeviceStruct(old_dev); * allow focusing old ptr*
x_axis = x; * keep track of new x-axis*
y_axis = y; * keep track of new y-axis*
if (x_axis != 0 || y_axis != 1)
axes_changed = TRUE; * remember axes have changed*
else
axes_changed = FALSE;
*************************************************************************/
return !Success;
}
/***********************************************************************
*
* Caller: ProcXCloseDevice
*
* Take care of implementation-dependent details of closing a device.
* Some implementations may actually close the device, others may just
* remove this clients interest in that device.
*
* The default implementation is to do nothing (assume all input devices
* are initialized during X server initialization and kept open).
*
***********************************************************************
*/
void
CloseInputDevice (DeviceIntPtr d, ClientPtr client)
CloseInputDevice(DeviceIntPtr dev,
ClientPtr client)
{
}
/***********************************************************************
*
* Caller: ProcXListInputDevices
*
* This is the implementation-dependent routine to initialize an input
* device to the point that information about it can be listed.
* Some implementations open all input devices when the server is first
* initialized, and never close them. Other implementations open only
* the X pointer and keyboard devices during server initialization,
* and only open other input devices when some client makes an
* XOpenDevice request. If some other process has the device open, the
* server may not be able to get information about the device to list it.
*
* This procedure should be used by implementations that do not initialize
* all input devices at server startup. It should do device-dependent
* initialization for any devices not previously initialized, and call
* AddInputDevice for each of those devices so that a DeviceIntRec will be
* created for them.
*
* The default implementation is to do nothing (assume all input devices
* are initialized during X server initialization and kept open).
* The commented-out sample code shows what you might do if you don't want
* the default.
*
***********************************************************************
*/
void
AddOtherInputDevices ()
{
}
/****************************************************************************
*
* Caller: ProcXSetDeviceMode
@ -475,6 +339,11 @@ ChangeDeviceControl (ClientPtr client, DeviceIntPtr dev, xDeviceCtl *control)
return (*local->control_proc)(local, control);
}
}
void
AddOtherInputDevices()
{
}
#endif
int

View File

@ -26,18 +26,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef XI_STUBS_H
#define XI_STUBS_H 1
int
ChangeKeyboardDevice (
DeviceIntPtr /* old_dev */,
DeviceIntPtr /* new_dev */);
int
ChangePointerDevice (
DeviceIntPtr /* old_dev */,
DeviceIntPtr /* new_dev */,
unsigned char /* x */,
unsigned char /* y */);
void
CloseInputDevice (
DeviceIntPtr /* d */,