xace: add hooks + new access codes: XFixes extension.

Required a new name argument to the selection access hook to handle
XFixesSelectSelectionInput.
This commit is contained in:
Eamon Walsh 2007-08-30 11:48:45 -04:00 committed by Eamon Walsh
parent 47ab4d648b
commit cda92bbf12
7 changed files with 87 additions and 47 deletions

View File

@ -173,6 +173,7 @@ int XaceHook(int hook, ...)
case XACE_SELECTION_ACCESS: { case XACE_SELECTION_ACCESS: {
XaceSelectionAccessRec rec = { XaceSelectionAccessRec rec = {
va_arg(ap, ClientPtr), va_arg(ap, ClientPtr),
va_arg(ap, Atom),
va_arg(ap, Selection*), va_arg(ap, Selection*),
va_arg(ap, Mask), va_arg(ap, Mask),
Success /* default allow */ Success /* default allow */

View File

@ -115,6 +115,7 @@ typedef struct {
/* XACE_SELECTION_ACCESS */ /* XACE_SELECTION_ACCESS */
typedef struct { typedef struct {
ClientPtr client; ClientPtr client;
Atom name;
Selection *selection; Selection *selection;
Mask access_mode; Mask access_mode;
int status; int status;

View File

@ -1013,10 +1013,6 @@ ProcSetSelectionOwner(ClientPtr client)
{ {
xEvent event; xEvent event;
rc = XaceHook(XACE_SELECTION_ACCESS, client, CurrentSelections[i],
DixSetAttrAccess);
if (rc != Success)
return rc;
/* If the timestamp in client's request is in the past relative /* If the timestamp in client's request is in the past relative
to the time stamp indicating the last time the owner of the to the time stamp indicating the last time the owner of the
selection was set, do not set the selection, just return selection was set, do not set the selection, just return
@ -1024,6 +1020,12 @@ ProcSetSelectionOwner(ClientPtr client)
if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged) if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged)
== EARLIER) == EARLIER)
return Success; return Success;
rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
CurrentSelections[i], DixSetAttrAccess);
if (rc != Success)
return rc;
if (CurrentSelections[i].client && if (CurrentSelections[i].client &&
(!pWin || (CurrentSelections[i].client != client))) (!pWin || (CurrentSelections[i].client != client)))
{ {
@ -1054,19 +1056,17 @@ ProcSetSelectionOwner(ClientPtr client)
CurrentSelections = newsels; CurrentSelections = newsels;
CurrentSelections[i].selection = stuff->selection; CurrentSelections[i].selection = stuff->selection;
CurrentSelections[i].devPrivates = NULL; CurrentSelections[i].devPrivates = NULL;
rc = XaceHook(XACE_SELECTION_ACCESS, CurrentSelections[i], rc = XaceHook(XACE_SELECTION_ACCESS, stuff->selection,
DixSetAttrAccess); CurrentSelections[i], DixSetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
} }
dixFreePrivates(CurrentSelections[i].devPrivates);
CurrentSelections[i].lastTimeChanged = time; CurrentSelections[i].lastTimeChanged = time;
CurrentSelections[i].window = stuff->window; CurrentSelections[i].window = stuff->window;
CurrentSelections[i].destwindow = stuff->window; CurrentSelections[i].destwindow = stuff->window;
CurrentSelections[i].pWin = pWin; CurrentSelections[i].pWin = pWin;
CurrentSelections[i].client = (pWin ? client : NullClient); CurrentSelections[i].client = (pWin ? client : NullClient);
CurrentSelections[i].destclient = (pWin ? client : NullClient); CurrentSelections[i].destclient = (pWin ? client : NullClient);
CurrentSelections[i].devPrivates = NULL;
if (SelectionCallback) if (SelectionCallback)
{ {
SelectionInfoRec info; SelectionInfoRec info;
@ -1092,7 +1092,7 @@ ProcGetSelectionOwner(ClientPtr client)
REQUEST_SIZE_MATCH(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq);
if (ValidAtom(stuff->id)) if (ValidAtom(stuff->id))
{ {
int i; int rc, i;
xGetSelectionOwnerReply reply; xGetSelectionOwnerReply reply;
i = 0; i = 0;
@ -1101,12 +1101,16 @@ ProcGetSelectionOwner(ClientPtr client)
reply.type = X_Reply; reply.type = X_Reply;
reply.length = 0; reply.length = 0;
reply.sequenceNumber = client->sequence; reply.sequenceNumber = client->sequence;
if (i < NumCurrentSelections && if (i < NumCurrentSelections)
XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i],
DixGetAttrAccess) == Success)
reply.owner = CurrentSelections[i].destwindow; reply.owner = CurrentSelections[i].destwindow;
else else
reply.owner = None; reply.owner = None;
rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->id, NULL,
DixGetAttrAccess);
if (rc != Success)
return rc;
WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply); WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
return(client->noClientException); return(client->noClientException);
} }
@ -1143,8 +1147,8 @@ ProcConvertSelection(ClientPtr client)
CurrentSelections[i].selection != stuff->selection) i++; CurrentSelections[i].selection != stuff->selection) i++;
if ((i < NumCurrentSelections) && if ((i < NumCurrentSelections) &&
(CurrentSelections[i].window != None) && (CurrentSelections[i].window != None) &&
XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i], XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
DixReadAccess) == Success) &CurrentSelections[i], DixReadAccess) == Success)
{ {
event.u.u.type = SelectionRequest; event.u.u.type = SelectionRequest;
event.u.selectionRequest.time = stuff->time; event.u.selectionRequest.time = stuff->time;

View File

@ -51,6 +51,7 @@
#include "servermd.h" #include "servermd.h"
#include "inputstr.h" #include "inputstr.h"
#include "windowstr.h" #include "windowstr.h"
#include "xace.h"
static RESTYPE CursorClientType; static RESTYPE CursorClientType;
static RESTYPE CursorHideCountType; static RESTYPE CursorHideCountType;
@ -238,7 +239,7 @@ ProcXFixesSelectCursorInput (ClientPtr client)
int rc; int rc;
REQUEST_SIZE_MATCH (xXFixesSelectCursorInputReq); REQUEST_SIZE_MATCH (xXFixesSelectCursorInputReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
if (stuff->eventMask & ~CursorAllEvents) if (stuff->eventMask & ~CursorAllEvents)
@ -343,14 +344,16 @@ ProcXFixesGetCursorImage (ClientPtr client)
xXFixesGetCursorImageReply *rep; xXFixesGetCursorImageReply *rep;
CursorPtr pCursor; CursorPtr pCursor;
CARD32 *image; CARD32 *image;
int npixels; int npixels, width, height, rc, x, y;
int width, height;
int x, y;
REQUEST_SIZE_MATCH(xXFixesGetCursorImageReq); REQUEST_SIZE_MATCH(xXFixesGetCursorImageReq);
pCursor = CursorCurrent; pCursor = CursorCurrent;
if (!pCursor) if (!pCursor)
return BadCursor; return BadCursor;
rc = XaceHook(XACE_RESOURCE_ACCESS, client, pCursor->id, RT_CURSOR,
DixReadAccess, pCursor);
if (rc != Success)
return rc;
GetSpritePosition (&x, &y); GetSpritePosition (&x, &y);
width = pCursor->bits->width; width = pCursor->bits->width;
height = pCursor->bits->height; height = pCursor->bits->height;
@ -411,7 +414,7 @@ ProcXFixesSetCursorName (ClientPtr client)
Atom atom; Atom atom;
REQUEST_AT_LEAST_SIZE(xXFixesSetCursorNameReq); REQUEST_AT_LEAST_SIZE(xXFixesSetCursorNameReq);
VERIFY_CURSOR(pCursor, stuff->cursor, client, DixWriteAccess); VERIFY_CURSOR(pCursor, stuff->cursor, client, DixSetAttrAccess);
tchar = (char *) &stuff[1]; tchar = (char *) &stuff[1];
atom = MakeAtom (tchar, stuff->nbytes, TRUE); atom = MakeAtom (tchar, stuff->nbytes, TRUE);
if (atom == BAD_RESOURCE) if (atom == BAD_RESOURCE)
@ -444,7 +447,7 @@ ProcXFixesGetCursorName (ClientPtr client)
int len; int len;
REQUEST_SIZE_MATCH(xXFixesGetCursorNameReq); REQUEST_SIZE_MATCH(xXFixesGetCursorNameReq);
VERIFY_CURSOR(pCursor, stuff->cursor, client, DixReadAccess); VERIFY_CURSOR(pCursor, stuff->cursor, client, DixGetAttrAccess);
if (pCursor->name) if (pCursor->name)
str = NameForAtom (pCursor->name); str = NameForAtom (pCursor->name);
else else
@ -493,12 +496,16 @@ ProcXFixesGetCursorImageAndName (ClientPtr client)
char *name; char *name;
int nbytes, nbytesRound; int nbytes, nbytesRound;
int width, height; int width, height;
int x, y; int rc, x, y;
REQUEST_SIZE_MATCH(xXFixesGetCursorImageAndNameReq); REQUEST_SIZE_MATCH(xXFixesGetCursorImageAndNameReq);
pCursor = CursorCurrent; pCursor = CursorCurrent;
if (!pCursor) if (!pCursor)
return BadCursor; return BadCursor;
rc = XaceHook(XACE_RESOURCE_ACCESS, client, pCursor->id, RT_CURSOR,
DixReadAccess|DixGetAttrAccess, pCursor);
if (rc != Success)
return rc;
GetSpritePosition (&x, &y); GetSpritePosition (&x, &y);
width = pCursor->bits->width; width = pCursor->bits->width;
height = pCursor->bits->height; height = pCursor->bits->height;
@ -675,8 +682,10 @@ ProcXFixesChangeCursor (ClientPtr client)
REQUEST(xXFixesChangeCursorReq); REQUEST(xXFixesChangeCursorReq);
REQUEST_SIZE_MATCH(xXFixesChangeCursorReq); REQUEST_SIZE_MATCH(xXFixesChangeCursorReq);
VERIFY_CURSOR (pSource, stuff->source, client, DixReadAccess); VERIFY_CURSOR (pSource, stuff->source, client,
VERIFY_CURSOR (pDestination, stuff->destination, client, DixWriteAccess); DixReadAccess|DixGetAttrAccess);
VERIFY_CURSOR (pDestination, stuff->destination, client,
DixWriteAccess|DixSetAttrAccess);
ReplaceCursor (pSource, TestForCursor, (pointer) pDestination); ReplaceCursor (pSource, TestForCursor, (pointer) pDestination);
return (client->noClientException); return (client->noClientException);
@ -710,7 +719,8 @@ ProcXFixesChangeCursorByName (ClientPtr client)
REQUEST(xXFixesChangeCursorByNameReq); REQUEST(xXFixesChangeCursorByNameReq);
REQUEST_FIXED_SIZE(xXFixesChangeCursorByNameReq, stuff->nbytes); REQUEST_FIXED_SIZE(xXFixesChangeCursorByNameReq, stuff->nbytes);
VERIFY_CURSOR(pSource, stuff->source, client, DixReadAccess); VERIFY_CURSOR(pSource, stuff->source, client,
DixReadAccess|DixGetAttrAccess);
tchar = (char *) &stuff[1]; tchar = (char *) &stuff[1];
name = MakeAtom (tchar, stuff->nbytes, FALSE); name = MakeAtom (tchar, stuff->nbytes, FALSE);
if (name) if (name)
@ -838,10 +848,11 @@ ProcXFixesHideCursor (ClientPtr client)
REQUEST_SIZE_MATCH (xXFixesHideCursorReq); REQUEST_SIZE_MATCH (xXFixesHideCursorReq);
pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW); ret = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW,
if (!pWin) { client, DixGetAttrAccess);
if (ret != Success) {
client->errorValue = stuff->window; client->errorValue = stuff->window;
return BadWindow; return (ret == BadValue) ? BadWindow : ret;
} }
/* /*
@ -859,6 +870,11 @@ ProcXFixesHideCursor (ClientPtr client)
* This is the first time this client has hid the cursor * This is the first time this client has hid the cursor
* for this screen. * for this screen.
*/ */
ret = XaceHook(XACE_SCREEN_ACCESS, client, pWin->drawable.pScreen,
DixHideAccess);
if (ret != Success)
return ret;
ret = createCursorHideCount(client, pWin->drawable.pScreen); ret = createCursorHideCount(client, pWin->drawable.pScreen);
if (ret == Success) { if (ret == Success) {
@ -885,14 +901,16 @@ ProcXFixesShowCursor (ClientPtr client)
{ {
WindowPtr pWin; WindowPtr pWin;
CursorHideCountPtr pChc; CursorHideCountPtr pChc;
int rc;
REQUEST(xXFixesShowCursorReq); REQUEST(xXFixesShowCursorReq);
REQUEST_SIZE_MATCH (xXFixesShowCursorReq); REQUEST_SIZE_MATCH (xXFixesShowCursorReq);
pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW); rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW,
if (!pWin) { client, DixGetAttrAccess);
if (rc != Success) {
client->errorValue = stuff->window; client->errorValue = stuff->window;
return BadWindow; return (rc == BadValue) ? BadWindow : rc;
} }
/* /*
@ -904,6 +922,11 @@ ProcXFixesShowCursor (ClientPtr client)
return BadMatch; return BadMatch;
} }
rc = XaceHook(XACE_SCREEN_ACCESS, client, pWin->drawable.pScreen,
DixShowAccess);
if (rc != Success)
return rc;
pChc->hideCount--; pChc->hideCount--;
if (pChc->hideCount <= 0) { if (pChc->hideCount <= 0) {
FreeResource(pChc->resource, 0); FreeResource(pChc->resource, 0);

View File

@ -109,18 +109,18 @@ ProcXFixesCreateRegionFromBitmap (ClientPtr client)
{ {
RegionPtr pRegion; RegionPtr pRegion;
PixmapPtr pPixmap; PixmapPtr pPixmap;
int rc;
REQUEST (xXFixesCreateRegionFromBitmapReq); REQUEST (xXFixesCreateRegionFromBitmapReq);
REQUEST_SIZE_MATCH (xXFixesCreateRegionFromBitmapReq); REQUEST_SIZE_MATCH (xXFixesCreateRegionFromBitmapReq);
LEGAL_NEW_RESOURCE (stuff->region, client); LEGAL_NEW_RESOURCE (stuff->region, client);
pPixmap = (PixmapPtr) SecurityLookupIDByType (client, stuff->bitmap, rc = dixLookupResource((pointer *)&pPixmap, stuff->bitmap, RT_PIXMAP,
RT_PIXMAP, client, DixReadAccess);
DixReadAccess); if (rc != Success)
if (!pPixmap)
{ {
client->errorValue = stuff->bitmap; client->errorValue = stuff->bitmap;
return BadPixmap; return (rc == BadValue) ? BadPixmap : rc;
} }
if (pPixmap->drawable.depth != 1) if (pPixmap->drawable.depth != 1)
return BadMatch; return BadMatch;
@ -155,15 +155,17 @@ ProcXFixesCreateRegionFromWindow (ClientPtr client)
RegionPtr pRegion; RegionPtr pRegion;
Bool copy = TRUE; Bool copy = TRUE;
WindowPtr pWin; WindowPtr pWin;
int rc;
REQUEST (xXFixesCreateRegionFromWindowReq); REQUEST (xXFixesCreateRegionFromWindowReq);
REQUEST_SIZE_MATCH (xXFixesCreateRegionFromWindowReq); REQUEST_SIZE_MATCH (xXFixesCreateRegionFromWindowReq);
LEGAL_NEW_RESOURCE (stuff->region, client); LEGAL_NEW_RESOURCE (stuff->region, client);
pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW); rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW,
if (!pWin) client, DixGetAttrAccess);
if (rc != Success)
{ {
client->errorValue = stuff->window; client->errorValue = stuff->window;
return BadWindow; return (rc == BadValue) ? BadWindow : rc;
} }
switch (stuff->kind) { switch (stuff->kind) {
case WindowRegionBounding: case WindowRegionBounding:
@ -224,7 +226,7 @@ ProcXFixesCreateRegionFromGC (ClientPtr client)
REQUEST_SIZE_MATCH (xXFixesCreateRegionFromGCReq); REQUEST_SIZE_MATCH (xXFixesCreateRegionFromGCReq);
LEGAL_NEW_RESOURCE (stuff->region, client); LEGAL_NEW_RESOURCE (stuff->region, client);
rc = dixLookupGC(&pGC, stuff->gc, client, DixReadAccess); rc = dixLookupGC(&pGC, stuff->gc, client, DixGetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -274,7 +276,7 @@ ProcXFixesCreateRegionFromPicture (ClientPtr client)
REQUEST_SIZE_MATCH (xXFixesCreateRegionFromPictureReq); REQUEST_SIZE_MATCH (xXFixesCreateRegionFromPictureReq);
LEGAL_NEW_RESOURCE (stuff->region, client); LEGAL_NEW_RESOURCE (stuff->region, client);
VERIFY_PICTURE(pPicture, stuff->picture, client, DixReadAccess, VERIFY_PICTURE(pPicture, stuff->picture, client, DixGetAttrAccess,
RenderErrBase + BadPicture); RenderErrBase + BadPicture);
switch (pPicture->clientClipType) { switch (pPicture->clientClipType) {
@ -635,7 +637,7 @@ ProcXFixesSetGCClipRegion (ClientPtr client)
REQUEST(xXFixesSetGCClipRegionReq); REQUEST(xXFixesSetGCClipRegionReq);
REQUEST_SIZE_MATCH(xXFixesSetGCClipRegionReq); REQUEST_SIZE_MATCH(xXFixesSetGCClipRegionReq);
rc = dixLookupGC(&pGC, stuff->gc, client, DixWriteAccess); rc = dixLookupGC(&pGC, stuff->gc, client, DixSetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -681,14 +683,16 @@ ProcXFixesSetWindowShapeRegion (ClientPtr client)
ScreenPtr pScreen; ScreenPtr pScreen;
RegionPtr pRegion; RegionPtr pRegion;
RegionPtr *pDestRegion; RegionPtr *pDestRegion;
int rc;
REQUEST(xXFixesSetWindowShapeRegionReq); REQUEST(xXFixesSetWindowShapeRegionReq);
REQUEST_SIZE_MATCH(xXFixesSetWindowShapeRegionReq); REQUEST_SIZE_MATCH(xXFixesSetWindowShapeRegionReq);
pWin = (WindowPtr) LookupIDByType (stuff->dest, RT_WINDOW); rc = dixLookupResource((pointer *)&pWin, stuff->dest, RT_WINDOW,
if (!pWin) client, DixSetAttrAccess);
if (rc != Success)
{ {
client->errorValue = stuff->dest; client->errorValue = stuff->dest;
return BadWindow; return (rc == BadValue) ? BadWindow : rc;
} }
VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, DixWriteAccess); VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, DixWriteAccess);
pScreen = pWin->drawable.pScreen; pScreen = pWin->drawable.pScreen;
@ -780,7 +784,7 @@ ProcXFixesSetPictureClipRegion (ClientPtr client)
REQUEST(xXFixesSetPictureClipRegionReq); REQUEST(xXFixesSetPictureClipRegionReq);
REQUEST_SIZE_MATCH (xXFixesSetPictureClipRegionReq); REQUEST_SIZE_MATCH (xXFixesSetPictureClipRegionReq);
VERIFY_PICTURE(pPicture, stuff->picture, client, DixWriteAccess, VERIFY_PICTURE(pPicture, stuff->picture, client, DixSetAttrAccess,
RenderErrBase + BadPicture); RenderErrBase + BadPicture);
pScreen = pPicture->pDrawable->pScreen; pScreen = pPicture->pDrawable->pScreen;
ps = GetPictureScreen (pScreen); ps = GetPictureScreen (pScreen);

View File

@ -35,7 +35,7 @@ ProcXFixesChangeSaveSet(ClientPtr client)
REQUEST(xXFixesChangeSaveSetReq); REQUEST(xXFixesChangeSaveSetReq);
REQUEST_SIZE_MATCH(xXFixesChangeSaveSetReq); REQUEST_SIZE_MATCH(xXFixesChangeSaveSetReq);
result = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); result = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess);
if (result != Success) if (result != Success)
return result; return result;
if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id))) if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id)))

View File

@ -25,6 +25,7 @@
#endif #endif
#include "xfixesint.h" #include "xfixesint.h"
#include "xace.h"
static RESTYPE SelectionClientType, SelectionWindowType; static RESTYPE SelectionClientType, SelectionWindowType;
static Bool SelectionCallbackRegistered = FALSE; static Bool SelectionCallbackRegistered = FALSE;
@ -131,8 +132,14 @@ XFixesSelectSelectionInput (ClientPtr pClient,
WindowPtr pWindow, WindowPtr pWindow,
CARD32 eventMask) CARD32 eventMask)
{ {
int rc;
SelectionEventPtr *prev, e; SelectionEventPtr *prev, e;
rc = XaceHook(XACE_SELECTION_ACCESS, pClient, selection, NULL,
DixGetAttrAccess);
if (rc != Success)
return rc;
for (prev = &selectionEvents; (e = *prev); prev = &e->next) for (prev = &selectionEvents; (e = *prev); prev = &e->next)
{ {
if (e->selection == selection && if (e->selection == selection &&
@ -196,7 +203,7 @@ ProcXFixesSelectSelectionInput (ClientPtr client)
int rc; int rc;
REQUEST_SIZE_MATCH (xXFixesSelectSelectionInputReq); REQUEST_SIZE_MATCH (xXFixesSelectSelectionInputReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
if (stuff->eventMask & ~SelectionAllEvents) if (stuff->eventMask & ~SelectionAllEvents)