2004-06-01 23:09:25 +02:00
|
|
|
/************************************************************
|
|
|
|
|
2009-09-02 23:56:52 +02:00
|
|
|
Author: Eamon Walsh <ewalsh@tycho.nsa.gov>
|
2004-06-01 23:09:25 +02: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 21:23:06 +02:00
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2004-06-01 23:09:25 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include "scrnintstr.h"
|
2008-02-06 03:06:05 +01:00
|
|
|
#include "extnsionst.h"
|
|
|
|
#include "pixmapstr.h"
|
|
|
|
#include "regionstr.h"
|
|
|
|
#include "gcstruct.h"
|
2004-06-01 23:09:25 +02:00
|
|
|
#include "xacestr.h"
|
|
|
|
|
2008-12-18 19:58:35 +01:00
|
|
|
#define XSERV_t
|
|
|
|
#define TRANS_SERVER
|
|
|
|
#include <X11/Xtrans/Xtrans.h>
|
|
|
|
#include "../os/osdep.h"
|
|
|
|
|
2008-12-18 18:35:57 +01:00
|
|
|
_X_EXPORT CallbackListPtr XaceHooks[XACE_NUM_HOOKS] = {0};
|
2004-06-01 23:09:25 +02:00
|
|
|
|
2007-11-06 22:26:09 +01:00
|
|
|
/* Special-cased hook functions. Called by Xserver.
|
|
|
|
*/
|
2008-01-25 23:28:17 +01:00
|
|
|
int XaceHookDispatch(ClientPtr client, int major)
|
2007-11-06 22:26:09 +01:00
|
|
|
{
|
2008-01-25 23:28:17 +01:00
|
|
|
/* Call the audit begin callback, there is no return value. */
|
|
|
|
XaceAuditRec rec = { client, 0 };
|
2007-11-06 22:26:09 +01:00
|
|
|
CallCallbacks(&XaceHooks[XACE_AUDIT_BEGIN], &rec);
|
2008-01-25 23:28:17 +01:00
|
|
|
|
|
|
|
if (major < 128) {
|
|
|
|
/* Call the core dispatch hook */
|
|
|
|
XaceCoreDispatchRec rec = { client, Success /* default allow */ };
|
|
|
|
CallCallbacks(&XaceHooks[XACE_CORE_DISPATCH], &rec);
|
|
|
|
return rec.status;
|
|
|
|
} else {
|
|
|
|
/* Call the extension dispatch hook */
|
|
|
|
ExtensionEntry *ext = GetExtensionEntry(major);
|
|
|
|
XaceExtAccessRec rec = { client, ext, DixUseAccess, Success };
|
|
|
|
if (ext)
|
|
|
|
CallCallbacks(&XaceHooks[XACE_EXT_DISPATCH], &rec);
|
|
|
|
/* On error, pretend extension doesn't exist */
|
|
|
|
return (rec.status == Success) ? Success : BadRequest;
|
|
|
|
}
|
2007-11-06 22:26:09 +01:00
|
|
|
}
|
|
|
|
|
2008-02-06 02:07:08 +01:00
|
|
|
int XaceHookPropertyAccess(ClientPtr client, WindowPtr pWin,
|
2008-02-29 23:55:31 +01:00
|
|
|
PropertyPtr *ppProp, Mask access_mode)
|
2008-02-06 02:07:08 +01:00
|
|
|
{
|
2008-02-29 23:55:31 +01:00
|
|
|
XacePropertyAccessRec rec = { client, pWin, ppProp, access_mode, Success };
|
2008-02-06 02:07:08 +01:00
|
|
|
CallCallbacks(&XaceHooks[XACE_PROPERTY_ACCESS], &rec);
|
|
|
|
return rec.status;
|
|
|
|
}
|
|
|
|
|
2008-02-29 23:55:31 +01:00
|
|
|
int XaceHookSelectionAccess(ClientPtr client,
|
|
|
|
Selection **ppSel, Mask access_mode)
|
2008-02-13 01:59:10 +01:00
|
|
|
{
|
2008-02-29 23:55:31 +01:00
|
|
|
XaceSelectionAccessRec rec = { client, ppSel, access_mode, Success };
|
2008-02-13 01:59:10 +01:00
|
|
|
CallCallbacks(&XaceHooks[XACE_SELECTION_ACCESS], &rec);
|
|
|
|
return rec.status;
|
|
|
|
}
|
|
|
|
|
2007-11-06 22:26:09 +01:00
|
|
|
void XaceHookAuditEnd(ClientPtr ptr, int result)
|
|
|
|
{
|
|
|
|
XaceAuditRec rec = { ptr, result };
|
|
|
|
/* call callbacks, there is no return value. */
|
|
|
|
CallCallbacks(&XaceHooks[XACE_AUDIT_END], &rec);
|
|
|
|
}
|
|
|
|
|
2004-06-01 23:09:25 +02:00
|
|
|
/* Entry point for hook functions. Called by Xserver.
|
|
|
|
*/
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
int XaceHook(int hook, ...)
|
2004-06-01 23:09:25 +02:00
|
|
|
{
|
2010-08-10 20:30:20 +02:00
|
|
|
union {
|
|
|
|
XaceResourceAccessRec res;
|
|
|
|
XaceDeviceAccessRec dev;
|
|
|
|
XaceSendAccessRec send;
|
|
|
|
XaceReceiveAccessRec recv;
|
|
|
|
XaceClientAccessRec client;
|
|
|
|
XaceExtAccessRec ext;
|
|
|
|
XaceServerAccessRec server;
|
|
|
|
XaceScreenAccessRec screen;
|
|
|
|
XaceAuthAvailRec auth;
|
|
|
|
XaceKeyAvailRec key;
|
|
|
|
} u;
|
2004-06-01 23:09:25 +02:00
|
|
|
int *prv = NULL; /* points to return value from callback */
|
|
|
|
va_list ap; /* argument list */
|
|
|
|
va_start(ap, hook);
|
|
|
|
|
|
|
|
/* Marshal arguments for passing to callback.
|
|
|
|
* Each callback has its own case, which sets up a structure to hold
|
|
|
|
* the arguments and integer return parameter, or in some cases just
|
|
|
|
* sets calldata directly to a single argument (with no return result)
|
|
|
|
*/
|
|
|
|
switch (hook)
|
|
|
|
{
|
2010-08-10 20:30:20 +02:00
|
|
|
case XACE_RESOURCE_ACCESS:
|
|
|
|
u.res.client = va_arg(ap, ClientPtr);
|
|
|
|
u.res.id = va_arg(ap, XID);
|
|
|
|
u.res.rtype = va_arg(ap, RESTYPE);
|
|
|
|
u.res.res = va_arg(ap, pointer);
|
|
|
|
u.res.ptype = va_arg(ap, RESTYPE);
|
|
|
|
u.res.parent = va_arg(ap, pointer);
|
|
|
|
u.res.access_mode = va_arg(ap, Mask);
|
|
|
|
u.res.status = Success; /* default allow */
|
|
|
|
prv = &u.res.status;
|
2004-06-01 23:09:25 +02:00
|
|
|
break;
|
2010-08-10 20:30:20 +02:00
|
|
|
case XACE_DEVICE_ACCESS:
|
|
|
|
u.dev.client = va_arg(ap, ClientPtr);
|
|
|
|
u.dev.dev = va_arg(ap, DeviceIntPtr);
|
|
|
|
u.dev.access_mode = va_arg(ap, Mask);
|
|
|
|
u.dev.status = Success; /* default allow */
|
|
|
|
prv = &u.dev.status;
|
2004-06-01 23:09:25 +02:00
|
|
|
break;
|
2010-08-10 20:30:20 +02:00
|
|
|
case XACE_SEND_ACCESS:
|
|
|
|
u.send.client = va_arg(ap, ClientPtr);
|
|
|
|
u.send.dev = va_arg(ap, DeviceIntPtr);
|
|
|
|
u.send.pWin = va_arg(ap, WindowPtr);
|
|
|
|
u.send.events = va_arg(ap, xEventPtr);
|
|
|
|
u.send.count = va_arg(ap, int);
|
|
|
|
u.send.status = Success; /* default allow */
|
|
|
|
prv = &u.send.status;
|
2007-08-29 20:16:46 +02:00
|
|
|
break;
|
2010-08-10 20:30:20 +02:00
|
|
|
case XACE_RECEIVE_ACCESS:
|
|
|
|
u.recv.client = va_arg(ap, ClientPtr);
|
|
|
|
u.recv.pWin = va_arg(ap, WindowPtr);
|
|
|
|
u.recv.events = va_arg(ap, xEventPtr);
|
|
|
|
u.recv.count = va_arg(ap, int);
|
|
|
|
u.recv.status = Success; /* default allow */
|
|
|
|
prv = &u.recv.status;
|
2004-06-01 23:09:25 +02:00
|
|
|
break;
|
2010-08-10 20:30:20 +02:00
|
|
|
case XACE_CLIENT_ACCESS:
|
|
|
|
u.client.client = va_arg(ap, ClientPtr);
|
|
|
|
u.client.target = va_arg(ap, ClientPtr);
|
|
|
|
u.client.access_mode = va_arg(ap, Mask);
|
|
|
|
u.client.status = Success; /* default allow */
|
|
|
|
prv = &u.client.status;
|
2007-08-16 16:44:51 +02:00
|
|
|
break;
|
2010-08-10 20:30:20 +02:00
|
|
|
case XACE_EXT_ACCESS:
|
|
|
|
u.ext.client = va_arg(ap, ClientPtr);
|
|
|
|
u.ext.ext = va_arg(ap, ExtensionEntry*);
|
|
|
|
u.ext.access_mode = DixGetAttrAccess;
|
|
|
|
u.ext.status = Success; /* default allow */
|
|
|
|
prv = &u.ext.status;
|
2004-06-01 23:09:25 +02:00
|
|
|
break;
|
2010-08-10 20:30:20 +02:00
|
|
|
case XACE_SERVER_ACCESS:
|
|
|
|
u.server.client = va_arg(ap, ClientPtr);
|
|
|
|
u.server.access_mode = va_arg(ap, Mask);
|
|
|
|
u.server.status = Success; /* default allow */
|
|
|
|
prv = &u.server.status;
|
2007-03-21 19:39:00 +01:00
|
|
|
break;
|
2007-08-06 15:16:30 +02:00
|
|
|
case XACE_SCREEN_ACCESS:
|
2010-08-10 20:30:20 +02:00
|
|
|
case XACE_SCREENSAVER_ACCESS:
|
|
|
|
u.screen.client = va_arg(ap, ClientPtr);
|
|
|
|
u.screen.screen = va_arg(ap, ScreenPtr);
|
|
|
|
u.screen.access_mode = va_arg(ap, Mask);
|
|
|
|
u.screen.status = Success; /* default allow */
|
|
|
|
prv = &u.screen.status;
|
2004-06-01 23:09:25 +02:00
|
|
|
break;
|
2010-08-10 20:30:20 +02:00
|
|
|
case XACE_AUTH_AVAIL:
|
|
|
|
u.auth.client = va_arg(ap, ClientPtr);
|
|
|
|
u.auth.authId = va_arg(ap, XID);
|
2004-06-01 23:09:25 +02:00
|
|
|
break;
|
2010-08-10 20:30:20 +02:00
|
|
|
case XACE_KEY_AVAIL:
|
|
|
|
u.key.event = va_arg(ap, xEventPtr);
|
|
|
|
u.key.keybd = va_arg(ap, DeviceIntPtr);
|
|
|
|
u.key.count = va_arg(ap, int);
|
2006-08-26 00:17:01 +02:00
|
|
|
break;
|
2010-08-10 20:30:20 +02:00
|
|
|
default:
|
2004-06-01 23:09:25 +02:00
|
|
|
va_end(ap);
|
|
|
|
return 0; /* unimplemented hook number */
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
/* call callbacks and return result, if any. */
|
2010-08-10 20:30:20 +02:00
|
|
|
CallCallbacks(&XaceHooks[hook], &u);
|
2007-10-17 19:51:11 +02:00
|
|
|
return prv ? *prv : Success;
|
2004-06-01 23:09:25 +02: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 23:09:25 +02:00
|
|
|
{
|
|
|
|
RegionRec imageRegion; /* region representing x,y,w,h */
|
|
|
|
RegionRec censorRegion; /* region to obliterate */
|
|
|
|
BoxRec imageBox;
|
|
|
|
int nRects;
|
|
|
|
|
|
|
|
imageBox.x1 = x;
|
|
|
|
imageBox.y1 = y;
|
|
|
|
imageBox.x2 = x + w;
|
|
|
|
imageBox.y2 = y + h;
|
2010-05-22 00:05:48 +02:00
|
|
|
RegionInit(&imageRegion, &imageBox, 1);
|
|
|
|
RegionNull(&censorRegion);
|
2004-06-01 23:09:25 +02:00
|
|
|
|
|
|
|
/* censorRegion = imageRegion - visibleRegion */
|
2010-05-22 00:05:48 +02:00
|
|
|
RegionSubtract(&censorRegion, &imageRegion, pVisibleRegion);
|
|
|
|
nRects = RegionNumRects(&censorRegion);
|
2004-06-01 23:09:25 +02: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;
|
|
|
|
|
|
|
|
/* convert region to list-of-rectangles for PolyFillRect */
|
|
|
|
|
2010-05-05 20:44:06 +02:00
|
|
|
pRects = malloc(nRects * sizeof(xRectangle));
|
2004-06-01 23:09:25 +02:00
|
|
|
if (!pRects)
|
|
|
|
{
|
|
|
|
failed = TRUE;
|
|
|
|
goto failSafe;
|
|
|
|
}
|
2010-05-22 00:05:48 +02:00
|
|
|
for (pBox = RegionRects(&censorRegion), i = 0;
|
2004-06-01 23:09:25 +02:00
|
|
|
i < nRects;
|
|
|
|
i++, pBox++)
|
|
|
|
{
|
|
|
|
pRects[i].x = pBox->x1;
|
|
|
|
pRects[i].y = pBox->y1 - imageBox.y1;
|
|
|
|
pRects[i].width = pBox->x2 - pBox->x1;
|
|
|
|
pRects[i].height = pBox->y2 - pBox->y1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use pBuf as a fake pixmap */
|
|
|
|
|
|
|
|
if (format == ZPixmap)
|
|
|
|
{
|
|
|
|
depth = pDraw->depth;
|
|
|
|
bitsPerPixel = pDraw->bitsPerPixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
pPix = GetScratchPixmapHeader(pDraw->pScreen, w, h,
|
|
|
|
depth, bitsPerPixel,
|
|
|
|
widthBytesLine, (pointer)pBuf);
|
|
|
|
if (!pPix)
|
|
|
|
{
|
|
|
|
failed = TRUE;
|
|
|
|
goto failSafe;
|
|
|
|
}
|
|
|
|
|
|
|
|
pScratchGC = GetScratchGC(depth, pPix->drawable.pScreen);
|
|
|
|
if (!pScratchGC)
|
|
|
|
{
|
|
|
|
failed = TRUE;
|
|
|
|
goto failSafe;
|
|
|
|
}
|
|
|
|
|
|
|
|
ValidateGC(&pPix->drawable, pScratchGC);
|
|
|
|
(* pScratchGC->ops->PolyFillRect)(&pPix->drawable,
|
|
|
|
pScratchGC, nRects, pRects);
|
|
|
|
|
|
|
|
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 10:35:31 +02:00
|
|
|
memset(pBuf, 0, (int)(widthBytesLine * h));
|
2004-06-01 23:09:25 +02:00
|
|
|
}
|
2010-06-06 10:28:30 +02:00
|
|
|
free(pRects);
|
2004-06-01 23:09:25 +02:00
|
|
|
if (pScratchGC) FreeScratchGC(pScratchGC);
|
|
|
|
if (pPix) FreeScratchPixmapHeader(pPix);
|
|
|
|
}
|
2010-05-22 00:05:48 +02:00
|
|
|
RegionUninit(&imageRegion);
|
|
|
|
RegionUninit(&censorRegion);
|
2004-06-01 23:09:25 +02:00
|
|
|
} /* XaceCensorImage */
|
2008-12-18 19:58:35 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Xtrans wrappers for use by modules
|
|
|
|
*/
|
|
|
|
int XaceGetConnectionNumber(ClientPtr client)
|
|
|
|
{
|
|
|
|
XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
|
|
|
|
return _XSERVTransGetConnectionNumber(ci);
|
|
|
|
}
|
|
|
|
|
|
|
|
int XaceIsLocal(ClientPtr client)
|
|
|
|
{
|
|
|
|
XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
|
|
|
|
return _XSERVTransIsLocal(ci);
|
|
|
|
}
|