From 60cdc592fe042c03ceb5d4c3344acfbbf5d8ae28 Mon Sep 17 00:00:00 2001 From: Eamon Walsh Date: Thu, 14 Dec 2006 14:46:03 -0500 Subject: Add new, combined dix lookup functions. --- dix/dixutils.c | 176 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 95 insertions(+), 81 deletions(-) (limited to 'dix/dixutils.c') 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, -- cgit v1.2.3