summaryrefslogtreecommitdiff
path: root/dix/window.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter@cs.unisa.edu.au>2008-01-03 17:04:54 +1030
committerPeter Hutterer <peter@cs.unisa.edu.au>2008-01-03 17:04:54 +1030
commit8da83836b60f7cdb75d08482f4311fa0e2ab4e1d (patch)
tree092efcfc39e3e293baaf04c4c84027ee453d3e13 /dix/window.c
parenteace88989c3b65d5c20e9f37ea9b23c7c8e19335 (diff)
parentae869fc7669764729e13fdd70149ed636753f2a3 (diff)
Merge branch 'master' into mpx
Conflicts: XTrap/xtrapddmi.c Xext/security.c Xext/xprint.c Xext/xtest.c Xext/xvdisp.c Xi/exevents.c Xi/grabdevb.c Xi/grabdevk.c Xi/opendev.c Xi/ungrdev.c Xi/ungrdevb.c Xi/ungrdevk.c dix/cursor.c dix/devices.c dix/dixutils.c dix/events.c dix/getevents.c dix/main.c dix/window.c hw/xfree86/ramdac/xf86Cursor.c include/dix.h include/input.h include/inputstr.h mi/midispcur.c mi/miinitext.c mi/misprite.c render/animcur.c xfixes/cursor.c xkb/xkbAccessX.c
Diffstat (limited to 'dix/window.c')
-rw-r--r--dix/window.c271
1 files changed, 125 insertions, 146 deletions
diff --git a/dix/window.c b/dix/window.c
index 76e5dec05..d937ca856 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -127,6 +127,7 @@ Equipment Corporation.
#ifdef XAPPGROUP
#include "appgroup.h"
#endif
+#include "privates.h"
#include "xace.h"
/******
@@ -155,14 +156,7 @@ _X_EXPORT int screenIsSaved = SCREEN_SAVER_OFF;
_X_EXPORT ScreenSaverStuffRec savedScreenInfo[MAXSCREENS];
-_X_EXPORT int FocusPrivatesIndex = -1;
-
-#if 0
-extern void DeleteWindowFromAnyEvents();
-extern Mask EventMaskForClient();
-extern void WindowHasNewCursor();
-extern void RecalculateDeliverableEvents();
-#endif
+_X_EXPORT DevPrivateKey FocusPrivatesKey = &FocusPrivatesKey;
static Bool TileScreenSaver(int i, int kind);
@@ -283,6 +277,8 @@ Bool disableSaveUnders = FALSE;
static void
SetWindowToDefaults(WindowPtr pWin)
{
+ FocusSemaphoresPtr sem;
+
pWin->prevSib = NullWindow;
pWin->firstChild = NullWindow;
pWin->lastChild = NullWindow;
@@ -313,11 +309,8 @@ SetWindowToDefaults(WindowPtr pWin)
pWin->redirectDraw = RedirectDrawNone;
#endif
- ((FocusSemaphoresPtr)
- pWin->devPrivates[FocusPrivatesIndex].ptr)->enterleave = 0;
- ((FocusSemaphoresPtr)
- pWin->devPrivates[FocusPrivatesIndex].ptr)->focusinout = 0;
-
+ sem = xcalloc(1, sizeof(FocusSemaphoresRec));
+ dixSetPrivate(&pWin->devPrivates, FocusPrivatesKey, sem);
}
static void
@@ -363,41 +356,6 @@ MakeRootTile(WindowPtr pWin)
}
-WindowPtr
-AllocateWindow(ScreenPtr pScreen)
-{
- WindowPtr pWin;
- char *ptr;
- DevUnion *ppriv;
- unsigned *sizes;
- unsigned size;
- int i;
-
- pWin = (WindowPtr)xalloc(pScreen->totalWindowSize);
- if (pWin)
- {
- ppriv = (DevUnion *)(pWin + 1);
- pWin->devPrivates = ppriv;
- sizes = pScreen->WindowPrivateSizes;
- ptr = (char *)(ppriv + pScreen->WindowPrivateLen);
- for (i = pScreen->WindowPrivateLen; --i >= 0; ppriv++, sizes++)
- {
- if ( (size = *sizes) )
- {
- ppriv->ptr = (pointer)ptr;
- ptr += size;
- }
- else
- ppriv->ptr = (pointer)NULL;
- }
-#if _XSERVER64
- pWin->drawable.pad0 = 0;
- pWin->drawable.pad1 = 0;
-#endif
- }
- return pWin;
-}
-
/*****
* CreateRootWindow
* Makes a window at initialization time for specified screen
@@ -410,7 +368,7 @@ CreateRootWindow(ScreenPtr pScreen)
BoxRec box;
PixmapFormatRec *format;
- pWin = AllocateWindow(pScreen);
+ pWin = (WindowPtr)xalloc(sizeof(WindowRec));
if (!pWin)
return FALSE;
@@ -423,6 +381,7 @@ CreateRootWindow(ScreenPtr pScreen)
pWin->drawable.pScreen = pScreen;
pWin->drawable.type = DRAWABLE_WINDOW;
+ pWin->devPrivates = NULL;
pWin->drawable.depth = pScreen->rootDepth;
for (format = screenInfo.formats;
@@ -498,6 +457,12 @@ CreateRootWindow(ScreenPtr pScreen)
pWin->border.pixel = pScreen->blackPixel;
pWin->borderWidth = 0;
+ /* security creation/labeling check
+ */
+ if (XaceHook(XACE_RESOURCE_ACCESS, serverClient, pWin->drawable.id,
+ RT_WINDOW, pWin, RT_NONE, NULL, DixCreateAccess))
+ return FALSE;
+
if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin))
return FALSE;
@@ -555,8 +520,6 @@ InitRootWindow(WindowPtr pWin)
/* We SHOULD check for an error value here XXX */
(*pScreen->ChangeWindowAttributes)(pWin, backFlag);
- XaceHook(XACE_WINDOW_INIT, serverClient, pWin);
-
MapWindow(pWin, serverClient);
}
@@ -721,13 +684,14 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
return NullWindow;
}
- pWin = AllocateWindow(pScreen);
+ pWin = (WindowPtr)xalloc(sizeof(WindowRec));
if (!pWin)
{
*error = BadAlloc;
return NullWindow;
}
pWin->drawable = pParent->drawable;
+ pWin->devPrivates = NULL;
pWin->drawable.depth = depth;
if (depth == pParent->drawable.depth)
pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel;
@@ -761,16 +725,18 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
pWin->borderWidth = bw;
- /* can't let untrusted clients have background None windows;
- * they make it too easy to steal window contents
+ /* security creation/labeling check
*/
- if (XaceHook(XACE_BACKGRND_ACCESS, client, pWin))
- pWin->backgroundState = None;
- else {
- pWin->backgroundState = BackgroundPixel;
- pWin->background.pixel = 0;
+ *error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, RT_WINDOW, pWin,
+ RT_WINDOW, pWin->parent, DixCreateAccess|DixSetAttrAccess);
+ if (*error != Success) {
+ xfree(pWin);
+ return NullWindow;
}
+ pWin->backgroundState = XaceBackgroundNoneState;
+ pWin->background.pixel = 0;
+
pWin->borderIsPixel = pParent->borderIsPixel;
pWin->border = pParent->border;
if (pWin->borderIsPixel == FALSE)
@@ -789,8 +755,6 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
REGION_NULL(pScreen, &pWin->winSize);
REGION_NULL(pScreen, &pWin->borderSize);
- XaceHook(XACE_WINDOW_INIT, client, pWin);
-
pHead = RealChildHead(pParent);
if (pHead)
{
@@ -1020,11 +984,12 @@ DeleteWindow(pointer value, XID wid)
if (pWin->prevSib)
pWin->prevSib->nextSib = pWin->nextSib;
}
+ dixFreePrivates(pWin->devPrivates);
xfree(pWin);
return Success;
}
-void
+int
DestroySubwindows(WindowPtr pWin, ClientPtr client)
{
/* XXX
@@ -1036,8 +1001,15 @@ DestroySubwindows(WindowPtr pWin, ClientPtr client)
* If you care, simply delete the call to UnmapSubwindows.
*/
UnmapSubwindows(pWin);
- while (pWin->lastChild)
+ while (pWin->lastChild) {
+ int rc = XaceHook(XACE_RESOURCE_ACCESS, client,
+ pWin->lastChild->drawable.id, RT_WINDOW,
+ pWin->lastChild, RT_NONE, NULL, DixDestroyAccess);
+ if (rc != Success)
+ return rc;
FreeResource(pWin->lastChild->drawable.id, RT_NONE);
+ }
+ return Success;
}
#define DeviceEventMasks (KeyPressMask | KeyReleaseMask | ButtonPressMask | \
@@ -1054,25 +1026,20 @@ DestroySubwindows(WindowPtr pWin, ClientPtr client)
_X_EXPORT int
ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
{
- Mask index2;
XID *pVlist;
PixmapPtr pPixmap;
Pixmap pixID;
CursorPtr pCursor, pOldCursor;
Cursor cursorID;
- WindowPtr pChild;
+ WindowPtr pChild, pLayerWin;
Colormap cmap;
ColormapPtr pCmap;
xEvent xE;
- int result;
+ int error, rc;
ScreenPtr pScreen;
- Mask vmaskCopy = 0;
- Mask tmask;
+ Mask index2, tmask, vmaskCopy = 0;
unsigned int val;
- int error;
- Bool checkOptional = FALSE;
- Bool borderRelative = FALSE;
- WindowPtr pLayerWin;
+ Bool checkOptional = FALSE, borderRelative = FALSE;
if ((pWin->drawable.class == InputOnly) && (vmask & (~INPUTONLY_LEGAL_MASK)))
return BadMatch;
@@ -1094,17 +1061,13 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
borderRelative = TRUE;
if (pixID == None)
{
- /* can't let untrusted clients have background None windows */
- if (XaceHook(XACE_BACKGRND_ACCESS, client, pWin)) {
- if (pWin->backgroundState == BackgroundPixmap)
- (*pScreen->DestroyPixmap)(pWin->background.pixmap);
- if (!pWin->parent)
- MakeRootTile(pWin);
- else
- pWin->backgroundState = None;
- } else {
- /* didn't change the backgrnd to None, so don't tell ddx */
- index2 = 0;
+ if (pWin->backgroundState == BackgroundPixmap)
+ (*pScreen->DestroyPixmap)(pWin->background.pixmap);
+ if (!pWin->parent)
+ MakeRootTile(pWin);
+ else {
+ pWin->backgroundState = XaceBackgroundNoneState;
+ pWin->background.pixel = 0;
}
}
else if (pixID == ParentRelative)
@@ -1127,9 +1090,9 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
}
else
{
- pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID,
- RT_PIXMAP, DixReadAccess);
- if (pPixmap != (PixmapPtr) NULL)
+ rc = dixLookupResource((pointer *)&pPixmap, pixID, RT_PIXMAP,
+ client, DixReadAccess);
+ if (rc == Success)
{
if ((pPixmap->drawable.depth != pWin->drawable.depth) ||
(pPixmap->drawable.pScreen != pScreen))
@@ -1145,7 +1108,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
}
else
{
- error = BadPixmap;
+ error = (rc == BadValue) ? BadPixmap : rc;
client->errorValue = pixID;
goto PatchUp;
}
@@ -1174,42 +1137,40 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
error = BadMatch;
goto PatchUp;
}
- if (pWin->borderIsPixel == FALSE)
- (*pScreen->DestroyPixmap)(pWin->border.pixmap);
- pWin->border = pWin->parent->border;
- if ((pWin->borderIsPixel = pWin->parent->borderIsPixel) == TRUE)
- {
+ if (pWin->parent->borderIsPixel == TRUE) {
+ if (pWin->borderIsPixel == FALSE)
+ (*pScreen->DestroyPixmap)(pWin->border.pixmap);
+ pWin->border = pWin->parent->border;
+ pWin->borderIsPixel = TRUE;
index2 = CWBorderPixel;
+ break;
}
else
{
- pWin->parent->border.pixmap->refcnt++;
+ pixID = pWin->parent->border.pixmap->drawable.id;
}
}
- else
- {
- pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID,
- RT_PIXMAP, DixReadAccess);
- if (pPixmap)
- {
- if ((pPixmap->drawable.depth != pWin->drawable.depth) ||
- (pPixmap->drawable.pScreen != pScreen))
- {
- error = BadMatch;
- goto PatchUp;
- }
- if (pWin->borderIsPixel == FALSE)
- (*pScreen->DestroyPixmap)(pWin->border.pixmap);
- pWin->borderIsPixel = FALSE;
- pWin->border.pixmap = pPixmap;
- pPixmap->refcnt++;
- }
- else
+ rc = dixLookupResource((pointer *)&pPixmap, pixID, RT_PIXMAP,
+ client, DixReadAccess);
+ if (rc == Success)
+ {
+ if ((pPixmap->drawable.depth != pWin->drawable.depth) ||
+ (pPixmap->drawable.pScreen != pScreen))
{
- error = BadPixmap;
- client->errorValue = pixID;
+ error = BadMatch;
goto PatchUp;
}
+ if (pWin->borderIsPixel == FALSE)
+ (*pScreen->DestroyPixmap)(pWin->border.pixmap);
+ pWin->borderIsPixel = FALSE;
+ pWin->border.pixmap = pPixmap;
+ pPixmap->refcnt++;
+ }
+ else
+ {
+ error = (rc == BadValue) ? BadPixmap : rc;
+ client->errorValue = pixID;
+ goto PatchUp;
}
break;
case CWBorderPixel:
@@ -1334,20 +1295,20 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
#endif /* DO_SAVE_UNDERS */
break;
case CWEventMask:
- result = EventSelectForWindow(pWin, client, (Mask )*pVlist);
- if (result)
+ rc = EventSelectForWindow(pWin, client, (Mask )*pVlist);
+ if (rc)
{
- error = result;
+ error = rc;
goto PatchUp;
}
pVlist++;
break;
case CWDontPropagate:
- result = EventSuppressForWindow(pWin, client, (Mask )*pVlist,
+ rc = EventSuppressForWindow(pWin, client, (Mask )*pVlist,
&checkOptional);
- if (result)
+ if (rc)
{
- error = result;
+ error = rc;
goto PatchUp;
}
pVlist++;
@@ -1361,6 +1322,15 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
client->errorValue = val;
goto PatchUp;
}
+ if (val == xTrue) {
+ rc = XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id,
+ RT_WINDOW, pWin, RT_NONE, NULL, DixGrabAccess);
+ if (rc != Success) {
+ error = rc;
+ client->errorValue = pWin->drawable.id;
+ goto PatchUp;
+ }
+ }
pWin->overrideRedirect = val;
break;
case CWColormap:
@@ -1398,11 +1368,11 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
error = BadMatch;
goto PatchUp;
}
- pCmap = (ColormapPtr)SecurityLookupIDByType(client, cmap,
- RT_COLORMAP, DixReadAccess);
- if (!pCmap)
+ rc = dixLookupResource((pointer *)&pCmap, cmap, RT_COLORMAP,
+ client, DixUseAccess);
+ if (rc != Success)
{
- error = BadColor;
+ error = (rc == BadValue) ? BadColor : rc;
client->errorValue = cmap;
goto PatchUp;
}
@@ -1474,11 +1444,11 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
}
else
{
- pCursor = (CursorPtr)SecurityLookupIDByType(client, cursorID,
- RT_CURSOR, DixReadAccess);
- if (!pCursor)
+ rc = dixLookupResource((pointer *)&pCursor, cursorID,
+ RT_CURSOR, client, DixUseAccess);
+ if (rc != Success)
{
- error = BadCursor;
+ error = (rc == BadValue) ? BadCursor : rc;
client->errorValue = cursorID;
goto PatchUp;
}
@@ -2311,7 +2281,7 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client)
unsigned short w = pWin->drawable.width,
h = pWin->drawable.height,
bw = pWin->borderWidth;
- int action, smode = Above;
+ int rc, action, smode = Above;
#ifdef XAPPGROUP
ClientPtr win_owner;
ClientPtr ag_leader = NULL;
@@ -2372,12 +2342,11 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client)
case CWSibling:
sibwid = (Window ) *pVlist;
pVlist++;
- pSib = (WindowPtr )SecurityLookupIDByType(client, sibwid,
- RT_WINDOW, DixReadAccess);
- if (!pSib)
+ rc = dixLookupWindow(&pSib, sibwid, client, DixGetAttrAccess);
+ if (rc != Success)
{
client->errorValue = sibwid;
- return(BadWindow);
+ return rc;
}
if (pSib->parent != pParent)
return(BadMatch);
@@ -2824,8 +2793,9 @@ MapWindow(WindowPtr pWin, ClientPtr client)
return(Success);
/* general check for permission to map window */
- if (!XaceHook(XACE_MAP_ACCESS, client, pWin))
- return Success;
+ if (XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, RT_WINDOW,
+ pWin, RT_NONE, NULL, DixShowAccess) != Success)
+ return Success;
pScreen = pWin->drawable.pScreen;
if ( (pParent = pWin->parent) )
@@ -3409,12 +3379,10 @@ static void DrawLogo(
);
#endif
-_X_EXPORT void
-SaveScreens(int on, int mode)
+_X_EXPORT int
+dixSaveScreens(ClientPtr client, int on, int mode)
{
- int i;
- int what;
- int type;
+ int rc, i, what, type;
if (on == SCREEN_SAVER_FORCER)
{
@@ -3433,6 +3401,13 @@ SaveScreens(int on, int mode)
if (what == screenIsSaved)
type = SCREEN_SAVER_CYCLE;
}
+
+ for (i = 0; i < screenInfo.numScreens; i++) {
+ rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, screenInfo.screens[i],
+ DixShowAccess | DixHideAccess);
+ if (rc != Success)
+ return rc;
+ }
for (i = 0; i < screenInfo.numScreens; i++)
{
if (on == SCREEN_SAVER_FORCER)
@@ -3520,6 +3495,13 @@ SaveScreens(int on, int mode)
screenIsSaved = what;
if (mode == ScreenSaverReset)
SetScreenSaverTimer();
+ return Success;
+}
+
+_X_EXPORT int
+SaveScreens(int on, int mode)
+{
+ return dixSaveScreens(serverClient, on, mode);
}
static Bool
@@ -3581,7 +3563,8 @@ TileScreenSaver(int i, int kind)
{
for (j=0; j<BitmapBytePad(32)*16; j++)
srcbits[j] = mskbits[j] = 0x0;
- cursor = AllocCursor(srcbits, mskbits, &cm, 0, 0, 0, 0, 0, 0);
+ result = AllocARGBCursor(srcbits, mskbits, NULL, &cm, 0, 0, 0, 0, 0, 0,
+ &cursor, serverClient, (XID)0);
if (cursor)
{
cursorID = FakeClientID(0);
@@ -4006,11 +3989,7 @@ WindowParentHasDeviceCursor(WindowPtr pWin,
_X_EXPORT Bool
InitWindowPrivates(ScreenPtr screen)
{
- if (FocusPrivatesIndex == -1)
- FocusPrivatesIndex = AllocateWindowPrivateIndex();
-
- return AllocateWindowPrivate(screen, FocusPrivatesIndex,
- sizeof(FocusSemaphoresRec));
+ /* obsolete with devPrivates rework */
}
#ifndef NOLOGOHACK