XORG_NV/sun-src/xc/programs/Xserver/tsol/tsolprotocol.c
changeset 36 07b00e5ea8c8
parent 0 b949c5054bc4
child 64 c03273ff2fb9
equal deleted inserted replaced
35:b52017b8441e 36:07b00e5ea8c8
    24  * shall not be used in advertising or otherwise to promote the sale, use
    24  * shall not be used in advertising or otherwise to promote the sale, use
    25  * or other dealings in this Software without prior written authorization
    25  * or other dealings in this Software without prior written authorization
    26  * of the copyright holder.
    26  * of the copyright holder.
    27  */ 
    27  */ 
    28 
    28 
    29 #pragma ident	"@(#)tsolprotocol.c 1.8	06/03/07 SMI"
    29 #pragma ident	"@(#)tsolprotocol.c 1.12	06/05/25 SMI"
    30 
    30 
    31 #include <sys/param.h>
    31 #include <sys/param.h>
    32 #include <fcntl.h>
    32 #include <fcntl.h>
    33 #include <sys/types.h>
    33 #include <sys/types.h>
    34 #include <sys/stat.h>
    34 #include <sys/stat.h>
    66  */
    66  */
    67 
    67 
    68 #define MAX_AUDIT_EVENTS 100
    68 #define MAX_AUDIT_EVENTS 100
    69 
    69 
    70 int audit_eventsid[100][2] = {
    70 int audit_eventsid[100][2] = {
    71     X_CreateWindow, 9103,
    71 	X_CreateWindow, AUE_CreateWindow,
    72     X_ChangeWindowAttributes, 9104,
    72 	X_ChangeWindowAttributes, AUE_ChangeWindowAttributes,
    73     X_GetWindowAttributes, 9105,
    73 	X_GetWindowAttributes, AUE_GetWindowAttributes,
    74     X_DestroyWindow, 9106,
    74 	X_DestroyWindow, AUE_DestroyWindow,
    75     X_DestroySubwindows, 9107,
    75 	X_DestroySubwindows, AUE_DestroySubwindows,
    76     X_ChangeSaveSet, 9108,
    76 	X_ChangeSaveSet, AUE_ChangeSaveSet,
    77     X_ReparentWindow, 9109,
    77 	X_ReparentWindow, AUE_ReparentWindow,
    78     X_MapWindow, 9110,
    78 	X_MapWindow, AUE_MapWindow,
    79     X_MapSubwindows, 9111,
    79 	X_MapSubwindows, AUE_MapSubwindows,
    80     X_UnmapWindow, 9112, 
    80 	X_UnmapWindow, AUE_UnmapWindow,
    81     X_UnmapSubwindows, 9113,
    81 	X_UnmapSubwindows, AUE_UnmapSubwindows,
    82     X_ConfigureWindow, 9114,
    82 	X_ConfigureWindow, AUE_ConfigureWindow,
    83     X_CirculateWindow, 9115,
    83 	X_CirculateWindow, AUE_CirculateWindow,
    84     X_GetGeometry, 9116,
    84 	X_GetGeometry, AUE_GetGeometry,
    85     X_QueryTree, 9117,
    85 	X_QueryTree, AUE_QueryTree,
    86     X_InternAtom, 9118,
    86 	X_InternAtom, AUE_InternAtom,
    87     X_GetAtomName, 9119,
    87 	X_GetAtomName, AUE_GetAtomName,
    88     X_ChangeProperty, 9120,
    88 	X_ChangeProperty, AUE_ChangeProperty,
    89     X_DeleteProperty, 9121,
    89 	X_DeleteProperty, AUE_DeleteProperty,
    90     X_GetProperty, 9122,
    90 	X_GetProperty, AUE_GetProperty,
    91     X_ListProperties, 9123,
    91 	X_ListProperties, AUE_ListProperties,
    92     X_SetSelectionOwner, 9124,
    92 	X_SetSelectionOwner, AUE_SetSelectionOwner,
    93     X_GetSelectionOwner, 9125,
    93 	X_GetSelectionOwner, AUE_GetSelectionOwner,
    94     X_ConvertSelection, 9126,
    94 	X_ConvertSelection, AUE_ConvertSelection,
    95     X_SendEvent, 9127,
    95 	X_SendEvent, AUE_SendEvent,
    96     X_GrabPointer, 9128,
    96 	X_GrabPointer, AUE_GrabPointer,
    97     X_UngrabPointer, 9129,
    97 	X_UngrabPointer, AUE_UngrabPointer,
    98     X_GrabButton, 9130,
    98 	X_GrabButton, AUE_GrabButton,
    99     X_UngrabButton, 9131,
    99 	X_UngrabButton, AUE_UngrabButton,
   100     X_ChangeActivePointerGrab, 9132,
   100 	X_ChangeActivePointerGrab, AUE_ChangeActivePointerGrab,
   101     X_GrabKeyboard, 9133,
   101 	X_GrabKeyboard, AUE_GrabKeyboard,
   102     X_UngrabKeyboard, 9134,
   102 	X_UngrabKeyboard, AUE_UngrabKeyboard,
   103     X_GrabKey, 9135,
   103 	X_GrabKey, AUE_GrabKey,
   104     X_UngrabKey, 9136,
   104 	X_UngrabKey, AUE_UngrabKey,
   105     X_GrabServer, 9137,
   105 	X_GrabServer, AUE_GrabServer,
   106     X_UngrabServer, 9138,
   106 	X_UngrabServer, AUE_UngrabServer,
   107     X_QueryPointer, 9139,
   107 	X_QueryPointer, AUE_QueryPointer,
   108     X_GetMotionEvents, 9140,
   108 	X_GetMotionEvents, AUE_GetMotionEvents,
   109     X_TranslateCoords, 9141,
   109 	X_TranslateCoords, AUE_TranslateCoords,
   110     X_WarpPointer, 9142,
   110 	X_WarpPointer, AUE_WarpPointer,
   111     X_SetInputFocus, 9143,
   111 	X_SetInputFocus, AUE_SetInputFocus,
   112     X_GetInputFocus, 9144,
   112 	X_GetInputFocus, AUE_GetInputFocus,
   113     X_QueryKeymap, 9145,
   113 	X_QueryKeymap, AUE_QueryKeymap,
   114     X_SetFontPath, 9146,
   114 	X_SetFontPath, AUE_SetFontPath,
   115     X_FreePixmap, 9147,
   115 	X_FreePixmap, AUE_FreePixmap,
   116     X_ChangeGC, 9148,
   116 	X_ChangeGC, AUE_ChangeGC,
   117     X_CopyGC, 9149,
   117 	X_CopyGC, AUE_CopyGC,
   118     X_SetDashes, 9150,
   118 	X_SetDashes, AUE_SetDashes,
   119     X_SetClipRectangles, 9151,
   119 	X_SetClipRectangles, AUE_SetClipRectangles,
   120     X_FreeGC, 9152,
   120 	X_FreeGC, AUE_FreeGC,
   121     X_ClearArea, 9153,
   121 	X_ClearArea, AUE_ClearArea,
   122     X_CopyArea, 9154,
   122 	X_CopyArea, AUE_CopyArea,
   123     X_CopyPlane, 9155,
   123 	X_CopyPlane, AUE_CopyPlane,
   124     X_PolyPoint, 9156,
   124 	X_PolyPoint, AUE_PolyPoint,
   125     X_PolyLine, 9157,
   125 	X_PolyLine, AUE_PolyLine,
   126     X_PolySegment, 9158,
   126 	X_PolySegment, AUE_PolySegment,
   127     X_PolyRectangle, 9159,
   127 	X_PolyRectangle, AUE_PolyRectangle,
   128     X_PolyArc, 9160,
   128 	X_PolyArc, AUE_PolyArc,
   129     X_FillPoly, 9161,
   129 	X_FillPoly, AUE_FillPolygon,
   130     X_PolyFillRectangle, 9162,
   130 	X_PolyFillRectangle, AUE_PolyFillRectangle,
   131     X_PolyFillArc, 9163,
   131 	X_PolyFillArc, AUE_PolyFillArc,
   132     X_PutImage, 9164,
   132 	X_PutImage, AUE_PutImage,
   133     X_GetImage, 9165,
   133 	X_GetImage, AUE_GetImage,
   134     X_PolyText8, 9166,
   134 	X_PolyText8, AUE_PolyText8,
   135     X_PolyText16, 9167,
   135 	X_PolyText16, AUE_PolyText16,
   136     X_ImageText8, 9168,
   136 	X_ImageText8, AUE_ImageText8,
   137     X_ImageText16, 9169,
   137 	X_ImageText16, AUE_ImageText16,
   138     X_CreateColormap, 9170,
   138 	X_CreateColormap, AUE_CreateColormap,
   139     X_FreeColormap, 9171,
   139 	X_FreeColormap, AUE_FreeColormap,
   140     X_CopyColormapAndFree, 9172,
   140 	X_CopyColormapAndFree, AUE_CopyColormapAndFree,
   141     X_InstallColormap, 9173,
   141 	X_InstallColormap, AUE_InstallColormap,
   142     X_UninstallColormap, 9174,
   142 	X_UninstallColormap, AUE_UninstallColormap,
   143     X_ListInstalledColormaps, 9175,
   143 	X_ListInstalledColormaps, AUE_ListInstalledColormaps,
   144     X_AllocColor, 9176,
   144 	X_AllocColor, AUE_AllocColor,
   145     X_AllocNamedColor, 9177,
   145 	X_AllocNamedColor, AUE_AllocNamedColor,
   146     X_AllocColorCells, 9178,
   146 	X_AllocColorCells, AUE_AllocColorCells,
   147     X_AllocColorPlanes, 9179,
   147 	X_AllocColorPlanes, AUE_AllocColorPlanes,
   148     X_FreeColors, 9180,
   148 	X_FreeColors, AUE_FreeColors,
   149     X_StoreColors, 9181,
   149 	X_StoreColors, AUE_StoreColors,
   150     X_StoreNamedColor, 9182,
   150 	X_StoreNamedColor, AUE_StoreNamedColor,
   151     X_QueryColors, 9183,
   151 	X_QueryColors, AUE_QueryColors,
   152     X_LookupColor, 9184,
   152 	X_LookupColor, AUE_LookupColor,
   153     X_CreateCursor, 9185,
   153 	X_CreateCursor, AUE_CreateCursor,
   154     X_CreateGlyphCursor, 9186,
   154 	X_CreateGlyphCursor, AUE_CreateGlyphCursor,
   155     X_FreeCursor, 9187,
   155 	X_FreeCursor, AUE_FreeCursor,
   156     X_RecolorCursor, 9188,
   156 	X_RecolorCursor, AUE_RecolorCursor,
   157     X_ChangeKeyboardMapping, 9189,
   157 	X_ChangeKeyboardMapping, AUE_ChangeKeyboardMapping,
   158     X_ChangeKeyboardControl, 9190,
   158 	X_ChangeKeyboardControl, AUE_ChangeKeyboardControl,
   159     X_Bell, 9191,
   159 	X_Bell, AUE_Bell,
   160     X_ChangePointerControl, 9192,
   160 	X_ChangePointerControl, AUE_ChangePointerControl,
   161     X_SetScreenSaver, 9193,
   161 	X_SetScreenSaver, AUE_SetScreenSaver,
   162     X_ChangeHosts, 9194,
   162 	X_ChangeHosts, AUE_ChangeHosts,
   163     X_SetAccessControl, 9195,
   163 	X_SetAccessControl, AUE_SetAccessControl,
   164     X_SetCloseDownMode, 9196,
   164 	X_SetCloseDownMode, AUE_SetCloseDownMode,
   165     X_KillClient, 9197,
   165 	X_KillClient, AUE_KillClient,
   166     X_RotateProperties, 9198,
   166 	X_RotateProperties, AUE_RotateProperties,
   167     X_ForceScreenSaver, 9199,
   167 	X_ForceScreenSaver, AUE_ForceScreenSaver,
   168     X_SetPointerMapping, 9200,
   168 	X_SetPointerMapping, AUE_SetPointerMapping,
   169     X_SetModifierMapping, 9201,
   169 	X_SetModifierMapping, AUE_SetModifierMapping,
   170     X_NoOperation, 9202
   170 	X_NoOperation, AUE_XExtensions
   171 };
   171 };
   172 extern void Swap32Write();
   172 extern void Swap32Write();
   173 extern int (*TsolSavedProcVector[PROCVECTORSIZE])(ClientPtr /*client*/);
   173 extern int (*TsolSavedProcVector[PROCVECTORSIZE])(ClientPtr /*client*/);
   174 extern int (*TsolSavedSwappedProcVector[PROCVECTORSIZE])(ClientPtr /*client*/);
   174 extern int (*TsolSavedSwappedProcVector[PROCVECTORSIZE])(ClientPtr /*client*/);
   175 
   175 
  1088     {
  1088     {
  1089         tsolinfo = GetClientTsolInfo(client);
  1089         tsolinfo = GetClientTsolInfo(client);
  1090 	tsolres->uid = tsolinfo->uid;
  1090 	tsolres->uid = tsolinfo->uid;
  1091 	tsolres->sl = tsolinfo->sl;
  1091 	tsolres->sl = tsolinfo->sl;
  1092     }
  1092     }
       
  1093 
       
  1094     return (Success);
  1093 }
  1095 }
  1094 
  1096 
  1095 int
  1097 int
  1096 TsolDeleteProperty(client, pWin, propName)
  1098 TsolDeleteProperty(client, pWin, propName)
  1097     ClientPtr client;
  1099     ClientPtr client;
  1439 
  1441 
  1440 int
  1442 int
  1441 ProcTsolChangeKeyboardMapping(client)
  1443 ProcTsolChangeKeyboardMapping(client)
  1442     ClientPtr client;
  1444     ClientPtr client;
  1443 {
  1445 {
  1444     int err_code;
  1446     int status;
  1445 
  1447     int savedtrust = client->trustLevel;
  1446     if (err_code = xtsol_policy(TSOL_RES_KEYMAP, TSOL_MODIFY, 
  1448 
       
  1449     client->trustLevel = XSecurityClientTrusted;
       
  1450 
       
  1451     if (xtsol_policy(TSOL_RES_KEYMAP, TSOL_MODIFY, 
  1447 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1452 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1448     {
  1453     {
  1449 	/* Ignore error */
  1454 	status = client->noClientException; /* ignore error */
  1450 	return client->noClientException;
       
  1451     }
  1455     }
  1452     else
  1456     else
  1453     {
  1457     {
  1454 	return (*TsolSavedProcVector[X_ChangeKeyboardMapping])(client);
  1458 	status = (*TsolSavedProcVector[X_ChangeKeyboardMapping])(client);
  1455     }
  1459     }
       
  1460 
       
  1461     client->trustLevel = savedtrust;
       
  1462     return (status);
  1456 }
  1463 }
  1457 
  1464 
  1458 int
  1465 int
  1459 ProcTsolSetPointerMapping(client)
  1466 ProcTsolSetPointerMapping(client)
  1460     ClientPtr client;
  1467     ClientPtr client;
  1461 {
  1468 {
  1462     int err_code;
  1469     int status;
  1463 
  1470     int savedtrust = client->trustLevel;
  1464     if (err_code = xtsol_policy(TSOL_RES_PTRMAP, TSOL_MODIFY, 
  1471 
       
  1472     client->trustLevel = XSecurityClientTrusted;
       
  1473 
       
  1474     if (xtsol_policy(TSOL_RES_PTRMAP, TSOL_MODIFY, 
  1465 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1475 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1466     {
  1476     {
  1467 	/* Ignore error */
  1477 	status = Success; /* ignore error */
  1468 	return Success;
       
  1469     }
  1478     }
  1470     else
  1479     else
  1471     {
  1480     {
  1472 	return (*TsolSavedProcVector[X_SetPointerMapping])(client);
  1481 	status = (*TsolSavedProcVector[X_SetPointerMapping])(client);
  1473     }
  1482     }
       
  1483 
       
  1484     client->trustLevel = savedtrust;
       
  1485     return (status);
  1474 }
  1486 }
  1475 
  1487 
  1476 int
  1488 int
  1477 ProcTsolChangeKeyboardControl(client)
  1489 ProcTsolChangeKeyboardControl(client)
  1478     ClientPtr client;
  1490     ClientPtr client;
  1479 {
  1491 {
  1480     int err_code;
  1492     int status;
  1481 
  1493     int savedtrust = client->trustLevel;
  1482     if (err_code = xtsol_policy(TSOL_RES_KBDCTL, TSOL_MODIFY, 
  1494 
       
  1495     client->trustLevel = XSecurityClientTrusted;
       
  1496 
       
  1497     if (xtsol_policy(TSOL_RES_KBDCTL, TSOL_MODIFY, 
  1483 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1498 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1484     {
  1499     {
  1485 	/* Ignore error */
  1500 	status = Success; /* ignore error */
  1486 	return Success;
       
  1487     }
  1501     }
  1488     else
  1502     else
  1489     {
  1503     {
  1490 	return (*TsolSavedProcVector[X_ChangeKeyboardControl])(client);
  1504 	status = (*TsolSavedProcVector[X_ChangeKeyboardControl])(client);
  1491     }
  1505     }
       
  1506 
       
  1507     client->trustLevel = savedtrust;
       
  1508     return (status);
  1492 }
  1509 }
  1493 
  1510 
  1494 int
  1511 int
  1495 ProcTsolBell(client)
  1512 ProcTsolBell(client)
  1496     ClientPtr client;
  1513     ClientPtr client;
  1497 {
  1514 {
  1498     int err_code;
  1515     int status;
  1499 
  1516     int savedtrust = client->trustLevel;
  1500     if (err_code = xtsol_policy(TSOL_RES_BELL, TSOL_MODIFY, 
  1517 
       
  1518     client->trustLevel = XSecurityClientTrusted;
       
  1519 
       
  1520     if (xtsol_policy(TSOL_RES_BELL, TSOL_MODIFY, 
  1501 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1521 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1502     {
  1522     {
  1503 	/* Ignore error */
  1523 	status = Success; /* ignore error */
  1504 	return Success;
       
  1505     }
  1524     }
  1506     else
  1525     else
  1507     {
  1526     {
  1508 	return (*TsolSavedProcVector[X_Bell])(client);
  1527 	status = (*TsolSavedProcVector[X_Bell])(client);
  1509     }
  1528     }
       
  1529 
       
  1530     client->trustLevel = savedtrust;
       
  1531     return (status);
  1510 }
  1532 }
  1511 
  1533 
  1512 int
  1534 int
  1513 ProcTsolChangePointerControl(client)
  1535 ProcTsolChangePointerControl(client)
  1514     ClientPtr client;
  1536     ClientPtr client;
  1515 {
  1537 {
  1516     int err_code;
  1538     int status;
  1517 
  1539     int savedtrust = client->trustLevel;
  1518     if (err_code = xtsol_policy(TSOL_RES_PTRCTL, TSOL_MODIFY, 
  1540 
       
  1541     client->trustLevel = XSecurityClientTrusted;
       
  1542 
       
  1543     if (xtsol_policy(TSOL_RES_PTRCTL, TSOL_MODIFY, 
  1519 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1544 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1520     {
  1545     {
  1521 	/* Ignore error */
  1546 	status = Success; /* ignore error */
  1522 	return Success;
       
  1523     }
  1547     }
  1524     else
  1548     else
  1525     {
  1549     {
  1526 	return (*TsolSavedProcVector[X_ChangePointerControl])(client);
  1550 	status = (*TsolSavedProcVector[X_ChangePointerControl])(client);
  1527     }
  1551     }
       
  1552 
       
  1553     client->trustLevel = savedtrust;
       
  1554     return (status);
  1528 }
  1555 }
  1529 
  1556 
  1530 int 
  1557 int 
  1531 ProcTsolSetModifierMapping(client)
  1558 ProcTsolSetModifierMapping(client)
  1532     ClientPtr client;
  1559     ClientPtr client;
  1533 {
  1560 {
       
  1561 
  1534     xSetModifierMappingReply rep;
  1562     xSetModifierMappingReply rep;
  1535     REQUEST(xSetModifierMappingReq);
  1563     REQUEST(xSetModifierMappingReq);
  1536     KeyCode *inputMap;
  1564     KeyCode *inputMap;
  1537     int inputMapLen;
  1565     int inputMapLen;
  1538     register int i;
  1566     register int i;
  1539     int err_code;
  1567     int status;
  1540     DeviceIntPtr keybd = inputInfo.keyboard;
  1568     DeviceIntPtr keybd = inputInfo.keyboard;
  1541     register KeyClassPtr keyc = keybd->key;
  1569     register KeyClassPtr keyc = keybd->key;
       
  1570     int savedtrust = client->trustLevel;
  1542     
  1571     
  1543     REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
  1572     REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
  1544 
  1573 
  1545     if (client->req_len != ((stuff->numKeyPerModifier<<1) +
  1574     if (client->req_len != ((stuff->numKeyPerModifier<<1) +
  1546 			    (sizeof (xSetModifierMappingReq)>>2)))
  1575 			    (sizeof (xSetModifierMappingReq)>>2)))
  1569     rep.type = X_Reply;
  1598     rep.type = X_Reply;
  1570     rep.length = 0;
  1599     rep.length = 0;
  1571     rep.sequenceNumber = client->sequence;
  1600     rep.sequenceNumber = client->sequence;
  1572     rep.success = MappingSuccess;
  1601     rep.success = MappingSuccess;
  1573 
  1602 
  1574 
  1603     client->trustLevel = XSecurityClientTrusted;
  1575     if (err_code = xtsol_policy(TSOL_RES_MODMAP, TSOL_MODIFY, 
  1604 
       
  1605     if (xtsol_policy(TSOL_RES_MODMAP, TSOL_MODIFY, 
  1576 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1606 	NULL, client, TSOL_ALL, (void *)MAJOROP))
  1577     {
  1607     {
  1578 	/* 
  1608 	/* 
  1579 	 * silently ignore the request. xview apps 
  1609 	 * silently ignore the request. xview apps 
  1580 	 * complain if we return error code. If we don't
  1610 	 * complain if we return error code. If we don't
  1581 	 * send the map notify event application hangs
  1611 	 * send the map notify event application hangs
  1582 	 */
  1612 	 */
  1583          SendMappingNotify(MappingModifier, 0, 0,client);
  1613          SendMappingNotify(MappingModifier, 0, 0,client);
  1584 	 WriteReplyToClient(client, sizeof(xSetModifierMappingReply), &rep);
  1614 	 WriteReplyToClient(client, sizeof(xSetModifierMappingReply), &rep);
  1585 	 return(client->noClientException);
  1615 	 status = client->noClientException;
  1586     }
  1616     }
  1587     else
  1617     else
  1588     {
  1618     {
  1589 	return (*TsolSavedProcVector[X_SetModifierMapping])(client);
  1619 	status = (*TsolSavedProcVector[X_SetModifierMapping])(client);
  1590     }
  1620     }
       
  1621 
       
  1622     client->trustLevel = savedtrust;
       
  1623     return (status);
  1591 }
  1624 }
  1592 
  1625 
  1593 void
  1626 void
  1594 RemoveStripeWindow()
  1627 RemoveStripeWindow()
  1595 {
  1628 {
  1609     if (tpwin == pParent->lastChild) {
  1642     if (tpwin == pParent->lastChild) {
  1610 	pParent->lastChild = tpwin->nextSib;
  1643 	pParent->lastChild = tpwin->nextSib;
  1611     }
  1644     }
  1612 }
  1645 }
  1613 
  1646 
  1614 void
  1647 static void
  1615 ResetStripeWindow()
  1648 ResetStripeWindow(ClientPtr client)
  1616 {
  1649 {
  1617     WindowPtr pParent;
  1650     WindowPtr pParent;
  1618 
  1651     WindowPtr pWin = NULL;
  1619     /* Ignore if stripe is not set */
  1652 
  1620     if (!tpwin)
  1653     /* Validate trusted stripe window */
       
  1654     if (tpwin)
       
  1655         pWin = LookupWindow(tpwin->drawable.id, client);
       
  1656 
       
  1657     if (tpwin == NullWindow || pWin == NullWindow)
  1621 	return;
  1658 	return;
  1622 
  1659 
  1623     pParent = tpwin->parent;
  1660     pParent = tpwin->parent;
  1624     /* stripe is already at head, nothing to do */
  1661     /* stripe is already at head, nothing to do */
  1625     if (!pParent || pParent->firstChild == tpwin)
  1662     if (!pParent || pParent->firstChild == tpwin)
  1674     if (blequal(tsolres->sl, &admin_low))
  1711     if (blequal(tsolres->sl, &admin_low))
  1675         tsolres->flags = TRUSTED_MASK;
  1712         tsolres->flags = TRUSTED_MASK;
  1676     else
  1713     else
  1677         tsolres->flags = 0;
  1714         tsolres->flags = 0;
  1678 
  1715 
  1679     ResetStripeWindow();
  1716     ResetStripeWindow(client);
  1680 
  1717 
  1681     return result;
  1718     return result;
  1682 }
  1719 }
  1683 
  1720 
  1684 int
  1721 int
  1701         if (!WindowIsRoot(pWin))
  1738         if (!WindowIsRoot(pWin))
  1702             return (result);
  1739             return (result);
  1703     }
  1740     }
  1704 
  1741 
  1705     result = (*TsolSavedProcVector[X_ChangeWindowAttributes])(client);
  1742     result = (*TsolSavedProcVector[X_ChangeWindowAttributes])(client);
  1706     ResetStripeWindow();
  1743     ResetStripeWindow(client);
  1707 
  1744 
  1708     return result;
  1745     return result;
  1709 }
  1746 }
  1710 
  1747 
  1711 int
  1748 int
  1713     register ClientPtr client;
  1750     register ClientPtr client;
  1714 {
  1751 {
  1715     int result;
  1752     int result;
  1716 
  1753 
  1717     result = (*TsolSavedProcVector[X_ConfigureWindow])(client);
  1754     result = (*TsolSavedProcVector[X_ConfigureWindow])(client);
  1718     ResetStripeWindow();
  1755     ResetStripeWindow(client);
  1719 
  1756 
  1720     return result;
  1757     return result;
  1721 }
  1758 }
  1722 
  1759 
  1723 int
  1760 int
  1725     register ClientPtr client;
  1762     register ClientPtr client;
  1726 {
  1763 {
  1727     int result;
  1764     int result;
  1728 
  1765 
  1729     result = (*TsolSavedProcVector[X_CirculateWindow])(client);
  1766     result = (*TsolSavedProcVector[X_CirculateWindow])(client);
  1730     ResetStripeWindow();
  1767     ResetStripeWindow(client);
  1731 
  1768 
  1732     return result;
  1769     return result;
  1733 }
  1770 }
  1734 
  1771 
  1735 int
  1772 int
  1737     register ClientPtr client;
  1774     register ClientPtr client;
  1738 {
  1775 {
  1739     int result;
  1776     int result;
  1740 
  1777 
  1741     result = (*TsolSavedProcVector[X_ReparentWindow])(client);
  1778     result = (*TsolSavedProcVector[X_ReparentWindow])(client);
  1742     ResetStripeWindow();
  1779     ResetStripeWindow(client);
  1743 
  1780 
  1744     return result;
  1781     return result;
  1745 }
  1782 }
  1746 
  1783 
  1747 int
  1784 int
  2046 int
  2083 int
  2047 ProcTsolChangeHosts(client)
  2084 ProcTsolChangeHosts(client)
  2048     register ClientPtr client;
  2085     register ClientPtr client;
  2049 {
  2086 {
  2050     int result;
  2087     int result;
       
  2088     int savedtrust = client->trustLevel;
  2051 
  2089 
  2052     REQUEST(xChangeHostsReq);
  2090     REQUEST(xChangeHostsReq);
  2053 
  2091 
  2054     REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength);
  2092     REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength);
  2055 
  2093 
  2056     if (result = xtsol_policy(TSOL_RES_ACL, TSOL_MODIFY, NULL,
  2094     if (result = xtsol_policy(TSOL_RES_ACL, TSOL_MODIFY, NULL,
  2057              client, TSOL_ALL, (void *)MAJOROP))
  2095              client, TSOL_ALL, (void *)MAJOROP))
  2058         return (result);
  2096         return (result);
  2059 
  2097 
  2060     return (*TsolSavedProcVector[X_ChangeHosts])(client);
  2098     client->trustLevel = XSecurityClientTrusted;
       
  2099     result = (*TsolSavedProcVector[X_ChangeHosts])(client);
       
  2100     client->trustLevel = savedtrust;
       
  2101 
       
  2102     return (result);
  2061 }
  2103 }
  2062 
  2104 
  2063 int
  2105 int
  2064 ProcTsolChangeAccessControl(client)
  2106 ProcTsolChangeAccessControl(client)
  2065     register ClientPtr client;
  2107     register ClientPtr client;
  2066 {
  2108 {
  2067     int result;
  2109     int result;
       
  2110     int savedtrust = client->trustLevel;
  2068 
  2111 
  2069     REQUEST(xSetAccessControlReq);
  2112     REQUEST(xSetAccessControlReq);
  2070 
  2113 
  2071     REQUEST_SIZE_MATCH(xSetAccessControlReq);
  2114     REQUEST_SIZE_MATCH(xSetAccessControlReq);
  2072 
  2115 
  2075     {
  2118     {
  2076         client->errorValue = stuff->mode;
  2119         client->errorValue = stuff->mode;
  2077         return (result);
  2120         return (result);
  2078     }
  2121     }
  2079 
  2122 
  2080     return (*TsolSavedProcVector[X_SetAccessControl])(client);
  2123     client->trustLevel = XSecurityClientTrusted;
       
  2124     result = (*TsolSavedProcVector[X_SetAccessControl])(client);
       
  2125     client->trustLevel = savedtrust;
       
  2126 
       
  2127     return (result);
  2081 }
  2128 }
  2082 
  2129 
  2083 int
  2130 int
  2084 ProcTsolKillClient(client)
  2131 ProcTsolKillClient(client)
  2085     register ClientPtr client;
  2132     register ClientPtr client;
  2531     Bool do_x_audit = FALSE;
  2578     Bool do_x_audit = FALSE;
  2532     Bool audit_event = FALSE;
  2579     Bool audit_event = FALSE;
  2533     char audit_ret = (char)NULL;
  2580     char audit_ret = (char)NULL;
  2534     TsolInfoPtr tsolinfo = (TsolInfoPtr)NULL;
  2581     TsolInfoPtr tsolinfo = (TsolInfoPtr)NULL;
  2535     tsolinfo = GetClientTsolInfo(client);
  2582     tsolinfo = GetClientTsolInfo(client);
  2536     if (system_audit_on &&
  2583     if (system_audit_on && 
  2537     (tsolinfo->aw_auinfo.ai_mask.am_success ||
  2584 	(tsolinfo->amask.am_success || tsolinfo->amask.am_failure)) {
  2538     tsolinfo->aw_auinfo.ai_mask.am_failure))
  2585 
  2539     {
  2586 	do_x_audit = TRUE;
  2540         do_x_audit = TRUE;
  2587         auditwrite(AW_PRESELECT, &(tsolinfo->amask), AW_END);
  2541         auditwrite(AW_PRESELECT, &(tsolinfo->aw_auinfo.ai_mask), AW_END);
  2588 		
  2542     }
  2589         /*
  2543     return;
  2590          * X audit events start from 9101 in audit_uevents.h. The first two
  2544             /*
  2591          * events are non-protocol ones viz. ClientConnect, mapped to 9101
  2545              * X audit events start from 9101 in audit_uevents.h. The first two
  2592          * and ClientDisconnect, mapped to 9102.
  2546              * events are non-protocol ones viz. ClientConnect, mapped to 9101
  2593          * The protocol events are mapped from 9103 onwards in the serial
  2547              * and ClientDisconnect, mapped to 9102.
  2594          * order of their respective protocol opcode, for eg, the protocol
  2548              * The protocol events are mapped from 9103 onwards in the serial
  2595          * UngrabPointer which is has a protocol opcode 27 is mapped to
  2549              * order of their respective protocol opcode, for eg, the protocol
  2596          * 9129 (9102 + 27).
  2550              * UngrabPointer which is has a protocol opcode 27 is mapped to
  2597          * All extension protocols are mapped to a single audit event
  2551              * 9129 (9102 + 27).
  2598          * AUE_XExtension as opcodes are assigined dynamically to these
  2552              * All extension protocols are mapped to a single audit event
  2599          * protocols. We set the extension protocol opcode to be 128, one
  2553              * AUE_XExtension as opcodes are assigined dynamically to these
  2600          * more than the last standard opcode.
  2554              * protocols. We set the extension protocol opcode to be 128, one
  2601          */
  2555              * more than the last standard opcode.
  2602         protocol = (unsigned int)MAJOROP;
  2556              */
  2603 	if (protocol > X_NoOperation) {
  2557             protocol = (unsigned int)MAJOROP;
  2604              xevent_num = audit_eventsid[MAX_AUDIT_EVENTS - 1][1];
  2558             if (protocol > X_NoOperation)
  2605              audit_event = TRUE;
  2559             {
  2606 	} else {
  2560                 xevent_num = audit_eventsid[MAX_AUDIT_EVENTS - 1][1];
  2607             for (count = 0; count < MAX_AUDIT_EVENTS; count++) {
  2561                 audit_event = TRUE;
  2608                  if (protocol == audit_eventsid[count][0]) {
  2562             }
  2609                  	xevent_num = audit_eventsid[count][1];
  2563             else
       
  2564             {
       
  2565                 for (count = 0; count < MAX_AUDIT_EVENTS; count++)
       
  2566                 {
       
  2567                     if (protocol == audit_eventsid[count][0])
       
  2568                     {
       
  2569                         xevent_num = audit_eventsid[count][1];
       
  2570                         audit_event = TRUE;
  2610                         audit_event = TRUE;
  2571                         break;
  2611                         break;
  2572                     }
  2612                   }
  2573                 }
  2613 	    }
  2574             }
  2614 	}
  2575             if (audit_event &&
  2615 
  2576                 do_x_audit &&
  2616 	/*
  2577                 (au_preselect(xevent_num,
  2617 	 * Exclude Clients with Trusted Path such as tsoldtwm, tsoldtsession etc
  2578                               &(tsolinfo->aw_auinfo.ai_mask),
  2618 	 * from generating the audit records for X protocols
  2579                               AU_PRS_BOTH,
  2619 	 */
  2580                               AU_PRS_USECACHE) == 1))
  2620 	if (audit_event && do_x_audit &&  !HasTrustedPath(tsolinfo) &&
  2581             {
  2621 	    (au_preselect(xevent_num, &(tsolinfo->amask), AU_PRS_BOTH,
  2582                 tsolinfo->flags |= TSOL_AUDITEVENT;
  2622                               AU_PRS_USECACHE) == 1)) {
  2583                 status = auditwrite(AW_EVENTNUM, xevent_num, AW_APPEND, AW_END);
  2623             tsolinfo->flags |= TSOL_AUDITEVENT;
  2584 
  2624             status = auditwrite(AW_EVENTNUM, xevent_num, AW_APPEND, AW_END);
  2585             }
  2625 	} else {
  2586             else
  2626 	    tsolinfo->flags &= ~TSOL_AUDITEVENT;
  2587             {
  2627             tsolinfo->flags &= ~TSOL_DOXAUDIT;
  2588                 tsolinfo->flags &= ~TSOL_AUDITEVENT;
  2628 	}
  2589                 tsolinfo->flags &= ~TSOL_DOXAUDIT;
  2629     }
  2590             }
       
  2591 }
  2630 }
  2592 
  2631 
  2593 void
  2632 void
  2594 TsolAuditEnd(ClientPtr client, int result)
  2633 TsolAuditEnd(ClientPtr client, int result)
  2595 {
  2634 {
  2657 
  2696 
  2658     WriteReplyToClient(client, sizeof(xQueryPointerReply), &rep);
  2697     WriteReplyToClient(client, sizeof(xQueryPointerReply), &rep);
  2659 
  2698 
  2660     return(Success);    
  2699     return(Success);    
  2661 }
  2700 }
       
  2701 
       
  2702 int
       
  2703 ProcTsolQueryExtension(client)
       
  2704     ClientPtr client;
       
  2705 {
       
  2706     xQueryExtensionReply reply;
       
  2707     int savedtrust;
       
  2708     int status = client->noClientException;
       
  2709    
       
  2710     REQUEST(xQueryExtensionReq);
       
  2711 
       
  2712     REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes);
       
  2713     
       
  2714     reply.type = X_Reply;
       
  2715     reply.length = 0;
       
  2716     reply.major_opcode = 0;
       
  2717     reply.sequenceNumber = client->sequence;
       
  2718 
       
  2719     /* Allow extensions in the labeled zones */
       
  2720     savedtrust = client->trustLevel;
       
  2721     client->trustLevel = XSecurityClientTrusted;
       
  2722 
       
  2723     if (!TsolDisabledExtension((char *)&stuff[1],  stuff->nbytes)) {
       
  2724     	status = (*TsolSavedProcVector[X_QueryExtension])(client);
       
  2725     } else {
       
  2726 	/* Hide this extension */
       
  2727         reply.present = xFalse;
       
  2728         WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply);
       
  2729         status = client->noClientException;
       
  2730     }
       
  2731 
       
  2732     client->trustLevel = savedtrust;
       
  2733 
       
  2734     return (status);
       
  2735 }
       
  2736 
       
  2737 int
       
  2738 ProcTsolListExtensions(client)
       
  2739     ClientPtr client;
       
  2740 {
       
  2741     int savedtrust;
       
  2742     int status;
       
  2743 
       
  2744     REQUEST(xReq);
       
  2745     REQUEST_SIZE_MATCH(xReq);
       
  2746 
       
  2747     /* Allow extensions in the labeled zones */
       
  2748     savedtrust = client->trustLevel;
       
  2749     client->trustLevel = XSecurityClientTrusted;
       
  2750     status = (*TsolSavedProcVector[X_ListExtensions])(client);
       
  2751     client->trustLevel = savedtrust;
       
  2752 
       
  2753     return (status);
       
  2754 }
       
  2755 
       
  2756 int
       
  2757 ProcTsolMapWindow(register ClientPtr client)
       
  2758 {
       
  2759     int savedtrust;
       
  2760 
       
  2761     WindowPtr pWin;
       
  2762     REQUEST(xResourceReq);
       
  2763 
       
  2764     REQUEST_SIZE_MATCH(xResourceReq);
       
  2765     pWin = (WindowPtr)SecurityLookupWindow(stuff->id, client,
       
  2766 					   SecurityReadAccess);
       
  2767     if (!pWin)
       
  2768         return(BadWindow);
       
  2769     savedtrust = client->trustLevel;
       
  2770     client->trustLevel = XSecurityClientTrusted;
       
  2771     MapWindow(pWin, client);
       
  2772     client->trustLevel = savedtrust;
       
  2773 
       
  2774     return(client->noClientException);
       
  2775 }
       
  2776 
       
  2777 int
       
  2778 ProcTsolMapSubwindows(register ClientPtr client)
       
  2779 {
       
  2780     int savedtrust;
       
  2781 
       
  2782     WindowPtr pWin;
       
  2783     REQUEST(xResourceReq);
       
  2784 
       
  2785     REQUEST_SIZE_MATCH(xResourceReq);
       
  2786     pWin = (WindowPtr)SecurityLookupWindow( stuff->id, client,
       
  2787 					    SecurityReadAccess);
       
  2788     if (!pWin)
       
  2789         return(BadWindow);
       
  2790     savedtrust = client->trustLevel;
       
  2791     client->trustLevel = XSecurityClientTrusted;
       
  2792     MapSubwindows(pWin, client);
       
  2793     client->trustLevel = savedtrust;
       
  2794 
       
  2795     return(client->noClientException);
       
  2796 }