1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
/************************************************************
Author: Eamon Walsh <ewalsh@tycho.nsa.gov>
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.
********************************************************/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <stdarg.h>
#include "scrnintstr.h"
#include "extnsionst.h"
#include "pixmapstr.h"
#include "regionstr.h"
#include "gcstruct.h"
#include "xacestr.h"
CallbackListPtr XaceHooks[XACE_NUM_HOOKS] = { 0 };
/* Special-cased hook functions. Called by Xserver.
*/
int
XaceHookDispatch0(ClientPtr client, int major)
{
/* 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;
}
int
XaceHookPropertyAccess(ClientPtr client, WindowPtr pWin,
PropertyPtr *ppProp, Mask access_mode)
{
XacePropertyAccessRec rec = { client, pWin, ppProp, access_mode, Success };
CallCallbacks(&XaceHooks[XACE_PROPERTY_ACCESS], &rec);
return rec.status;
}
int
XaceHookSelectionAccess(ClientPtr client, Selection ** ppSel, Mask access_mode)
{
XaceSelectionAccessRec rec = { client, ppSel, access_mode, Success };
CallCallbacks(&XaceHooks[XACE_SELECTION_ACCESS], &rec);
return rec.status;
}
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;
}
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;
}
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;
}
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;
}
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;
}
int XaceHookExtAccess(ClientPtr client, ExtensionEntry *ext)
{
XaceExtAccessRec rec = { client, ext, DixGetAttrAccess, Success };
CallCallbacks(&XaceHooks[XACE_EXT_ACCESS], &rec);
return rec.status;
}
int XaceHookServerAccess(ClientPtr client, Mask access_mode)
{
XaceServerAccessRec rec = { client, access_mode, Success };
CallCallbacks(&XaceHooks[XACE_SERVER_ACCESS], &rec);
return rec.status;
}
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;
}
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;
}
int XaceHookAuthAvail(ClientPtr client, XID authId)
{
XaceAuthAvailRec rec = { client, authId };
CallCallbacks(&XaceHooks[XACE_AUTH_AVAIL], &rec);
return Success;
}
int XaceHookKeyAvail(xEventPtr ev, DeviceIntPtr dev, int count)
{
XaceKeyAvailRec rec = { ev, dev, count };
CallCallbacks(&XaceHooks[XACE_KEY_AVAIL], &rec);
return Success;
}
/* 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;
}
/* 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
XaceCensorImage(ClientPtr client,
RegionPtr pVisibleRegion,
long widthBytesLine,
DrawablePtr pDraw,
int x, int y, int w, int h, unsigned int format, char *pBuf)
{
RegionRec imageRegion; /* region representing x,y,w,h */
RegionRec censorRegion; /* region to obliterate */
BoxRec imageBox;
int nRects;
imageBox.x1 = pDraw->x + x;
imageBox.y1 = pDraw->y + y;
imageBox.x2 = pDraw->x + x + w;
imageBox.y2 = pDraw->y + y + h;
RegionInit(&imageRegion, &imageBox, 1);
RegionNull(&censorRegion);
/* censorRegion = imageRegion - visibleRegion */
RegionSubtract(&censorRegion, &imageRegion, pVisibleRegion);
nRects = RegionNumRects(&censorRegion);
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 */
pRects = malloc(nRects * sizeof(xRectangle));
if (!pRects) {
failed = TRUE;
goto failSafe;
}
for (pBox = RegionRects(&censorRegion), i = 0; i < nRects; i++, pBox++) {
pRects[i].x = pBox->x1 - imageBox.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, (void *) 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.
*/
memset(pBuf, 0, (int) (widthBytesLine * h));
}
free(pRects);
if (pScratchGC)
FreeScratchGC(pScratchGC);
if (pPix)
FreeScratchPixmapHeader(pPix);
}
RegionUninit(&imageRegion);
RegionUninit(&censorRegion);
} /* XaceCensorImage */
/*
* Xtrans wrappers for use by modules
*/
int
XaceGetConnectionNumber(ClientPtr client)
{
return GetClientFd(client);
}
int
XaceIsLocal(ClientPtr client)
{
return ClientIsLocal(client);
}
|