Add new, combined dix lookup functions.

This commit is contained in:
Eamon Walsh 2006-12-14 14:46:03 -05:00 committed by Eamon Walsh
parent 6c46645cfc
commit 60cdc592fe
4 changed files with 148 additions and 127 deletions

View File

@ -194,115 +194,129 @@ CompareISOLatin1Lowered(unsigned char *s1, int s1len,
return (int) c1 - (int) c2; return (int) c1 - (int) c2;
} }
#ifdef XACE /*
* dixLookupWindow and dixLookupDrawable:
/* SecurityLookupWindow and SecurityLookupDrawable: * Look up the window/drawable taking into account the client doing the
* Look up the window/drawable taking into account the client doing * lookup, the type of drawable desired, and the type of access desired.
* the lookup and the type of access desired. Return the window/drawable * Return Success with *pDraw set if the window/drawable exists and the client
* if it exists and the client is allowed access, else return NULL. * is allowed access, else return an error code with *pDraw set to NULL. The
* Most Proc* functions should be calling these instead of * access mask values are defined in resource.h. The type mask values are
* LookupWindow and LookupDrawable, which do no access checks. * defined in pixmap.h, with zero equivalent to M_DRAWABLE.
* XACE note: need to see if client->lastDrawableID can still be used here.
*/ */
_X_EXPORT int
_X_EXPORT WindowPtr dixLookupDrawable(DrawablePtr *pDraw, XID id, ClientPtr client,
SecurityLookupWindow(XID rid, ClientPtr client, Mask access_mode) Mask type, Mask access)
{ {
client->errorValue = rid; DrawablePtr pTmp;
if(rid == INVALID) RESTYPE rtype;
return NULL; *pDraw = NULL;
return (WindowPtr)SecurityLookupIDByType(client, rid, RT_WINDOW, access_mode); client->errorValue = id;
}
if (id == INVALID)
return BadDrawable;
_X_EXPORT pointer if (id == client->lastDrawableID) {
SecurityLookupDrawable(XID rid, ClientPtr client, Mask access_mode) pTmp = client->lastDrawable;
{
register DrawablePtr pDraw;
if(rid == INVALID) /* an access check is required for cached drawables */
return (pointer) NULL; rtype = (pTmp->type | M_WINDOW) ? RT_WINDOW : RT_PIXMAP;
pDraw = (DrawablePtr)SecurityLookupIDByClass(client, rid, RC_DRAWABLE, if (!XaceHook(XACE_RESOURCE_ACCESS, client, id, rtype, access, pTmp))
access_mode); return BadDrawable;
if (pDraw && (pDraw->type != UNDRAWABLE_WINDOW)) } else
return (pointer)pDraw; pTmp = (DrawablePtr)SecurityLookupIDByClass(client, id, RC_DRAWABLE,
return (pointer)NULL; access);
} if (!pTmp)
return BadDrawable;
if (!((1 << pTmp->type) | (type ? type : M_DRAWABLE)))
return BadMatch;
/* We can't replace the LookupWindow and LookupDrawable functions with if (pTmp->type | M_DRAWABLE) {
* macros because of compatibility with loadable servers. client->lastDrawable = pTmp;
*/ client->lastDrawableID = id;
_X_EXPORT WindowPtr
LookupWindow(XID rid, ClientPtr client)
{
return SecurityLookupWindow(rid, client, DixUnknownAccess);
}
_X_EXPORT pointer
LookupDrawable(XID rid, ClientPtr client)
{
return SecurityLookupDrawable(rid, client, DixUnknownAccess);
}
#else /* not XACE */
WindowPtr
LookupWindow(XID rid, ClientPtr client)
{
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->lastGCID = INVALID;
client->lastGC = (GCPtr)NULL; client->lastGC = (GCPtr)NULL;
} }
return pWin; *pDraw = pTmp;
return Success;
} }
_X_EXPORT int
pointer dixLookupWindow(WindowPtr *pWin, XID id, ClientPtr client, Mask access)
LookupDrawable(XID rid, ClientPtr client)
{ {
register DrawablePtr pDraw; int rc;
rc = dixLookupDrawable((DrawablePtr*)pWin, id, client, M_WINDOW, access);
if(rid == INVALID) return (rc == BadDrawable) ? BadWindow : rc;
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;
} }
#endif /* XACE */ _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 ClientPtr _X_EXPORT int
LookupClient(XID rid, ClientPtr client) dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client)
{ {
pointer pRes = (pointer)SecurityLookupIDByClass(client, rid, RC_ANY, pointer pRes = (pointer)SecurityLookupIDByClass(client, rid, RC_ANY,
DixReadAccess); DixReadAccess);
int clientIndex = CLIENT_ID(rid); int clientIndex = CLIENT_ID(rid);
if (clientIndex && pRes && clients[clientIndex] && !(rid & SERVER_BIT)) if (clientIndex && pRes && clients[clientIndex] && !(rid & SERVER_BIT)) {
{ *pClient = clients[clientIndex];
return clients[clientIndex]; return Success;
} }
return (ClientPtr)NULL; *pClient = NULL;
return BadValue;
} }
/*
* These are deprecated compatibility functions and will be removed soon!
* Please use the new dixLookup*() functions above.
*/
_X_EXPORT WindowPtr
SecurityLookupWindow(XID id, ClientPtr client, Mask access_mode)
{
WindowPtr pWin;
int i = dixLookupWindow(&pWin, id, client, access_mode);
return (i == Success) ? pWin : NULL;
}
_X_EXPORT WindowPtr
LookupWindow(XID id, ClientPtr client)
{
return SecurityLookupWindow(id, client, DixUnknownAccess);
}
_X_EXPORT pointer
SecurityLookupDrawable(XID id, ClientPtr client, Mask access_mode)
{
DrawablePtr pDraw;
int i = dixLookupDrawable(&pDraw, id, client, access_mode, TRUE);
return (i == Success) ? pDraw : NULL;
}
_X_EXPORT pointer
LookupDrawable(XID id, ClientPtr client)
{
return SecurityLookupDrawable(id, client, DixUnknownAccess);
}
_X_EXPORT ClientPtr
LookupClient(XID id, ClientPtr client)
{
ClientPtr pClient;
int i = dixLookupClient(&pClient, id, client);
return (i == Success) ? pClient : NULL;
}
/* end deprecated functions */
int int
AlterSaveSetForClient(ClientPtr client, WindowPtr pWin, unsigned mode, AlterSaveSetForClient(ClientPtr client, WindowPtr pWin, unsigned mode,

View File

@ -155,17 +155,21 @@ _X_HIDDEN void *dixLookupTab[] = {
SYMFUNC(CompareTimeStamps) SYMFUNC(CompareTimeStamps)
SYMFUNC(CopyISOLatin1Lowered) SYMFUNC(CopyISOLatin1Lowered)
SYMFUNC(DeleteCallback) SYMFUNC(DeleteCallback)
SYMFUNC(dixLookupDrawable)
SYMFUNC(dixLookupWindow)
SYMFUNC(dixLookupClient)
SYMFUNC(dixLookupGC)
/* following are deprecated */
SYMFUNC(LookupClient) SYMFUNC(LookupClient)
SYMFUNC(LookupDrawable) SYMFUNC(LookupDrawable)
SYMFUNC(LookupWindow) SYMFUNC(LookupWindow)
SYMFUNC(SecurityLookupDrawable)
SYMFUNC(SecurityLookupWindow)
/* end deprecated */
SYMFUNC(NoopDDA) SYMFUNC(NoopDDA)
SYMFUNC(QueueWorkProc) SYMFUNC(QueueWorkProc)
SYMFUNC(RegisterBlockAndWakeupHandlers) SYMFUNC(RegisterBlockAndWakeupHandlers)
SYMFUNC(RemoveBlockAndWakeupHandlers) SYMFUNC(RemoveBlockAndWakeupHandlers)
#ifdef XACE
SYMFUNC(SecurityLookupDrawable)
SYMFUNC(SecurityLookupWindow)
#endif
/* events.c */ /* events.c */
SYMFUNC(CheckCursorConfinement) SYMFUNC(CheckCursorConfinement)
SYMFUNC(DeliverEvents) SYMFUNC(DeliverEvents)

View File

@ -375,47 +375,40 @@ extern int CompareISOLatin1Lowered(
unsigned char * /*b*/, unsigned char * /*b*/,
int blen); int blen);
#ifdef XACE extern int dixLookupWindow(
WindowPtr *result,
XID id,
ClientPtr client,
Mask access_mode);
extern WindowPtr SecurityLookupWindow( extern int dixLookupDrawable(
XID /*rid*/, DrawablePtr *result,
ClientPtr /*client*/, XID id,
Mask /*access_mode*/); ClientPtr client,
Mask type_mask,
Mask access_mode);
extern pointer SecurityLookupDrawable( extern int dixLookupGC(
XID /*rid*/, GCPtr *result,
ClientPtr /*client*/, XID id,
Mask /*access_mode*/); ClientPtr client,
Mask access_mode);
extern WindowPtr LookupWindow( extern int dixLookupClient(
XID /*rid*/, ClientPtr *result,
ClientPtr /*client*/); XID id,
ClientPtr client);
extern pointer LookupDrawable( /*
XID /*rid*/, * These are deprecated compatibility functions and will be removed soon!
ClientPtr /*client*/); * Please use the new dixLookup*() functions above.
*/
#else extern WindowPtr SecurityLookupWindow(XID, ClientPtr, Mask);
extern WindowPtr LookupWindow(XID, ClientPtr);
extern WindowPtr LookupWindow( extern pointer SecurityLookupDrawable(XID, ClientPtr, Mask);
XID /*rid*/, extern pointer LookupDrawable(XID, ClientPtr);
ClientPtr /*client*/); extern ClientPtr LookupClient(XID, ClientPtr);
/* end deprecated functions */
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 ClientPtr LookupClient(
XID /*rid*/,
ClientPtr /*client*/);
extern void NoopDDA(void); extern void NoopDDA(void);

View File

@ -58,6 +58,16 @@ SOFTWARE.
#define UNDRAWABLE_WINDOW 2 #define UNDRAWABLE_WINDOW 2
#define DRAWABLE_BUFFER 3 #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() */ /* flags to PaintWindow() */
#define PW_BACKGROUND 0 #define PW_BACKGROUND 0
#define PW_BORDER 1 #define PW_BORDER 1