2004-06-01 21:09:25 +00:00
|
|
|
/************************************************************
|
|
|
|
|
|
2009-09-02 17:56:52 -04:00
|
|
|
Author: Eamon Walsh <ewalsh@tycho.nsa.gov>
|
2004-06-01 21:09:25 +00:00
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
|
this permission notice appear in supporting documentation. This permission
|
|
|
|
|
notice shall be included in all copies or substantial portions of the
|
|
|
|
|
Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
********************************************************/
|
|
|
|
|
|
2006-09-08 15:23:06 -04:00
|
|
|
#include <dix-config.h>
|
|
|
|
|
|
2004-06-01 21:09:25 +00:00
|
|
|
#include <stdarg.h>
|
2025-02-13 16:58:21 +01:00
|
|
|
|
|
|
|
|
#include "os/client_priv.h"
|
|
|
|
|
|
2004-06-01 21:09:25 +00:00
|
|
|
#include "scrnintstr.h"
|
2008-02-05 21:06:05 -05:00
|
|
|
#include "extnsionst.h"
|
|
|
|
|
#include "pixmapstr.h"
|
|
|
|
|
#include "regionstr.h"
|
|
|
|
|
#include "gcstruct.h"
|
2004-06-01 21:09:25 +00:00
|
|
|
#include "xacestr.h"
|
|
|
|
|
|
2024-02-06 16:43:50 +01:00
|
|
|
CallbackListPtr XaceHooks[XACE_NUM_HOOKS] = { 0 };
|
2004-06-01 21:09:25 +00:00
|
|
|
|
2007-11-06 16:26:09 -05:00
|
|
|
/* Special-cased hook functions. Called by Xserver.
|
|
|
|
|
*/
|
2008-01-25 17:28:17 -05:00
|
|
|
int
|
2024-05-15 20:20:10 +02:00
|
|
|
XaceHookDispatch0(ClientPtr client, int major)
|
2007-11-06 16:26:09 -05:00
|
|
|
{
|
2016-04-29 14:22:52 -04:00
|
|
|
/* Call the extension dispatch hook */
|
|
|
|
|
ExtensionEntry *ext = GetExtensionEntry(major);
|
|
|
|
|
XaceExtAccessRec erec = { client, ext, DixUseAccess, Success };
|
|
|
|
|
if (ext)
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_EXT_DISPATCH], &erec);
|
|
|
|
|
/* On error, pretend extension doesn't exist */
|
|
|
|
|
return (erec.status == Success) ? Success : BadRequest;
|
2007-11-06 16:26:09 -05:00
|
|
|
}
|
|
|
|
|
|
2008-02-05 20:07:08 -05:00
|
|
|
int
|
|
|
|
|
XaceHookPropertyAccess(ClientPtr client, WindowPtr pWin,
|
2008-02-29 17:55:31 -05:00
|
|
|
PropertyPtr *ppProp, Mask access_mode)
|
2008-02-05 20:07:08 -05:00
|
|
|
{
|
2008-02-29 17:55:31 -05:00
|
|
|
XacePropertyAccessRec rec = { client, pWin, ppProp, access_mode, Success };
|
2008-02-05 20:07:08 -05:00
|
|
|
CallCallbacks(&XaceHooks[XACE_PROPERTY_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-29 17:55:31 -05:00
|
|
|
int
|
|
|
|
|
XaceHookSelectionAccess(ClientPtr client, Selection ** ppSel, Mask access_mode)
|
2008-02-12 19:59:10 -05:00
|
|
|
{
|
2008-02-29 17:55:31 -05:00
|
|
|
XaceSelectionAccessRec rec = { client, ppSel, access_mode, Success };
|
2008-02-12 19:59:10 -05:00
|
|
|
CallCallbacks(&XaceHooks[XACE_SELECTION_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 17:49:33 +02:00
|
|
|
int XaceHookResourceAccess(ClientPtr client, XID id, RESTYPE rtype, void *res,
|
|
|
|
|
RESTYPE ptype, void *parent, Mask access_mode)
|
|
|
|
|
{
|
|
|
|
|
XaceResourceAccessRec rec = { client, id, rtype, res, ptype, parent,
|
|
|
|
|
access_mode, Success };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_RESOURCE_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 20:15:56 +02:00
|
|
|
int XaceHookDeviceAccess(ClientPtr client, DeviceIntPtr dev, Mask access_mode)
|
|
|
|
|
{
|
|
|
|
|
XaceDeviceAccessRec rec = { client, dev, access_mode, Success };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_DEVICE_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 20:34:50 +02:00
|
|
|
int XaceHookSendAccess(ClientPtr client, DeviceIntPtr dev, WindowPtr win,
|
|
|
|
|
xEventPtr ev, int count)
|
|
|
|
|
{
|
|
|
|
|
XaceSendAccessRec rec = { client, dev, win, ev, count, Success };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_SEND_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 08:55:58 +02:00
|
|
|
int XaceHookReceiveAccess(ClientPtr client, WindowPtr win,
|
|
|
|
|
xEventPtr ev, int count)
|
|
|
|
|
{
|
|
|
|
|
XaceReceiveAccessRec rec = { client, win, ev, count, Success };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_RECEIVE_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 14:18:28 +02:00
|
|
|
int XaceHookClientAccess(ClientPtr client, ClientPtr target, Mask access_mode)
|
|
|
|
|
{
|
|
|
|
|
XaceClientAccessRec rec = { client, target, access_mode, Success };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_CLIENT_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 15:06:19 +02:00
|
|
|
int XaceHookExtAccess(ClientPtr client, ExtensionEntry *ext)
|
|
|
|
|
{
|
|
|
|
|
XaceExtAccessRec rec = { client, ext, DixGetAttrAccess, Success };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_EXT_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 15:17:27 +02:00
|
|
|
int XaceHookServerAccess(ClientPtr client, Mask access_mode)
|
|
|
|
|
{
|
|
|
|
|
XaceServerAccessRec rec = { client, access_mode, Success };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_SERVER_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 15:22:46 +02:00
|
|
|
int XaceHookScreenAccess(ClientPtr client, ScreenPtr screen, Mask access_mode)
|
|
|
|
|
{
|
|
|
|
|
XaceScreenAccessRec rec = { client, screen, access_mode, Success };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_SCREEN_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 15:33:21 +02:00
|
|
|
int XaceHookScreensaverAccess(ClientPtr client, ScreenPtr screen, Mask access_mode)
|
|
|
|
|
{
|
|
|
|
|
XaceScreenAccessRec rec = { client, screen, access_mode, Success };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_SCREENSAVER_ACCESS], &rec);
|
|
|
|
|
return rec.status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 15:41:45 +02:00
|
|
|
int XaceHookAuthAvail(ClientPtr client, XID authId)
|
|
|
|
|
{
|
|
|
|
|
XaceAuthAvailRec rec = { client, authId };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_AUTH_AVAIL], &rec);
|
|
|
|
|
return Success;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 15:41:45 +02:00
|
|
|
int XaceHookKeyAvail(xEventPtr ev, DeviceIntPtr dev, int count)
|
2004-06-01 21:09:25 +00:00
|
|
|
{
|
2024-05-17 15:41:45 +02:00
|
|
|
XaceKeyAvailRec rec = { ev, dev, count };
|
|
|
|
|
CallCallbacks(&XaceHooks[XACE_KEY_AVAIL], &rec);
|
|
|
|
|
return Success;
|
2004-06-01 21:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-04 13:23:19 -05:00
|
|
|
/* XaceHookIsSet
|
|
|
|
|
*
|
|
|
|
|
* Utility function to determine whether there are any callbacks listening on a
|
|
|
|
|
* particular XACE hook.
|
|
|
|
|
*
|
|
|
|
|
* Returns non-zero if there is a callback, zero otherwise.
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
XaceHookIsSet(int hook)
|
|
|
|
|
{
|
|
|
|
|
if (hook < 0 || hook >= XACE_NUM_HOOKS)
|
|
|
|
|
return 0;
|
|
|
|
|
return XaceHooks[hook] != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-01 21:09:25 +00:00
|
|
|
/* XaceCensorImage
|
|
|
|
|
*
|
|
|
|
|
* Called after pScreen->GetImage to prevent pieces or trusted windows from
|
|
|
|
|
* being returned in image data from an untrusted window.
|
|
|
|
|
*
|
|
|
|
|
* Arguments:
|
|
|
|
|
* client is the client doing the GetImage.
|
|
|
|
|
* pVisibleRegion is the visible region of the window.
|
|
|
|
|
* widthBytesLine is the width in bytes of one horizontal line in pBuf.
|
|
|
|
|
* pDraw is the source window.
|
|
|
|
|
* x, y, w, h is the rectangle of image data from pDraw in pBuf.
|
|
|
|
|
* format is the format of the image data in pBuf: ZPixmap or XYPixmap.
|
|
|
|
|
* pBuf is the image data.
|
|
|
|
|
*
|
|
|
|
|
* Returns: nothing.
|
|
|
|
|
*
|
|
|
|
|
* Side Effects:
|
|
|
|
|
* Any part of the rectangle (x, y, w, h) that is outside the visible
|
|
|
|
|
* region of the window will be destroyed (overwritten) in pBuf.
|
|
|
|
|
*/
|
|
|
|
|
void
|
2009-01-11 08:16:12 +01:00
|
|
|
XaceCensorImage(ClientPtr client,
|
|
|
|
|
RegionPtr pVisibleRegion,
|
|
|
|
|
long widthBytesLine,
|
|
|
|
|
DrawablePtr pDraw,
|
|
|
|
|
int x, int y, int w, int h, unsigned int format, char *pBuf)
|
2004-06-01 21:09:25 +00:00
|
|
|
{
|
|
|
|
|
RegionRec imageRegion; /* region representing x,y,w,h */
|
|
|
|
|
RegionRec censorRegion; /* region to obliterate */
|
|
|
|
|
BoxRec imageBox;
|
|
|
|
|
int nRects;
|
|
|
|
|
|
2016-09-25 14:19:08 +03:00
|
|
|
imageBox.x1 = pDraw->x + x;
|
|
|
|
|
imageBox.y1 = pDraw->y + y;
|
|
|
|
|
imageBox.x2 = pDraw->x + x + w;
|
|
|
|
|
imageBox.y2 = pDraw->y + y + h;
|
2010-05-21 15:05:48 -07:00
|
|
|
RegionInit(&imageRegion, &imageBox, 1);
|
|
|
|
|
RegionNull(&censorRegion);
|
2004-06-01 21:09:25 +00:00
|
|
|
|
|
|
|
|
/* censorRegion = imageRegion - visibleRegion */
|
2010-05-21 15:05:48 -07:00
|
|
|
RegionSubtract(&censorRegion, &imageRegion, pVisibleRegion);
|
|
|
|
|
nRects = RegionNumRects(&censorRegion);
|
2004-06-01 21:09:25 +00:00
|
|
|
if (nRects > 0) { /* we have something to censor */
|
|
|
|
|
GCPtr pScratchGC = NULL;
|
|
|
|
|
PixmapPtr pPix = NULL;
|
|
|
|
|
xRectangle *pRects = NULL;
|
|
|
|
|
Bool failed = FALSE;
|
|
|
|
|
int depth = 1;
|
|
|
|
|
int bitsPerPixel = 1;
|
|
|
|
|
int i;
|
|
|
|
|
BoxPtr pBox;
|
2012-03-21 12:55:09 -07:00
|
|
|
|
2004-06-01 21:09:25 +00:00
|
|
|
/* convert region to list-of-rectangles for PolyFillRect */
|
2012-03-21 12:55:09 -07:00
|
|
|
|
2010-05-06 01:44:06 +07:00
|
|
|
pRects = malloc(nRects * sizeof(xRectangle));
|
2004-06-01 21:09:25 +00:00
|
|
|
if (!pRects) {
|
|
|
|
|
failed = TRUE;
|
|
|
|
|
goto failSafe;
|
|
|
|
|
}
|
2010-05-21 15:05:48 -07:00
|
|
|
for (pBox = RegionRects(&censorRegion), i = 0; i < nRects; i++, pBox++) {
|
2016-09-25 14:19:08 +03:00
|
|
|
pRects[i].x = pBox->x1 - imageBox.x1;
|
|
|
|
|
pRects[i].y = pBox->y1 - imageBox.y1;
|
2004-06-01 21:09:25 +00:00
|
|
|
pRects[i].width = pBox->x2 - pBox->x1;
|
|
|
|
|
pRects[i].height = pBox->y2 - pBox->y1;
|
|
|
|
|
}
|
2012-03-21 12:55:09 -07:00
|
|
|
|
2004-06-01 21:09:25 +00:00
|
|
|
/* use pBuf as a fake pixmap */
|
2012-03-21 12:55:09 -07:00
|
|
|
|
2004-06-01 21:09:25 +00:00
|
|
|
if (format == ZPixmap) {
|
|
|
|
|
depth = pDraw->depth;
|
|
|
|
|
bitsPerPixel = pDraw->bitsPerPixel;
|
|
|
|
|
}
|
2012-03-21 12:55:09 -07:00
|
|
|
|
2004-06-01 21:09:25 +00:00
|
|
|
pPix = GetScratchPixmapHeader(pDraw->pScreen, w, h,
|
|
|
|
|
depth, bitsPerPixel,
|
2013-12-15 01:05:51 -08:00
|
|
|
widthBytesLine, (void *) pBuf);
|
2004-06-01 21:09:25 +00:00
|
|
|
if (!pPix) {
|
|
|
|
|
failed = TRUE;
|
|
|
|
|
goto failSafe;
|
|
|
|
|
}
|
2012-03-21 12:55:09 -07:00
|
|
|
|
2004-06-01 21:09:25 +00:00
|
|
|
pScratchGC = GetScratchGC(depth, pPix->drawable.pScreen);
|
|
|
|
|
if (!pScratchGC) {
|
|
|
|
|
failed = TRUE;
|
|
|
|
|
goto failSafe;
|
|
|
|
|
}
|
2012-03-21 12:55:09 -07:00
|
|
|
|
2004-06-01 21:09:25 +00:00
|
|
|
ValidateGC(&pPix->drawable, pScratchGC);
|
|
|
|
|
(*pScratchGC->ops->PolyFillRect) (&pPix->drawable,
|
|
|
|
|
pScratchGC, nRects, pRects);
|
2012-03-21 12:55:09 -07:00
|
|
|
|
2004-06-01 21:09:25 +00:00
|
|
|
failSafe:
|
|
|
|
|
if (failed) {
|
|
|
|
|
/* Censoring was not completed above. To be safe, wipe out
|
|
|
|
|
* all the image data so that nothing trusted gets out.
|
|
|
|
|
*/
|
2010-06-04 15:35:31 +07:00
|
|
|
memset(pBuf, 0, (int) (widthBytesLine * h));
|
2004-06-01 21:09:25 +00:00
|
|
|
}
|
2010-06-06 15:28:30 +07:00
|
|
|
free(pRects);
|
2004-06-01 21:09:25 +00:00
|
|
|
if (pScratchGC)
|
|
|
|
|
FreeScratchGC(pScratchGC);
|
|
|
|
|
if (pPix)
|
|
|
|
|
FreeScratchPixmapHeader(pPix);
|
|
|
|
|
}
|
2010-05-21 15:05:48 -07:00
|
|
|
RegionUninit(&imageRegion);
|
|
|
|
|
RegionUninit(&censorRegion);
|
2004-06-01 21:09:25 +00:00
|
|
|
} /* XaceCensorImage */
|
2008-12-18 13:58:35 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Xtrans wrappers for use by modules
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
XaceGetConnectionNumber(ClientPtr client)
|
|
|
|
|
{
|
2015-09-21 07:16:14 +01:00
|
|
|
return GetClientFd(client);
|
2008-12-18 13:58:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
XaceIsLocal(ClientPtr client)
|
|
|
|
|
{
|
2015-09-21 07:16:14 +01:00
|
|
|
return ClientIsLocal(client);
|
2008-12-18 13:58:35 -05:00
|
|
|
}
|