diff options
-rw-r--r-- | dix/dixutils.c | 176 | ||||
-rw-r--r-- | hw/xfree86/loader/dixsym.c | 12 | ||||
-rw-r--r-- | include/dix.h | 73 | ||||
-rw-r--r-- | include/pixmap.h | 10 |
4 files changed, 146 insertions, 125 deletions
diff --git a/dix/dixutils.c b/dix/dixutils.c index fca55d99f..f9980c5a8 100644 --- a/dix/dixutils.c +++ b/dix/dixutils.c @@ -194,115 +194,129 @@ CompareISOLatin1Lowered(unsigned char *s1, int s1len, return (int) c1 - (int) c2; } -#ifdef XACE - -/* SecurityLookupWindow and SecurityLookupDrawable: - * Look up the window/drawable taking into account the client doing - * the lookup and the type of access desired. Return the window/drawable - * if it exists and the client is allowed access, else return NULL. - * Most Proc* functions should be calling these instead of - * LookupWindow and LookupDrawable, which do no access checks. - * XACE note: need to see if client->lastDrawableID can still be used here. +/* + * dixLookupWindow and dixLookupDrawable: + * Look up the window/drawable taking into account the client doing the + * lookup, the type of drawable desired, and the type of access desired. + * Return Success with *pDraw set if the window/drawable exists and the client + * is allowed access, else return an error code with *pDraw set to NULL. The + * access mask values are defined in resource.h. The type mask values are + * defined in pixmap.h, with zero equivalent to M_DRAWABLE. */ +_X_EXPORT int +dixLookupDrawable(DrawablePtr *pDraw, XID id, ClientPtr client, + Mask type, Mask access) +{ + DrawablePtr pTmp; + RESTYPE rtype; + *pDraw = NULL; + client->errorValue = id; + + if (id == INVALID) + return BadDrawable; + + if (id == client->lastDrawableID) { + pTmp = client->lastDrawable; + + /* an access check is required for cached drawables */ + rtype = (pTmp->type | M_WINDOW) ? RT_WINDOW : RT_PIXMAP; + if (!XaceHook(XACE_RESOURCE_ACCESS, client, id, rtype, access, pTmp)) + return BadDrawable; + } else + pTmp = (DrawablePtr)SecurityLookupIDByClass(client, id, RC_DRAWABLE, + access); + if (!pTmp) + return BadDrawable; + if (!((1 << pTmp->type) | (type ? type : M_DRAWABLE))) + return BadMatch; + + if (pTmp->type | M_DRAWABLE) { + client->lastDrawable = pTmp; + client->lastDrawableID = id; + client->lastGCID = INVALID; + client->lastGC = (GCPtr)NULL; + } + *pDraw = pTmp; + return Success; +} -_X_EXPORT WindowPtr -SecurityLookupWindow(XID rid, ClientPtr client, Mask access_mode) +_X_EXPORT int +dixLookupWindow(WindowPtr *pWin, XID id, ClientPtr client, Mask access) { - client->errorValue = rid; - if(rid == INVALID) - return NULL; - return (WindowPtr)SecurityLookupIDByType(client, rid, RT_WINDOW, access_mode); + int rc; + rc = dixLookupDrawable((DrawablePtr*)pWin, id, client, M_WINDOW, access); + return (rc == BadDrawable) ? BadWindow : rc; } +_X_EXPORT int +dixLookupGC(GCPtr *pGC, XID id, ClientPtr client, Mask access) +{ + GCPtr pTmp = (GCPtr)SecurityLookupIDByType(client, id, RT_GC, access); + if (pTmp) { + *pGC = pTmp; + return Success; + } + client->errorValue = id; + *pGC = NULL; + return BadGC; +} -_X_EXPORT pointer -SecurityLookupDrawable(XID rid, ClientPtr client, Mask access_mode) +_X_EXPORT int +dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client) { - register DrawablePtr pDraw; + pointer pRes = (pointer)SecurityLookupIDByClass(client, rid, RC_ANY, + DixReadAccess); + int clientIndex = CLIENT_ID(rid); - if(rid == INVALID) - return (pointer) NULL; - pDraw = (DrawablePtr)SecurityLookupIDByClass(client, rid, RC_DRAWABLE, - access_mode); - if (pDraw && (pDraw->type != UNDRAWABLE_WINDOW)) - return (pointer)pDraw; - return (pointer)NULL; + if (clientIndex && pRes && clients[clientIndex] && !(rid & SERVER_BIT)) { + *pClient = clients[clientIndex]; + return Success; + } + *pClient = NULL; + return BadValue; } -/* We can't replace the LookupWindow and LookupDrawable functions with - * macros because of compatibility with loadable servers. +/* + * These are deprecated compatibility functions and will be removed soon! + * Please use the new dixLookup*() functions above. */ - _X_EXPORT WindowPtr -LookupWindow(XID rid, ClientPtr client) +SecurityLookupWindow(XID id, ClientPtr client, Mask access_mode) { - return SecurityLookupWindow(rid, client, DixUnknownAccess); + WindowPtr pWin; + int i = dixLookupWindow(&pWin, id, client, access_mode); + return (i == Success) ? pWin : NULL; } -_X_EXPORT pointer -LookupDrawable(XID rid, ClientPtr client) +_X_EXPORT WindowPtr +LookupWindow(XID id, ClientPtr client) { - return SecurityLookupDrawable(rid, client, DixUnknownAccess); + return SecurityLookupWindow(id, client, DixUnknownAccess); } -#else /* not XACE */ - -WindowPtr -LookupWindow(XID rid, ClientPtr client) +_X_EXPORT pointer +SecurityLookupDrawable(XID id, ClientPtr client, Mask access_mode) { - WindowPtr pWin; - - client->errorValue = rid; - if(rid == INVALID) - return NULL; - if (client->lastDrawableID == rid) - { - if (client->lastDrawable->type == DRAWABLE_WINDOW) - return ((WindowPtr) client->lastDrawable); - return (WindowPtr) NULL; - } - pWin = (WindowPtr)LookupIDByType(rid, RT_WINDOW); - if (pWin && pWin->drawable.type == DRAWABLE_WINDOW) { - client->lastDrawable = (DrawablePtr) pWin; - client->lastDrawableID = rid; - client->lastGCID = INVALID; - client->lastGC = (GCPtr)NULL; - } - return pWin; + DrawablePtr pDraw; + int i = dixLookupDrawable(&pDraw, id, client, access_mode, TRUE); + return (i == Success) ? pDraw : NULL; } - -pointer -LookupDrawable(XID rid, ClientPtr client) +_X_EXPORT pointer +LookupDrawable(XID id, ClientPtr client) { - register DrawablePtr pDraw; - - if(rid == INVALID) - return (pointer) NULL; - if (client->lastDrawableID == rid) - return ((pointer) client->lastDrawable); - pDraw = (DrawablePtr)LookupIDByClass(rid, RC_DRAWABLE); - if (pDraw && (pDraw->type != UNDRAWABLE_WINDOW)) - return (pointer)pDraw; - return (pointer)NULL; + return SecurityLookupDrawable(id, client, DixUnknownAccess); } -#endif /* XACE */ - _X_EXPORT ClientPtr -LookupClient(XID rid, ClientPtr client) +LookupClient(XID id, ClientPtr client) { - pointer pRes = (pointer)SecurityLookupIDByClass(client, rid, RC_ANY, - DixReadAccess); - int clientIndex = CLIENT_ID(rid); - - if (clientIndex && pRes && clients[clientIndex] && !(rid & SERVER_BIT)) - { - return clients[clientIndex]; - } - return (ClientPtr)NULL; + ClientPtr pClient; + int i = dixLookupClient(&pClient, id, client); + return (i == Success) ? pClient : NULL; } +/* end deprecated functions */ int AlterSaveSetForClient(ClientPtr client, WindowPtr pWin, unsigned mode, diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c index 27a3093b1..32e0e4f68 100644 --- a/hw/xfree86/loader/dixsym.c +++ b/hw/xfree86/loader/dixsym.c @@ -155,17 +155,21 @@ _X_HIDDEN void *dixLookupTab[] = { SYMFUNC(CompareTimeStamps) SYMFUNC(CopyISOLatin1Lowered) SYMFUNC(DeleteCallback) + SYMFUNC(dixLookupDrawable) + SYMFUNC(dixLookupWindow) + SYMFUNC(dixLookupClient) + SYMFUNC(dixLookupGC) + /* following are deprecated */ SYMFUNC(LookupClient) SYMFUNC(LookupDrawable) SYMFUNC(LookupWindow) + SYMFUNC(SecurityLookupDrawable) + SYMFUNC(SecurityLookupWindow) + /* end deprecated */ SYMFUNC(NoopDDA) SYMFUNC(QueueWorkProc) SYMFUNC(RegisterBlockAndWakeupHandlers) SYMFUNC(RemoveBlockAndWakeupHandlers) -#ifdef XACE - SYMFUNC(SecurityLookupDrawable) - SYMFUNC(SecurityLookupWindow) -#endif /* events.c */ SYMFUNC(CheckCursorConfinement) SYMFUNC(DeliverEvents) diff --git a/include/dix.h b/include/dix.h index 2c87a48c3..09d5fef95 100644 --- a/include/dix.h +++ b/include/dix.h @@ -375,47 +375,40 @@ extern int CompareISOLatin1Lowered( unsigned char * /*b*/, int blen); -#ifdef XACE - -extern WindowPtr SecurityLookupWindow( - XID /*rid*/, - ClientPtr /*client*/, - Mask /*access_mode*/); - -extern pointer SecurityLookupDrawable( - XID /*rid*/, - ClientPtr /*client*/, - Mask /*access_mode*/); - -extern WindowPtr LookupWindow( - XID /*rid*/, - ClientPtr /*client*/); - -extern pointer LookupDrawable( - XID /*rid*/, - ClientPtr /*client*/); - -#else - -extern WindowPtr LookupWindow( - XID /*rid*/, - ClientPtr /*client*/); - -extern pointer LookupDrawable( - XID /*rid*/, - ClientPtr /*client*/); - -#define SecurityLookupWindow(rid, client, access_mode) \ - LookupWindow(rid, client) - -#define SecurityLookupDrawable(rid, client, access_mode) \ - LookupDrawable(rid, client) - -#endif /* XACE */ +extern int dixLookupWindow( + WindowPtr *result, + XID id, + ClientPtr client, + Mask access_mode); + +extern int dixLookupDrawable( + DrawablePtr *result, + XID id, + ClientPtr client, + Mask type_mask, + Mask access_mode); + +extern int dixLookupGC( + GCPtr *result, + XID id, + ClientPtr client, + Mask access_mode); + +extern int dixLookupClient( + ClientPtr *result, + XID id, + ClientPtr client); -extern ClientPtr LookupClient( - XID /*rid*/, - ClientPtr /*client*/); +/* + * These are deprecated compatibility functions and will be removed soon! + * Please use the new dixLookup*() functions above. + */ +extern WindowPtr SecurityLookupWindow(XID, ClientPtr, Mask); +extern WindowPtr LookupWindow(XID, ClientPtr); +extern pointer SecurityLookupDrawable(XID, ClientPtr, Mask); +extern pointer LookupDrawable(XID, ClientPtr); +extern ClientPtr LookupClient(XID, ClientPtr); +/* end deprecated functions */ extern void NoopDDA(void); diff --git a/include/pixmap.h b/include/pixmap.h index 3276fadb6..19e682a50 100644 --- a/include/pixmap.h +++ b/include/pixmap.h @@ -58,6 +58,16 @@ SOFTWARE. #define UNDRAWABLE_WINDOW 2 #define DRAWABLE_BUFFER 3 +/* corresponding type masks for dixLookupDrawable() */ +#define M_DRAWABLE_WINDOW (1<<0) +#define M_DRAWABLE_PIXMAP (1<<1) +#define M_UNDRAWABLE_WINDOW (1<<2) +#define M_DRAWABLE_BUFFER (1<<3) +#define M_ANY (-1) +#define M_WINDOW (M_DRAWABLE_WINDOW|M_UNDRAWABLE_WINDOW) +#define M_DRAWABLE (M_DRAWABLE_WINDOW|M_DRAWABLE_PIXMAP|M_DRAWABLE_BUFFER) +#define M_UNDRAWABLE (M_UNDRAWABLE_WINDOW) + /* flags to PaintWindow() */ #define PW_BACKGROUND 0 #define PW_BORDER 1 |