open-src/xserver/xorg/sun-src/tsol/tsolextension.c
changeset 606 068c11b419c9
parent 470 77e77d76a7c9
child 614 5ef3ebaba4c3
equal deleted inserted replaced
605:e5259db5befc 606:068c11b419c9
     1 /* Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     1 /* Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     2  *
     2  *
     3  * Permission is hereby granted, free of charge, to any person obtaining a
     3  * Permission is hereby granted, free of charge, to any person obtaining a
     4  * copy of this software and associated documentation files (the
     4  * copy of this software and associated documentation files (the
     5  * "Software"), to deal in the Software without restriction, including
     5  * "Software"), to deal in the Software without restriction, including
     6  * without limitation the rights to use, copy, modify, merge, publish,
     6  * without limitation the rights to use, copy, modify, merge, publish,
    22  *
    22  *
    23  * Except as contained in this notice, the name of a copyright holder
    23  * Except as contained in this notice, the name of a copyright holder
    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   "@(#)tsolextension.c 1.30     08/07/21 SMI"
    29 #pragma ident   "@(#)tsolextension.c 1.31     09/01/14 SMI"
    30 
    30 
    31 #include <stdio.h>
    31 #include <stdio.h>
    32 #include "auditwrite.h"
    32 #include "auditwrite.h"
    33 #include <bsm/libbsm.h>
    33 #include <bsm/libbsm.h>
    34 #include <bsm/audit_uevents.h>
    34 #include <bsm/audit_uevents.h>
    60 #include "osdep.h"
    60 #include "osdep.h"
    61 #include <X11/Xauth.h>
    61 #include <X11/Xauth.h>
    62 #include "tsol.h"
    62 #include "tsol.h"
    63 #include "inputstr.h"
    63 #include "inputstr.h"
    64 #include "extnsionst.h"
    64 #include "extnsionst.h"
       
    65 #include "dixstruct.h"
       
    66 #include "xace.h"
       
    67 #include "xacestr.h"
    65 #ifdef PANORAMIX
    68 #ifdef PANORAMIX
    66 #include "../Xext/panoramiXsrv.h"
    69 #include "../Xext/panoramiXsrv.h"
    67 #endif
    70 #endif
    68 #ifdef XCSECURITY
    71 #ifdef XCSECURITY
    69 #define _SECURITY_SERVER
    72 #define _SECURITY_SERVER
    70 #include "security.h"
    73 #include "security.h"
       
    74 #include "../Xext/securitysrv.h"
    71 #endif
    75 #endif
    72 #include "tsolpolicy.h"
    76 #include "tsolpolicy.h"
    73 
    77 
    74 #define  BadCmapCookie      0
    78 #define  BadCmapCookie      0
    75 #define  Tsolextension      0x0080    /* Tsol extensions begin at 128 */
    79 #define  Tsolextension      0x0080    /* Tsol extensions begin at 128 */
    77 #define EXTNSIZE 128
    81 #define EXTNSIZE 128
    78 
    82 
    79 #define SECURE_RPC_AUTH	"SUN-DES-1"
    83 #define SECURE_RPC_AUTH	"SUN-DES-1"
    80 #define SECURE_RPC_LEN	9
    84 #define SECURE_RPC_LEN	9
    81 
    85 
    82 extern bslabel_t *lookupSL();
    86 #define CALLBACK(name) void \
    83 extern void (*ReplySwapVector[]) ();
    87 name(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
    84 extern TsolInfoPtr GetClientTsolInfo();
       
    85 extern char *NameForAtom(Atom atom);
       
    86 
    88 
    87 static int ProcTsolDispatch(ClientPtr);
    89 static int ProcTsolDispatch(ClientPtr);
    88 static int ProcSetPolyInstInfo(ClientPtr);
    90 static int ProcSetPolyInstInfo(ClientPtr);
    89 static int ProcSetPropLabel(ClientPtr);
    91 static int ProcSetPropLabel(ClientPtr);
    90 static int ProcSetPropUID(ClientPtr);
    92 static int ProcSetPropUID(ClientPtr);
   110 static int SProcGetResAttributes(ClientPtr);
   112 static int SProcGetResAttributes(ClientPtr);
   111 static int SProcMakeTPWindow(ClientPtr);
   113 static int SProcMakeTPWindow(ClientPtr);
   112 static int SProcMakeTrustedWindow(ClientPtr);
   114 static int SProcMakeTrustedWindow(ClientPtr);
   113 static int SProcMakeUntrustedWindow(ClientPtr);
   115 static int SProcMakeUntrustedWindow(ClientPtr);
   114 
   116 
   115 static void TsolReset();
   117 static void TsolReset(ExtensionEntry *extension);
   116 static void BreakAllGrabs(ClientPtr client);
   118 static void BreakAllGrabs(ClientPtr client);
   117 
   119 
   118 extern void init_xtsol();
   120 extern void init_xtsol(void);
   119 extern void init_win_privsets();
       
   120 extern void free_win_privsets();
       
   121 extern int DoScreenStripeHeight(int screen_num);
   121 extern int DoScreenStripeHeight(int screen_num);
   122 extern int AddUID(int *userid);
   122 extern int AddUID(int *userid);
   123 
   123 
   124 static unsigned char TsolReqCode = 0;
   124 static unsigned char TsolReqCode = 0;
   125 static int tsolEventBase = -1;
   125 static int tsolEventBase = -1;
   126 extern unsigned int StripeHeight;
   126 extern unsigned int StripeHeight;
   127 int ScreenStripeHeight[MAX_SCREENS - 1] = {0, 0};
   127 int ScreenStripeHeight[MAX_SCREENS - 1] = {0, 0};
   128 
       
   129 extern int tsolClientPrivateIndex;
       
   130 extern int tsolWindowPrivateIndex;
       
   131 extern int tsolPixmapPrivateIndex;
       
   132 
   128 
   133 static HotKeyRec hotkey = {FALSE, 0, 0, 0, 0};
   129 static HotKeyRec hotkey = {FALSE, 0, 0, 0, 0};
   134 
   130 
   135 int tsolMultiLevel = TRUE;
   131 int tsolMultiLevel = TRUE;
   136 
   132 
   140 extern WindowPtr tpwin;
   136 extern WindowPtr tpwin;
   141 extern bclear_t SessionHI;        /* HI Clearance */
   137 extern bclear_t SessionHI;        /* HI Clearance */
   142 extern bclear_t SessionLO;        /* LO Clearance */
   138 extern bclear_t SessionLO;        /* LO Clearance */
   143 extern TsolPolyInstInfoRec tsolpolyinstinfo;
   139 extern TsolPolyInstInfoRec tsolpolyinstinfo;
   144 
   140 
   145 extern void LoadTsolConfig();
   141 extern void LoadTsolConfig(void);
   146 extern void MakeTSOLAtoms();
   142 extern void MakeTSOLAtoms(void);
   147 extern void UpdateTsolNode();
   143 extern void UpdateTsolNode(void);
   148 /*
       
   149  * Protocol handling vectors
       
   150  */
       
   151 extern int (*ProcVector[])();
       
   152 extern int (*SwappedProcVector[])();
       
   153 
   144 
   154 int (*TsolSavedProcVector[PROCVECTORSIZE])(ClientPtr client);
   145 int (*TsolSavedProcVector[PROCVECTORSIZE])(ClientPtr client);
   155 int (*TsolSavedSwappedProcVector[PROCVECTORSIZE])(ClientPtr client);
   146 int (*TsolSavedSwappedProcVector[PROCVECTORSIZE])(ClientPtr client);
   156 
   147 
   157 extern SecurityHookPtr pSecHook;
   148 extern SecurityHookPtr pSecHook;
   158 SecurityHook tsolSecHook;
   149 SecurityHook tsolSecHook;
   159 
   150 
   160 XID TsolCheckAuthorization (unsigned int name_length,
   151 XID TsolCheckAuthorization (unsigned int name_length,
   161 	char *name, unsigned int data_length, 
   152 	char *name, unsigned int data_length,
   162 	char *data, ClientPtr client, char **reason);
   153 	char *data, ClientPtr client, char **reason);
   163 void TsolDeleteClientFromAnySelections(ClientPtr);
   154 void TsolDeleteClientFromAnySelections(ClientPtr);
   164 void TsolDeleteWindowFromAnySelections(WindowPtr);
   155 void TsolDeleteWindowFromAnySelections(WindowPtr);
   165 
   156 
   166 extern int TsolChangeWindowProperty(ClientPtr, WindowPtr, Atom, Atom, int, int,
   157 extern int TsolChangeWindowProperty(ClientPtr, WindowPtr, Atom, Atom, int, int,
   167 	unsigned long, pointer, Bool);
   158 	unsigned long, pointer, Bool);
   168 extern int TsolDeleteProperty(ClientPtr, WindowPtr, Atom);
   159 extern int TsolDeleteProperty(ClientPtr, WindowPtr, Atom);
   169 extern int TsolInitWindow(ClientPtr, WindowPtr);
   160 extern int TsolInitWindow(ClientPtr, WindowPtr);
   170 extern void TsolAuditStart(ClientPtr);
       
   171 extern void TsolAuditEnd(ClientPtr, int);
       
   172 
       
   173 static void TsolClientStateCallback(CallbackListPtr *pcbl,
       
   174 	pointer nulldata, pointer calldata);
       
   175 static void TsolSetClientInfo(ClientPtr client);
   161 static void TsolSetClientInfo(ClientPtr client);
   176 static void TsolProcessKeyboard(xEvent *, KeyClassPtr);
   162 
   177 static char TsolCheckPropertyAccess(ClientPtr client, WindowPtr pWin, ATOM propertyName,
   163 /* XACE hook callbacks */
   178 	Mask access_mode);
   164 static CALLBACK(TsolCheckExtensionAccess);
       
   165 static CALLBACK(TsolCheckPropertyAccess);
       
   166 static CALLBACK(TsolCheckResourceIDAccess);
       
   167 static CALLBACK(TsolProcessKeyboard);
       
   168 extern CALLBACK(TsolAuditStart);
       
   169 extern CALLBACK(TsolAuditEnd);
       
   170 
       
   171 /* other callbacks */
       
   172 static CALLBACK(TsolClientStateCallback);
   179 
   173 
   180 extern int ProcTsolInternAtom(ClientPtr client);
   174 extern int ProcTsolInternAtom(ClientPtr client);
   181 extern int ProcTsolSetSelectionOwner(ClientPtr client);
   175 extern int ProcTsolSetSelectionOwner(ClientPtr client);
   182 extern int ProcTsolGetSelectionOwner(ClientPtr client);
   176 extern int ProcTsolGetSelectionOwner(ClientPtr client);
   183 extern int ProcTsolConvertSelection(ClientPtr client);
   177 extern int ProcTsolConvertSelection(ClientPtr client);
   229  * Initialize the extension. Main entry point for this loadable
   223  * Initialize the extension. Main entry point for this loadable
   230  * module.
   224  * module.
   231  */
   225  */
   232 
   226 
   233 void
   227 void
   234 TsolExtensionInit()
   228 TsolExtensionInit(void)
   235 {
   229 {
   236 	ExtensionEntry *extEntry;
   230 	ExtensionEntry *extEntry;
   237 	ScreenPtr pScreen;
       
   238 	int i;
   231 	int i;
   239 	priv_set_t	*pset;
       
   240 
   232 
   241 	/* sleep(20); */
   233 	/* sleep(20); */
   242 
   234 
   243 	/* This extension is supported on a labeled system */
   235 	/* This extension is supported on a labeled system */
   244 	if (!is_system_labeled()) {
   236 	if (!is_system_labeled()) {
   250 
   242 
   251 	init_xtsol();
   243 	init_xtsol();
   252 	init_win_privsets();
   244 	init_win_privsets();
   253 
   245 
   254 	extEntry = AddExtension(TSOLNAME, TSOL_NUM_EVENTS, TSOL_NUM_ERRORS,
   246 	extEntry = AddExtension(TSOLNAME, TSOL_NUM_EVENTS, TSOL_NUM_ERRORS,
   255 		ProcTsolDispatch, SProcTsolDispatch, TsolReset, 
   247 		ProcTsolDispatch, SProcTsolDispatch, TsolReset,
   256 		StandardMinorOpcode);
   248 		StandardMinorOpcode);
   257 
   249 
   258 	if (extEntry == NULL) {
   250 	if (extEntry == NULL) {
   259 		ErrorF("TsolExtensionInit: AddExtension failed for X Trusted Extensions\n");
   251 		ErrorF("TsolExtensionInit: AddExtension failed for X Trusted Extensions\n");
   260 		return;
   252 		return;
   261 	}
   253 	}
   262 
   254 
   263 	extEntry->secure = TRUE;
       
   264         TsolReqCode = (unsigned char) extEntry->base;
   255         TsolReqCode = (unsigned char) extEntry->base;
   265         tsolEventBase = extEntry->eventBase;
   256         tsolEventBase = extEntry->eventBase;
   266 
   257 
   267 	if (!AddCallback(&ClientStateCallback, TsolClientStateCallback, NULL))
   258 	if (!AddCallback(&ClientStateCallback, TsolClientStateCallback, NULL))
   268 		return;
   259 		return;
   269 
   260 
   270 	/* Allocate the client private index */
   261 	/* Allocate storage in devPrivates */
   271 	tsolClientPrivateIndex = AllocateClientPrivateIndex();
   262 	if (!dixRequestPrivate(tsolPrivKey, sizeof (TsolPrivRec))) {
   272 	if (!AllocateClientPrivate(tsolClientPrivateIndex,
   263 		ErrorF("TsolExtensionInit: Cannot allocate devPrivate.\n");
   273 		   sizeof (TsolInfoRec))) {
       
   274 		ErrorF("TsolExtensionInit: Cannot allocate client private.\n");
       
   275 		return;
   264 		return;
   276 	}
       
   277 
       
   278 	/* Allocate per screen window/pixmap private index */
       
   279 	tsolWindowPrivateIndex = AllocateWindowPrivateIndex();
       
   280 	tsolPixmapPrivateIndex = AllocatePixmapPrivateIndex();
       
   281 
       
   282 	for (i = 0; i < screenInfo.numScreens; i++) {
       
   283 		pScreen = screenInfo.screens[i];
       
   284 		if (!AllocateWindowPrivate(pScreen, tsolWindowPrivateIndex,
       
   285 			   sizeof (TsolResRec))) {
       
   286 			ErrorF("TsolExtensionInit: Cannot allocate window private.\n");
       
   287             		return;
       
   288 		}
       
   289 
       
   290 		if (!AllocatePixmapPrivate(pScreen, tsolPixmapPrivateIndex,
       
   291                                    sizeof (TsolResRec))) {
       
   292 			ErrorF("TsolExtensionInit: Cannot allocate pixmap private.\n");
       
   293 			return;
       
   294 		}
       
   295 	}
   265 	}
   296 
   266 
   297 	LoadTsolConfig();
   267 	LoadTsolConfig();
   298 
   268 
   299 	MakeTSOLAtoms();
   269 	MakeTSOLAtoms();
   300 	UpdateTsolNode();
   270 	UpdateTsolNode();
       
   271 
       
   272 	/* Initialize security hooks */
       
   273 	tsolSecHook.CheckAuthorization = TsolCheckAuthorization;
       
   274 	tsolSecHook.ChangeWindowProperty = TsolChangeWindowProperty;
       
   275 	tsolSecHook.DeleteProperty = TsolDeleteProperty;
       
   276 	tsolSecHook.DeleteClientFromAnySelections = TsolDeleteClientFromAnySelections;
       
   277 	tsolSecHook.DeleteWindowFromAnySelections = TsolDeleteWindowFromAnySelections;
       
   278 	pSecHook = &tsolSecHook;
       
   279 
       
   280 	XaceRegisterCallback(XACE_RESOURCE_ACCESS, TsolCheckResourceIDAccess,
       
   281 			     NULL);
       
   282 	XaceRegisterCallback(XACE_PROPERTY_ACCESS, TsolCheckPropertyAccess,
       
   283 			     NULL);
       
   284 	XaceRegisterCallback(XACE_EXT_ACCESS, TsolCheckExtensionAccess, NULL);
       
   285 	XaceRegisterCallback(XACE_KEY_AVAIL, TsolProcessKeyboard, NULL);
       
   286 	XaceRegisterCallback(XACE_AUDIT_BEGIN, TsolAuditStart, NULL);
       
   287 	XaceRegisterCallback(XACE_AUDIT_END, TsolAuditEnd, NULL);
   301 
   288 
   302 	/* Save original Proc vectors */
   289 	/* Save original Proc vectors */
   303 	for (i = 0; i < PROCVECTORSIZE; i++) {
   290 	for (i = 0; i < PROCVECTORSIZE; i++) {
   304 		TsolSavedProcVector[i] = ProcVector[i];
   291 		TsolSavedProcVector[i] = ProcVector[i];
   305 		TsolSavedSwappedProcVector[i] = SwappedProcVector[i];
   292 		TsolSavedSwappedProcVector[i] = SwappedProcVector[i];
   306 	}
   293 	}
   307 
       
   308 	/* Initialize security hooks */
       
   309 	tsolSecHook.CheckAuthorization = TsolCheckAuthorization;
       
   310 	tsolSecHook.ChangeWindowProperty = TsolChangeWindowProperty;
       
   311 	tsolSecHook.CheckPropertyAccess = TsolCheckPropertyAccess;
       
   312 	tsolSecHook.DeleteProperty = TsolDeleteProperty;
       
   313 	tsolSecHook.InitWindow = TsolInitWindow;
       
   314 	tsolSecHook.ProcessKeyboard = TsolProcessKeyboard;
       
   315 	tsolSecHook.DeleteClientFromAnySelections = TsolDeleteClientFromAnySelections;
       
   316 	tsolSecHook.DeleteWindowFromAnySelections = TsolDeleteWindowFromAnySelections;
       
   317 	tsolSecHook.AuditStart = TsolAuditStart;
       
   318 	tsolSecHook.AuditEnd = TsolAuditEnd;
       
   319 	pSecHook = &tsolSecHook;
       
   320 
   294 
   321 	/* Replace some of the original Proc vectors with our own TBD */
   295 	/* Replace some of the original Proc vectors with our own TBD */
   322 	ProcVector[X_InternAtom] = ProcTsolInternAtom;
   296 	ProcVector[X_InternAtom] = ProcTsolInternAtom;
   323 	ProcVector[X_SetSelectionOwner] = ProcTsolSetSelectionOwner;
   297 	ProcVector[X_SetSelectionOwner] = ProcTsolSetSelectionOwner;
   324 	ProcVector[X_GetSelectionOwner] = ProcTsolGetSelectionOwner;
   298 	ProcVector[X_GetSelectionOwner] = ProcTsolGetSelectionOwner;
   365 	ProcVector[X_PolySegment] = ProcTsolPolySegment;
   339 	ProcVector[X_PolySegment] = ProcTsolPolySegment;
   366 	ProcVector[X_PolyRectangle] = ProcTsolPolyRectangle;
   340 	ProcVector[X_PolyRectangle] = ProcTsolPolyRectangle;
   367 
   341 
   368 }
   342 }
   369 
   343 
   370 static pointer
   344 static CALLBACK(
   371 TsolCheckResourceIDAccess(
   345     TsolCheckResourceIDAccess)
   372     ClientPtr client,
   346 {
   373     XID id,
   347     XaceResourceAccessRec *rec = calldata;
   374     RESTYPE rtype,
   348     ClientPtr client = rec->client;
   375     Mask access_mode,
   349     XID id = rec->id;
   376     pointer rval)
   350     RESTYPE rtype = rec->rtype;
   377 {
   351     pointer rval = rec->res;
       
   352     Mask access_mode = rec->access_mode;
       
   353 
   378     int cid = CLIENT_ID(id);
   354     int cid = CLIENT_ID(id);
   379     int reqtype = ((xReq *)client->requestBuffer)->reqType;  /* protocol */
   355     int reqtype;
   380     pointer retval;
   356 
   381     char msgbuf[1024];
   357     if (client->requestBuffer) {
   382 
   358 	reqtype = MAJOROP;  /* protocol */
   383 
   359     } else {
   384     retval = rval;
   360 	reqtype = -1;
       
   361     }
   385 
   362 
   386     switch (rtype) {
   363     switch (rtype) {
   387 	case RT_GC:
   364         case RT_GC:
   388 		switch (access_mode) {
   365 	    if (access_mode & DixReadAccess) {
   389 		case SecurityReadAccess:
   366 		if (xtsol_policy(TSOL_RES_GC, TSOL_READ, (void *)id,
   390 		    if (xtsol_policy(TSOL_RES_GC, TSOL_READ, (void *)id,
   367 				 client, TSOL_ALL, (void *)MAJOROP))
   391 			client, TSOL_ALL, (void *)MAJOROP))
   368 		    rec->status = BadAccess;
   392 				retval = NULL;
   369 	    }
   393 		    break;
   370 
   394 
   371 	    if (access_mode & DixWriteAccess) {
   395 		case SecurityWriteAccess:
   372 		if (xtsol_policy(TSOL_RES_GC, TSOL_MODIFY, (void *)id,
   396 		    if (xtsol_policy(TSOL_RES_GC, TSOL_MODIFY, (void *)id,
   373 				 client, TSOL_ALL, (void *)MAJOROP))
   397 			client, TSOL_ALL, (void *)MAJOROP))
   374 		    rec->status = BadAccess;
   398 				retval = NULL;
   375 	    }
   399 		    break;
   376 
   400 
   377 	    if (access_mode & DixDestroyAccess) {
   401 		case SecurityDestroyAccess:
   378 		if (xtsol_policy(TSOL_RES_GC, TSOL_DESTROY, (void *)id,
   402 		    if (xtsol_policy(TSOL_RES_GC, TSOL_DESTROY, (void *)id,
   379 				 client, TSOL_ALL, (void *)MAJOROP))
   403 			client, TSOL_ALL, (void *)MAJOROP))
   380 		    rec->status = BadAccess;
   404 				retval = NULL;
   381 	    }
   405 		    break;
   382 	    break;
   406 		}
       
   407 		break;
       
   408 
   383 
   409 	case RT_WINDOW:		/* Drawables */
   384 	case RT_WINDOW:		/* Drawables */
       
   385 	    if (access_mode & DixCreateAccess) {
       
   386 		/* Replaces InitWindow hook */
       
   387 		TsolInitWindow(client, (WindowPtr) rval);
       
   388 	    }
       
   389 	    /* The rest falls through to code shared with RT_PIXMAP */
   410 	case RT_PIXMAP:
   390 	case RT_PIXMAP:
   411 	    /* Drawing operations use pixel access policy */
   391 	    /* Drawing operations use pixel access policy */
   412 	    switch (reqtype) {
   392 	    switch (reqtype) {
   413 		case X_PolyPoint:
   393 		case X_PolyPoint:
   414 		case X_PolyLine:
   394 		case X_PolyLine:
   419 		case X_PutImage:
   399 		case X_PutImage:
   420 		case X_PolyText8:
   400 		case X_PolyText8:
   421 		case X_PolyText16:
   401 		case X_PolyText16:
   422 		case X_ImageText8:
   402 		case X_ImageText8:
   423 		case X_ImageText16:
   403 		case X_ImageText16:
   424 		switch (access_mode) {
   404 		    if (access_mode & DixReadAccess) {
   425 		case SecurityReadAccess:
   405 			if (xtsol_policy(TSOL_RES_PIXEL, TSOL_READ,
   426 		    if (xtsol_policy(TSOL_RES_PIXEL, TSOL_READ, (void *)rval,
   406 					 (void *)rval, client, TSOL_ALL,
   427 			client, TSOL_ALL, (void *)MAJOROP))
   407 					 (void *)MAJOROP))
   428 				retval = NULL;
   408 			    rec->status = BadAccess;
   429 		    break;
   409 		    }
   430 
   410 
   431 		case SecurityWriteAccess:
   411 		    if (access_mode & DixWriteAccess) {
   432 		    if (xtsol_policy(TSOL_RES_PIXEL, TSOL_MODIFY, (void *)rval,
   412 			if (xtsol_policy(TSOL_RES_PIXEL, TSOL_MODIFY,
   433 			client, TSOL_ALL, (void *)MAJOROP))
   413 					 (void *)rval, client, TSOL_ALL,
   434 				retval = NULL;
   414 					 (void *)MAJOROP))
   435 		    break;
   415 			    rec->status = BadAccess;
   436     		}
   416 		    }
   437 		break;
   417 		break;
   438 
   418 
   439 		/* Property protocols */
   419 		/* Property protocols */
   440 		case X_ChangeProperty:
   420 		case X_ChangeProperty:
   441 		case X_DeleteProperty:
   421 		case X_DeleteProperty:
   442 		case X_GetProperty:
   422 		case X_GetProperty:
   443 		case X_ListProperties:
   423 		case X_ListProperties:
   444 		case X_RotateProperties:
   424 		case X_RotateProperties:
   445 		switch (access_mode) {
   425 		    if (access_mode & DixReadAccess) {
   446 		case SecurityReadAccess:
   426 			if (xtsol_policy(TSOL_RES_PROPWIN, TSOL_READ,
   447 		    if (xtsol_policy(TSOL_RES_PROPWIN, TSOL_READ, (void *)rval,
   427 					 (void *)rval, client, TSOL_ALL,
   448 			client, TSOL_ALL, (void *)MAJOROP))
   428 					 (void *)MAJOROP))
   449 				retval = NULL;
   429 			    rec->status = BadAccess;
       
   430 		    }
       
   431 
       
   432 		    if (access_mode & DixWriteAccess) {
       
   433 			if (xtsol_policy(TSOL_RES_PROPWIN, TSOL_MODIFY,
       
   434 					 (void *)rval, client, TSOL_ALL,
       
   435 					 (void *)MAJOROP))
       
   436 			    rec->status = BadAccess;
       
   437 		    }
   450 		    break;
   438 		    break;
   451 
   439 	    }
   452 		case SecurityWriteAccess:
   440 	    break;
   453 		    if (xtsol_policy(TSOL_RES_PROPWIN, TSOL_MODIFY, (void *)rval,
   441     }
   454 			client, TSOL_ALL, (void *)MAJOROP))
   442 
   455 				retval = NULL;
   443     if (rec->status == BadAccess) {
   456 		    break;
   444     	TsolInfoPtr tsolinfo = GetClientTsolInfo(client);
   457     		}
   445 
   458 		break;
   446 	ErrorF("Access failed: cid = %d, rtype=%X, access=%d,"
   459 		}
   447 	       " xid=%X, proto = %d, pid = %d\n",
   460 		break;
   448 	       cid, (uint_t) rtype, access_mode, id, reqtype, tsolinfo->pid);
   461     }
   449     }
   462 
   450 }
   463     if (retval == NULL) {
   451 
   464     	TsolInfoPtr tsolinfo, res_tsolinfo;
   452 static
   465     	tsolinfo = GetClientTsolInfo(client);
   453 CALLBACK(TsolClientStateCallback)
   466 
       
   467 	snprintf(msgbuf, sizeof (msgbuf), 
       
   468 	    "Access failed: cid = %d, rtype=%X, access=%d, xid=%X, proto = %d, pid = %d\n",
       
   469 		cid, rtype, access_mode, id, reqtype, tsolinfo->pid);
       
   470 	ErrorF(msgbuf);
       
   471     }
       
   472 
       
   473     return retval;
       
   474 }
       
   475 
       
   476 static void
       
   477 TsolClientStateCallback(CallbackListPtr *pcbl,
       
   478 	pointer nulldata,
       
   479 	pointer calldata)
       
   480 {
   454 {
   481  	NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
   455  	NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
   482 	ClientPtr client = pci->client;
   456 	ClientPtr client = pci->client;
   483 	TsolInfoPtr tsolinfo = (TsolInfoPtr)
   457 	TsolInfoPtr tsolinfo = TsolClientPriv(client);
   484 		(client->devPrivates[tsolClientPrivateIndex].ptr);
       
   485 
   458 
   486 	switch (client->clientState) {
   459 	switch (client->clientState) {
   487 
   460 
   488 	case ClientStateInitial:
   461 	case ClientStateInitial:
   489 		/* Got a new connection */
   462 		/* Got a new connection */
   490 		TsolSetClientInfo(client);
   463 		TsolSetClientInfo(client);
   491 		client->CheckAccess = TsolCheckResourceIDAccess;
       
   492 		break;
   464 		break;
   493 
   465 
   494 	case ClientStateRunning:
   466 	case ClientStateRunning:
   495 		break;
   467 		break;
   496 
   468 
   525 	}
   497 	}
   526 
   498 
   527 }
   499 }
   528 
   500 
   529 static void
   501 static void
   530 TsolReset()
   502 TsolReset(ExtensionEntry *extension)
   531 {
   503 {
   532 	free_win_privsets();
   504     free_win_privsets();
       
   505     XaceDeleteCallback(XACE_RESOURCE_ACCESS, TsolCheckResourceIDAccess, NULL);
       
   506     XaceDeleteCallback(XACE_PROPERTY_ACCESS, TsolCheckPropertyAccess, NULL);
       
   507     XaceDeleteCallback(XACE_EXT_ACCESS, TsolCheckExtensionAccess, NULL);
       
   508     XaceDeleteCallback(XACE_KEY_AVAIL, TsolProcessKeyboard, NULL);
       
   509     XaceDeleteCallback(XACE_AUDIT_BEGIN, TsolAuditStart, NULL);
       
   510     XaceDeleteCallback(XACE_AUDIT_END, TsolAuditEnd, NULL);
   533 }
   511 }
   534 
   512 
   535 /*
   513 /*
   536  * Dispatch routine
   514  * Dispatch routine
   537  *
   515  *
   538  */
   516  */
   539 static int
   517 static int
   540 ProcTsolDispatch(client)
   518 ProcTsolDispatch(register ClientPtr client)
   541 register ClientPtr client;
       
   542 {
   519 {
   543     int retval;
   520     int retval;
   544 
   521 
   545     REQUEST(xReq);
   522     REQUEST(xReq);
   546 
   523 
   567         case X_GetClientLabel:
   544         case X_GetClientLabel:
   568             retval = ProcGetClientLabel(client);
   545             retval = ProcGetClientLabel(client);
   569             break;
   546             break;
   570         case X_GetPropAttributes:
   547         case X_GetPropAttributes:
   571             retval =  ProcGetPropAttributes(client);
   548             retval =  ProcGetPropAttributes(client);
   572             break;            
   549             break;
   573         case X_GetResAttributes:
   550         case X_GetResAttributes:
   574             retval =  ProcGetResAttributes(client);
   551             retval =  ProcGetResAttributes(client);
   575             break;
   552             break;
   576         case X_MakeTPWindow:
   553         case X_MakeTPWindow:
   577             retval =  ProcMakeTPWindow(client);
   554             retval =  ProcMakeTPWindow(client);
   589     return (retval);
   566     return (retval);
   590 }
   567 }
   591 
   568 
   592 
   569 
   593 static int
   570 static int
   594 SProcTsolDispatch(client)
   571 SProcTsolDispatch(register ClientPtr client)
   595 register ClientPtr client;
       
   596 {
   572 {
   597     int n;
   573     int n;
   598     int retval;
   574     int retval;
   599 
   575 
   600     REQUEST(xReq);
   576     REQUEST(xReq);
   623         case X_GetClientLabel:
   599         case X_GetClientLabel:
   624             retval = SProcGetClientLabel(client);
   600             retval = SProcGetClientLabel(client);
   625             break;
   601             break;
   626         case X_GetPropAttributes:
   602         case X_GetPropAttributes:
   627             retval =  SProcGetPropAttributes(client);
   603             retval =  SProcGetPropAttributes(client);
   628             break;            
   604             break;
   629         case X_GetResAttributes:
   605         case X_GetResAttributes:
   630             retval =  SProcGetResAttributes(client);
   606             retval =  SProcGetResAttributes(client);
   631             break;
   607             break;
   632         case X_MakeTPWindow:
   608         case X_MakeTPWindow:
   633             retval =  SProcMakeTPWindow(client);
   609             retval =  SProcMakeTPWindow(client);
   800 
   776 
   801     return (ProcMakeUntrustedWindow(client));
   777     return (ProcMakeUntrustedWindow(client));
   802 }
   778 }
   803 
   779 
   804 /*
   780 /*
   805  * Set PolyInstantiation Info. 
   781  * Set PolyInstantiation Info.
   806  * Normally a get(prop) will
   782  * Normally a get(prop) will
   807  * get the prop. that has match sl, uid of the client. Setting
   783  * get the prop. that has match sl, uid of the client. Setting
   808  * enabled to true will get only the prop. corresponding to
   784  * enabled to true will get only the prop. corresponding to
   809  * sl, uid specified instead of that of client. This is used
   785  * sl, uid specified instead of that of client. This is used
   810  * by dtwm/dtfile in special motif lib. 
   786  * by dtwm/dtfile in special motif lib.
   811  */
   787  */
   812 static int
   788 static int
   813 ProcSetPolyInstInfo(ClientPtr client)
   789 ProcSetPolyInstInfo(ClientPtr client)
   814 {
   790 {
   815     bslabel_t *sl;
   791     bslabel_t *sl;
   839 ProcSetPropLabel(ClientPtr client)
   815 ProcSetPropLabel(ClientPtr client)
   840 {
   816 {
   841     bslabel_t   *sl;
   817     bslabel_t   *sl;
   842     WindowPtr    pWin;
   818     WindowPtr    pWin;
   843     TsolPropPtr  tsolprop;
   819     TsolPropPtr  tsolprop;
       
   820     TsolPropPtr *tsolpropP;
   844     PropertyPtr  pProp;
   821     PropertyPtr  pProp;
   845     int          err_code;
   822     int          err_code;
   846     
   823 
   847     REQUEST(xSetPropLabelReq);
   824     REQUEST(xSetPropLabelReq);
   848 
   825 
   849     REQUEST_AT_LEAST_SIZE(xSetPropLabelReq);
   826     REQUEST_AT_LEAST_SIZE(xSetPropLabelReq);
   850 
   827 
   851 
   828 
   881         client->errorValue = stuff->atom;
   858         client->errorValue = stuff->atom;
   882         return (BadAtom);
   859         return (BadAtom);
   883     }
   860     }
   884 
   861 
   885     /* Initialize property created internally by server */
   862     /* Initialize property created internally by server */
   886     if (pProp->secPrivate == NULL)
   863     tsolpropP = TsolPropertyPriv(pProp);
   887     {
   864     if (*tsolpropP == NULL)
   888         pProp->secPrivate = (pointer)AllocServerTsolProp();
   865     {
   889         if (pProp->secPrivate == NULL)
   866         *tsolpropP = (pointer)AllocServerTsolProp();
       
   867         if (*tsolpropP == NULL)
   890 	    return(BadAlloc);
   868 	    return(BadAlloc);
   891     }
   869     }
   892 
   870 
   893     tsolprop = (TsolPropPtr)(pProp->secPrivate);
   871     tsolprop = *tsolpropP;
   894 
   872 
   895     sl = (bslabel_t *)(stuff + 1);
   873     sl = (bslabel_t *)(stuff + 1);
   896 
   874 
   897     if (!blequal(tsolprop->sl, sl))
   875     if (!blequal(tsolprop->sl, sl))
   898     {
   876     {
   901 	{
   879 	{
   902 	    return (err_code);
   880 	    return (err_code);
   903 	}
   881 	}
   904 	tsolprop->sl = lookupSL(sl);
   882 	tsolprop->sl = lookupSL(sl);
   905     }
   883     }
   906     
   884 
   907     return (client->noClientException);
   885     return (client->noClientException);
   908 }
   886 }
   909 
   887 
   910 static int
   888 static int
   911 ProcSetPropUID(ClientPtr client)
   889 ProcSetPropUID(ClientPtr client)
   912 {
   890 {
   913     WindowPtr   pWin;
   891     WindowPtr   pWin;
   914     TsolPropPtr tsolprop;
   892     TsolPropPtr tsolprop;
       
   893     TsolPropPtr *tsolpropP;
   915     PropertyPtr pProp;
   894     PropertyPtr pProp;
   916     int         err_code;
   895     int         err_code;
   917 
   896 
   918     REQUEST(xSetPropUIDReq);
   897     REQUEST(xSetPropUIDReq);
   919 
   898 
   920     REQUEST_SIZE_MATCH(xSetPropUIDReq);
   899     REQUEST_SIZE_MATCH(xSetPropUIDReq);
   921     
   900 
   922     pWin = LookupWindow(stuff->id, client);
   901     pWin = LookupWindow(stuff->id, client);
   923     if (!pWin)
   902     if (!pWin)
   924     {
   903     {
   925         client->errorValue = stuff->id;
   904         client->errorValue = stuff->id;
   926         return (BadWindow);
   905         return (BadWindow);
   955                                 client, TSOL_ALL, (void *)MAJOROP))
   934                                 client, TSOL_ALL, (void *)MAJOROP))
   956     {
   935     {
   957         return (err_code);
   936         return (err_code);
   958     }
   937     }
   959     /* Initialize property created internally by server */
   938     /* Initialize property created internally by server */
   960     if (pProp->secPrivate == NULL)
   939     tsolpropP = TsolPropertyPriv(pProp);
   961     {
   940     if (*tsolpropP == NULL)
   962         pProp->secPrivate = (pointer)AllocServerTsolProp();
   941     {
   963         if (pProp->secPrivate == NULL)
   942         *tsolpropP = AllocServerTsolProp();
   964 	    return(BadAlloc);
   943         if (*tsolpropP == NULL)
   965     }
   944 	    return (BadAlloc);
   966 
   945     }
   967     tsolprop = (TsolPropPtr)(pProp->secPrivate);
   946 
       
   947     tsolprop = *tsolpropP;
   968     tsolprop->uid = stuff->uid;
   948     tsolprop->uid = stuff->uid;
   969 
   949 
   970     return (client->noClientException);
   950     return (client->noClientException);
   971 }
   951 }
   972 
   952 
   976     bslabel_t  *sl;
   956     bslabel_t  *sl;
   977     PixmapPtr   pMap;
   957     PixmapPtr   pMap;
   978     WindowPtr   pWin;
   958     WindowPtr   pWin;
   979     xEvent      message;
   959     xEvent      message;
   980     TsolResPtr  tsolres;
   960     TsolResPtr  tsolres;
   981     DrawablePtr pDraw;
       
   982     int         err_code;
   961     int         err_code;
   983     
   962 
   984     REQUEST(xSetResLabelReq);
   963     REQUEST(xSetResLabelReq);
   985 
   964 
   986     REQUEST_AT_LEAST_SIZE(xSetResLabelReq);
   965     REQUEST_AT_LEAST_SIZE(xSetResLabelReq);
   987 
   966 
   988     sl = (bslabel_t *)(stuff + 1);
   967     sl = (bslabel_t *)(stuff + 1);
  1006             return (client->noClientException);
   985             return (client->noClientException);
  1007         case IsWindow:
   986         case IsWindow:
  1008             pWin = LookupWindow(stuff->id, client);
   987             pWin = LookupWindow(stuff->id, client);
  1009             if (pWin)
   988             if (pWin)
  1010             {
   989             {
  1011                 tsolres =
   990                 tsolres = TsolWindowPriv(pWin);
  1012                     (TsolResPtr)(pWin->devPrivates[tsolWindowPrivateIndex].ptr);
       
  1013             }
   991             }
  1014             else
   992             else
  1015             {
   993             {
  1016                 client->errorValue = stuff->id;
   994                 client->errorValue = stuff->id;
  1017                 return (BadWindow);
   995                 return (BadWindow);
  1024             break;
  1002             break;
  1025         case IsPixmap:
  1003         case IsPixmap:
  1026             pMap = (PixmapPtr)LookupIDByType(stuff->id, RT_PIXMAP);
  1004             pMap = (PixmapPtr)LookupIDByType(stuff->id, RT_PIXMAP);
  1027             if (pMap)
  1005             if (pMap)
  1028             {
  1006             {
  1029                 tsolres =
  1007                 tsolres = TsolPixmapPriv(pMap);
  1030                     (TsolResPtr)(pMap->devPrivates[tsolPixmapPrivateIndex].ptr);
       
  1031             }
  1008             }
  1032             else
  1009             else
  1033             {
  1010             {
  1034                 client->errorValue = stuff->id;
  1011                 client->errorValue = stuff->id;
  1035                 return (BadPixmap);
  1012                 return (BadPixmap);
  1112             return (client->noClientException);
  1089             return (client->noClientException);
  1113         case IsWindow:
  1090         case IsWindow:
  1114             pWin = LookupWindow(stuff->id, client);
  1091             pWin = LookupWindow(stuff->id, client);
  1115             if (pWin)
  1092             if (pWin)
  1116             {
  1093             {
  1117                 tsolres =
  1094                 tsolres = TsolWindowPriv(pWin);
  1118                     (TsolResPtr)(pWin->devPrivates[tsolWindowPrivateIndex].ptr);
       
  1119             }
  1095             }
  1120             else
  1096             else
  1121             {
  1097             {
  1122                 client->errorValue = stuff->id;
  1098                 client->errorValue = stuff->id;
  1123                 return (BadWindow);
  1099                 return (BadWindow);
  1130             break;
  1106             break;
  1131         case IsPixmap:
  1107         case IsPixmap:
  1132             pMap = (PixmapPtr)LookupIDByType(stuff->id, RT_PIXMAP);
  1108             pMap = (PixmapPtr)LookupIDByType(stuff->id, RT_PIXMAP);
  1133             if (pMap)
  1109             if (pMap)
  1134             {
  1110             {
  1135                 tsolres =
  1111                 tsolres = TsolPixmapPriv(pMap);
  1136                     (TsolResPtr)(pMap->devPrivates[tsolPixmapPrivateIndex].ptr);
       
  1137             }
  1112             }
  1138             else
  1113             else
  1139             {
  1114             {
  1140                 client->errorValue = stuff->id;
  1115                 client->errorValue = stuff->id;
  1141                 return (BadPixmap);
  1116                 return (BadPixmap);
  1147             }
  1122             }
  1148             break;
  1123             break;
  1149         default:
  1124         default:
  1150             return (BadValue);
  1125             return (BadValue);
  1151     }
  1126     }
  1152     
  1127 
  1153     if (err_code = xtsol_policy(TSOL_RES_UID, TSOL_MODIFY, NULL,
  1128     if (err_code = xtsol_policy(TSOL_RES_UID, TSOL_MODIFY, NULL,
  1154                                 client, TSOL_ALL, (void *)MAJOROP))
  1129                                 client, TSOL_ALL, (void *)MAJOROP))
  1155     {
  1130     {
  1156         return (err_code);
  1131         return (err_code);
  1157     }
  1132     }
  1168     ClientPtr   res_client; /* resource owner client */
  1143     ClientPtr   res_client; /* resource owner client */
  1169     TsolInfoPtr tsolinfo, res_tsolinfo;
  1144     TsolInfoPtr tsolinfo, res_tsolinfo;
  1170     WindowPtr	pWin;
  1145     WindowPtr	pWin;
  1171 
  1146 
  1172     xGetClientAttributesReply rep;
  1147     xGetClientAttributesReply rep;
  1173     
  1148 
  1174     REQUEST(xGetClientAttributesReq);
  1149     REQUEST(xGetClientAttributesReq);
  1175     REQUEST_SIZE_MATCH(xGetClientAttributesReq);
  1150     REQUEST_SIZE_MATCH(xGetClientAttributesReq);
  1176 
  1151 
  1177     /* Valid window check */
  1152     /* Valid window check */
  1178     /* Valid window check */
  1153     /* Valid window check */
  1196     res_tsolinfo = GetClientTsolInfo(res_client);
  1171     res_tsolinfo = GetClientTsolInfo(res_client);
  1197 
  1172 
  1198     /* Transfer the client info to reply rec */
  1173     /* Transfer the client info to reply rec */
  1199     rep.type = X_Reply;
  1174     rep.type = X_Reply;
  1200     rep.sequenceNumber = client->sequence;
  1175     rep.sequenceNumber = client->sequence;
  1201     rep.trustflag = (res_tsolinfo->forced_trust == 1 
  1176     rep.trustflag = (res_tsolinfo->forced_trust == 1
  1202 	|| res_tsolinfo->trusted_path) ? (BYTE)1 : (BYTE)0;
  1177 	|| res_tsolinfo->trusted_path) ? (BYTE)1 : (BYTE)0;
  1203     rep.uid = (CARD32) res_tsolinfo->uid;
  1178     rep.uid = (CARD32) res_tsolinfo->uid;
  1204     rep.pid = (CARD32) res_tsolinfo->pid;
  1179     rep.pid = (CARD32) res_tsolinfo->pid;
  1205     rep.gid = (CARD32) res_tsolinfo->gid;
  1180     rep.gid = (CARD32) res_tsolinfo->gid;
  1206     rep.auditid = (CARD32) res_tsolinfo->auid;
  1181     rep.auditid = (CARD32) res_tsolinfo->auid;
  1265     /* Transfer the client info to reply rec */
  1240     /* Transfer the client info to reply rec */
  1266     rep.type = X_Reply;
  1241     rep.type = X_Reply;
  1267     rep.sequenceNumber = client->sequence;
  1242     rep.sequenceNumber = client->sequence;
  1268 
  1243 
  1269     /* allocate temp storage for labels */
  1244     /* allocate temp storage for labels */
  1270     sl = (bslabel_t *)(ALLOCATE_LOCAL(SL_SIZE));
  1245     sl = (bslabel_t *)(xalloc(SL_SIZE));
  1271     rep.data00 = rep.data01 = 0;
  1246     rep.data00 = rep.data01 = 0;
  1272     if (sl == NULL)
  1247     if (sl == NULL)
  1273         return (BadAlloc);
  1248         return (BadAlloc);
  1274     
  1249 
  1275     /* fill the fields as per request mask */
  1250     /* fill the fields as per request mask */
  1276     if (stuff->mask & RES_SL)
  1251     if (stuff->mask & RES_SL)
  1277     {
  1252     {
  1278         memcpy(sl, res_tsolinfo->sl, SL_SIZE);
  1253         memcpy(sl, res_tsolinfo->sl, SL_SIZE);
  1279         rep.data00 = SL_SIZE;
  1254         rep.data00 = SL_SIZE;
  1280     }
  1255     }
  1281     
  1256 
  1282     rep.length = (CARD32)(rep.data00)/4;
  1257     rep.length = (CARD32)(rep.data00)/4;
  1283 
  1258 
  1284     if (rep.length > 0)
  1259     if (rep.length > 0)
  1285     {
  1260     {
  1286         reply_length = rep.length*4;
  1261         reply_length = rep.length*4;
  1298 
  1273 
  1299     if (write_to_client == 1)
  1274     if (write_to_client == 1)
  1300     {
  1275     {
  1301         WriteToClient(client, reply_length, (char *)sl);
  1276         WriteToClient(client, reply_length, (char *)sl);
  1302     }
  1277     }
  1303     DEALLOCATE_LOCAL(sl);
  1278     xfree(sl);
  1304 
  1279 
  1305     return (client->noClientException);
  1280     return (client->noClientException);
  1306 }
  1281 }
  1307 
  1282 
  1308 static int
  1283 static int
  1309 ProcGetPropAttributes(ClientPtr client)
  1284 ProcGetPropAttributes(ClientPtr client)
  1310 {
  1285 {
  1311     int          n;
  1286     int          n;
  1312     int          reply_length;
  1287     int          reply_length;
  1313     int          extralen;
       
  1314     int          err_code;
  1288     int          err_code;
  1315     Bool         write_to_client = 0;
  1289     Bool         write_to_client = 0;
  1316     PropertyPtr  pProp;
  1290     PropertyPtr  pProp;
  1317     bslabel_t   *sl;
  1291     bslabel_t   *sl;
  1318     WindowPtr    pWin;
  1292     WindowPtr    pWin;
  1324     REQUEST(xGetPropAttributesReq);
  1298     REQUEST(xGetPropAttributesReq);
  1325 
  1299 
  1326     REQUEST_SIZE_MATCH(xGetPropAttributesReq);
  1300     REQUEST_SIZE_MATCH(xGetPropAttributesReq);
  1327 
  1301 
  1328     pWin = LookupWindow(stuff->id, client);
  1302     pWin = LookupWindow(stuff->id, client);
  1329     if (pWin)
  1303     if (!pWin)
  1330     {
       
  1331         tsolprop = (TsolPropPtr)(pWin->devPrivates[tsolWindowPrivateIndex].ptr);
       
  1332     }
       
  1333     else
       
  1334     {
  1304     {
  1335         client->errorValue = stuff->id;
  1305         client->errorValue = stuff->id;
  1336         return (BadWindow);
  1306         return (BadWindow);
  1337     }
  1307     }
  1338     if (err_code = xtsol_policy(TSOL_RES_WINDOW, TSOL_READ, pWin,
  1308     if (err_code = xtsol_policy(TSOL_RES_WINDOW, TSOL_READ, pWin,
  1359     {
  1329     {
  1360         /* property does not exist */
  1330         /* property does not exist */
  1361         client->errorValue = stuff->atom;
  1331         client->errorValue = stuff->atom;
  1362         return (BadAtom);
  1332         return (BadAtom);
  1363     }
  1333     }
  1364     tsolprop = (TsolPropPtr)(pProp->secPrivate);
  1334     tsolprop = TsolPropertyPriv(pProp);
  1365     tmp_prop = tsolprop;
  1335     tmp_prop = tsolprop;
  1366     while (tmp_prop)
  1336     while (tmp_prop)
  1367     {
  1337     {
  1368         if (tsolpolyinstinfo.enabled)
  1338         if (tsolpolyinstinfo.enabled)
  1369         {
  1339         {
  1393     {
  1363     {
  1394         rep.uid = tsolprop->uid;
  1364         rep.uid = tsolprop->uid;
  1395     }
  1365     }
  1396 
  1366 
  1397     /* allocate temp storage for labels */
  1367     /* allocate temp storage for labels */
  1398     sl = (bslabel_t *)(ALLOCATE_LOCAL(SL_SIZE));
  1368     sl = (bslabel_t *)(xalloc(SL_SIZE));
  1399     rep.sllength = rep.illength = 0;
  1369     rep.sllength = rep.illength = 0;
  1400     if (sl == NULL)
  1370     if (sl == NULL)
  1401         return (BadAlloc);
  1371         return (BadAlloc);
  1402     
  1372 
  1403     /* fill the fields as per request mask */
  1373     /* fill the fields as per request mask */
  1404     if (stuff->mask & RES_SL)
  1374     if (stuff->mask & RES_SL)
  1405     {
  1375     {
  1406         memcpy(sl, tsolprop->sl, SL_SIZE);
  1376         memcpy(sl, tsolprop->sl, SL_SIZE);
  1407         rep.sllength = SL_SIZE;
  1377         rep.sllength = SL_SIZE;
  1429 
  1399 
  1430     if (write_to_client == 1)
  1400     if (write_to_client == 1)
  1431     {
  1401     {
  1432         WriteToClient(client, reply_length, (char *)sl);
  1402         WriteToClient(client, reply_length, (char *)sl);
  1433     }
  1403     }
  1434     DEALLOCATE_LOCAL(sl);
  1404     xfree(sl);
  1435 
  1405 
  1436     return (client->noClientException);
  1406     return (client->noClientException);
  1437 }
  1407 }
  1438 
  1408 
  1439 static int
  1409 static int
  1440 ProcGetResAttributes(ClientPtr client)
  1410 ProcGetResAttributes(ClientPtr client)
  1441 {
  1411 {
  1442     int         n;
  1412     int         n;
  1443     int         reply_length;
  1413     int         reply_length;
  1444     int         extralen;
       
  1445     int         err_code;
  1414     int         err_code;
  1446     Bool        write_to_client = 0;
  1415     Bool        write_to_client = 0;
  1447     bslabel_t  *sl;
  1416     bslabel_t  *sl;
  1448     PixmapPtr   pMap;
  1417     PixmapPtr   pMap;
  1449     WindowPtr   pWin;
  1418     WindowPtr   pWin;
  1461     }
  1430     }
  1462     if (stuff->mask & RES_OUID)
  1431     if (stuff->mask & RES_OUID)
  1463     {
  1432     {
  1464         rep.owneruid = OwnerUID;
  1433         rep.owneruid = OwnerUID;
  1465     }
  1434     }
  1466     if (stuff->resourceType == IsWindow && 
  1435     if (stuff->resourceType == IsWindow &&
  1467         (stuff->mask & (RES_UID | RES_SL )))
  1436         (stuff->mask & (RES_UID | RES_SL )))
  1468     {
  1437     {
  1469         pWin = LookupWindow(stuff->id, client);
  1438         pWin = LookupWindow(stuff->id, client);
  1470         if (pWin)
  1439         if (pWin)
  1471         {
  1440         {
  1472             tsolres = (TsolResPtr)
  1441             tsolres = TsolWindowPriv(pWin);
  1473                 (pWin->devPrivates[tsolWindowPrivateIndex].ptr);
       
  1474         }
  1442         }
  1475         else
  1443         else
  1476         {
  1444         {
  1477             client->errorValue = stuff->id;
  1445             client->errorValue = stuff->id;
  1478             return (BadWindow);
  1446             return (BadWindow);
  1481                                     client, TSOL_ALL, (void *)MAJOROP))
  1449                                     client, TSOL_ALL, (void *)MAJOROP))
  1482         {
  1450         {
  1483             return (err_code);
  1451             return (err_code);
  1484         }
  1452         }
  1485     }
  1453     }
  1486     if (stuff->resourceType == IsPixmap && 
  1454     if (stuff->resourceType == IsPixmap &&
  1487         (stuff->mask & (RES_UID | RES_SL )))
  1455         (stuff->mask & (RES_UID | RES_SL )))
  1488     {
  1456     {
  1489         pMap = (PixmapPtr)LookupIDByType(stuff->id, RT_PIXMAP);
  1457         pMap = (PixmapPtr)LookupIDByType(stuff->id, RT_PIXMAP);
  1490         if (pMap)
  1458         if (pMap)
  1491         {
  1459         {
  1492             tsolres = (TsolResPtr)
  1460             tsolres = TsolPixmapPriv(pMap);
  1493                 (pMap->devPrivates[tsolPixmapPrivateIndex].ptr);
       
  1494         }
  1461         }
  1495         else
  1462         else
  1496         {
  1463         {
  1497             client->errorValue = stuff->id;
  1464             client->errorValue = stuff->id;
  1498             return (BadPixmap);
  1465             return (BadPixmap);
  1508     {
  1475     {
  1509         rep.uid = tsolres->uid;
  1476         rep.uid = tsolres->uid;
  1510     }
  1477     }
  1511 
  1478 
  1512     /* allocate temp storage for labels */
  1479     /* allocate temp storage for labels */
  1513     sl = (bslabel_t *)(ALLOCATE_LOCAL(SL_SIZE));
  1480     sl = (bslabel_t *)(xalloc(SL_SIZE));
  1514     rep.sllength = rep.illength = rep.iillength = 0;
  1481     rep.sllength = rep.illength = rep.iillength = 0;
  1515     if (sl == NULL)
  1482     if (sl == NULL)
  1516         return (BadAlloc);
  1483         return (BadAlloc);
  1517     
  1484 
  1518     /* fill the fields as per request mask */
  1485     /* fill the fields as per request mask */
  1519     if (stuff->mask & RES_SL)
  1486     if (stuff->mask & RES_SL)
  1520     {
  1487     {
  1521         memcpy(sl, tsolres->sl, SL_SIZE);
  1488         memcpy(sl, tsolres->sl, SL_SIZE);
  1522         rep.sllength = SL_SIZE;
  1489         rep.sllength = SL_SIZE;
  1546 
  1513 
  1547     if (write_to_client == 1)
  1514     if (write_to_client == 1)
  1548     {
  1515     {
  1549             WriteToClient(client, reply_length, (char *)sl);
  1516             WriteToClient(client, reply_length, (char *)sl);
  1550     }
  1517     }
  1551     DEALLOCATE_LOCAL(sl);
  1518     xfree(sl);
  1552 
  1519 
  1553     return (client->noClientException);
  1520     return (client->noClientException);
  1554 }
  1521 }
  1555 
  1522 
  1556 int
  1523 int
  1564 
  1531 
  1565     REQUEST(xMakeTPWindowReq);
  1532     REQUEST(xMakeTPWindowReq);
  1566     REQUEST_SIZE_MATCH(xMakeTPWindowReq);
  1533     REQUEST_SIZE_MATCH(xMakeTPWindowReq);
  1567 
  1534 
  1568     /*
  1535     /*
  1569      * Session type single-level? This is set by the 
  1536      * Session type single-level? This is set by the
  1570      * label builder
  1537      * label builder
  1571      */
  1538      */
  1572     tsolinfo = GetClientTsolInfo(client);
  1539     tsolinfo = GetClientTsolInfo(client);
  1573     if (tsolinfo && HasTrustedPath(tsolinfo) && 
  1540     if (tsolinfo && HasTrustedPath(tsolinfo) &&
  1574 		blequal(&SessionLO, &SessionHI) && stuff->id == 0) {
  1541 		blequal(&SessionLO, &SessionHI) && stuff->id == 0) {
  1575 	tsolMultiLevel = FALSE;
  1542 	tsolMultiLevel = FALSE;
  1576 	return (client->noClientException);
  1543 	return (client->noClientException);
  1577     }
  1544     }
  1578 
  1545 
  1579 #if defined(PANORAMIX) 
  1546 #if defined(PANORAMIX)
  1580     if (!noPanoramiXExtension) 
  1547     if (!noPanoramiXExtension)
  1581     {
  1548     {
  1582 #if defined(IN_MODULE)
       
  1583 	/* Xorg X server */
       
  1584         PanoramiXRes     *panres = NULL;
  1549         PanoramiXRes     *panres = NULL;
  1585         int         j;
  1550         int         j;
  1586 
  1551 
  1587 	if ((panres = (PanoramiXRes *)LookupIDByType(stuff->id, XRT_WINDOW))
  1552 	if ((panres = (PanoramiXRes *)LookupIDByType(stuff->id, XRT_WINDOW))
  1588 		== NULL)
  1553 		== NULL)
  1609 		{
  1574 		{
  1610 		    tpwin = (WindowPtr)NULL;
  1575 		    tpwin = (WindowPtr)NULL;
  1611 		    ReflectStackChange(pWin, pParent->firstChild, VTStack);
  1576 		    ReflectStackChange(pWin, pParent->firstChild, VTStack);
  1612 		}
  1577 		}
  1613 	}
  1578 	}
  1614 #else
  1579     } else
  1615 	/* Xsun X server */
       
  1616         PanoramiXWindow     *pPanoramiXWin = PanoramiXWinRoot;
       
  1617         int         j;
       
  1618 
       
  1619         PANORAMIXFIND_ID(pPanoramiXWin, stuff->id);
       
  1620         IF_RETURN(!pPanoramiXWin, BadWindow);
       
  1621 
       
  1622 	FOR_NSCREENS_OR_ONCE(pPanoramiXWin, j)
       
  1623 	{
       
  1624 		pWin = LookupWindow(pPanoramiXWin->info[j].id, client);
       
  1625 
       
  1626 		/* window should not be root but child of root */
       
  1627 		if (!pWin || (!pWin->parent))
       
  1628 		{
       
  1629 		    client->errorValue = stuff->id;
       
  1630 		    return (BadWindow);
       
  1631 		}
       
  1632 		if (err_code = xtsol_policy(TSOL_RES_TPWIN, TSOL_MODIFY, pWin,
       
  1633 					client, TSOL_ALL, (void *)MAJOROP))
       
  1634 		{
       
  1635 		    return (err_code);
       
  1636 		}
       
  1637 
       
  1638 		pParent = pWin->parent;
       
  1639 		if (pParent->firstChild != pWin)
       
  1640 		{
       
  1641 		    tpwin = (WindowPtr)NULL;
       
  1642 		    ReflectStackChange(pWin, pParent->firstChild, VTStack);
       
  1643 		}
       
  1644 	}
       
  1645 #endif
       
  1646 
       
  1647     } else 
       
  1648 #endif
  1580 #endif
  1649     {
  1581     {
  1650 	pWin = LookupWindow(stuff->id, client);
  1582 	pWin = LookupWindow(stuff->id, client);
  1651 
  1583 
  1652 	/* window should not be root but child of root */
  1584 	/* window should not be root but child of root */
  1704     if (err_code = xtsol_policy(TSOL_RES_TPWIN, TSOL_MODIFY, pWin,
  1636     if (err_code = xtsol_policy(TSOL_RES_TPWIN, TSOL_MODIFY, pWin,
  1705                                 client, TSOL_ALL, (void *)MAJOROP))
  1637                                 client, TSOL_ALL, (void *)MAJOROP))
  1706     {
  1638     {
  1707         return (err_code);
  1639         return (err_code);
  1708     }
  1640     }
  1709     tsolinfo = GetClientTsolInfo(client);    
  1641     tsolinfo = GetClientTsolInfo(client);
  1710     /* Turn on Trusted bit of the window */
  1642     /* Turn on Trusted bit of the window */
  1711     tsolinfo->forced_trust = 1;
  1643     tsolinfo->forced_trust = 1;
  1712     return (client->noClientException);
  1644     return (client->noClientException);
  1713 }
  1645 }
  1714 
  1646 
  1736     if (err_code = xtsol_policy(TSOL_RES_TPWIN, TSOL_MODIFY, pWin,
  1668     if (err_code = xtsol_policy(TSOL_RES_TPWIN, TSOL_MODIFY, pWin,
  1737                                 client, TSOL_ALL, (void *)MAJOROP))
  1669                                 client, TSOL_ALL, (void *)MAJOROP))
  1738     {
  1670     {
  1739         return (err_code);
  1671         return (err_code);
  1740     }
  1672     }
  1741     tsolinfo = GetClientTsolInfo(client);    
  1673     tsolinfo = GetClientTsolInfo(client);
  1742     tsolinfo->forced_trust = 0;
  1674     tsolinfo->forced_trust = 0;
  1743     tsolinfo->trusted_path = FALSE;
  1675     tsolinfo->trusted_path = FALSE;
  1744     
  1676 
  1745     return (client->noClientException);
  1677     return (client->noClientException);
  1746 }
  1678 }
  1747 
  1679 
  1748 /*
  1680 /*
  1749  * Break keyboard & ptr grabs of clients other than
  1681  * Break keyboard & ptr grabs of clients other than
  1780 TsolSetClientInfo(ClientPtr client)
  1712 TsolSetClientInfo(ClientPtr client)
  1781 {
  1713 {
  1782 	bslabel_t *sl;
  1714 	bslabel_t *sl;
  1783 	bslabel_t admin_low;
  1715 	bslabel_t admin_low;
  1784 	priv_set_t *privs;
  1716 	priv_set_t *privs;
  1785 	const au_tid64_addr_t *tid64;
       
  1786 	const au_mask_t *amask;
  1717 	const au_mask_t *amask;
  1787 	au_mask_t mask;		/* user audit mask */
       
  1788 	socklen_t namelen;
  1718 	socklen_t namelen;
  1789 	struct passwd *pw;
       
  1790 	struct auditinfo auinfo;
  1719 	struct auditinfo auinfo;
  1791 	struct auditinfo *pauinfo;
  1720 	struct auditinfo *pauinfo;
  1792 	OsCommPtr oc = (OsCommPtr)client->osPrivate;
  1721 	OsCommPtr oc = (OsCommPtr)client->osPrivate;
  1793 	register ConnectionInputPtr oci = oc->input;
       
  1794 	int fd = oc->fd;
  1722 	int fd = oc->fd;
  1795 	ucred_t *uc = NULL;
  1723 	ucred_t *uc = NULL;
  1796 	extern  au_id_t ucred_getauid(const ucred_t *uc);
  1724 	extern  au_id_t ucred_getauid(const ucred_t *uc);
  1797 	extern  au_asid_t ucred_getasid(const ucred_t *uc);
  1725 	extern  au_asid_t ucred_getasid(const ucred_t *uc);
  1798 	extern  const au_mask_t *ucred_getamask(const ucred_t *uc);
  1726 	extern  const au_mask_t *ucred_getamask(const ucred_t *uc);
  1799 
  1727 
  1800 	TsolInfoPtr tsolinfo = (TsolInfoPtr)
  1728 	TsolInfoPtr tsolinfo = TsolClientPriv(client);
  1801 		(client->devPrivates[tsolClientPrivateIndex].ptr);
       
  1802 
  1729 
  1803 	/* Get client attributes from the socket */
  1730 	/* Get client attributes from the socket */
  1804 	if (getpeerucred(fd, &uc) == -1) {
  1731 	if (getpeerucred(fd, &uc) == -1) {
  1805 		tsolinfo->uid = (uid_t)(-1);
  1732 		tsolinfo->uid = (uid_t)(-1);
  1806 		tsolinfo->sl = NULL;
  1733 		tsolinfo->sl = NULL;
  1827 				priv_emptyset(tsolinfo->privs);
  1754 				priv_emptyset(tsolinfo->privs);
  1828 			} else {
  1755 			} else {
  1829 				priv_copyset(privs, tsolinfo->privs);
  1756 				priv_copyset(privs, tsolinfo->privs);
  1830 			}
  1757 			}
  1831 		} else {
  1758 		} else {
  1832 			priv_fillset(tsolinfo->privs); 
  1759 			priv_fillset(tsolinfo->privs);
  1833 		}
  1760 		}
  1834 	}
  1761 	}
  1835 
  1762 
  1836 	tsolinfo->priv_debug = FALSE;
  1763 	tsolinfo->priv_debug = FALSE;
  1837 
  1764 
  1838 
  1765 
  1839 	/* 
  1766 	/*
  1840 	 * For remote hosts, the uid is determined during access control
  1767 	 * For remote hosts, the uid is determined during access control
  1841 	 * using Secure RPC
  1768 	 * using Secure RPC
  1842 	 */
  1769 	 */
  1843 	if (tsolinfo->zid == (zoneid_t)-1) {
  1770 	if (tsolinfo->zid == (zoneid_t)-1) {
  1844 		tsolinfo->client_type = CLIENT_REMOTE;
  1771 		tsolinfo->client_type = CLIENT_REMOTE;
  1845 	} else {
  1772 	} else {
  1846 		tsolinfo->client_type = CLIENT_LOCAL;
  1773 		tsolinfo->client_type = CLIENT_LOCAL;
  1847 	}
  1774 	}
  1848 
  1775 
  1849 	
  1776 
  1850 	/* Set Trusted Path for local clients */
  1777 	/* Set Trusted Path for local clients */
  1851 	if (tsolinfo->zid == GLOBAL_ZONEID) {
  1778 	if (tsolinfo->zid == GLOBAL_ZONEID) {
  1852 		tsolinfo->trusted_path = TRUE;
  1779 		tsolinfo->trusted_path = TRUE;
  1853 	}else {
  1780 	}else {
  1854 		tsolinfo->trusted_path = FALSE;
  1781 		tsolinfo->trusted_path = FALSE;
  1855 	}
  1782 	}
  1856 
  1783 
  1857 	if (tsolinfo->trusted_path || !tsolMultiLevel)
  1784 	if (tsolinfo->trusted_path || !tsolMultiLevel)
  1858 		client->trustLevel = XSecurityClientTrusted;
  1785 		setClientTrustLevel(client, XSecurityClientTrusted);
  1859 	else
  1786 	else
  1860 		client->trustLevel = XSecurityClientUntrusted;
  1787 		setClientTrustLevel(client, XSecurityClientUntrusted);
  1861 
  1788 
  1862         tsolinfo->forced_trust = 0;
  1789         tsolinfo->forced_trust = 0;
  1863         tsolinfo->iaddr = 0;
  1790         tsolinfo->iaddr = 0;
  1864 
  1791 
  1865 	bsllow(&admin_low);
  1792 	bsllow(&admin_low);
  1868 	namelen = sizeof (tsolinfo->saddr);
  1795 	namelen = sizeof (tsolinfo->saddr);
  1869 	if (getpeername(fd, (struct sockaddr *)&tsolinfo->saddr, &namelen) == 0
  1796 	if (getpeername(fd, (struct sockaddr *)&tsolinfo->saddr, &namelen) == 0
  1870 	  && (tsolinfo->client_type == CLIENT_REMOTE)) {
  1797 	  && (tsolinfo->client_type == CLIENT_REMOTE)) {
  1871 		int errcode;
  1798 		int errcode;
  1872 		char hostbuf[NI_MAXHOST];
  1799 		char hostbuf[NI_MAXHOST];
  1873 		tsol_host_type_t host_type; 
  1800 		tsol_host_type_t host_type;
  1874 		struct sockaddr sname;
       
  1875 		extern tsol_host_type_t tsol_getrhtype(char *);
  1801 		extern tsol_host_type_t tsol_getrhtype(char *);
  1876 
  1802 
  1877 		/* Use NI_NUMERICHOST to avoid DNS lookup */
  1803 		/* Use NI_NUMERICHOST to avoid DNS lookup */
  1878 		errcode = getnameinfo((struct sockaddr *)&(tsolinfo->saddr), namelen,
  1804 		errcode = getnameinfo((struct sockaddr *)&(tsolinfo->saddr), namelen,
  1879 			hostbuf, sizeof(hostbuf), NULL, 0, NI_NUMERICHOST);
  1805 			hostbuf, sizeof(hostbuf), NULL, 0, NI_NUMERICHOST);
  1880 
  1806 
  1881 		if (errcode) {
  1807 		if (errcode) {
  1882 			perror(gai_strerror(errcode));
  1808 			perror(gai_strerror(errcode));
  1883 		} else {
  1809 		} else {
  1884 			host_type = tsol_getrhtype(hostbuf);
  1810 			host_type = tsol_getrhtype(hostbuf);
  1885 			if ((host_type == SUN_CIPSO) && 
  1811 			if ((host_type == SUN_CIPSO) &&
  1886 				blequal(tsolinfo->sl, &admin_low)) {
  1812 				blequal(tsolinfo->sl, &admin_low)) {
  1887 				tsolinfo->trusted_path = TRUE;
  1813 				tsolinfo->trusted_path = TRUE;
  1888 				client->trustLevel = XSecurityClientTrusted;
  1814 				setClientTrustLevel(client,
       
  1815 						    XSecurityClientTrusted);
  1889 				priv_fillset(tsolinfo->privs);
  1816 				priv_fillset(tsolinfo->privs);
  1890 			}
  1817 			}
  1891 		}
  1818 		}
  1892 	}
  1819 	}
  1893 
  1820 
  1924 	ucred_free(uc);
  1851 	ucred_free(uc);
  1925 }
  1852 }
  1926 
  1853 
  1927 static enum auth_stat tsol_why;
  1854 static enum auth_stat tsol_why;
  1928 
  1855 
  1929 static char * 
  1856 static char *
  1930 tsol_authdes_decode(inmsg, len)
  1857 tsol_authdes_decode(char *inmsg, int len)
  1931 char *inmsg;
       
  1932 int  len;
       
  1933 {
  1858 {
  1934     struct rpc_msg  msg;
  1859     struct rpc_msg  msg;
  1935     char            cred_area[MAX_AUTH_BYTES];
  1860     char            cred_area[MAX_AUTH_BYTES];
  1936     char            verf_area[MAX_AUTH_BYTES];
  1861     char            verf_area[MAX_AUTH_BYTES];
  1937     char            *temp_inmsg;
  1862     char            *temp_inmsg;
  1938     struct svc_req  r;
  1863     struct svc_req  r;
  1939     bool_t          res0, res1, auth_ret;
  1864     bool_t          res0, res1;
  1940     XDR             xdr;
  1865     XDR             xdr;
  1941     SVCXPRT         xprt;
  1866     SVCXPRT         xprt;
  1942     extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
  1867     extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
  1943 
  1868 
  1944     temp_inmsg = (char *) xalloc(len);
  1869     temp_inmsg = (char *) xalloc(len);
  1949     memset(cred_area, 0, sizeof(cred_area));
  1874     memset(cred_area, 0, sizeof(cred_area));
  1950     memset(verf_area, 0, sizeof(verf_area));
  1875     memset(verf_area, 0, sizeof(verf_area));
  1951 
  1876 
  1952     msg.rm_call.cb_cred.oa_base = cred_area;
  1877     msg.rm_call.cb_cred.oa_base = cred_area;
  1953     msg.rm_call.cb_verf.oa_base = verf_area;
  1878     msg.rm_call.cb_verf.oa_base = verf_area;
  1954     tsol_why = AUTH_FAILED; 
  1879     tsol_why = AUTH_FAILED;
  1955     xdrmem_create(&xdr, temp_inmsg, len, XDR_DECODE);
  1880     xdrmem_create(&xdr, temp_inmsg, len, XDR_DECODE);
  1956 
  1881 
  1957     if ((r.rq_clntcred = (caddr_t) xalloc(MAX_AUTH_BYTES)) == NULL)
  1882     if ((r.rq_clntcred = (caddr_t) xalloc(MAX_AUTH_BYTES)) == NULL)
  1958         goto bad1;
  1883         goto bad1;
  1959     r.rq_xprt = &xprt;
  1884     r.rq_xprt = &xprt;
  1960 
  1885 
  1961     /* decode into msg */
  1886     /* decode into msg */
  1962     res0 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_cred)); 
  1887     res0 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_cred));
  1963     res1 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_verf));
  1888     res1 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_verf));
  1964     if ( ! (res0 && res1) )
  1889     if ( ! (res0 && res1) )
  1965          goto bad2;
  1890          goto bad2;
  1966 
  1891 
  1967     /* do the authentication */
  1892     /* do the authentication */
  1976 #else
  1901 #else
  1977     if ((tsol_why = _authenticate(&r, &msg)) != AUTH_OK) {
  1902     if ((tsol_why = _authenticate(&r, &msg)) != AUTH_OK) {
  1978 #endif
  1903 #endif
  1979             goto bad2;
  1904             goto bad2;
  1980     }
  1905     }
  1981     return (((struct authdes_cred *) r.rq_clntcred)->adc_fullname.name); 
  1906     return (((struct authdes_cred *) r.rq_clntcred)->adc_fullname.name);
  1982 
  1907 
  1983 bad2:
  1908 bad2:
  1984     Xfree(r.rq_clntcred);
  1909     Xfree(r.rq_clntcred);
  1985 bad1:
  1910 bad1:
  1986     return ((char *)0); /* ((struct authdes_cred *) NULL); */
  1911     return ((char *)0); /* ((struct authdes_cred *) NULL); */
  1987 }
  1912 }
       
  1913 
  1988 static Bool
  1914 static Bool
  1989 TsolCheckNetName (unsigned char *addr, short len, pointer closure)
  1915 TsolCheckNetName (unsigned char *addr, short len, pointer closure)
  1990 {
  1916 {
  1991     return (len == (short) strlen ((char *) closure) &&
  1917     return (len == (short) strlen ((char *) closure) &&
  1992             strncmp ((char *) addr, (char *) closure, len) == 0);
  1918             strncmp ((char *) addr, (char *) closure, len) == 0);
  1993 }
  1919 }
  1994 
  1920 
  1995 
  1921 
  1996 XID
  1922 XID
  1997 TsolCheckAuthorization(unsigned int name_length, char *name, unsigned int data_length, 
  1923 TsolCheckAuthorization(unsigned int name_length, char *name, unsigned int data_length,
  1998 	char *data, ClientPtr client, char **reason)
  1924 	char *data, ClientPtr client, char **reason)
  1999 {
  1925 {
  2000 	char	domainname[128];
  1926 	char	domainname[128];
  2001 	char	netname[128];
  1927 	char	netname[128];
  2002 	char	audit_ret;
  1928 	char	audit_ret;
  2015 		if (strncmp(name, SECURE_RPC_AUTH, (size_t)name_length) == 0) {
  1941 		if (strncmp(name, SECURE_RPC_AUTH, (size_t)name_length) == 0) {
  2016 			fullname = tsol_authdes_decode(data, data_length);
  1942 			fullname = tsol_authdes_decode(data, data_length);
  2017 			if (fullname == NULL) {
  1943 			if (fullname == NULL) {
  2018 				ErrorF("Unable to authenticate Secure RPC client");
  1944 				ErrorF("Unable to authenticate Secure RPC client");
  2019 			} else {
  1945 			} else {
  2020 				if (netname2user(fullname, 
  1946 				if (netname2user(fullname,
  2021 					&client_uid, &client_gid, 
  1947 					&client_uid, &client_gid,
  2022 					&client_gidlen, &client_gidlist)) {
  1948 					&client_gidlen, &client_gidlist)) {
  2023 					tsolinfo->uid = client_uid;
  1949 					tsolinfo->uid = client_uid;
  2024 				} else {
  1950 				} else {
  2025 					ErrorF("netname2user failed");
  1951 					ErrorF("netname2user failed");
  2026 				}
  1952 				}
  2027 			}
  1953 			}
  2028 		}
  1954 		}
  2029 	}
  1955 	}
  2030 	 
  1956 
  2031 	if (tsolinfo->uid == (uid_t)-1) {
  1957 	if (tsolinfo->uid == (uid_t)-1) {
  2032 		tsolinfo->uid = UID_NOBODY; /* uid not available */
  1958 		tsolinfo->uid = UID_NOBODY; /* uid not available */
  2033 	}
  1959 	}
  2034 
  1960 
  2035 	/* 
  1961 	/*
  2036 	 * For multilevel desktop, limit connections to the trusted path
  1962 	 * For multilevel desktop, limit connections to the trusted path
  2037 	 * i.e. global zone until a user logs in and the trusted stripe 
  1963 	 * i.e. global zone until a user logs in and the trusted stripe
  2038 	 * is in place. Unlabeled connections are rejected.
  1964 	 * is in place. Unlabeled connections are rejected.
  2039 	 */
  1965 	 */
  2040 	if ((OwnerUID == (uid_t )(-1)) || (tsolMultiLevel && tpwin == NULL)) {
  1966 	if ((OwnerUID == (uid_t )(-1)) || (tsolMultiLevel && tpwin == NULL)) {
  2041 		if (HasTrustedPath(tsolinfo)) {
  1967 		if (HasTrustedPath(tsolinfo)) {
  2042 			auth_token = CheckAuthorization(name_length, name, data_length,
  1968 			auth_token = CheckAuthorization(name_length, name, data_length,
  2043 				data, client, reason);
  1969 				data, client, reason);
  2044 		}
  1970 		}
  2045 	} else {
  1971 	} else {
  2046 		/* 
  1972 		/*
  2047 		 * Workstation Owner set, client must be within label
  1973 		 * Workstation Owner set, client must be within label
  2048 		 * range or have trusted path
  1974 		 * range or have trusted path
  2049 		 */
  1975 		 */
  2050 		if (tsolinfo->uid == OwnerUID) {
  1976 		if (tsolinfo->uid == OwnerUID) {
  2051 			if (tsolinfo->sl != NULL && 
  1977 			if ((tsolinfo->sl != NULL &&
  2052 					(bldominates(tsolinfo->sl, &SessionLO) &&
  1978 			     (bldominates(tsolinfo->sl, &SessionLO) &&
  2053 					bldominates(&SessionHI, tsolinfo->sl)) || 
  1979 			      bldominates(&SessionHI, tsolinfo->sl))) ||
  2054 					(HasTrustedPath(tsolinfo))) {
  1980 			    (HasTrustedPath(tsolinfo))) {
  2055 				auth_token = (XID)(tsolinfo->uid);
  1981 			    auth_token = (XID)(tsolinfo->uid);
  2056 			}
  1982 			}
  2057 		} else {
  1983 		} else {
  2058 			/* Allow root from global zone */
  1984 			/* Allow root from global zone */
  2059 			if (tsolinfo->uid == 0 && HasTrustedPath(tsolinfo)) {
  1985 			if (tsolinfo->uid == 0 && HasTrustedPath(tsolinfo)) {
  2060 				auth_token = (XID)(tsolinfo->uid);
  1986 				auth_token = (XID)(tsolinfo->uid);
  2061 			} else {
  1987 			} else {
  2062 				/* 
  1988 				/*
  2063 				 * Access check based on uid. Check if
  1989 				 * Access check based on uid. Check if
  2064 				 * roles or other uids have  been added by
  1990 				 * roles or other uids have  been added by
  2065 				 * xhost +role@
  1991 				 * xhost +role@
  2066 				 */
  1992 				 */
  2067 				getdomainname(domainname, sizeof(domainname));
  1993 				getdomainname(domainname, sizeof(domainname));
  2133 	}
  2059 	}
  2134 
  2060 
  2135 	return (auth_token);
  2061 	return (auth_token);
  2136 }
  2062 }
  2137 
  2063 
  2138 static void
  2064 static CALLBACK(
  2139 TsolProcessKeyboard(xEvent *xE, KeyClassPtr keyc)
  2065 TsolProcessKeyboard)
  2140 {
  2066 {
       
  2067     XaceKeyAvailRec *rec = (XaceKeyAvailRec *) calldata;
       
  2068     xEvent *xE = rec->event;
       
  2069     DeviceIntPtr keybd = rec->keybd;
       
  2070 /*  int count = rec->count; */
       
  2071     KeyClassPtr keyc = keybd->key;
       
  2072 
  2141     extern void InitHotKey(HotKeyPtr hk);
  2073     extern void InitHotKey(HotKeyPtr hk);
  2142     extern void HandleHotKey();
  2074     extern void HandleHotKey(void);
  2143 
  2075 
  2144     if (xE->u.u.type == KeyPress)
  2076     if (xE->u.u.type == KeyPress)
  2145     {
  2077     {
  2146 	if (!hotkey.initialized)
  2078 	if (!hotkey.initialized)
  2147 	    InitHotKey(&hotkey);
  2079 	    InitHotKey(&hotkey);
  2152 		(keyc->state != 0 && keyc->state == hotkey.altshift)))
  2084 		(keyc->state != 0 && keyc->state == hotkey.altshift)))
  2153             		HandleHotKey();
  2085             		HandleHotKey();
  2154     }
  2086     }
  2155 }
  2087 }
  2156 
  2088 
  2157 static char
  2089 static CALLBACK(
  2158 TsolCheckPropertyAccess(ClientPtr client, WindowPtr pWin, ATOM propertyName,
  2090 TsolCheckPropertyAccess)
  2159 	Mask access_mode)
  2091 {
  2160 {
  2092     XacePropertyAccessRec *rec = (XacePropertyAccessRec *) calldata;
  2161 	char	action;
  2093     ClientPtr client = rec->client;
  2162 	PropertyPtr pProp;
  2094     WindowPtr pWin = rec->pWin;
  2163 
  2095     PropertyPtr pProp = *rec->ppProp;
  2164         pProp = wUserProps (pWin);
  2096     Atom propertyName = pProp->propertyName;
  2165         while (pProp)
  2097     Mask access_mode = rec->access_mode;
  2166         {
  2098 
  2167             if (pProp->propertyName == propertyName)
  2099     if (pProp == NULL) {
  2168 		break;
  2100 	return;
  2169 	    pProp = pProp->next;
  2101     }
  2170         }
  2102 
  2171 
  2103     if (access_mode & DixReadAccess) {
  2172 	if (pProp == NULL)
  2104 	if (!PolyProperty(propertyName, pWin) &&
  2173 		return SecurityAllowOperation;
  2105 	    xtsol_policy(TSOL_RES_PROPERTY, TSOL_READ,
  2174 
  2106 			 pProp, client, TSOL_ALL, (void *)MAJOROP))
  2175 	if (access_mode & SecurityReadAccess) {
  2107 	    rec->status = BadAccess;
  2176 		if (!PolyProperty(propertyName, pWin) &&
  2108 /* this used to be:
  2177 		    xtsol_policy(TSOL_RES_PROPERTY, TSOL_READ,
  2109                    return SecurityIgnoreOperation;
  2178 			pProp, client, TSOL_ALL, (void *)MAJOROP))
  2110                 else
  2179 		   return SecurityIgnoreOperation;
  2111                    return SecurityAllowOperation;
  2180 		else
  2112 */
  2181 		   return SecurityAllowOperation;
  2113     }
  2182 	}
  2114 
  2183 
  2115     if (access_mode & DixWriteAccess) {
  2184 	if (access_mode & SecurityWriteAccess) {
  2116 	if (!PolyProperty(propertyName, pWin) &&
  2185 		if (!PolyProperty(propertyName, pWin) &&
  2117 	    xtsol_policy(TSOL_RES_PROPERTY, TSOL_MODIFY,
  2186 		    xtsol_policy(TSOL_RES_PROPERTY, TSOL_MODIFY,
  2118 			 pProp, client, TSOL_ALL, (void *)MAJOROP))
  2187 			pProp, client, TSOL_ALL, (void *)MAJOROP))
  2119 	    rec->status = BadAccess;
  2188 		   return SecurityIgnoreOperation;
  2120 /* this used to be:
  2189 		else
  2121                    return SecurityIgnoreOperation;
  2190 		   return SecurityAllowOperation;
  2122                 else
  2191 	}
  2123                    return SecurityAllowOperation;
  2192 
  2124 */
  2193 	if (access_mode & SecurityDestroyAccess) {
  2125     }
  2194 		if (!PolyProperty(propertyName, pWin) &&
  2126 
  2195 		    xtsol_policy(TSOL_RES_PROPERTY, TSOL_DESTROY,
  2127     if (access_mode & DixDestroyAccess) {
  2196 			pProp, client, TSOL_ALL, (void *)MAJOROP))
  2128 	if (!PolyProperty(propertyName, pWin) &&
  2197 		   return SecurityIgnoreOperation;
  2129 	    xtsol_policy(TSOL_RES_PROPERTY, TSOL_DESTROY,
  2198 		else
  2130 			 pProp, client, TSOL_ALL, (void *)MAJOROP))
  2199 		   return SecurityAllowOperation;
  2131 	    rec->status = BadAccess;
  2200 	}
  2132 /* this used to be:
  2201 
  2133                    return SecurityIgnoreOperation;
  2202 	return SecurityAllowOperation;
  2134                 else
  2203 }
  2135                    return SecurityAllowOperation;
  2204 
  2136 */
       
  2137     }
       
  2138 }
       
  2139 
       
  2140 static CALLBACK(
       
  2141 TsolCheckExtensionAccess)
       
  2142 {
       
  2143     XaceExtAccessRec *rec = (XaceExtAccessRec *) calldata;
       
  2144 
       
  2145     if (TsolDisabledExtension(rec->ext->name)) {
       
  2146 	rec->status = BadAccess;
       
  2147     }
       
  2148 }
       
  2149 
       
  2150 #ifdef UNUSED
  2205 /*
  2151 /*
  2206  * Return TRUE if host is cipso
  2152  * Return TRUE if host is cipso
  2207  */
  2153  */
  2208 int
  2154 int
  2209 host_is_cipso(int fd)
  2155 host_is_cipso(int fd)
  2210 {
  2156 {
  2211 	struct sockaddr sname;
  2157 	struct sockaddr sname;
  2212 	socklen_t namelen;
  2158 	socklen_t namelen;
  2213 	char *rhost;
  2159 	char *rhost;
  2214 	tsol_host_type_t host_type; 
  2160 	tsol_host_type_t host_type;
  2215 	struct sockaddr_in *so = (struct sockaddr_in *)&sname;
  2161 	struct sockaddr_in *so = (struct sockaddr_in *)&sname;
  2216 	extern tsol_host_type_t tsol_getrhtype(char *);
  2162 	extern tsol_host_type_t tsol_getrhtype(char *);
  2217 
  2163 
  2218 	namelen = sizeof (sname);
  2164 	namelen = sizeof (sname);
  2219 	if (getpeername(fd, &sname, &namelen) == -1) {
  2165 	if (getpeername(fd, &sname, &namelen) == -1) {
  2227 		return TRUE;
  2173 		return TRUE;
  2228 	}
  2174 	}
  2229 
  2175 
  2230 	return FALSE;
  2176 	return FALSE;
  2231 }
  2177 }
       
  2178 #endif