6819661 [nevada][tjds] many desktop applications do not launch in TX
authorLokanath Das <Lokanath.Das@Sun.COM>
Thu, 02 Apr 2009 14:22:10 -0700
changeset 679 5f3986f48115
parent 678 a6c6280ef0b7
child 680 f420e9b51ef5
6819661 [nevada][tjds] many desktop applications do not launch in TX
open-src/xserver/xorg/sun-src/tsol/tsol.h
open-src/xserver/xorg/sun-src/tsol/tsolextension.c
open-src/xserver/xorg/sun-src/tsol/tsolinfo.h
open-src/xserver/xorg/sun-src/tsol/tsolpolicy.c
open-src/xserver/xorg/sun-src/tsol/tsolprotocol.c
open-src/xserver/xorg/sun-src/tsol/tsolutils.c
open-src/xserver/xorg/xtsol.patch
--- a/open-src/xserver/xorg/sun-src/tsol/tsol.h	Tue Mar 31 17:01:13 2009 -0700
+++ b/open-src/xserver/xorg/sun-src/tsol/tsol.h	Thu Apr 02 14:22:10 2009 -0700
@@ -26,7 +26,7 @@
  * of the copyright holder.
  */ 
 
-#pragma ident   "@(#)tsol.h 1.9     09/02/10 SMI"
+#pragma ident   "@(#)tsol.h 1.10     09/04/02 SMI"
 
 /*
  * tsol.h server side extension
@@ -98,9 +98,6 @@
 
 /* tsolextension.c */
 extern void TsolExtensionInit(void);
-extern int TsolCheckPropertyAccess(ClientPtr client, WindowPtr pWin,
-				   PropertyPtr pProp, Atom propertyName,
-				   Mask access_mode);
 extern int tsolMultiLevel;
 extern int (*TsolSavedProcVector[PROCVECTORSIZE])(ClientPtr /*client*/);
 extern int (*TsolSavedSwappedProcVector[PROCVECTORSIZE])(ClientPtr /*client*/);
@@ -111,6 +108,7 @@
 	unsigned long, pointer, Bool);
 extern int TsolDeleteProperty(ClientPtr, WindowPtr, Atom);
 extern int TsolInitWindow(ClientPtr, WindowPtr);
+extern int TsolInitPixmap(ClientPtr, PixmapPtr);
 extern void TsolDeleteClientFromAnySelections(ClientPtr);
 extern void TsolDeleteWindowFromAnySelections(WindowPtr);
 
--- a/open-src/xserver/xorg/sun-src/tsol/tsolextension.c	Tue Mar 31 17:01:13 2009 -0700
+++ b/open-src/xserver/xorg/sun-src/tsol/tsolextension.c	Thu Apr 02 14:22:10 2009 -0700
@@ -26,7 +26,7 @@
  * of the copyright holder.
  */
 
-#pragma ident   "@(#)tsolextension.c 1.36     09/03/12 SMI"
+#pragma ident   "@(#)tsolextension.c 1.37     09/04/02 SMI"
 
 #include <stdio.h>
 #include "auditwrite.h"
@@ -123,6 +123,8 @@
 int tsolMultiLevel = TRUE;
 
 static int OwnerUIDint;
+static Selection *tsol_sel_agnt = NULL; /* entry in CurrentSelection to get seln */
+static Atom tsol_atom_sel_agnt = 0; /* selection agent atom created during init */
 
 int (*TsolSavedProcVector[PROCVECTORSIZE])(ClientPtr client);
 int (*TsolSavedSwappedProcVector[PROCVECTORSIZE])(ClientPtr client);
@@ -137,12 +139,17 @@
 
 /* XACE hook callbacks */
 static CALLBACK(TsolCheckExtensionAccess);
-static CALLBACK(TsolAceCheckPropertyAccess);
+static CALLBACK(TsolCheckPropertyAccess);
 static CALLBACK(TsolCheckResourceIDAccess);
+static CALLBACK(TsolCheckSendAccess);
+static CALLBACK(TsolCheckReceiveAccess);
+static CALLBACK(TsolCheckDeviceAccess);
+static CALLBACK(TsolCheckSelectionAccess);
 static CALLBACK(TsolProcessKeyboard);
 
 /* other callbacks */
 static CALLBACK(TsolClientStateCallback);
+static CALLBACK(TsolSelectionCallback);
 
 
 /*
@@ -184,30 +191,49 @@
 	if (!AddCallback(&ClientStateCallback, TsolClientStateCallback, NULL))
 		return;
 
+	if (!AddCallback(&SelectionCallback, TsolSelectionCallback, NULL))
+		return;
+
 	/* Allocate storage in devPrivates */
 	if (!dixRequestPrivate(tsolPrivKey, sizeof (TsolPrivRec))) {
 		ErrorF("TsolExtensionInit: Cannot allocate devPrivate.\n");
 		return;
 	}
 
+	/* Initialize the client info for server itself */
+    	if (serverClient) {
+        	TsolInfoPtr tsolinfo = GetClientTsolInfo(serverClient);
+		if (tsolinfo->sl == NULL) {
+			tsolinfo->sl = (bslabel_t *)lookupSL_low();
+			tsolinfo->uid = 0;
+			tsolinfo->pid = getpid();
+			snprintf(tsolinfo->pname, MAXNAME, "client id %d (pid %d)",
+  				serverClient->index, tsolinfo->pid);
+		}
+	}
+
 	LoadTsolConfig();
 
 	MakeTSOLAtoms();
 	UpdateTsolNode();
 
+	tsol_atom_sel_agnt = MakeAtom("_TSOL_SEL_AGNT", 14, 1);
+
 	/* Initialize security hooks */
 	tsolSecHook.CheckAuthorization = TsolCheckAuthorization;
-	tsolSecHook.ChangeWindowProperty = TsolChangeWindowProperty;
-	tsolSecHook.DeleteProperty = TsolDeleteProperty;
+/*
 	tsolSecHook.DeleteClientFromAnySelections = TsolDeleteClientFromAnySelections;
 	tsolSecHook.DeleteWindowFromAnySelections = TsolDeleteWindowFromAnySelections;
+*/
 	pSecHook = &tsolSecHook;
 
-	XaceRegisterCallback(XACE_RESOURCE_ACCESS, TsolCheckResourceIDAccess,
-			     NULL);
-	XaceRegisterCallback(XACE_PROPERTY_ACCESS, TsolAceCheckPropertyAccess,
-			     NULL);
+	XaceRegisterCallback(XACE_RESOURCE_ACCESS, TsolCheckResourceIDAccess, NULL);
+	XaceRegisterCallback(XACE_PROPERTY_ACCESS, TsolCheckPropertyAccess, NULL);
+	XaceRegisterCallback(XACE_SEND_ACCESS, TsolCheckSendAccess, NULL);
+	XaceRegisterCallback(XACE_RECEIVE_ACCESS, TsolCheckReceiveAccess, NULL);
 	XaceRegisterCallback(XACE_EXT_ACCESS, TsolCheckExtensionAccess, NULL);
+	XaceRegisterCallback(XACE_DEVICE_ACCESS, TsolCheckDeviceAccess, NULL);
+	XaceRegisterCallback(XACE_SELECTION_ACCESS, TsolCheckSelectionAccess, NULL);
 	XaceRegisterCallback(XACE_KEY_AVAIL, TsolProcessKeyboard, NULL);
 	XaceRegisterCallback(XACE_AUDIT_BEGIN, TsolAuditStart, NULL);
 	XaceRegisterCallback(XACE_AUDIT_END, TsolAuditEnd, NULL);
@@ -220,32 +246,15 @@
 
 	/* Replace some of the original Proc vectors with our own TBD */
 	ProcVector[X_InternAtom] = ProcTsolInternAtom;
-	ProcVector[X_SetSelectionOwner] = ProcTsolSetSelectionOwner;
-	ProcVector[X_GetSelectionOwner] = ProcTsolGetSelectionOwner;
-	ProcVector[X_ConvertSelection] = ProcTsolConvertSelection;
-	ProcVector[X_GetProperty] = ProcTsolGetProperty;
-	ProcVector[X_ListProperties] = ProcTsolListProperties;
-	ProcVector[X_ChangeKeyboardMapping] = ProcTsolChangeKeyboardMapping;
-	ProcVector[X_SetPointerMapping] = ProcTsolSetPointerMapping;
-	ProcVector[X_ChangeKeyboardControl] = ProcTsolChangeKeyboardControl;
-	ProcVector[X_Bell] = ProcTsolBell;
-	ProcVector[X_ChangePointerControl] = ProcTsolChangePointerControl;
-	ProcVector[X_SetModifierMapping] = ProcTsolSetModifierMapping;
 
 	ProcVector[X_CreateWindow] = ProcTsolCreateWindow;
-	/* ProcVector[X_ChangeWindowAttributes] = ProcTsolChangeWindowAttributes; */
+	ProcVector[X_ChangeWindowAttributes] = ProcTsolChangeWindowAttributes;
 	ProcVector[X_ConfigureWindow] = ProcTsolConfigureWindow;
 	ProcVector[X_CirculateWindow] = ProcTsolCirculateWindow;
 	ProcVector[X_ReparentWindow] = ProcTsolReparentWindow;
-	ProcVector[X_SetInputFocus] = ProcTsolSetInputFocus;
-	ProcVector[X_GetInputFocus] = ProcTsolGetInputFocus;
-	ProcVector[X_SendEvent] = ProcTsolSendEvent;
-	ProcVector[X_SetInputFocus] = ProcTsolSetInputFocus;
-	ProcVector[X_GetInputFocus] = ProcTsolGetInputFocus;
 	ProcVector[X_GetGeometry] = ProcTsolGetGeometry;
 	ProcVector[X_GrabServer] = ProcTsolGrabServer;
 	ProcVector[X_UngrabServer] = ProcTsolUngrabServer;
-	ProcVector[X_CreatePixmap] = ProcTsolCreatePixmap;
 	ProcVector[X_SetScreenSaver] = ProcTsolSetScreenSaver;
 	ProcVector[X_ChangeHosts] = ProcTsolChangeHosts;
 	ProcVector[X_SetAccessControl] = ProcTsolChangeAccessControl;
@@ -253,7 +262,7 @@
 	ProcVector[X_SetFontPath] = ProcTsolSetFontPath;
 	ProcVector[X_SetCloseDownMode] = ProcTsolChangeCloseDownMode;
 	ProcVector[X_ListInstalledColormaps] = ProcTsolListInstalledColormaps;
-	ProcVector[X_GetImage] = ProcTsolGetImage;
+	/* ProcVector[X_GetImage] = ProcTsolGetImage; */
 	ProcVector[X_QueryTree] = ProcTsolQueryTree;
 	ProcVector[X_QueryPointer] = ProcTsolQueryPointer;
 	ProcVector[X_QueryExtension] = ProcTsolQueryExtension;
@@ -291,20 +300,17 @@
 
 #define CHECK_RESOURCE_POLICY(DIX_MODE, TSOL_TYPE, TSOL_MODE, VAL, ID)	\
 	    if (check_mode & (DIX_MODE)) {				\
-	        if (xtsol_policy((TSOL_TYPE), (TSOL_MODE), (VAL),	\
-				 (ID), client, TSOL_ALL, &reqtype))	\
-			rec->status = BadAccess;			\
-		else 							\
-			rec->status = Success;				\
+	        rec->status = xtsol_policy((TSOL_TYPE), (TSOL_MODE), 	\
+			(VAL), (ID), client, TSOL_ALL, &reqtype);	\
 		check_mode &= ~(DIX_MODE);				\
 	    }
 
     switch (rtype) {
         case RT_GC:
-	    CHECK_RESOURCE_POLICY(DixReadAccess, TSOL_RES_GC, TSOL_READ,
-				  NULL, id);
-	    CHECK_RESOURCE_POLICY(DixWriteAccess, TSOL_RES_GC, TSOL_MODIFY,
-				  NULL, id);
+	    CHECK_RESOURCE_POLICY((DixReadAccess|DixGetAttrAccess|DixUseAccess),
+			TSOL_RES_GC, TSOL_READ, NULL, id);
+	    CHECK_RESOURCE_POLICY((DixWriteAccess|DixSetAttrAccess),
+			TSOL_RES_GC, TSOL_MODIFY, NULL, id);
 	    CHECK_RESOURCE_POLICY(DixCreateAccess, TSOL_RES_GC, TSOL_CREATE,
 				  NULL, id);
 	    CHECK_RESOURCE_POLICY(DixDestroyAccess, TSOL_RES_GC, TSOL_DESTROY,
@@ -313,25 +319,80 @@
 	    break;
 
 	case RT_WINDOW:		/* Drawables */
-	    if (check_mode & DixCreateAccess) {
-		/* Replaces InitWindow hook */
-		TsolInitWindow(client, (WindowPtr) rval);
-		check_mode &= ~(DixCreateAccess);
-	    }
-	    if (check_mode & DixReceiveAccess) {
-	        CHECK_RESOURCE_POLICY(DixReceiveAccess, TSOL_RES_WINDOW, 
-		    TSOL_SPECIAL, rval, 0);
-		break;
-	    }
-	    if (check_mode & DixSetAttrAccess) {
-	        CHECK_RESOURCE_POLICY(DixSetAttrAccess, TSOL_RES_WINDOW, 
-		    TSOL_SPECIAL, rval, 0);
-		break;
+	    switch (reqtype) {
+		case X_SetInputFocus:
+	    	    CHECK_RESOURCE_POLICY(DixSetAttrAccess,
+				TSOL_RES_FOCUSWIN, TSOL_MODIFY, rval, 0); 
+		    break;
+		case X_GetInputFocus:
+	    	    CHECK_RESOURCE_POLICY(DixGetAttrAccess,
+				TSOL_RES_FOCUSWIN, TSOL_READ, rval, 0); 
+		    break;
+		case X_ChangeWindowAttributes:
+		    CHECK_RESOURCE_POLICY((DixSetAttrAccess|DixReceiveAccess),
+					TSOL_RES_WINDOW, TSOL_SPECIAL, rval, 0); 
+		    if (rec->status != Success) {
+			WindowPtr pWin = (WindowPtr)rval;
+			if (WindowIsRoot(pWin))
+		    	    rec->status = Success;
+		    }
+		    break;
+		case X_GrabPointer:
+		case X_UngrabPointer:
+		case X_GrabKeyboard:
+		case X_UngrabKeyboard:
+		case X_GrabKey:
+		case X_UngrabKey:
+		case X_GrabButton:
+		case X_UngrabButton:
+	    	    CHECK_RESOURCE_POLICY(DixSetAttrAccess,
+				TSOL_RES_GRABWIN, TSOL_MODIFY, rval, 0); 
+		    break;
+
+		default:
+		    /* CreateWindow, policy check on the parent */
+		    CHECK_RESOURCE_POLICY((DixAddAccess|DixRemoveAccess), 
+					TSOL_RES_WINDOW, TSOL_CREATE, rval, 0);
+
+		    /* Newly created window. Just initialize it. */
+		    if (check_mode & DixCreateAccess) {
+			TsolInitWindow(client, (WindowPtr) rval);
+			check_mode &= ~(DixCreateAccess);
+		    }
+
+		    CHECK_RESOURCE_POLICY((DixReadAccess|DixGetAttrAccess|DixListAccess),
+					TSOL_RES_WINDOW, TSOL_READ, rval, 0);
+		    CHECK_RESOURCE_POLICY((DixWriteAccess|DixSetAttrAccess|DixShowAccess|
+						DixHideAccess|DixManageAccess),
+					TSOL_RES_WINDOW, TSOL_MODIFY, rval, 0); 
+		    CHECK_RESOURCE_POLICY(DixDestroyAccess, TSOL_RES_WINDOW, 
+					TSOL_DESTROY, rval, 0);
+
+		    /* Event access, actual policy is implemented in the hook */
+		    CHECK_RESOURCE_POLICY(DixSendAccess, TSOL_RES_WINDOW,
+					TSOL_SPECIAL, rval, 0);
+		    CHECK_RESOURCE_POLICY(DixReceiveAccess, TSOL_RES_WINDOW,
+					TSOL_SPECIAL, rval, 0);
+
+		    /* Property related access */
+		    CHECK_RESOURCE_POLICY((DixGetPropAccess|DixListPropAccess),
+					TSOL_RES_PROPWIN, TSOL_READ, rval, 0);
+		    CHECK_RESOURCE_POLICY(DixSetPropAccess,
+					TSOL_RES_PROPWIN, TSOL_MODIFY, rval, 0);
+
+		    break;
 	    }
 	    /* The rest falls through to code shared with RT_PIXMAP */
 	case RT_PIXMAP:
 	    /* Drawing operations use pixel access policy */
 	    switch (reqtype) {
+		case X_CreatePixmap:
+		    /* Newly created window. Just initialize it. */
+		    if (check_mode & DixCreateAccess) {
+			TsolInitPixmap(client, (PixmapPtr) rval);
+			check_mode &= ~(DixCreateAccess);
+		    }
+		    break;
 		case X_PolyPoint:
 		case X_PolyLine:
 		case X_PolyArc:
@@ -344,33 +405,41 @@
 		case X_ImageText8:
 		case X_ImageText16:
 		    CHECK_RESOURCE_POLICY((DixReadAccess | DixBlendAccess),
-					  TSOL_RES_PIXEL, TSOL_READ,
-					  rval, 0);
+					  TSOL_RES_PIXEL, TSOL_READ, rval, 0);
 		    CHECK_RESOURCE_POLICY(DixWriteAccess,
-					  TSOL_RES_PIXEL, TSOL_MODIFY,
-					  rval, 0);
+					  TSOL_RES_PIXEL, TSOL_MODIFY, rval, 0);
 		break;
-
-	    /* Property protocols */
-		case X_ChangeProperty:
-		case X_DeleteProperty:
-		case X_GetProperty:
-		case X_ListProperties:
-		case X_RotateProperties:
-		    CHECK_RESOURCE_POLICY((DixGetPropAccess|DixListPropAccess),
-					  TSOL_RES_PROPWIN, TSOL_READ,
-					  rval, 0);
-		    CHECK_RESOURCE_POLICY(DixSetPropAccess,
-					  TSOL_RES_PROPWIN, TSOL_MODIFY,
-					  rval, 0);
-		    break;
+		case X_GetImage:
 		case X_ClearArea:
 		    rec->status = Success;
 		    break;
+		default:
+		    if (check_mode & (DixReadAccess|DixWriteAccess)) {
+			check_mode &= ~(DixReadAccess|DixWriteAccess);
+			rec->status = Success;
+		    }
+/*
+		    CHECK_RESOURCE_POLICY(DixReadAccess,
+					  TSOL_RES_PIXMAP, TSOL_READ, rval, 0);
+		    CHECK_RESOURCE_POLICY(DixWriteAccess,
+					  TSOL_RES_PIXMAP, TSOL_MODIFY, rval, 0);
+*/
+		    break;
 	    }
 	    break;
 
-	  default:
+        case RT_CURSOR:
+	    CHECK_RESOURCE_POLICY((DixUseAccess|DixWriteAccess),
+			TSOL_RES_CURSOR, TSOL_MODIFY, NULL, id);
+	    CHECK_RESOURCE_POLICY(DixCreateAccess,
+			TSOL_RES_CURSOR, TSOL_CREATE, NULL, id);
+	    break;
+        case RT_FONT:
+	    CHECK_RESOURCE_POLICY(DixUseAccess,
+			TSOL_RES_CURSOR, TSOL_READ, NULL, id);
+	    break;
+
+	default:
 		rec->status = Success;
 		break;
     }
@@ -386,7 +455,7 @@
     }
 #endif /* !NO_TSOL_DEBUG_MESSAGES */
 
-    if (rec->status == BadAccess) {
+    if (rec->status != Success) {
 	msgType = X_ERROR;
 	msgVerb = TSOL_MSG_ERROR;
     } else {
@@ -412,6 +481,30 @@
 }
 
 static
+CALLBACK(TsolSelectionCallback)
+{
+	SelectionInfoRec *pselinfo = (SelectionInfoRec *)calldata;
+	Selection *pSel = pselinfo->selection;
+	TsolSelnPtr tsolseln = TsolSelectionPriv(pSel);
+
+	switch (pselinfo->kind) {
+	case SelectionClientClose:
+	    if (tsol_sel_agnt && pSel->selection ==  tsol_sel_agnt->selection) {
+		tsol_sel_agnt = NULL; /* selection manager died. */
+	    }
+	/* fall through to reset the SL */
+
+	case SelectionWindowDestroy:
+	    tsolseln->sl = NULL; 
+	    break;
+
+	default:
+	    /* All others handled in SelectionAccess handler */
+	    break;
+	}
+}
+
+static
 CALLBACK(TsolClientStateCallback)
 {
  	NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
@@ -465,8 +558,12 @@
 {
     free_win_privsets();
     XaceDeleteCallback(XACE_RESOURCE_ACCESS, TsolCheckResourceIDAccess, NULL);
-    XaceDeleteCallback(XACE_PROPERTY_ACCESS, TsolAceCheckPropertyAccess, NULL);
+    XaceDeleteCallback(XACE_PROPERTY_ACCESS, TsolCheckPropertyAccess, NULL);
+    XaceDeleteCallback(XACE_SEND_ACCESS, TsolCheckSendAccess, NULL);
+    XaceDeleteCallback(XACE_RECEIVE_ACCESS, TsolCheckReceiveAccess, NULL);
     XaceDeleteCallback(XACE_EXT_ACCESS, TsolCheckExtensionAccess, NULL);
+    XaceDeleteCallback(XACE_DEVICE_ACCESS, TsolCheckDeviceAccess, NULL);
+    XaceDeleteCallback(XACE_SELECTION_ACCESS, TsolCheckSelectionAccess, NULL);
     XaceDeleteCallback(XACE_KEY_AVAIL, TsolProcessKeyboard, NULL);
     XaceDeleteCallback(XACE_AUDIT_BEGIN, TsolAuditStart, NULL);
     XaceDeleteCallback(XACE_AUDIT_END, TsolAuditEnd, NULL);
@@ -779,16 +876,19 @@
     bslabel_t   *sl;
     WindowPtr    pWin;
     TsolPropPtr  tsolprop;
-    TsolPropPtr *tsolpropP;
     PropertyPtr  pProp;
     int          err_code;
+    int rc;
 
     REQUEST(xSetPropLabelReq);
 
     REQUEST_AT_LEAST_SIZE(xSetPropLabelReq);
 
 
-    pWin = LookupWindow(stuff->id, client);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    if (rc != Success)
+        return rc;
+
     if (!pWin)
     {
         client->errorValue = stuff->id;
@@ -822,15 +922,7 @@
     }
 
     /* Initialize property created internally by server */
-    tsolpropP = TsolPropertyPriv(pProp);
-    if (*tsolpropP == NULL)
-    {
-        *tsolpropP = (pointer)AllocServerTsolProp();
-        if (*tsolpropP == NULL)
-	    return(BadAlloc);
-    }
-
-    tsolprop = *tsolpropP;
+    tsolprop = TsolPropertyPriv(pProp);
 
     sl = (bslabel_t *)(stuff + 1);
 
@@ -852,25 +944,24 @@
 {
     WindowPtr   pWin;
     TsolPropPtr tsolprop;
-    TsolPropPtr *tsolpropP;
     PropertyPtr pProp;
     int         err_code;
+    int 	rc;
 
     REQUEST(xSetPropUIDReq);
 
     REQUEST_SIZE_MATCH(xSetPropUIDReq);
 
-    pWin = LookupWindow(stuff->id, client);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    if (rc != Success)
+        return rc;
+
     if (!pWin)
     {
         client->errorValue = stuff->id;
         return (BadWindow);
     }
-    if ((err_code = xtsol_policy(TSOL_RES_WINDOW, TSOL_MODIFY, pWin, 0,
-				 client, TSOL_ALL, &(MAJOROP))))
-    {
-        return (err_code);
-    }
+
     if (!ValidAtom(stuff->atom))
     {
         client->errorValue = stuff->atom;
@@ -898,15 +989,8 @@
         return (err_code);
     }
     /* Initialize property created internally by server */
-    tsolpropP = TsolPropertyPriv(pProp);
-    if (*tsolpropP == NULL)
-    {
-        *tsolpropP = AllocServerTsolProp();
-        if (*tsolpropP == NULL)
-	    return (BadAlloc);
-    }
+    tsolprop = TsolPropertyPriv(pProp);
 
-    tsolprop = *tsolpropP;
     tsolprop->uid = stuff->uid;
 
     return (client->noClientException);
@@ -921,6 +1005,7 @@
     xEvent      message;
     TsolResPtr  tsolres;
     int         err_code;
+    int		rc;
 
     REQUEST(xSetResLabelReq);
 
@@ -946,7 +1031,10 @@
             memcpy(&SessionLO, sl, SL_SIZE);
             return (client->noClientException);
         case IsWindow:
-            pWin = LookupWindow(stuff->id, client);
+	    rc = dixLookupWindow(&pWin, stuff->id, client, DixWriteAccess);
+    	    if (rc != Success)
+		return rc;
+
             if (pWin)
             {
                 tsolres = TsolWindowPriv(pWin);
@@ -956,14 +1044,12 @@
                 client->errorValue = stuff->id;
                 return (BadWindow);
             }
-            if ((err_code = xtsol_policy(TSOL_RES_WINDOW, TSOL_MODIFY, pWin,
-					 0, client, TSOL_ALL, &(MAJOROP))))
-            {
-                return (err_code);
-            }
             break;
         case IsPixmap:
-            pMap = (PixmapPtr)LookupIDByType(stuff->id, RT_PIXMAP);
+	    rc = dixLookupResource((pointer *)&pMap, stuff->id, RT_PIXMAP,
+			client, DixWriteAccess);
+    	    if (rc != Success)
+		return rc;
             if (pMap)
             {
                 tsolres = TsolPixmapPriv(pMap);
@@ -973,11 +1059,6 @@
                 client->errorValue = stuff->id;
                 return (BadPixmap);
             }
-            if ((err_code = xtsol_policy(TSOL_RES_PIXMAP, TSOL_MODIFY, pMap,
-					 0, client, TSOL_ALL, &(MAJOROP))))
-            {
-                return (err_code);
-            }
             break;
 	default:
 	    client->errorValue = stuff->resourceType;
@@ -998,7 +1079,10 @@
 
     if (stuff->resourceType == IsWindow)
     {
-        pWin = LookupWindow(stuff->id, client);
+	rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    	if (rc != Success)
+	    return rc;
+
         message.u.u.type = ClientMessage; /* 33 */
         message.u.u.detail = 32;
         message.u.clientMessage.window = RootOf(pWin);
@@ -1021,6 +1105,7 @@
     WindowPtr pWin;
     TsolResPtr tsolres;
     int        err_code;
+    int        rc;
 
     REQUEST(xSetResUIDReq);
 
@@ -1053,7 +1138,10 @@
             AddUID(&OwnerUIDint);
             return (client->noClientException);
         case IsWindow:
-            pWin = LookupWindow(stuff->id, client);
+	    rc = dixLookupWindow(&pWin, stuff->id, client, DixWriteAccess);
+    	    if (rc != Success)
+		return rc;
+
             if (pWin)
             {
                 tsolres = TsolWindowPriv(pWin);
@@ -1063,14 +1151,13 @@
                 client->errorValue = stuff->id;
                 return (BadWindow);
             }
-            if ((err_code = xtsol_policy(TSOL_RES_WINDOW, TSOL_MODIFY, pWin, 0,
-					 client, TSOL_ALL, &(MAJOROP))))
-            {
-                return (err_code);
-            }
             break;
         case IsPixmap:
-            pMap = (PixmapPtr)LookupIDByType(stuff->id, RT_PIXMAP);
+	    rc = dixLookupResource((pointer *)&pMap, stuff->id, RT_PIXMAP,
+			client, DixWriteAccess);
+    	    if (rc != Success)
+		return rc;
+
             if (pMap)
             {
                 tsolres = TsolPixmapPriv(pMap);
@@ -1080,11 +1167,6 @@
                 client->errorValue = stuff->id;
                 return (BadPixmap);
             }
-            if ((err_code = xtsol_policy(TSOL_RES_PIXMAP, TSOL_MODIFY, pMap, 0,
-					 client, TSOL_ALL, &(MAJOROP))))
-            {
-                return (err_code);
-            }
             break;
         default:
             return (BadValue);
@@ -1105,6 +1187,7 @@
 {
     int         n;
     int         err_code;
+    int         rc;
     ClientPtr   res_client; /* resource owner client */
     TsolInfoPtr tsolinfo, res_tsolinfo;
     WindowPtr	pWin;
@@ -1115,11 +1198,9 @@
     REQUEST_SIZE_MATCH(xGetClientAttributesReq);
 
     /* Valid window check */
-    if ((pWin = LookupWindow(stuff->id, client)) == NULL)
-    {
-        client->errorValue = stuff->id;
-        return (BadWindow);
-    }
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    if (rc != Success)
+	return rc;
 
     if (!(res_client = clients[CLIENT_ID(stuff->id)]))
     {
@@ -1169,6 +1250,7 @@
 {
     int         n;
     int         reply_length = 0;
+    int         rc;
     int         err_code;
     Bool        write_to_client = 0;
     bslabel_t   *sl;
@@ -1182,11 +1264,9 @@
     REQUEST_SIZE_MATCH(xGetClientLabelReq);
 
     /* Valid window check */
-    if ((pWin = LookupWindow(stuff->id, client)) == NULL)
-    {
-        client->errorValue = stuff->id;
-        return (BadWindow);
-    }
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    if (rc != Success)
+	return rc;
 
     if (!(res_client = clients[CLIENT_ID(stuff->id)]))
     {
@@ -1249,13 +1329,13 @@
 {
     int          n;
     int          reply_length = 0;
-    int          err_code;
+    int          rc;
     Bool         write_to_client = 0;
     PropertyPtr  pProp;
     bslabel_t   *sl;
     WindowPtr    pWin;
-    TsolPropPtr  tsolprop, tmp_prop;
-    TsolPropPtr *tsolpropP;
+    TsolPropPtr  tsolprop;
+    TsolResPtr	tsolres;
     TsolInfoPtr  tsolinfo = GetClientTsolInfo(client);
 
     xGetPropAttributesReply rep;
@@ -1264,17 +1344,10 @@
 
     REQUEST_SIZE_MATCH(xGetPropAttributesReq);
 
-    pWin = LookupWindow(stuff->id, client);
-    if (!pWin)
-    {
-        client->errorValue = stuff->id;
-        return (BadWindow);
-    }
-    if ((err_code = xtsol_policy(TSOL_RES_WINDOW, TSOL_READ, pWin, 0,
-				 client, TSOL_ALL, &(MAJOROP))))
-    {
-        return (err_code);
-    }
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    if (rc != Success)
+	return rc;
+
     if (!ValidAtom(stuff->atom))
     {
         client->errorValue = stuff->atom;
@@ -1285,49 +1358,34 @@
     pProp = wUserProps (pWin);
     while (pProp)
     {
-        if (pProp->propertyName == stuff->atom)
-            break;
+        tsolprop = TsolPropertyPriv(pProp);
+
+        if (pProp->propertyName == stuff->atom) {
+
+            if (tsolpolyinstinfo.enabled) {
+                if (tsolprop->uid == tsolpolyinstinfo.uid &&
+                        tsolprop->sl == tsolpolyinstinfo.sl)
+                    break; /* match found */
+            } else {
+                if (tsolprop->uid == tsolinfo->uid &&
+                        tsolprop->sl == tsolinfo->sl) {
+                    break; /* match found */
+                }
+            }
+        }
         pProp = pProp->next;
     }
 
     if (!pProp)
     {
-        /* property does not exist */
-        client->errorValue = stuff->atom;
-        return (BadAtom);
+        /* property does not exist, use window's attributes */
+	tsolres = TsolWindowPriv(pWin);
+	tsolprop = NULL;
     }
-    tsolpropP = TsolPropertyPriv(pProp);
-    tsolprop = *tsolpropP;
-    tmp_prop = tsolprop;
-    while (tmp_prop)
-    {
-        if (tsolpolyinstinfo.enabled)
-        {
-            if (tmp_prop->uid == tsolpolyinstinfo.uid &&
-                tmp_prop->sl == tsolpolyinstinfo.sl)
-            {
-                tsolprop = tmp_prop;
-                break;
-            }
-        }
-        else
-        {
-            if (tmp_prop->uid == tsolinfo->uid &&
-                tmp_prop->sl == tsolinfo->sl)
-            {
-                tsolprop = tmp_prop;
-                break;
-            }
-        }
-        tmp_prop = tmp_prop->next;
-    }
-    if (!tsolprop)
-    {
-        return (client->noClientException);
-    }
+
     if (stuff->mask & RES_UID)
     {
-        rep.uid = tsolprop->uid;
+        rep.uid = tsolprop ? tsolprop->uid : tsolres->uid;
     }
 
     /* allocate temp storage for labels */
@@ -1339,7 +1397,7 @@
     /* fill the fields as per request mask */
     if (stuff->mask & RES_SL)
     {
-        memcpy(sl, tsolprop->sl, SL_SIZE);
+        memcpy(sl, tsolprop ? tsolprop->sl : tsolres->sl, SL_SIZE);
         rep.sllength = SL_SIZE;
     }
 
@@ -1377,7 +1435,7 @@
 {
     int         n;
     int         reply_length = 0;
-    int         err_code;
+    int         rc;
     Bool        write_to_client = 0;
     bslabel_t  *sl;
     PixmapPtr   pMap;
@@ -1401,40 +1459,22 @@
     if (stuff->resourceType == IsWindow &&
         (stuff->mask & (RES_UID | RES_SL )))
     {
-        pWin = LookupWindow(stuff->id, client);
-        if (pWin)
-        {
-            tsolres = TsolWindowPriv(pWin);
-        }
-        else
-        {
-            client->errorValue = stuff->id;
-            return (BadWindow);
-        }
-        if ((err_code = xtsol_policy(TSOL_RES_WINDOW, TSOL_READ, pWin, 0,
-				     client, TSOL_ALL, &(MAJOROP))))
-        {
-            return (err_code);
-        }
+	rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+	if (rc != Success)
+	    return rc;
+
+	tsolres = TsolWindowPriv(pWin);
     }
+
     if (stuff->resourceType == IsPixmap &&
         (stuff->mask & (RES_UID | RES_SL )))
     {
-        pMap = (PixmapPtr)LookupIDByType(stuff->id, RT_PIXMAP);
-        if (pMap)
-        {
-            tsolres = TsolPixmapPriv(pMap);
-        }
-        else
-        {
-            client->errorValue = stuff->id;
-            return (BadPixmap);
-        }
-        if ((err_code = xtsol_policy(TSOL_RES_PIXMAP, TSOL_READ, pMap, 0,
-				     client, TSOL_ALL, &(MAJOROP))))
-        {
-            return (err_code);
-        }
+	rc = dixLookupResource((pointer *)&pMap, stuff->id, RT_PIXMAP,
+		client, DixWriteAccess);
+	if (rc != Success)
+	    return rc;
+
+	tsolres = TsolPixmapPriv(pMap);
     }
 
     if (stuff->mask & RES_UID)
@@ -1490,6 +1530,7 @@
 ProcMakeTPWindow(ClientPtr client)
 {
     WindowPtr pWin = NULL, pParent;
+    int       rc;
     int       err_code;
     TsolInfoPtr  tsolinfo;
 
@@ -1519,7 +1560,10 @@
 
 	FOR_NSCREENS_BACKWARD(j)
 	{
-		pWin = LookupWindow(panres->info[j].id, client);
+		rc = dixLookupWindow(&pWin, panres->info[j].id, 
+			client, DixWriteAccess);
+		if (rc != Success)
+		    return rc;
 
 		/* window should not be root but child of root */
 		if (!pWin || (!pWin->parent))
@@ -1543,7 +1587,10 @@
     } else
 #endif
     {
-	pWin = LookupWindow(stuff->id, client);
+	rc = dixLookupWindow(&pWin, stuff->id, client, DixWriteAccess);
+	if (rc != Success)
+	    return rc;
+
 
 	/* window should not be root but child of root */
 	if (!pWin || (!pWin->parent))
@@ -1583,13 +1630,16 @@
 ProcMakeTrustedWindow(ClientPtr client)
 {
     WindowPtr    pWin;
+    int          rc;
     int          err_code;
     TsolInfoPtr  tsolinfo;
 
     REQUEST(xMakeTrustedWindowReq);
     REQUEST_SIZE_MATCH(xMakeTrustedWindowReq);
 
-    pWin = LookupWindow(stuff->id, client);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixWriteAccess);
+    if (rc != Success)
+	return rc;
 
     /* window should not be root but child of root */
     if (!pWin || (!pWin->parent))
@@ -1615,13 +1665,16 @@
 ProcMakeUntrustedWindow(ClientPtr client)
 {
     WindowPtr    pWin;
+    int          rc;
     int          err_code;
     TsolInfoPtr  tsolinfo;
 
     REQUEST(xMakeUntrustedWindowReq);
     REQUEST_SIZE_MATCH(xMakeUntrustedWindowReq);
 
-    pWin = LookupWindow(stuff->id, client);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixWriteAccess);
+    if (rc != Success)
+	return rc;
 
     /* window should not be root but child of root */
     if (!pWin || (!pWin->parent))
@@ -2060,14 +2113,38 @@
     }
 }
 
-_X_HIDDEN int
-TsolCheckPropertyAccess(ClientPtr client, WindowPtr pWin, PropertyPtr pProp,
-			Atom propertyName, Mask access_mode)
+static CALLBACK(
+TsolCheckSendAccess)
 {
-    int returnVal = XTSOL_ALLOW;
-    TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
-    Mask check_mode = access_mode;
+    XaceSendAccessRec *rec = (XaceSendAccessRec *) calldata;
+    ClientPtr client = rec->client;
+    WindowPtr pWin = rec->pWin;
+
+    if (client == NULL) {
+	rec->status = Success;
+	return;
+    }
+
+    rec->status = xtsol_policy(TSOL_RES_EVENTWIN, TSOL_MODIFY,
+            pWin, 0, client, TSOL_ALL, (&(MAJOROP)));
+}
+
+static CALLBACK(
+TsolCheckReceiveAccess)
+{
+    XaceReceiveAccessRec *rec = (XaceReceiveAccessRec *) calldata;
+
+	rec->status = Success;
+}
+
+static CALLBACK(
+TsolCheckDeviceAccess)
+{
+    XaceDeviceAccessRec *rec = (XaceDeviceAccessRec *) calldata;
+    ClientPtr client = rec->client;
+    Mask access_mode = rec->access_mode;
     int reqtype;
+    TsolInfoPtr tsolinfo;
 
     if (client->requestBuffer) {
 	reqtype = MAJOROP;  /* protocol */
@@ -2075,56 +2152,234 @@
 	reqtype = -1;
     }
 
-    if (pProp != NULL) {
-	int isPolyProp = PolyProperty(propertyName, pWin);
+   /*
+    * The Create case seems to be for initialization, so we don't 
+    * want it to fail and there isn't a corresponding protocol request type.
+    */
+    if (access_mode & DixCreateAccess) {
+	rec->status = Success;
+	return;
+    }
+
+    switch (reqtype) {
+	case X_Bell:
+	    rec->status = xtsol_policy(TSOL_RES_BELL, TSOL_MODIFY, 
+		NULL, 0, client, TSOL_ALL, &(MAJOROP));
+	    break;
+
+	case X_GetPointerControl:
+	    rec->status = xtsol_policy(TSOL_RES_PTRCTL, TSOL_READ,
+		NULL, 0, client, TSOL_ALL, &(MAJOROP));
+              break;
+
+	case X_ChangePointerControl:
+	    rec->status = xtsol_policy(TSOL_RES_PTRCTL, TSOL_MODIFY, 
+		NULL, 0, client, TSOL_ALL, &(MAJOROP));
+	    break;
+
+	case X_GetKeyboardControl:
+	    rec->status = xtsol_policy(TSOL_RES_KBDCTL, TSOL_READ,
+		NULL, 0, client, TSOL_ALL, &(MAJOROP));
+            break;
+	case X_ChangeKeyboardControl:
+	    rec->status = xtsol_policy(TSOL_RES_KBDCTL, TSOL_MODIFY, 
+		NULL, 0, client, TSOL_ALL, &(MAJOROP));
+	    break;
+
+	case X_GetKeyboardMapping:
+	    rec->status = xtsol_policy(TSOL_RES_KEYMAP, TSOL_READ, 
+		NULL, 0, client, TSOL_ALL, &(MAJOROP));
+	    break;
+
+	case X_ChangeKeyboardMapping:
+	    rec->status = xtsol_policy(TSOL_RES_KEYMAP, TSOL_MODIFY, 
+		NULL, 0, client, TSOL_ALL, &(MAJOROP));
+	    break;
+
+	case X_GetMotionEvents:
+	    rec->status = xtsol_policy(TSOL_RES_PTRMOTION, TSOL_READ, 
+		NULL, 0, client, TSOL_ALL, &(MAJOROP));
+	    break;
+
+	case X_QueryKeymap:
+	    rec->status = xtsol_policy(TSOL_RES_KEYMAP, TSOL_READ, 
+		NULL, 0, client, TSOL_ALL, &(MAJOROP));
+	    break;
+
+	case X_SetModifierMapping:
+	    rec->status = xtsol_policy(TSOL_RES_MODMAP, TSOL_MODIFY, 
+		NULL, 0, client, TSOL_ALL, &(MAJOROP));
+	    break;
 
-#define CHECK_PROPERTY_POLICY(DIX_MODE, TSOL_MODE)			\
-	if (check_mode & (DIX_MODE)) {					\
-	    if (!isPolyProp &&						\
-		xtsol_policy(TSOL_RES_PROPERTY, (TSOL_MODE), pProp,	\
-			     0, client, TSOL_ALL, &reqtype))		\
-		returnVal = XTSOL_IGNORE;				\
-	    check_mode &= ~(DIX_MODE);					\
-	}
+	default:
+#ifndef NO_TSOL_DEBUG_MESSAGES
+               tsolinfo = GetClientTsolInfo(client);
+               LogMessageVerb(X_NOT_IMPLEMENTED, TSOL_MSG_UNIMPLEMENTED,
+                      TSOL_LOG_PREFIX
+                      "policy not implemented for CheckDeviceAccess(%s, %s, %s) = %s\n",
+                       tsolinfo->pname,
+                      TsolDixAccessModeNameString(access_mode),
+                      TsolRequestNameString(reqtype),
+                      TsolErrorNameString(rec->status));
+#endif /* !NO_TSOL_DEBUG_MESSAGES */
+              rec->status = Success;
+              break;
+    }
+} 
+
 
-	/* Don't need to check for write access on property creation */
-	if (check_mode & DixCreateAccess) {
-	    check_mode &= ~(DixWriteAccess | DixBlendAccess);
+static CALLBACK(
+TsolCheckSelectionAccess)
+{
+    XaceSelectionAccessRec *rec = (XaceSelectionAccessRec *) calldata;
+    ClientPtr client = rec->client;
+    Selection *pSel = *rec->ppSel;
+    Atom selAtom = pSel->selection;
+    Mask access_mode = rec->access_mode;
+    int reqtype;
+    TsolSelnPtr tsolseln;
+    TsolInfoPtr tsolinfo; /* tsol client info */
+    tsolinfo = GetClientTsolInfo(client);
+    int polySelection = PolySelection(selAtom);
+
+    rec->status = Success;
+
+    if (client->requestBuffer) {
+        reqtype = MAJOROP;  /* protocol */
+    } else {
+        reqtype = -1;
+    }
+
+    switch (reqtype) {
+      case X_SetSelectionOwner:
+	/*
+	 * Special processing for selection agent. This is how
+	 * we know who to redirect privileged ConvertSelection requests.
+	 * This is also used to fake the onwership of GetSelectionOwner requests.
+	 */
+	if (selAtom == tsol_atom_sel_agnt) {
+	    if (HasWinSelection(tsolinfo)) {
+	        if (tsolinfo->flags & TSOL_AUDITEVENT)
+		   auditwrite(AW_USEOFPRIV, 1, PRIV_WIN_SELECTION,
+			      AW_APPEND, AW_END);
+	        tsol_sel_agnt = pSel; /* owner of this seln */
+	    } else {
+	        if (tsolinfo->flags & TSOL_AUDITEVENT)
+		    auditwrite(AW_USEOFPRIV, 0, PRIV_WIN_SELECTION,
+			      AW_APPEND, AW_END);
+		client->errorValue = selAtom;
+		rec->status = BadAtom;
+		return;
+	   }
 	}
 
-	CHECK_PROPERTY_POLICY(DixCreateAccess, TSOL_CREATE);	    
-	CHECK_PROPERTY_POLICY(DixDestroyAccess, TSOL_DESTROY);
-	CHECK_PROPERTY_POLICY((DixReadAccess | DixGetAttrAccess), TSOL_READ);
-	CHECK_PROPERTY_POLICY((DixWriteAccess | DixBlendAccess), TSOL_MODIFY);
+        /*
+         * The callback function is only called if at least one matching selection exists.
+         * If it has no tsol attributes then we know it is the only match so we don't need to
+         * check for polyinstantiation. Just initialize it and return.
+         */
+
+	tsolseln = TsolSelectionPriv(pSel);
+
+	if (tsolseln->sl == NULL) {
+            tsolseln->sl = tsolinfo->sl;
+            tsolseln->uid = tsolinfo->uid;
+	    break;
+	}
+
+	if (polySelection) {
+
+	    /* for poly-selections, search from the beginning to see if sl,uid match */
+	    for (pSel = CurrentSelections; pSel; pSel = pSel->next) {
 
-	if (check_mode) { /* Any access mode bits not yet handled ? */
-#ifndef NO_TSOL_DEBUG_MESSAGES
-	    LogMessageVerb(X_NOT_IMPLEMENTED, TSOL_MSG_UNIMPLEMENTED,
-			   TSOL_LOG_PREFIX
-			   "policy not implemented for CheckPropertyAccess, "
-			   "mode=0x%x (%s)\n", check_mode,
-			   TsolDixAccessModeNameString(check_mode));
-#endif /* !NO_TSOL_DEBUG_MESSAGES */
-	    returnVal = XTSOL_IGNORE;
+		if (pSel->selection == selAtom) {
+		    tsolseln = TsolSelectionPriv(pSel);
+		    if (tsolseln->uid == tsolinfo->uid &&
+			 tsolseln->sl == tsolinfo->sl)
+		        break;
+		}
+	    }               
+
+	    if (pSel) {
+		/* found a match */
+	        *rec->ppSel = pSel; 
+	    } else {
+		/*
+		* Doesn't match yet; we'll get called again
+		* After it gets created.
+		*/
+		rec->status = BadMatch;
+	    }
+	} else {
+	    /* Assign the sl & uid */
+	    tsolseln->sl = tsolinfo->sl;
+            tsolseln->uid = tsolinfo->uid;
 	}
-    }
+	break;
+
+      case X_GetSelectionOwner:
+      case X_ConvertSelection:
+	    if (polySelection) {
+
+		/* for poly-selections, search from the beginning to see if sl,uid match */
+		for (pSel = CurrentSelections; pSel; pSel = pSel->next) {
+
+		    if (pSel->selection == selAtom) {
+		        tsolseln = TsolSelectionPriv(pSel);
+		        if (tsolseln->uid == tsolinfo->uid &&
+			     tsolseln->sl == tsolinfo->sl)
+		            break;
+		    }
+		}               
 
+	        if (pSel) {
+	            *rec->ppSel = pSel; /* found match */
+	        } else {
+		    /*
+		    * Doesn't match yet; we'll get called again
+		    * After it gets created.
+		    */
+		    rec->status = BadMatch;
+		    return;
+	        }
+	    }
+
+	    /*
+	     * Selection Agent processing. Override the owner
+	     */
+	    tsolseln = TsolSelectionPriv(pSel);
+	    if (!HasWinSelection(tsolinfo) &&
+			(tsolseln->uid != tsolinfo->uid ||
+			tsolseln->sl != tsolinfo->sl) && 
+			pSel->window != None && tsol_sel_agnt != NULL) {
+                pSel = tsol_sel_agnt;
+           } else {
+		if (HasWinSelection(tsolinfo) && 
+			(tsolinfo->flags & TSOL_AUDITEVENT)) {
+		    auditwrite(AW_USEOFPRIV, 1, PRIV_WIN_SELECTION, AW_APPEND, AW_END);
+		}
+	    }
+	    *rec->ppSel = pSel;
+	    break;
+
+       default:
 #ifndef NO_TSOL_DEBUG_MESSAGES
-    LogMessageVerb(X_INFO, TSOL_MSG_ACCESS_TRACE,
-		   TSOL_LOG_PREFIX
-		   "CheckPropertyAccess(%s, 0x%x, %s, %s) = %s\n",
-		   tsolinfo->pname, pWin->drawable.id,
-		   NameForAtom(propertyName),
-		   TsolDixAccessModeNameString(access_mode),
-		   TsolPolicyReturnString(returnVal));
+              tsolinfo = GetClientTsolInfo(client);
+              LogMessageVerb(X_NOT_IMPLEMENTED, TSOL_MSG_UNIMPLEMENTED,
+                     TSOL_LOG_PREFIX
+                     "policy not implemented for CheckSelectionAccess(%s, %s, %s, %s) = %s\n",
+                      tsolinfo->pname,
+                     TsolDixAccessModeNameString(access_mode),
+                     TsolRequestNameString(reqtype),
+                     NameForAtom(selAtom),
+                     TsolErrorNameString(rec->status));
 #endif /* !NO_TSOL_DEBUG_MESSAGES */
-
-    /* Only returns allow if all checks succeeded */        
-    return returnVal;
+             break;
+    }
 }
 
 static CALLBACK(
-TsolAceCheckPropertyAccess)
+TsolCheckPropertyAccess)
 {
     XacePropertyAccessRec *rec = (XacePropertyAccessRec *) calldata;
     ClientPtr client = rec->client;
@@ -2132,10 +2387,96 @@
     PropertyPtr pProp = *rec->ppProp;
     Atom propertyName = pProp->propertyName;
     Mask access_mode = rec->access_mode;
+    TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
+    int reqtype;
+    TsolPropPtr tsolprop;
+    TsolResPtr tsolres;
+    int tsol_method;
+    Status retcode;
 
-    if (TsolCheckPropertyAccess(client, pWin, pProp,
-				propertyName, access_mode) != XTSOL_ALLOW) {
-	rec->status = BadAccess;
+
+    if (client->requestBuffer) {
+        reqtype = MAJOROP;  /* protocol */
+    } else {
+        reqtype = -1;
+    }
+
+    if (pProp != NULL) {
+	int polyprop = PolyProperty(propertyName, pWin);
+
+	tsolprop = TsolPropertyPriv(pProp);
+
+	if (!polyprop) {
+
+	    tsolres = TsolWindowPriv(pWin);
+	    if (tsolprop->sl == NULL) {
+		/* Initialize with label/uid etc */
+		if (WindowIsRoot(pWin)) {
+		    tsolprop->sl = tsolinfo->sl;        /* use client's sl/uid */
+		    tsolprop->uid = tsolinfo->uid;
+		    tsolprop->pid = tsolinfo->pid;
+		} else {
+		    tsolprop->sl = tsolres->sl;         /* use window's sl/uid */
+		    tsolprop->uid = tsolres->uid;
+		    tsolprop->pid = tsolres->pid;
+                }
+	    }
+
+	    if (access_mode & (DixReadAccess | DixGetAttrAccess))
+		tsol_method = TSOL_READ;
+	    else
+		tsol_method = TSOL_MODIFY;
+
+	    retcode = xtsol_policy(TSOL_RES_PROPERTY, tsol_method, pProp, 0, 
+		client, TSOL_ALL, &reqtype);
+	    if (retcode != Success && (access_mode & DixGetAttrAccess)) {
+		/* If current property is not accessible, move on to 
+		 *  next one for ListProperty
+		 */
+		retcode = Success;
+		*rec->ppProp = pProp->next; /* ignore failurefor List Prop */
+	    }
+	    rec->status = retcode;
+	} else {
+	    /* Handle polyinstantiated property */
+	    if (tsolprop->sl == NULL) { /* New PolyProp */
+		if (!(access_mode & DixCreateAccess)) {
+		    rec->status = BadImplementation;
+		    return;
+	        }
+		/* Initialize with label/uid */
+		tsolprop->sl = tsolinfo->sl;
+		tsolprop->uid = tsolinfo->uid;
+		tsolprop->next = (TsolPropPtr)NULL;
+		rec->status = Success;
+	    } else {
+		/* search for a matching (sl, uid) pair */
+		while (pProp) {
+	    	    tsolprop = TsolPropertyPriv(pProp);
+		    if (pProp->propertyName == propertyName &&
+			    tsolprop->sl == tsolinfo->sl &&
+			    tsolprop->uid == tsolinfo->uid)
+			break; /* match found */
+		    pProp = pProp->next;
+		} 
+
+		if (pProp) {
+		    *rec->ppProp = pProp; /* found */
+		    rec->status = Success;
+		} else {
+		    rec->status = BadMatch;
+	        }
+	    }
+	}
+#ifndef NO_TSOL_DEBUG_MESSAGES
+    LogMessageVerb(X_INFO, TSOL_MSG_ACCESS_TRACE,
+		   TSOL_LOG_PREFIX
+		   "TsolCheckPropertyAccess(%s, 0x%x, %s, %s) = %s\n",
+		   tsolinfo->pname, pWin->drawable.id,
+		   NameForAtom(propertyName),
+		   TsolDixAccessModeNameString(access_mode),
+		   TsolPolicyReturnString(rec->status));
+#endif /* !NO_TSOL_DEBUG_MESSAGES */
     }
 }
 
--- a/open-src/xserver/xorg/sun-src/tsol/tsolinfo.h	Tue Mar 31 17:01:13 2009 -0700
+++ b/open-src/xserver/xorg/sun-src/tsol/tsolinfo.h	Thu Apr 02 14:22:10 2009 -0700
@@ -26,7 +26,7 @@
  * of the copyright holder.
  */
 
-#pragma ident   "@(#)tsolinfo.h 1.22     09/03/12 SMI"
+#pragma ident   "@(#)tsolinfo.h 1.23     09/04/02 SMI"
 
 
 #ifndef    _TSOL_INFO_H
@@ -246,8 +246,8 @@
     TsolInfoRec		clientPriv;
     TsolResRec		windowPriv;
     TsolResRec		pixmapPriv;
-    TsolPropPtr		propertyPriv;
-    TsolSelnPtr		selectionPriv;
+    TsolPropRec		propertyPriv;
+    TsolSelnRec		selectionPriv;
 } TsolPrivRec, *TsolPrivPtr;
 
 extern DevPrivateKey tsolPrivKey;
@@ -262,30 +262,10 @@
     ((TsolResPtr) dixLookupPrivate(&(pPix)->devPrivates, tsolPrivKey))
 
 #define TsolPropertyPriv(pProp)	\
-    ((TsolPropPtr *) dixLookupPrivate(&(pProp)->devPrivates, tsolPrivKey))
+    ((TsolPropPtr ) dixLookupPrivate(&(pProp)->devPrivates, tsolPrivKey))
 
 #define TsolSelectionPriv(pSel) \
-    ((TsolSelnPtr *) dixLookupPrivate(&(pSel)->devPrivates, tsolPrivKey))
-
-#if 0
-/*
- * NodeRec struct defined here is used instead of the
- * one defined in atom.c. This is used in policy functions
- */
-typedef struct _Node {
-    struct _Node  *left,   *right;
-    Atom           a;
-    unsigned int   fingerPrint;
-    char          *string;
-#ifdef TSOL
-    int            slsize;              /* size of the sl array below */
-    int            clientCount;         /* actual no. of clients */
-    int            IsSpecial;           /* special atoms for polyprops */
-    bslabel_t    **sl;                  /* an array of sl's. */
-#endif /* TSOL */
-} NodeRec, *NodePtr;
-
-#endif
+    ((TsolSelnPtr ) dixLookupPrivate(&(pSel)->devPrivates, tsolPrivKey))
 
 #define NODE_SLSIZE	16	/* increase sl array by this amount */
 typedef struct _TsolNodeRec {
--- a/open-src/xserver/xorg/sun-src/tsol/tsolpolicy.c	Tue Mar 31 17:01:13 2009 -0700
+++ b/open-src/xserver/xorg/sun-src/tsol/tsolpolicy.c	Thu Apr 02 14:22:10 2009 -0700
@@ -26,7 +26,7 @@
  * of the copyright holder.
  */
 
-#pragma ident   "@(#)tsolpolicy.c 1.25     09/02/12 SMI"
+#pragma ident   "@(#)tsolpolicy.c 1.26     09/04/02 SMI"
 
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
@@ -551,6 +551,7 @@
 {
 	int ret_stat = PASSED;
 	Bool do_audit = FALSE;
+	int	rc;
 	int	err_code = BadDrawable;
 	int obj_code = 0;
 	XID obj_id = (XID)NULL;
@@ -567,7 +568,10 @@
 
 	if (pDraw->type == DRAWABLE_WINDOW)
 	{
-		pWin = (WindowPtr)LookupWindow(pDraw->id, client);
+		rc = dixLookupWindow(&pWin, pDraw->id, client, DixReadAccess);
+		if (rc != Success)
+		    return rc;
+
 		if (pWin == NULL)
 			return (PASSED); /* server will handle bad params */
 		tsolres = TsolWindowPriv(pWin);
@@ -576,7 +580,11 @@
 	}
 	else if (pDraw->type == DRAWABLE_PIXMAP)
 	{
-		pMap = (PixmapPtr)LookupIDByType(pDraw->id, RT_PIXMAP);
+		rc = dixLookupResource((pointer *)&pMap, pDraw->id, RT_PIXMAP,
+				client, DixReadAccess);
+		if (rc != Success)
+		    return rc;
+
 		if (pMap == NULL)
 			return (PASSED); /* server will handle bad params */
 		tsolres = TsolPixmapPriv(pMap);
@@ -673,6 +681,7 @@
 {
 	int ret_stat = PASSED;
 	Bool do_audit = FALSE;
+	int	rc;
 	int	err_code = BadDrawable;
 	int obj_code = 0;
 	XID obj_id = (XID)NULL;
@@ -697,12 +706,20 @@
 		if (!noPanoramiXExtension)
 		{
 		    panres = (PanoramiXRes *)LookupIDByType(pDraw->id, XRT_WINDOW);
-		    if (panres)
-			pWin = (WindowPtr)LookupWindow(panres->info[0].id, client);
+		    if (panres) {
+		        rc = dixLookupWindow(&pWin, panres->info[0].id, 
+				client, DixWriteAccess);
+
+		        if (rc != Success)
+			    return rc;
+		    }
 		} else
+		    rc = dixLookupWindow(&pWin, pDraw->id, 
+			client, DixWriteAccess);
+
+		    if (rc != Success)
+			return rc;
 #endif
-		    pWin = (WindowPtr)LookupWindow(pDraw->id, client);
-
 		if (pWin == NULL)
 			return (PASSED);
 		tsolres = TsolWindowPriv(pWin);
@@ -719,7 +736,10 @@
 			pMap = (PixmapPtr)LookupIDByType(panres->info[0].id, RT_PIXMAP);
 	    } else
 #endif
-		pMap = (PixmapPtr)LookupIDByType(pDraw->id, RT_PIXMAP);
+		rc = dixLookupResource((pointer *)&pMap, pDraw->id, RT_PIXMAP,
+				client, DixWriteAccess);
+		if (rc != Success)
+		    return rc;
 
 		if (pMap == NULL)
 			return (PASSED);
@@ -1876,22 +1896,14 @@
 {
 	int ret_stat = PASSED;
 	Bool do_audit = FALSE;
-	int	err_code = BadAtom;
+	int	err_code = BadMatch;
 	PropertyPtr pProp = resource;
 	ClientPtr client = subject;
 	TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
 	TsolPropPtr tsolprop;
-	TsolPropPtr *tsolpropP;
 
 	/* Initialize property created internally by server */
-	tsolpropP = TsolPropertyPriv(pProp);
-	if (*tsolpropP == NULL)
-	{
-	    *tsolpropP = (pointer)AllocServerTsolProp();
-	    if (*tsolpropP == NULL)
-		return(BadAlloc);
-	}
-	tsolprop = *tsolpropP;
+	tsolprop = TsolPropertyPriv(pProp);
 
 	/*
 	 * MAC Check
@@ -1968,17 +1980,9 @@
 	ClientPtr client = subject;
 	TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
 	TsolPropPtr tsolprop;
-	TsolPropPtr *tsolpropP;
 
 	/* Initialize property created internally by server */
-	tsolpropP = TsolPropertyPriv(pProp);
-	if (*tsolpropP == NULL)
-	{
-	    *tsolpropP = (pointer)AllocServerTsolProp();
-	    if (*tsolpropP == NULL)
-		return(BadAlloc);
-	}
-	tsolprop = *tsolpropP;
+	tsolprop = TsolPropertyPriv(pProp);
 
 	/*
 	 * MAC Check
@@ -2052,17 +2056,9 @@
 	ClientPtr client = subject;
 	TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
 	TsolPropPtr tsolprop;
-	TsolPropPtr *tsolpropP;
 
 	/* Initialize property created internally by server */
-	tsolpropP = TsolPropertyPriv(pProp);
-	if (*tsolpropP == NULL)
-	{
-	    *tsolpropP = (pointer)AllocServerTsolProp();
-	    if (*tsolpropP == NULL)
-		return(BadAlloc);
-	}
-	tsolprop = *tsolpropP;
+	tsolprop = TsolPropertyPriv(pProp);
 
 	/*
 	 * MAC Check
@@ -2404,7 +2400,7 @@
 	Selection *selection = resource;
 	ClientPtr client = subject;
 	TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
-	TsolSelnPtr tsolseln = *(TsolSelectionPriv(selection));
+	TsolSelnPtr tsolseln = (TsolSelectionPriv(selection));
 
 	/*
 	 * MAC Check
@@ -3240,18 +3236,12 @@
 /*
  * Return value of 0 success,	errcode for failure
  *
- * Dummy function.
+ * Dummy function means no policy is needed for this access.
  */
 static int
 no_policy(xresource_t res, xmethod_t method, void *resource,
 	void *subject, xpolicy_t policy_flags, void *misc)
 {
-#ifndef NO_TSOL_DEBUG_MESSAGES
-	LogMessageVerb(X_NOT_IMPLEMENTED, TSOL_MSG_UNIMPLEMENTED,
-		       TSOL_LOG_PREFIX
-		       "policy not implemented for res=%d, method=%d\n",
-		       res, method);
-#endif /* NO_TSOL_DEBUG_MESSAGES */
 	return (PASSED);
 }
 
--- a/open-src/xserver/xorg/sun-src/tsol/tsolprotocol.c	Tue Mar 31 17:01:13 2009 -0700
+++ b/open-src/xserver/xorg/sun-src/tsol/tsolprotocol.c	Thu Apr 02 14:22:10 2009 -0700
@@ -26,7 +26,7 @@
  * of the copyright holder.
  */
 
-#pragma ident	"@(#)tsolprotocol.c 1.28	09/02/12 SMI"
+#pragma ident	"@(#)tsolprotocol.c 1.29	09/04/02 SMI"
 
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
@@ -181,8 +181,6 @@
 
 #define INITIAL_TSOL_NODELENGTH 1500
 
-static int tsol_sel_agnt = -1; /* index this to CurrentSelection to get seln */
-
 /*
  * Get number of atoms defined in the system
  */
@@ -383,1073 +381,36 @@
 	return newAtom;
 }
 
-
 int
-ProcTsolSetSelectionOwner(ClientPtr client)
-{
-    WindowPtr pWin = NULL;
-    TimeStamp time;
-    Selection *pSel;
-    int rc;
-
-#ifdef TSOL
-    TsolSelnPtr tsolseln = NULL;
-    TsolSelnPtr prevtsolseln = NULL;
-    TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
-#endif /* TSOL */
-
-    REQUEST(xSetSelectionOwnerReq);
-    REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
-
-    UpdateCurrentTime();
-    time = ClientTimeToServerTime(stuff->time);
-
-    /* If the client's time stamp is in the future relative to the server's
-	time stamp, do not set the selection, just return success. */
-    if (CompareTimeStamps(time, currentTime) == LATER)
-    	return Success;
-
-    if (stuff->window != None)
-    {
-        rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
-        if (rc != Success)
-            return rc;
-    }
-    if (!ValidAtom(stuff->selection)) {
-	client->errorValue = stuff->selection;
-        return BadAtom;
-    }
-
-    /*
-     * First, see if the selection is already set...
-     */
-    rc = dixLookupSelection(&pSel, stuff->selection, client, DixSetAttrAccess);
-
-    if (rc == Success) {
-	xEvent event;
-
-#ifdef TSOL
-	int i = 0;
-
-	for (pSel = CurrentSelections;
-	     (pSel != NULL) && pSel->selection != stuff->selection;
-	     pSel = pSel->next) {
-            i++;
-	}
-
-	/*
-	 * special processing for selection agent. Just note
-	 * the owner of this special selection
-	 */
-	if (stuff->selection == MakeAtom("_TSOL_SEL_AGNT", 14, 1))
-	{
-	    if (HasWinSelection(tsolinfo))
-	    {
-		if (tsolinfo->flags & TSOL_AUDITEVENT)
-		    auditwrite(AW_USEOFPRIV, 1, PRIV_WIN_SELECTION,
-			       AW_APPEND, AW_END);
-		tsol_sel_agnt = i; /* owner of this seln */
-	    }
-	    else
-	    {
-		if (tsolinfo->flags & TSOL_AUDITEVENT)
-		    auditwrite(AW_USEOFPRIV, 0, PRIV_WIN_SELECTION,
-			       AW_APPEND, AW_END);
-		client->errorValue = stuff->selection;
-		return(BadAtom);
-	    }
-	}
-
-	/* for poly-selections, search further to see if sl,uid match */
-	tsolseln = *(TsolSelectionPriv(pSel));
-	if (PolySelection(pSel->selection))
-	{
-	    prevtsolseln = tsolseln;
-	    while (tsolseln)
-	    {
-		if (tsolseln->uid == tsolinfo->uid &&
-		    tsolseln->sl == tsolinfo->sl)
-		    break; /* match found */
-		prevtsolseln = tsolseln;
-		tsolseln = tsolseln->next;
-	    }
-	}
-	if (PolySelection(pSel->selection) && tsolseln)
-	{
-	    if (CompareTimeStamps(time, tsolseln->lastTimeChanged)
-		== EARLIER)
-		return Success;
-	    if (tsolseln->client &&
-		(!pWin || (tsolseln->client != client)))
-	    {
-		event.u.u.type = SelectionClear;
-		event.u.selectionClear.time = time.milliseconds;
-		event.u.selectionClear.window = tsolseln->window;
-		event.u.selectionClear.atom = pSel->selection;
-		(void)TryClientEvents (tsolseln->client,
-				       &event,
-				       1,
-				       NoEventMask,
-				       NoEventMask /* CantBeFiltered */,
-				       NullGrab);
-	    }
-	}
-	else if (tsolseln)
-	{
-            /* we use the existing code. So we left it unindented */
-#endif /* TSOL */
-
-	/* If the timestamp in client's request is in the past relative
-	   to the time stamp indicating the last time the owner of the
-	   selection was set, do not set the selection, just return
-	   success. */
-	if (CompareTimeStamps(time, pSel->lastTimeChanged) == EARLIER)
-	    return Success;
-	if (pSel->client && (!pWin || (pSel->client != client)))
-	{
-	    event.u.u.type = SelectionClear;
-	    event.u.selectionClear.time = time.milliseconds;
-	    event.u.selectionClear.window = pSel->window;
-	    event.u.selectionClear.atom = pSel->selection;
-	    TryClientEvents(pSel->client, &event, 1, NoEventMask,
-			    NoEventMask /* CantBeFiltered */, NullGrab);
-	}
-#ifdef TSOL
-	}
-#endif /* TSOL */
-    }
-    else if (rc == BadMatch)
-    {
-	/*
-	 * It doesn't exist, so add it...
-	 */
-	pSel = xalloc(sizeof(Selection));
-	if (!pSel)
-	    return BadAlloc;
-
-	pSel->selection = stuff->selection;
-	pSel->devPrivates = NULL;
-
-	/* security creation/labeling check */
-	rc = XaceHookSelectionAccess(client, &pSel,
-				     DixCreateAccess|DixSetAttrAccess);
-	if (rc != Success) {
-	    xfree(pSel);
-	    return rc;
-	}
-
-	pSel->next = CurrentSelections;
-	CurrentSelections = pSel;
-    }
-    else
-	return rc;
-
-#ifdef TSOL
-    /*
-     * tsolseln == NULL, either seln does not exist,
-     * or there is no sl,uid match
-     */
-    if (!tsolseln)
-    {
-	/* create one & put  it in place */
-	tsolseln = (TsolSelnPtr)xalloc(sizeof(TsolSelnRec));
-	if (!tsolseln)
-	    return BadAlloc;
-	tsolseln->next = (TsolSelnPtr)NULL;
-
-	/* if necessary put at the end of the list */
-	if (prevtsolseln)
-	    prevtsolseln->next = tsolseln;
-	else
-	    *(TsolSelectionPriv(pSel)) = tsolseln;
-    }
-    /* fill it in */
-    tsolseln->sl = tsolinfo->sl;
-    tsolseln->uid = tsolinfo->uid;
-    tsolseln->lastTimeChanged = time;
-    tsolseln->window = stuff->window;
-    tsolseln->pWin = pWin;
-    tsolseln->client = (pWin ? client : NullClient);
-    if (!PolySelection(pSel->selection))
-    {
-        /* no change to existing code. left as it is */
-#endif /* TSOL */
-
-    pSel->lastTimeChanged = time;
-    pSel->window = stuff->window;
-    pSel->pWin = pWin;
-    pSel->client = (pWin ? client : NullClient);
-
-    if (SelectionCallback != NULL) {
-	SelectionInfoRec info = { pSel, client, SelectionSetOwner };
-	CallCallbacks(&SelectionCallback, &info);
-    }
-#ifdef TSOL
-    }
-#endif /* TSOL */
-
-    return (client->noClientException);
-}
-
-int
-ProcTsolGetSelectionOwner(ClientPtr client)
-{
-    int rc;
-    Selection *pSel;
-    xGetSelectionOwnerReply reply;
-
-    REQUEST(xResourceReq);
-    REQUEST_SIZE_MATCH(xResourceReq);
-
-    if (!ValidAtom(stuff->id)) {
-	client->errorValue = stuff->id;
-        return BadAtom;
-    }
-
-    reply.type = X_Reply;
-    reply.length = 0;
-    reply.sequenceNumber = client->sequence;
-
-    rc = dixLookupSelection(&pSel, stuff->id, client, DixGetAttrAccess);
-    if (rc == Success)
-#ifdef TSOL
-	{
-	    TsolSelnPtr tsolseln;
-	    TsolInfoPtr tsolinfo; /* tsol client info */
-	    tsolinfo = GetClientTsolInfo(client);
-
-	    /* find matching sl,uid in case of poly selns */
-	    tsolseln = *(TsolSelectionPriv(pSel));
-	    if (PolySelection(pSel->selection))
-	    {
-		while (tsolseln)
-		{
-		    if (tsolseln->uid == tsolinfo->uid &&
-			tsolseln->sl == tsolinfo->sl)
-			break; /* match found */
-		    tsolseln = tsolseln->next;
-		}
-		if (tsolseln)
-		    reply.owner = tsolseln->window;
-		else
-		    reply.owner = None;
-	    }
-	    else
-	    {
-		reply.owner = pSel->window;
-	    }
-	    /*
-	     * Selection Agent processing. Override the owner
-	     */
-	    if (!HasWinSelection(tsolinfo) &&
-		client->index != CLIENT_ID(reply.owner) &&
-		reply.owner != None &&
-		tsol_sel_agnt != -1 &&
-		CurrentSelections[tsol_sel_agnt].client)
-	    {
-		WindowPtr pWin;
-		pWin = (WindowPtr)LookupWindow(reply.owner, client);
-		if (tsolinfo->flags & TSOL_AUDITEVENT)
-		    auditwrite(AW_USEOFPRIV, 0, PRIV_WIN_SELECTION,
-			       AW_APPEND, AW_END);
-	    }
-	    else if (HasWinSelection(tsolinfo) &&
-		     tsolinfo->flags & TSOL_AUDITEVENT)
-	    {
-		auditwrite(AW_USEOFPRIV, 1, PRIV_WIN_SELECTION,
-			   AW_APPEND, AW_END);
-	    }
-	     /* end seln agent processing */
-	}
-#else /* TSOL */
-	reply.owner = pSel->window;
-#endif /* TSOL */
-    else if (rc == BadMatch)
-	reply.owner = None;
-    else
-	return rc;
-
-    WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
-    return client->noClientException;
-}
-
-int
-ProcTsolConvertSelection(ClientPtr client)
+TsolInitWindow(ClientPtr client, WindowPtr pWin)
 {
-    Bool paramsOkay;
-    xEvent event;
-    WindowPtr pWin;
-    Selection *pSel;
-    int rc;
-
-    REQUEST(xConvertSelectionReq);
-    REQUEST_SIZE_MATCH(xConvertSelectionReq);
-
-    rc = dixLookupWindow(&pWin, stuff->requestor, client, DixSetAttrAccess);
-    if (rc != Success)
-        return rc;
-
-    paramsOkay = ValidAtom(stuff->selection) && ValidAtom(stuff->target);
-    paramsOkay &= (stuff->property == None) || ValidAtom(stuff->property);
-    if (!paramsOkay) {
-	client->errorValue = stuff->property;
-        return BadAtom;
-    }
-
-    rc = dixLookupSelection(&pSel, stuff->selection, client, DixReadAccess);
-
-    if (rc != Success && rc != BadMatch)
-	return rc;
-#ifdef TSOL
-    else if (rc == Success) {
-	    TsolSelnPtr tsolseln;
-	    TsolInfoPtr tsolinfo; /* tsol client info */
-	    Window twin;          /* temporary win */
-	    ClientPtr tclient;    /* temporary client */
-
-	    tsolinfo = GetClientTsolInfo(client);
-
-	    /* find matching sl,uid in case of poly selns */
-	    tsolseln = *(TsolSelectionPriv(pSel));
-	    if (PolySelection(pSel->selection))
-	    {
-		while (tsolseln)
-		{
-		    if (tsolseln->uid == tsolinfo->uid &&
-			tsolseln->sl == tsolinfo->sl)
-			break; /* match found */
-		    tsolseln = tsolseln->next;
-		}
-		if (!tsolseln)
-		{
-		    client->errorValue = stuff->property;
-		    return (BadAtom);
-		}
-		twin = tsolseln->window;
-		tclient = tsolseln->client;
-	    }
-	    else
-	    {
-		twin = pSel->window;
-		tclient = pSel->client;
-	    }
-	    /*
-	     * Special case for seln agent.
-	     * SelectionRequest event is redirected to selection
-	     * agent for unpirvileged clients and who do not own
-	     * the selection
-	     */
-	    if (tsol_sel_agnt != -1 && CurrentSelections[tsol_sel_agnt].client)
-	    {
-	    /* Redirect only if client other than owner & does not have priv */
-	        if (!HasWinSelection(tsolinfo) && (client != tclient))
-		{
-		    tclient = CurrentSelections[tsol_sel_agnt].client;
-		    twin = CurrentSelections[tsol_sel_agnt].window;
-		    if (tsolinfo->flags & TSOL_AUDITEVENT)
-			auditwrite(AW_USEOFPRIV, 1, PRIV_WIN_SELECTION,
-				   AW_APPEND, AW_END);
-	        }
-		else if (HasWinSelection(tsolinfo) &&
-			 tsolinfo->flags & TSOL_AUDITEVENT)
-		{
-		    auditwrite(AW_USEOFPRIV, 0, PRIV_WIN_SELECTION,
-			       AW_APPEND, AW_END);
-		}
-	    }
-	    /* end of special case seln handling */
-
-	    if (twin != None)
-	    {
-		event.u.u.type = SelectionRequest;
-		event.u.selectionRequest.time = stuff->time;
-		event.u.selectionRequest.owner = twin;
-		event.u.selectionRequest.requestor = stuff->requestor;
-		event.u.selectionRequest.selection = stuff->selection;
-		event.u.selectionRequest.target = stuff->target;
-		event.u.selectionRequest.property = stuff->property;
-		if (TryClientEvents(tclient, &event, 1,
-				    NoEventMask,
-				    NoEventMask /* CantBeFiltered */,
-				    NullGrab))
-		    return (client->noClientException);
-	    }
-    }
-#else /* TSOL */
-        else if (rc == Success && pSel->window != None) {
-	event.u.u.type = SelectionRequest;
-	event.u.selectionRequest.owner = pSel->window;
-	event.u.selectionRequest.time = stuff->time;
-	event.u.selectionRequest.requestor = stuff->requestor;
-	event.u.selectionRequest.selection = stuff->selection;
-	event.u.selectionRequest.target = stuff->target;
-	event.u.selectionRequest.property = stuff->property;
-	if (TryClientEvents(pSel->client, &event, 1, NoEventMask,
-			    NoEventMask /* CantBeFiltered */, NullGrab))
-	    return client->noClientException;
-    }
-#endif /* TSOL */
-
-    event.u.u.type = SelectionNotify;
-    event.u.selectionNotify.time = stuff->time;
-    event.u.selectionNotify.requestor = stuff->requestor;
-    event.u.selectionNotify.selection = stuff->selection;
-    event.u.selectionNotify.target = stuff->target;
-    event.u.selectionNotify.property = None;
-    TryClientEvents(client, &event, 1, NoEventMask,
-		    NoEventMask /* CantBeFiltered */, NullGrab);
-    return client->noClientException;
-}
-
-/* Allocate and initialize a tsolprop */
-
-TsolPropPtr
-AllocTsolProp(void)
-{
-    TsolPropPtr tsolprop;
-
-    tsolprop = (TsolPropPtr)Xcalloc(sizeof(TsolPropRec));
-
-    if (tsolprop)
-    {
-	tsolprop->size = 0;
-	tsolprop->data = NULL;
-        tsolprop->next = NULL;
-        tsolprop->serverOwned = FALSE;
-    }
-
-    return tsolprop;
-}
-
-/*
- * Allocate and initialize tsolprop created
- * internally by the X server
- */
-
-TsolPropPtr
-AllocServerTsolProp(void)
-{
-    TsolPropPtr tsolprop;
-
-    tsolprop = (TsolPropPtr)Xcalloc(sizeof(TsolPropRec));
-
-    if (tsolprop)
-    {
-	tsolprop->size = 0;
-	tsolprop->data = NULL;
-        tsolprop->next = NULL;
-
-	tsolprop->serverOwned = TRUE;
-	tsolprop->uid = getuid(); /* of server process */
-	tsolprop->pid = getpid(); /* of server process */
-	tsolprop->sl = (bslabel_t *)lookupSL_low();
-    }
-
-    return tsolprop;
-}
-
-/*
- * property data/len is stored in pProp for single
- * instantiated properties. Polyinstanticated property
- * data/len stored in the tsolprop structure
- */
-
-int
-TsolChangeWindowProperty(
-    ClientPtr	client,
-    WindowPtr	pWin,
-    Atom	property,
-    Atom	type,
-    int		format,
-    int		mode,
-    unsigned long len,
-    pointer	value,
-    Bool	sendevent)
-{
-    PropertyPtr pProp;
-    xEvent event;
-    int sizeInBytes;
-    int totalSize;
-    pointer data;
-    TsolPropPtr tsolprop;
-    TsolPropPtr *tsolpropP;
-    TsolInfoPtr tsolinfo;
-    TsolResPtr tsolres;
-    int result;
-    int polyprop;
-
-    /* first see if property already exists */
-
-    pProp = wUserProps (pWin);
-    while (pProp)
-    {
-        if (pProp->propertyName == property)
-            break;
-        pProp = pProp->next;
-    }
-
-    result = TsolCheckPropertyAccess(client, pWin, pProp,
-				     property, DixWriteAccess);
-    if (result == XTSOL_IGNORE) {
-	return Success;
-    }
-
-    polyprop = PolyProperty(property, pWin);
-    if (!polyprop)
-    {
-        result = dixChangeWindowProperty(client, pWin, property, type,
-					 format, mode, len, value, sendevent);
-	if (result != Success)
-	    return (result);
-    }
-
-    sizeInBytes = format>>3;
-    totalSize = len * sizeInBytes;
-
-    tsolinfo = GetClientTsolInfo(client);
-    tsolres = TsolWindowPriv(pWin);
-
-    /* Initialize secPrviate if property is not polyinstantiated */
-    if (!polyprop && pProp)
-    {
-	/* Initialize for internally created properties */
-	tsolpropP = TsolPropertyPriv(pProp);
-	if (*tsolpropP == NULL)
-	{
-	    *tsolpropP = (pointer)AllocTsolProp();
-	    if (*tsolpropP == NULL)
-		return(BadAlloc);
-	}
-	tsolprop = *tsolpropP;
-
-        if (WindowIsRoot(pWin))
-        {
-            tsolprop->sl = tsolinfo->sl;	/* use client's sl/uid */
-            tsolprop->uid = tsolinfo->uid;
-            tsolprop->pid = tsolinfo->pid;
-        }
-        else
-        {
-            tsolprop->sl = tsolres->sl;		/* use window's sl/uid */
-            tsolprop->uid = tsolres->uid;
-            tsolprop->pid = tsolres->pid;
-        }
-
-	return (result);
-    }
-
-    /* Handle polyinstantiated property */
-    if (!pProp)   /* just add to list */
-    {
-        if (!pWin->optional && !MakeWindowOptional (pWin))
-            return(BadAlloc);
-        pProp = (PropertyPtr)xalloc(sizeof(PropertyRec));
-        if (!pProp)
-            return(BadAlloc);
-	pProp->devPrivates = NULL;
-	tsolpropP = TsolPropertyPriv(pProp);
-        *tsolpropP = (pointer)Xcalloc(sizeof(TsolPropRec));
-        if (!(*tsolpropP))
-            return(BadAlloc);
-        data = (pointer)xalloc(totalSize);
-        if (!data && len)
-        {
-            xfree(*tsolpropP);
-            xfree(pProp);
-            return(BadAlloc);
-        }
-        pProp->propertyName = property;
-        pProp->type = type;
-        pProp->format = format;
-        pProp->data = data;
-        if (len)
-            bcopy((char *)value, (char *)data, totalSize);
-        pProp->size = len;
-        tsolprop = *tsolpropP;
-        if (WindowIsRoot(pWin))
-        {
-            tsolprop->sl = tsolinfo->sl;
-            tsolprop->uid = tsolinfo->uid;
-        }
-        else
-        {
-            tsolprop->sl = tsolres->sl;
-            tsolprop->uid = tsolres->uid;
-        }
-        tsolprop->data = data;
-        tsolprop->size = len;
-        tsolprop->next = (TsolPropPtr)NULL;
-        pProp->next = pWin->optional->userProps;
-        pWin->optional->userProps = pProp;
-    }  /* end if !prop */
-    else
-    {
-        /* To append or prepend to a property the request format and type
-         * must match those of the already defined property.  The
-         * existing format and type are irrelevant when using the mode
-         * "PropModeReplace" since they will be written over.
-         */
-        if ((format != pProp->format) && (mode != PropModeReplace))
-            return(BadMatch);
-        if ((pProp->type != type) && (mode != PropModeReplace))
-            return(BadMatch);
-
-        tsolpropP = TsolPropertyPriv(pProp);
-	tsolprop = *tsolpropP;
-        /* search for a matching (sl, uid) pair */
-        while (tsolprop)
-        {
-            if (tsolprop->uid == tsolinfo->uid && tsolprop->sl == tsolinfo->sl)
-                    break; /* match found */
-            tsolprop = tsolprop->next;
-        }
-
-        if (!tsolprop)
-        {
-	    /* no match found. Create one */
-	    TsolPropPtr newtsol = (TsolPropPtr)Xcalloc(sizeof(TsolPropRec));
-	    if (!newtsol)
-	        return(BadAlloc);
-	    data = (pointer)Xcalloc(totalSize);
-	    if (!data && totalSize)
-	    {
-	        xfree(newtsol);
-	        return(BadAlloc);
-	    }
-	    if (len)
-	        memcpy((char *)data, (char *)value, totalSize);
-
-	    newtsol->sl = tsolinfo->sl;
-	    newtsol->uid = tsolinfo->uid;
-	    newtsol->data = data;
-	    newtsol->size = len;
-	    tsolpropP = TsolPropertyPriv(pProp);
-            newtsol->next = *tsolpropP;
-            *tsolpropP = newtsol;
-        }
-        else
-        {
-            switch (mode)
-            {
-                case PropModeReplace:
-                    if (totalSize != tsolprop->size * (pProp->format >> 3))
-                    {
-                        data = (pointer)xrealloc(tsolprop->data, totalSize);
-                        if (!data && len)
-                            return(BadAlloc);
-                        tsolprop->data = data;
-                    }
-                    if (len)
-                        bcopy((char *)value, (char *)tsolprop->data, totalSize);
-                    tsolprop->size = len;
-                    pProp->type = type;
-                    pProp->format = format;
-                    break;
-
-                case PropModeAppend:
-                    if (len)
-                    {
-                        data =
-                            (pointer)xrealloc(tsolprop->data,
-                                              sizeInBytes*(len+tsolprop->size));
-                        if (!data)
-                            return(BadAlloc);
-                        tsolprop->data = data;
-                        bcopy((char *)value,
-                              &((char *)data)[tsolprop->size * sizeInBytes],
-                              totalSize);
-                        tsolprop->size += len;
-                    }
-                    break;
-
-                case PropModePrepend:
-                    if (len)
-                    {
-                        data =
-                            (pointer)xalloc(sizeInBytes*(len + tsolprop->size));
-                        if (!data)
-                            return(BadAlloc);
-                        bcopy((char *)tsolprop->data,
-                              &((char *)data)[totalSize],
-                              (int)(tsolprop->size * sizeInBytes));
-                        bcopy((char *)value, (char *)data, totalSize);
-                        xfree(tsolprop->data);
-                        tsolprop->data = data;
-                        tsolprop->size += len;
-                    }
-                    break;
-            }
-        }
-    }  /* end else if !prop */
-
-    event.u.u.type = PropertyNotify;
-    event.u.property.window = pWin->drawable.id;
-    event.u.property.state = PropertyNewValue;
-    event.u.property.atom = pProp->propertyName;
-    event.u.property.time = currentTime.milliseconds;
-    DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
-
-    return(Success);
-}
-
-int
-TsolInitWindow(
-    ClientPtr client,
-    WindowPtr pWin)
-{
-    TsolInfoPtr tsolinfo;
+    bslabel_t admin_low;
+    TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
     TsolResPtr  tsolres = TsolWindowPriv(pWin);
 
-    if (client == serverClient)
-    {
-	tsolres->uid = 0;
-	tsolres->sl = (bslabel_t *)lookupSL_low();
-    }
+    tsolres->uid = tsolinfo->uid;
+    tsolres->sl = tsolinfo->sl;
+
+    bsllow(&admin_low);
+    if (blequal(tsolres->sl, &admin_low))
+        tsolres->flags = TRUSTED_MASK;
     else
-    {
-        tsolinfo = GetClientTsolInfo(client);
-	tsolres->uid = tsolinfo->uid;
-	tsolres->sl = tsolinfo->sl;
-    }
+        tsolres->flags = 0;
 
     return (Success);
 }
 
 int
-TsolDeleteProperty(
-    ClientPtr client,
-    WindowPtr pWin,
-    Atom propName)
+TsolInitPixmap(ClientPtr client, PixmapPtr pMap)
 {
-    PropertyPtr pProp, prevProp;
-    xEvent event;
-    TsolPropPtr tsolprop, tail_prop, prevtsolprop;
-    TsolPropPtr *tsolpropP;
     TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
-
-    if (!(pProp = wUserProps (pWin)))
-        return(Success);
-
-    if (!PolyProperty(propName, pWin))
-	return (DeleteProperty(client, pWin, propName));
-
-    prevProp = (PropertyPtr)NULL;
-    while (pProp)
-    {
-        if (pProp->propertyName == propName)
-        {
-	    tsolpropP = TsolPropertyPriv(pProp);
-	    tsolprop = *tsolpropP;
-            /* Found a matching name. Further match for SL,UID */
-            prevtsolprop = (TsolPropPtr)NULL;
-            tail_prop = tsolprop;
-            while (tsolprop)
-            {
-                if (tsolpolyinstinfo.enabled)
-                {
-                    if (tsolprop->uid == tsolpolyinstinfo.uid &&
-                        tsolprop->sl == tsolpolyinstinfo.sl)
-                    {
-                        break;
-                    }
-                }
-                else
-                {
-                    if (tsolprop->uid == tsolinfo->uid &&
-                        tsolprop->sl == tsolinfo->sl)
-                    {
-                        break;
-                    }
-                }
-                prevtsolprop = tsolprop;
-                tsolprop = tsolprop->next;
-	    }
-	    break;
-        }
-        prevProp = pProp;
-        pProp = pProp->next;
-    }
-
-    if (pProp)
-    {
-        event.u.u.type = PropertyNotify;
-        event.u.property.window = pWin->drawable.id;
-        event.u.property.state = PropertyDelete;
-        event.u.property.atom = pProp->propertyName;
-        event.u.property.time = currentTime.milliseconds;
-        DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
-
-        if (tsolprop)
-        {
-	    tsolpropP = TsolPropertyPriv(pProp);
-	    if (*tsolpropP == tsolprop)
-		*tsolpropP = tsolprop->next;
-
-            if (prevtsolprop)
-            {
-                prevtsolprop->next = tsolprop->next;
-            }
-            xfree(tsolprop->data);
-            xfree(tsolprop);
-
-        }
-    }
-    return(Success);
-}
-
-int
-ProcTsolListProperties(ClientPtr client)
-{
-    Atom *pAtoms = NULL, *temppAtoms;
-    xListPropertiesReply xlpr;
-    int	rc, numProps = 0;
-    WindowPtr pWin;
-    PropertyPtr pProp;
-    REQUEST(xResourceReq);
-
-    REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixListPropAccess);
-    if (rc != Success)
-        return rc;
-
-    /* policy check for window  */
-    if ((rc = xtsol_policy(TSOL_RES_PROPWIN, TSOL_READ, pWin, 0,
-			   client, TSOL_ALL, &(MAJOROP))))
-    {
-        client->errorValue = stuff->id;
-        return (rc);
-    }
-
-    for (pProp = wUserProps(pWin); pProp; pProp = pProp->next)
-	numProps++;
-
-    if (numProps && !(pAtoms = (Atom *)xalloc(numProps * sizeof(Atom))))
-        return BadAlloc;
-
-    numProps = 0;
-    temppAtoms = pAtoms;
-    for (pProp = wUserProps(pWin); pProp; pProp = pProp->next)
-    {
-        if (PolyProperty(pProp->propertyName, pWin))
-        {
-            if (PolyPropReadable(pProp, client)) {
-                *temppAtoms++ = pProp->propertyName;
-		numProps++;
-	    }
-        }
-        else
-        {
-            /* error ignored */
-            if (!xtsol_policy(TSOL_RES_PROPERTY, TSOL_READ, pProp, 0,
-                              client, TSOL_ALL, &(MAJOROP))) {
-                *temppAtoms++ = pProp->propertyName;
-		numProps++;
-	    }
-        }
-    }
-
-    xlpr.type = X_Reply;
-    xlpr.nProperties = numProps;
-    xlpr.length = (numProps * sizeof(Atom)) >> 2;
-    xlpr.sequenceNumber = client->sequence;
-    WriteReplyToClient(client, sizeof(xGenericReply), &xlpr);
-    if (numProps)
-    {
-    	client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
-        WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms);
-    }
-    xfree(pAtoms);
-    return(client->noClientException);
-}
-
-int
-ProcTsolGetProperty(ClientPtr client)
-{
-    PropertyPtr pProp, prevProp;
-    unsigned long n, len, ind;
-    int rc;
-    WindowPtr pWin;
-    xGetPropertyReply reply;
-    Mask win_mode = DixGetPropAccess, prop_mode = DixReadAccess;
-
-    TsolPropPtr tsolprop = NULL;
-    TsolPropPtr prevtsolprop = NULL;
-    TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
-
-    REQUEST(xGetPropertyReq);
+    TsolResPtr  tsolres = TsolPixmapPriv(pMap);
 
-    REQUEST_SIZE_MATCH(xGetPropertyReq);
-    if (stuff->delete) {
-        UpdateCurrentTime();
-        win_mode |= DixSetPropAccess;
-        prop_mode |= DixDestroyAccess;
-    }
-    rc = dixLookupWindow(&pWin, stuff->window, client, win_mode);
-    if (rc != Success)
-        return rc;
-
-    if (!ValidAtom(stuff->property))
-    {
-	client->errorValue = stuff->property;
-	return(BadAtom);
-    }
-    if ((stuff->delete != xTrue) && (stuff->delete != xFalse))
-    {
-	client->errorValue = stuff->delete;
-	return(BadValue);
-    }
-
-    if ((stuff->type != AnyPropertyType) && !ValidAtom(stuff->type))
-    {
-	client->errorValue = stuff->type;
-	return(BadAtom);
-    }
-
-
-    /* policy check for window  */
-    if ((rc = xtsol_policy(TSOL_RES_PROPWIN, TSOL_READ, pWin, 0,
-			   client, TSOL_ALL, &(MAJOROP))))
-    {
-        client->errorValue = stuff->window;
-        return (rc);
-    }
-
-    if (!PolyProperty(stuff->property, pWin))
-    {
-	return (*TsolSavedProcVector[X_GetProperty])(client);
-    }
-
-    pProp = wUserProps (pWin);
-    prevProp = (PropertyPtr)NULL;
-
-    while (pProp)
-    {
-        if (pProp->propertyName == stuff->property)
-	{
-            tsolprop = *(TsolPropertyPriv(pProp));
-	    prevtsolprop = tsolprop;
-            while (tsolprop)
-            {
-                if (tsolpolyinstinfo.enabled)
-                {
-                    if (tsolprop->uid == tsolpolyinstinfo.uid &&
-                        tsolprop->sl == tsolpolyinstinfo.sl)
-                        break;
-                }
-                else
-                {
-                    if (tsolprop->uid == tsolinfo->uid &&
-                        tsolprop->sl == tsolinfo->sl)
-                        break; /* match found */
-                }
-                prevtsolprop = tsolprop;
-                tsolprop = tsolprop->next;
-	    }
-            break;
-	}
-	prevProp = pProp;
-	pProp = pProp->next;
-    }
-
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    tsolres->uid = tsolinfo->uid;
+    tsolres->sl = tsolinfo->sl;
+    tsolres->flags = 0;
 
-    if ( (!pProp) || (!tsolprop) || rc)
-    {
-        reply.nItems = 0;
-        reply.length = 0;
-        reply.bytesAfter = 0;
-        reply.propertyType = None;
-        reply.format = 0;
-        WriteReplyToClient(client, sizeof(xGenericReply), &reply);
-    }
-    else
-    {
-        /* If the request type and actual type don't match. Return the
-           property information, but not the data. */
-
-        if (((stuff->type != pProp->type) &&
-	     (stuff->type != AnyPropertyType)))
-        {
-	    reply.bytesAfter = tsolprop->size;
-	    reply.format = pProp->format;
-	    reply.length = 0;
-	    reply.nItems = 0;
-	    reply.propertyType = pProp->type;
-	    WriteReplyToClient(client, sizeof(xGenericReply), &reply);
-	    return(Success);
-        }
-
-	/*
-         *  Return type, format, value to client
-         */
-        n = (pProp->format/8) * tsolprop->size;
-
-	ind = stuff->longOffset << 2;
-
-        /* If longOffset is invalid such that it causes "len" to
-           be negative, it's a value error. */
-
-	if (n < ind)
-	{
-	    client->errorValue = stuff->longOffset;
-	    return BadValue;
-	}
-
-	len = min(n - ind, 4 * stuff->longLength);
-
-	reply.bytesAfter = n - (ind + len);
-	reply.format = pProp->format;
-	reply.length = (len + 3) >> 2;
-	reply.nItems = len / (pProp->format / 8 );
-	reply.propertyType = pProp->type;
-
-        /* policy check for delete error ignored */
-        if (stuff->delete && (reply.bytesAfter == 0) &&
-            (!xtsol_policy(TSOL_RES_PROPERTY, TSOL_DESTROY, pProp, 0,
-                           client, TSOL_ALL, &(MAJOROP))))
-        { /* send the event */
-	    xEvent event;
-
-	    event.u.u.type = PropertyNotify;
-	    event.u.property.window = pWin->drawable.id;
-	    event.u.property.state = PropertyDelete;
-	    event.u.property.atom = pProp->propertyName;
-	    event.u.property.time = currentTime.milliseconds;
-	    DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
-	}
-
-	WriteReplyToClient(client, sizeof(xGenericReply), &reply);
-	if (len)
-	{
-	    switch (reply.format) {
-	    case 32: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap32Write; break;
-	    case 16: client->pSwapReplyFunc = (ReplySwapPtr)CopySwap16Write; break;
-	    default: client->pSwapReplyFunc = (ReplySwapPtr)WriteToClient; break;
-	    }
-	    WriteSwappedDataToClient(client, len, (char *)tsolprop->data + ind);
-	}
-
-        if (stuff->delete && (reply.bytesAfter == 0))
-        { /* delete the Property */
-            if (prevProp == (PropertyPtr)NULL) /* takes care of head */
-	    {
-		if (!(pWin->optional->userProps = pProp->next))
-		    CheckWindowOptionalNeed (pWin);
-	    }
-	    else
-		prevProp->next = pProp->next;
-
-	    /* remove the tsol struct */
-            prevtsolprop->next = tsolprop->next;
-            xfree(tsolprop->data);
-            xfree(tsolprop);
-            /* delete the prop for last reference */
-            if (tsolprop == prevtsolprop)
-                xfree(pProp);
-	}
-    }
-    return (client->noClientException);
+    return (Success);
 }
 
 /* Generic ProcVector wrapper for functions which just need to set the
@@ -1507,117 +468,12 @@
     return (status);
 }
 
-int
-ProcTsolChangeKeyboardMapping(ClientPtr client)
-{
-    return ProcTsolUnwrapResourceAccess(client, TSOL_RES_KEYMAP, TSOL_MODIFY,
-					NULL, IGNORE_ERRORS, RAISE_TRUSTLEVEL);
-}
-
-int
-ProcTsolSetPointerMapping(ClientPtr client)
-{
-    return ProcTsolUnwrapResourceAccess(client, TSOL_RES_PTRMAP, TSOL_MODIFY,
-					NULL, IGNORE_ERRORS, RAISE_TRUSTLEVEL);
-}
-
-int
-ProcTsolChangeKeyboardControl(ClientPtr client)
-{
-    return ProcTsolUnwrapResourceAccess(client, TSOL_RES_KBDCTL, TSOL_MODIFY,
-					NULL, IGNORE_ERRORS, RAISE_TRUSTLEVEL);
-}
-
-int
-ProcTsolBell(ClientPtr client)
-{
-    return ProcTsolUnwrapResourceAccess(client, TSOL_RES_BELL, TSOL_MODIFY,
-					NULL, IGNORE_ERRORS, RAISE_TRUSTLEVEL);
-}
-
-int
-ProcTsolChangePointerControl(ClientPtr client)
-{
-    return ProcTsolUnwrapResourceAccess(client, TSOL_RES_PTRCTL, TSOL_MODIFY,
-					NULL, IGNORE_ERRORS, RAISE_TRUSTLEVEL);
-}
-
-int
-ProcTsolSetModifierMapping(ClientPtr client)
-{
-
-    xSetModifierMappingReply rep;
-    REQUEST(xSetModifierMappingReq);
-    KeyCode *inputMap;
-    int inputMapLen;
-    register int i;
-    int status;
-    DeviceIntPtr pDev = NULL;
-    int savedtrust;
-
-    REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
-
-    if (client->req_len != ((stuff->numKeyPerModifier<<1) +
-			    (sizeof (xSetModifierMappingReq)>>2)))
-	return BadLength;
-
-    inputMapLen = 8 * stuff->numKeyPerModifier;
-    inputMap = (KeyCode *)&stuff[1];
-
-    /*
-     *	Now enforce the restriction that "all of the non-zero keycodes must be
-     *	in the range specified by min-keycode and max-keycode in the
-     *	connection setup (else a Value error)"
-     */
-    for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
-	if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
-	    for (i = 0; i < inputMapLen; i++) {
-		/* Check that all the new modifiers fall within the advertised
-		 * keycode range, and are okay with the DDX. */
-		if (inputMap[i] && ((inputMap[i] < pDev->key->curKeySyms.minKeyCode ||
-				     inputMap[i] > pDev->key->curKeySyms.maxKeyCode) ||
-				    !LegalModifier(inputMap[i], pDev))) {
-		    client->errorValue = inputMap[i];
-		    return BadValue;
-		}
-	    }
-	}
-    }
-
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.success = MappingSuccess;
-
-    savedtrust = setClientTrustLevel(client, XSecurityClientTrusted);
-
-
-    if (xtsol_policy(TSOL_RES_MODMAP, TSOL_MODIFY,
-		     NULL, 0, client, TSOL_ALL, &(MAJOROP)))
-    {
-	/*
-	 * silently ignore the request. xview apps
-	 * complain if we return error code. If we don't
-	 * send the map notify event application hangs
-	 */
-	SendMappingNotify(MappingModifier, 0, 0, client);
-	WriteReplyToClient(client, sizeof(xSetModifierMappingReply), &rep);
-	status = client->noClientException;
-    }
-    else
-    {
-	status = (*TsolSavedProcVector[X_SetModifierMapping])(client);
-    }
-
-    setClientTrustLevel(client, savedtrust);
-    return (status);
-}
-
 static void
 ResetStripeWindow(ClientPtr client)
 {
     WindowPtr pParent;
     WindowPtr pWin = NULL;
+    int	      rc;
 
 #if defined(PANORAMIX)
     if (!noPanoramiXExtension)
@@ -1636,7 +492,10 @@
 	    if (panres == NULL)
 		return;
 	    /* Validate trusted stripe window */
-	    pWin = LookupWindow(panres->info[j].id, client);
+	    rc = dixLookupWindow(&pWin, panres->info[j].id, client, 
+		DixReadAccess);
+	    if (rc != Success)
+	        return;
 
 	    if (tpwin == NullWindow || pWin == NullWindow)
 		return;
@@ -1651,8 +510,12 @@
 #endif
     {
 	/* Validate trusted stripe window */
-	if (tpwin)
-	    pWin = LookupWindow(tpwin->drawable.id, client);
+	if (tpwin) {
+            rc = dixLookupWindow(&pWin, tpwin->drawable.id, client, 
+		DixReadAccess);
+            if (rc != Success)
+                return;
+	}
 
 	if (tpwin == NullWindow || pWin == NullWindow)
 	    return;
@@ -1666,84 +529,6 @@
     }
 }
 
-int
-ProcTsolCreateWindow(ClientPtr client)
-{
-    int rc;
-    WindowPtr pParent;
-    WindowPtr pWin;
-    bslabel_t admin_low;
-    TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
-    TsolResPtr  tsolres;
-
-    REQUEST(xCreateWindowReq);
-
-    REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
-
-    LEGAL_NEW_RESOURCE(stuff->wid, client);
-    rc = dixLookupWindow(&pParent, stuff->parent, client, DixAddAccess);
-    if (rc != Success)
-        return rc;
-
-    if ((rc = xtsol_policy(TSOL_RES_WINDOW, TSOL_CREATE, pParent, 0,
-			   client, TSOL_ALL, &(MAJOROP))))
-	return rc;
-
-    /* Initialize tsol security attributes */
-    rc = (*TsolSavedProcVector[X_CreateWindow])(client);
-    pWin = pParent->firstChild;
-    tsolres = TsolWindowPriv(pWin);
-
-    /* stuff tsol info into window from client */
-    if (tsolinfo == NULL || client == serverClient) {
-	/* Client is Server itself */
-	tsolres->uid = 0;
-	tsolres->sl = (bslabel_t *)lookupSL_low();
-    }
-    else
-    {
-	tsolres->uid = tsolinfo->uid;
-	tsolres->sl = tsolinfo->sl;
-    }
-
-    bsllow(&admin_low);
-    if (blequal(tsolres->sl, &admin_low))
-        tsolres->flags = TRUSTED_MASK;
-    else
-        tsolres->flags = 0;
-
-    ResetStripeWindow(client);
-
-    return rc;
-}
-
-int
-ProcTsolChangeWindowAttributes(ClientPtr client)
-{
-    WindowPtr pWin;
-    REQUEST(xChangeWindowAttributesReq);
-    int rc;
-    Mask access_mode = 0;
-
-    REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
-    access_mode |= (stuff->valueMask & CWEventMask) ? DixReceiveAccess : 0;
-    access_mode |= (stuff->valueMask & ~CWEventMask) ? DixSetAttrAccess : 0;
-    rc = dixLookupWindow(&pWin, stuff->window, client, access_mode);
-    if (rc != Success)
-        return rc;
-
-    if ((rc = xtsol_policy(TSOL_RES_WINDOW, TSOL_MODIFY, pWin, 0,
-			   client, TSOL_ALL, &(MAJOROP))))
-    {
-        if (!WindowIsRoot(pWin))
-            return (rc);
-    }
-
-    rc = (*TsolSavedProcVector[X_ChangeWindowAttributes])(client);
-    ResetStripeWindow(client);
-
-    return rc;
-}
 
 /* Generic ProcVector wrapper for functions which just need to have
    ResetStripeWindow called after executing. */
@@ -1759,6 +544,18 @@
 }
 
 int
+ProcTsolCreateWindow(ClientPtr client)
+{
+    return ProcTsolUnwrapAndResetStripe(client, X_CreateWindow);
+}
+
+int
+ProcTsolChangeWindowAttributes(ClientPtr client)
+{
+    return ProcTsolUnwrapAndResetStripe(client, X_ChangeWindowAttributes);
+}
+
+int
 ProcTsolConfigureWindow(ClientPtr client)
 {
     return ProcTsolUnwrapAndResetStripe(client, X_ConfigureWindow);
@@ -1776,27 +573,6 @@
     return ProcTsolUnwrapAndResetStripe(client, X_ReparentWindow);
 }
 
-int
-ProcTsolSendEvent(ClientPtr client)
-{
-    WindowPtr pWin;
-    REQUEST(xSendEventReq);
-
-    REQUEST_SIZE_MATCH(xSendEventReq);
-
-    dixLookupWindow(&pWin, stuff->destination, client, DixSendAccess);
-
-    if (!pWin)
-	return BadWindow;
-
-    if (xtsol_policy(TSOL_RES_EVENTWIN, TSOL_MODIFY,
-		     pWin, 0, client, TSOL_ALL, &(MAJOROP)))
-	return Success; /* ignore error */
-
-    return (*TsolSavedProcVector[X_SendEvent])(client);
-}
-
-
 /*
  * HandleHotKey -
  * HotKey is Meta(Diamond)+ Stop Key
@@ -1858,31 +634,6 @@
 }
 
 int
-ProcTsolSetInputFocus(ClientPtr client)
-{
-    int rc;
-
-    REQUEST(xSetInputFocusReq);
-
-    REQUEST_SIZE_MATCH(xSetInputFocusReq);
-
-    if (stuff->focus != None)
-    {
-        WindowPtr focusWin;
-
-	rc = dixLookupWindow(&focusWin, stuff->focus,
-			     client, DixSetAttrAccess);
-	if ((rc == Success) && (focusWin != NullWindow) &&
-	    xtsol_policy(TSOL_RES_FOCUSWIN, TSOL_MODIFY, focusWin, 0,
-			 client, TSOL_ALL, &(MAJOROP)))
-	{
-	    return (client->noClientException);
-	}
-    }
-    return (*TsolSavedProcVector[X_SetInputFocus])(client);
-}
-
-int
 ProcTsolGetInputFocus(ClientPtr client)
 {
     xGetInputFocusReply rep;
@@ -2027,43 +778,6 @@
 }
 
 int
-ProcTsolCreatePixmap(ClientPtr client)
-{
-    PixmapPtr pMap;
-    int result;
-
-    REQUEST(xCreatePixmapReq);
-
-    REQUEST_SIZE_MATCH(xCreatePixmapReq);
-
-    result = (*TsolSavedProcVector[X_CreatePixmap])(client);
-
-    pMap = (PixmapPtr)SecurityLookupIDByType(client, stuff->pid, RT_PIXMAP,
-					     DixDestroyAccess);
-    if (pMap)
-    {
-	/* Initialize security info */
-        TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
-        TsolResPtr tsolres = TsolPixmapPriv(pMap);
-
-        if (tsolinfo == NULL || client == serverClient)
-	{
-	    /* Client is Server itself */
-	    tsolres->uid = 0;
-	    tsolres->sl = (bslabel_t *)lookupSL_low();
-        }
-        else
-        {
-	    tsolres->uid = tsolinfo->uid;
-	    tsolres->sl = tsolinfo->sl;
-        }
-        tsolres->flags = 0;
-    }
-
-    return result;
-}
-
-int
 ProcTsolSetScreenSaver(ClientPtr client)
 {
     /* REQUEST(xSetScreenSaverReq); */
@@ -2138,134 +852,6 @@
 }
 #endif /* UNUSED */
 
-void
-TsolDeleteWindowFromAnySelections(WindowPtr pWin)
-{
-    Selection *pSel;
-    TsolSelnPtr tsolseln = NULL;
-    TsolSelnPtr prevtsolseln = NULL;
-
-    for (pSel = CurrentSelections; pSel; pSel = pSel->next)
-    {
-        if (PolySelection(pSel->selection))
-        {
-            tsolseln = *(TsolSelectionPriv(pSel));
-            prevtsolseln = tsolseln;
-            while (tsolseln)
-            {
-                if (tsolseln->pWin == pWin)
-		    break; /* match found */
-                prevtsolseln = tsolseln;
-                tsolseln = tsolseln->next;
-            }
-
-            if (tsolseln)
-            {
-	        if (SelectionCallback)
-	        {
-		    SelectionInfoRec    info;
-
-		    info.selection = pSel;
-		    info.kind = SelectionClientClose;
-		    CallCallbacks(&SelectionCallback, &info);
-	        }
-
-                /* first on the list */
-                if (prevtsolseln == tsolseln)
-                    *(TsolSelectionPriv(pSel))
-			= tsolseln->next;
-                else
-                    prevtsolseln->next = tsolseln->next;
-                xfree(tsolseln);
-
-		/* handle the last reference */
-                if (*(TsolSelectionPriv(pSel)) == NULL)
-                {
-                    pSel->pWin = (WindowPtr)NULL;
-                    pSel->window = None;
-                    pSel->client = NullClient;
-                }
-            }
-        }
-        else
-        {
-            if (pSel->pWin == pWin)
-            {
-		SelectionInfoRec info = { pSel, NULL, SelectionWindowDestroy };
-		CallCallbacks(&SelectionCallback, &info);
-
-                pSel->pWin = (WindowPtr)NULL;
-                pSel->window = None;
-                pSel->client = NullClient;
-            }
-        }
-   }
-}
-
-void
-TsolDeleteClientFromAnySelections(ClientPtr client)
-{
-    Selection *pSel;
-    TsolSelnPtr tsolseln = NULL;
-    TsolSelnPtr prevtsolseln = NULL;
-
-    for (pSel = CurrentSelections; pSel; pSel = pSel->next)
-    {
-        if (PolySelection(pSel->selection))
-        {
-            tsolseln = *(TsolSelectionPriv(pSel));
-            prevtsolseln = tsolseln;
-            while (tsolseln)
-            {
-                if (tsolseln->client == client)
-		    break; /* match found */
-                prevtsolseln = tsolseln;
-                tsolseln = tsolseln->next;
-            }
-
-            if (tsolseln)
-            {
-	        if (SelectionCallback)
-	        {
-		    SelectionInfoRec    info;
-
-		    info.selection = pSel;
-		    info.kind = SelectionClientClose;
-		    CallCallbacks(&SelectionCallback, &info);
-	        }
-
-                /* first on the list */
-                if (prevtsolseln == tsolseln)
-                    *(TsolSelectionPriv(pSel))
-			= tsolseln->next;
-                else
-                    prevtsolseln->next = tsolseln->next;
-                xfree(tsolseln);
-
-		/* handle the last reference */
-                if (*(TsolSelectionPriv(pSel)) == NULL)
-                {
-                    pSel->pWin = (WindowPtr)NULL;
-                    pSel->window = None;
-                    pSel->client = NullClient;
-                }
-            }
-        }
-        else
-        {
-            if (pSel->client == client)
-            {
-		SelectionInfoRec info = { pSel, NULL, SelectionClientClose };
-		CallCallbacks(&SelectionCallback, &info);
-
-                pSel->pWin = (WindowPtr)NULL;
-                pSel->window = None;
-                pSel->client = NullClient;
-            }
-        }
-   }
-}
-
 int
 ProcTsolListInstalledColormaps(ClientPtr client)
 {
@@ -2524,9 +1110,6 @@
     rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
-    rc = XaceHook(XACE_DEVICE_ACCESS, client, mouse, DixReadAccess);
-    if (rc != Success)
-	return rc;
 
     ptrWin = TsolPointerWindow();
     if (!xtsol_policy(TSOL_RES_WINDOW, TSOL_READ, ptrWin, 0,
@@ -2663,9 +1246,13 @@
         {
             Window   root;
             WindowPtr tmpwin;
+	    int	     rc;
 
             not_root_window = TRUE;
-            tmpwin = (WindowPtr)LookupWindow(pDraw->id, client);
+            rc = dixLookupWindow(&tmpwin, pDraw->id, client, DixReadAccess);
+            if (rc != Success)
+		return rc;
+
             while (tmpwin)
             {
                 if (tmpwin->parent && WindowIsRoot(tmpwin->parent))
@@ -2682,7 +1269,9 @@
             box.y2 = box.y1;
             tsolres_win = TsolWindowPriv(pWin);
             root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id;
-            pRoot = (WindowPtr)LookupIDByType(root, RT_WINDOW);
+            rc = dixLookupWindow(&pRoot, root, client, DixReadAccess);
+            if (rc != Success)
+		return rc;
             pHead = pRoot->firstChild;
         }
 
--- a/open-src/xserver/xorg/sun-src/tsol/tsolutils.c	Tue Mar 31 17:01:13 2009 -0700
+++ b/open-src/xserver/xorg/sun-src/tsol/tsolutils.c	Thu Apr 02 14:22:10 2009 -0700
@@ -26,7 +26,7 @@
  * of the copyright holder.
  */
 
-#pragma ident   "@(#)tsolutils.c	1.21	09/02/12 SMI"
+#pragma ident   "@(#)tsolutils.c	1.22	09/04/02 SMI"
 
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
@@ -773,7 +773,7 @@
 int
 PolyPropReadable(PropertyPtr pProp, ClientPtr client)
 {
-    TsolPropPtr tsolprop = *(TsolPropertyPriv(pProp));
+    TsolPropPtr tsolprop = (TsolPropertyPriv(pProp));
     TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
 
     while (tsolprop)
--- a/open-src/xserver/xorg/xtsol.patch	Tue Mar 31 17:01:13 2009 -0700
+++ b/open-src/xserver/xorg/xtsol.patch	Thu Apr 02 14:22:10 2009 -0700
@@ -146,18 +146,6 @@
  DoGetImage(ClientPtr client, int format, Drawable drawable, 
             int x, int y, int width, int height, 
             Mask planemask, xGetImageReply **im_return)
-@@ -3400,6 +3414,11 @@ CloseDownClient(ClientPtr client)
- 	    UngrabServer(client);
- 	}
- 	BITCLEAR(grabWaiters, client->index);
-+#ifdef TSOL
-+        if (pSecHook)
-+            (*pSecHook->DeleteClientFromAnySelections)(client);
-+        else
-+#endif
- 	DeleteClientFromAnySelections(client);
- 	ReleaseActiveGrabs(client);
- 	DeleteClientFontStuff(client);
 diff -urp -x '*~' -x '*.orig' dix/events.c dix/events.c
 --- dix/events.c	2008-11-05 08:52:17.000000000 -0800
 +++ dix/events.c	2009-02-03 09:48:35.187905000 -0800
@@ -198,81 +186,6 @@
  XYToWindow(int x, int y)
  {
      WindowPtr  pWin;
-diff -urp -x '*~' -x '*.orig' dix/property.c dix/property.c
---- dix/property.c	2008-11-05 08:52:17.000000000 -0800
-+++ dix/property.c	2009-02-03 09:48:35.189032000 -0800
-@@ -45,6 +45,34 @@ SOFTWARE.
- 
- ******************************************************************/
- 
-+/* Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
-+ *
-+ * Permission is hereby granted, free of charge, to any person obtaining a
-+ * copy of this software and associated documentation files (the
-+ * "Software"), to deal in the Software without restriction, including
-+ * without limitation the rights to use, copy, modify, merge, publish,
-+ * distribute, and/or sell copies of the Software, and to permit persons
-+ * to whom the Software is furnished to do so, provided that the above
-+ * copyright notice(s) and this permission notice appear in all copies of
-+ * the Software and that both the above copyright notice(s) and this
-+ * permission notice appear in supporting documentation.
-+ *
-+ * 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
-+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
-+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
-+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
-+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-+ *
-+ * Except as contained in this notice, the name of a copyright holder
-+ * shall not be used in advertising or otherwise to promote the sale, use
-+ * or other dealings in this Software without prior written authorization
-+ * of the copyright holder.
-+ */ 
-+
- #ifdef HAVE_DIX_CONFIG_H
- #include <dix-config.h>
- #endif
-@@ -60,6 +88,11 @@ SOFTWARE.
- #include "swaprep.h"
- #include "xace.h"
- 
-+#ifdef TSOL
-+#include "extnsionst.h"
-+extern SecurityHookPtr pSecHook;
-+#endif /* TSOL */
-+
- /*****************************************************************
-  * Property Stuff
-  *
-@@ -239,6 +272,12 @@ ProcChangeProperty(ClientPtr client)
- 	return(BadAtom);
-     }
- 
-+#ifdef TSOL
-+    if (pSecHook)
-+	err = (*pSecHook->ChangeWindowProperty)(client, pWin, stuff->property,
-+	   stuff->type, (int)format, (int)mode, len, (pointer)&stuff[1], TRUE);
-+    else
-+#endif /* TSOL */
-     err = dixChangeWindowProperty(client, pWin, stuff->property, stuff->type,
- 				  (int)format, (int)mode, len, &stuff[1],
- 				  TRUE);
-@@ -629,6 +668,11 @@ ProcDeleteProperty(ClientPtr client)
- 	return (BadAtom);
-     }
- 
-+#ifdef TSOL
-+    if (pSecHook)
-+	result = (*pSecHook->DeleteProperty)(client, pWin, stuff->property);
-+    else
-+#endif /* TSOL */
-     result = DeleteProperty(client, pWin, stuff->property);
-     if (client->noClientException != Success)
- 	return(client->noClientException);
 diff -urp -x '*~' -x '*.orig' dix/window.c dix/window.c
 --- dix/window.c	2008-11-05 08:52:17.000000000 -0800
 +++ dix/window.c	2009-02-03 09:48:35.190851000 -0800
@@ -322,18 +235,6 @@
  #ifdef DEBUG
  /******
   * PrintWindowTree
-@@ -820,6 +852,11 @@ FreeWindowResources(WindowPtr pWin)
-     ScreenPtr pScreen = pWin->drawable.pScreen;
- 
-     DeleteWindowFromAnySaveSet(pWin);
-+#ifdef TSOL
-+    if (pSecHook)
-+	(*pSecHook->DeleteWindowFromAnySelections)(pWin);
-+    else
-+#endif
-     DeleteWindowFromAnySelections(pWin);
-     DeleteWindowFromAnyEvents(pWin, TRUE);
-     REGION_UNINIT(pScreen, &pWin->clipList);
 @@ -1915,7 +1952,12 @@ IsSiblingAboveMe(
      return(Below);
  }