2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 1996, 1998 The Open Group
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
the above copyright notice appear in all copies and that both that
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of The Open Group shall not be
|
|
|
|
used in advertising or otherwise to promote the sale, use or other dealings
|
|
|
|
in this Software without prior written authorization from The Open Group.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "scrnintstr.h"
|
2008-11-02 08:26:08 -07:00
|
|
|
#include "inputstr.h"
|
|
|
|
#include "windowstr.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "propertyst.h"
|
2008-11-02 08:26:08 -07:00
|
|
|
#include "colormapst.h"
|
|
|
|
#include "privates.h"
|
|
|
|
#include "registry.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "xacestr.h"
|
|
|
|
#include "securitysrv.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include <X11/extensions/securproto.h>
|
2013-06-07 11:28:45 -06:00
|
|
|
#include "extinit.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "protocol-versions.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* Extension stuff */
|
2012-06-10 07:21:05 -06:00
|
|
|
static int SecurityErrorBase; /* first Security error number */
|
|
|
|
static int SecurityEventBase; /* first Security event number */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */
|
2008-11-02 08:26:08 -07:00
|
|
|
static RESTYPE RTEventClient;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
static CallbackListPtr SecurityValidateGroupCallback = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* Private state record */
|
2010-12-05 08:36:02 -07:00
|
|
|
static DevPrivateKeyRec stateKeyRec;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
#define stateKey (&stateKeyRec)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* This is what we store as client security state */
|
|
|
|
typedef struct {
|
2014-05-02 13:27:46 -06:00
|
|
|
unsigned int haveState :1;
|
|
|
|
unsigned int live :1;
|
|
|
|
unsigned int trustLevel :2;
|
2008-11-02 08:26:08 -07:00
|
|
|
XID authId;
|
|
|
|
} SecurityStateRec;
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
/* The only extensions that untrusted clients have access to */
|
2012-06-10 07:21:05 -06:00
|
|
|
static const char *SecurityTrustedExtensions[] = {
|
2009-09-06 13:44:18 -06:00
|
|
|
"XC-MISC",
|
|
|
|
"BIG-REQUESTS",
|
2008-11-02 08:26:08 -07:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Access modes that untrusted clients are allowed on trusted objects.
|
|
|
|
*/
|
|
|
|
static const Mask SecurityResourceMask =
|
|
|
|
DixGetAttrAccess | DixReceiveAccess | DixListPropAccess |
|
|
|
|
DixGetPropAccess | DixListAccess;
|
2009-09-06 13:44:18 -06:00
|
|
|
static const Mask SecurityWindowExtraMask = DixRemoveAccess;
|
2008-11-02 08:26:08 -07:00
|
|
|
static const Mask SecurityRootWindowExtraMask =
|
|
|
|
DixReceiveAccess | DixSendAccess | DixAddAccess | DixRemoveAccess;
|
|
|
|
static const Mask SecurityDeviceMask =
|
|
|
|
DixGetAttrAccess | DixReceiveAccess | DixGetFocusAccess |
|
|
|
|
DixGrabAccess | DixSetAttrAccess | DixUseAccess;
|
|
|
|
static const Mask SecurityServerMask = DixGetAttrAccess | DixGrabAccess;
|
|
|
|
static const Mask SecurityClientMask = DixGetAttrAccess;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* SecurityAudit
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* format is the formatting string to be used to interpret the
|
|
|
|
* remaining arguments.
|
|
|
|
*
|
|
|
|
* Returns: nothing.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Writes the message to the log file if security logging is on.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
_X_ATTRIBUTE_PRINTF(1, 2)
|
|
|
|
SecurityAudit(const char *format, ...)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (auditTrailLevel < SECURITY_AUDIT_LEVEL)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
va_start(args, format);
|
|
|
|
VAuditF(format, args);
|
|
|
|
va_end(args);
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* SecurityAudit */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/*
|
|
|
|
* Performs a Security permission check.
|
|
|
|
*/
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityDoCheck(SecurityStateRec * subj, SecurityStateRec * obj,
|
|
|
|
Mask requested, Mask allowed)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
if (!subj->haveState || !obj->haveState)
|
2012-06-10 07:21:05 -06:00
|
|
|
return Success;
|
2008-11-02 08:26:08 -07:00
|
|
|
if (subj->trustLevel == XSecurityClientTrusted)
|
2012-06-10 07:21:05 -06:00
|
|
|
return Success;
|
2008-11-02 08:26:08 -07:00
|
|
|
if (obj->trustLevel != XSecurityClientTrusted)
|
2012-06-10 07:21:05 -06:00
|
|
|
return Success;
|
2008-11-02 08:26:08 -07:00
|
|
|
if ((requested | allowed) == allowed)
|
2012-06-10 07:21:05 -06:00
|
|
|
return Success;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
return BadAccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Labels initial server objects.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
SecurityLabelInitial(void)
|
|
|
|
{
|
|
|
|
SecurityStateRec *state;
|
|
|
|
|
|
|
|
/* Do the serverClient */
|
|
|
|
state = dixLookupPrivate(&serverClient->devPrivates, stateKey);
|
|
|
|
state->trustLevel = XSecurityClientTrusted;
|
|
|
|
state->haveState = TRUE;
|
2014-05-02 13:27:46 -06:00
|
|
|
state->live = FALSE;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Looks up a request name
|
|
|
|
*/
|
|
|
|
static _X_INLINE const char *
|
|
|
|
SecurityLookupRequestName(ClientPtr client)
|
|
|
|
{
|
2012-01-31 00:52:35 -07:00
|
|
|
return LookupRequestName(client->majorOp, client->minorOp);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/* SecurityDeleteAuthorization
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* value is the authorization to delete.
|
|
|
|
* id is its resource ID.
|
|
|
|
*
|
|
|
|
* Returns: Success.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Frees everything associated with the authorization.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityDeleteAuthorization(void *value, XID id)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr) value;
|
2006-11-26 11:13:41 -07:00
|
|
|
unsigned short name_len, data_len;
|
2012-06-10 07:21:05 -06:00
|
|
|
const char *name;
|
|
|
|
char *data;
|
2006-11-26 11:13:41 -07:00
|
|
|
int status;
|
|
|
|
int i;
|
|
|
|
OtherClientsPtr pEventClient;
|
|
|
|
|
|
|
|
/* Remove the auth using the os layer auth manager */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
status = AuthorizationFromID(pAuth->id, &name_len, &name, &data_len, &data);
|
2006-11-26 11:13:41 -07:00
|
|
|
assert(status);
|
|
|
|
status = RemoveAuthorization(name_len, name, data_len, data);
|
|
|
|
assert(status);
|
2012-06-10 07:21:05 -06:00
|
|
|
(void) status;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* free the auth timer if there is one */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pAuth->timer)
|
|
|
|
TimerFree(pAuth->timer);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* send revoke events */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
while ((pEventClient = pAuth->eventClients)) {
|
|
|
|
/* send revocation event event */
|
2013-06-07 11:28:45 -06:00
|
|
|
xSecurityAuthorizationRevokedEvent are = {
|
|
|
|
.type = SecurityEventBase + XSecurityAuthorizationRevoked,
|
|
|
|
.authId = pAuth->id
|
|
|
|
};
|
2012-06-10 07:21:05 -06:00
|
|
|
WriteEventsToClient(rClient(pEventClient), 1, (xEvent *) &are);
|
|
|
|
FreeResource(pEventClient->resource, RT_NONE);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* kill all clients using this auth */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 1; i < currentMaxClients; i++)
|
|
|
|
if (clients[i]) {
|
|
|
|
SecurityStateRec *state;
|
|
|
|
|
|
|
|
state = dixLookupPrivate(&clients[i]->devPrivates, stateKey);
|
|
|
|
if (state->haveState && state->authId == pAuth->id)
|
|
|
|
CloseDownClient(clients[i]);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2016-05-29 06:02:34 -06:00
|
|
|
SecurityAudit("revoked authorization ID %lu\n", (unsigned long)pAuth->id);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(pAuth);
|
2006-11-26 11:13:41 -07:00
|
|
|
return Success;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* SecurityDeleteAuthorization */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* resource delete function for RTEventClient */
|
|
|
|
static int
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityDeleteAuthorizationEventClient(void *value, XID id)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
OtherClientsPtr pEventClient, prev = NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr) value;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (pEventClient = pAuth->eventClients;
|
2012-06-10 07:21:05 -06:00
|
|
|
pEventClient; pEventClient = pEventClient->next) {
|
|
|
|
if (pEventClient->resource == id) {
|
|
|
|
if (prev)
|
|
|
|
prev->next = pEventClient->next;
|
|
|
|
else
|
|
|
|
pAuth->eventClients = pEventClient->next;
|
|
|
|
free(pEventClient);
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
prev = pEventClient;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
/*NOTREACHED*/ return -1; /* make compiler happy */
|
|
|
|
} /* SecurityDeleteAuthorizationEventClient */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* SecurityComputeAuthorizationTimeout
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* pAuth is the authorization for which we are computing the timeout
|
|
|
|
* seconds is the number of seconds we want to wait
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* the number of milliseconds that the auth timer should be set to
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Sets pAuth->secondsRemaining to any "overflow" amount of time
|
|
|
|
* that didn't fit in 32 bits worth of milliseconds
|
|
|
|
*/
|
|
|
|
|
|
|
|
static CARD32
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityComputeAuthorizationTimeout(SecurityAuthorizationPtr pAuth,
|
|
|
|
unsigned int seconds)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
/* maxSecs is the number of full seconds that can be expressed in
|
|
|
|
* 32 bits worth of milliseconds
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
CARD32 maxSecs = (CARD32) (~0) / (CARD32) MILLI_PER_SECOND;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (seconds > maxSecs) { /* only come here if we want to wait more than 49 days */
|
|
|
|
pAuth->secondsRemaining = seconds - maxSecs;
|
|
|
|
return maxSecs * MILLI_PER_SECOND;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
else { /* by far the common case */
|
|
|
|
pAuth->secondsRemaining = 0;
|
|
|
|
return seconds * MILLI_PER_SECOND;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* SecurityStartAuthorizationTimer */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* SecurityAuthorizationExpired
|
|
|
|
*
|
|
|
|
* This function is passed as an argument to TimerSet and gets called from
|
|
|
|
* the timer manager in the os layer when its time is up.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* timer is the timer for this authorization.
|
|
|
|
* time is the current time.
|
|
|
|
* pval is the authorization whose time is up.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* A new time delay in milliseconds if the timer should wait some
|
|
|
|
* more, else zero.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Frees the authorization resource if the timeout period is really
|
|
|
|
* over, otherwise recomputes pAuth->secondsRemaining.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static CARD32
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityAuthorizationExpired(OsTimerPtr timer, CARD32 time, void *pval)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr) pval;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
assert(pAuth->timer == timer);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pAuth->secondsRemaining) {
|
|
|
|
return SecurityComputeAuthorizationTimeout(pAuth,
|
|
|
|
pAuth->secondsRemaining);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
else {
|
|
|
|
FreeResource(pAuth->id, RT_NONE);
|
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* SecurityAuthorizationExpired */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* SecurityStartAuthorizationTimer
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* pAuth is the authorization whose timer should be started.
|
|
|
|
*
|
|
|
|
* Returns: nothing.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* A timer is started, set to expire after the timeout period for
|
|
|
|
* this authorization. When it expires, the function
|
|
|
|
* SecurityAuthorizationExpired will be called.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityStartAuthorizationTimer(SecurityAuthorizationPtr pAuth)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
pAuth->timer = TimerSet(pAuth->timer, 0,
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityComputeAuthorizationTimeout(pAuth,
|
|
|
|
pAuth->timeout),
|
|
|
|
SecurityAuthorizationExpired, pAuth);
|
|
|
|
} /* SecurityStartAuthorizationTimer */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* Proc functions all take a client argument, execute the request in
|
|
|
|
* client->requestBuffer, and return a protocol error status.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
ProcSecurityQueryVersion(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
/* REQUEST(xSecurityQueryVersionReq); */
|
2013-06-07 11:28:45 -06:00
|
|
|
xSecurityQueryVersionReply rep = {
|
|
|
|
.type = X_Reply,
|
|
|
|
.sequenceNumber = client->sequence,
|
|
|
|
.length = 0,
|
|
|
|
.majorVersion = SERVER_SECURITY_MAJOR_VERSION,
|
|
|
|
.minorVersion = SERVER_SECURITY_MINOR_VERSION
|
|
|
|
};
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xSecurityQueryVersionReq);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (client->swapped) {
|
|
|
|
swaps(&rep.sequenceNumber);
|
|
|
|
swaps(&rep.majorVersion);
|
|
|
|
swaps(&rep.minorVersion);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
WriteToClient(client, SIZEOF(xSecurityQueryVersionReply), &rep);
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* ProcSecurityQueryVersion */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityEventSelectForAuthorization(SecurityAuthorizationPtr pAuth,
|
|
|
|
ClientPtr client, Mask mask)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
OtherClients *pEventClient;
|
|
|
|
|
|
|
|
for (pEventClient = pAuth->eventClients;
|
2012-06-10 07:21:05 -06:00
|
|
|
pEventClient; pEventClient = pEventClient->next) {
|
|
|
|
if (SameClient(pEventClient, client)) {
|
|
|
|
if (mask == 0)
|
|
|
|
FreeResource(pEventClient->resource, RT_NONE);
|
|
|
|
else
|
|
|
|
pEventClient->mask = mask;
|
|
|
|
return Success;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
pEventClient = malloc(sizeof(OtherClients));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!pEventClient)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadAlloc;
|
2006-11-26 11:13:41 -07:00
|
|
|
pEventClient->mask = mask;
|
|
|
|
pEventClient->resource = FakeClientID(client->index);
|
|
|
|
pEventClient->next = pAuth->eventClients;
|
2014-09-27 11:52:59 -06:00
|
|
|
if (!AddResource(pEventClient->resource, RTEventClient, (void *) pAuth)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
free(pEventClient);
|
|
|
|
return BadAlloc;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
pAuth->eventClients = pEventClient;
|
|
|
|
|
|
|
|
return Success;
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* SecurityEventSelectForAuthorization */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
ProcSecurityGenerateAuthorization(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xSecurityGenerateAuthorizationReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
int len; /* request length in CARD32s */
|
|
|
|
Bool removeAuth = FALSE; /* if bailout, call RemoveAuthorization? */
|
|
|
|
SecurityAuthorizationPtr pAuth = NULL; /* auth we are creating */
|
|
|
|
int err; /* error to return from this function */
|
|
|
|
XID authId; /* authorization ID assigned by os layer */
|
|
|
|
xSecurityGenerateAuthorizationReply rep; /* reply struct */
|
2006-11-26 11:13:41 -07:00
|
|
|
unsigned int trustLevel; /* trust level of new auth */
|
2012-06-10 07:21:05 -06:00
|
|
|
XID group; /* group of new auth */
|
|
|
|
CARD32 timeout; /* timeout of new auth */
|
|
|
|
CARD32 *values; /* list of supplied attributes */
|
|
|
|
char *protoname; /* auth proto name sent in request */
|
|
|
|
char *protodata; /* auth proto data sent in request */
|
2006-11-26 11:13:41 -07:00
|
|
|
unsigned int authdata_len; /* # bytes of generated auth data */
|
2012-06-10 07:21:05 -06:00
|
|
|
char *pAuthdata; /* generated auth data */
|
|
|
|
Mask eventMask; /* what events on this auth does client want */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* check request length */
|
|
|
|
|
|
|
|
REQUEST_AT_LEAST_SIZE(xSecurityGenerateAuthorizationReq);
|
2010-07-27 13:02:24 -06:00
|
|
|
len = bytes_to_int32(SIZEOF(xSecurityGenerateAuthorizationReq));
|
|
|
|
len += bytes_to_int32(stuff->nbytesAuthProto);
|
|
|
|
len += bytes_to_int32(stuff->nbytesAuthData);
|
2012-06-10 07:21:05 -06:00
|
|
|
values = ((CARD32 *) stuff) + len;
|
2006-11-26 11:13:41 -07:00
|
|
|
len += Ones(stuff->valueMask);
|
|
|
|
if (client->req_len != len)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadLength;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* check valuemask */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (stuff->valueMask & ~XSecurityAllAuthorizationAttributes) {
|
|
|
|
client->errorValue = stuff->valueMask;
|
|
|
|
return BadValue;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check timeout */
|
|
|
|
timeout = 60;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (stuff->valueMask & XSecurityTimeout) {
|
|
|
|
timeout = *values++;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check trustLevel */
|
|
|
|
trustLevel = XSecurityClientUntrusted;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (stuff->valueMask & XSecurityTrustLevel) {
|
|
|
|
trustLevel = *values++;
|
|
|
|
if (trustLevel != XSecurityClientTrusted &&
|
|
|
|
trustLevel != XSecurityClientUntrusted) {
|
|
|
|
client->errorValue = trustLevel;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check group */
|
|
|
|
group = None;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (stuff->valueMask & XSecurityGroup) {
|
|
|
|
group = *values++;
|
|
|
|
if (SecurityValidateGroupCallback) {
|
|
|
|
SecurityValidateGroupInfoRec vgi;
|
|
|
|
|
|
|
|
vgi.group = group;
|
|
|
|
vgi.valid = FALSE;
|
2014-09-27 11:52:59 -06:00
|
|
|
CallCallbacks(&SecurityValidateGroupCallback, (void *) &vgi);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
/* if nobody said they recognized it, it's an error */
|
|
|
|
|
|
|
|
if (!vgi.valid) {
|
|
|
|
client->errorValue = group;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check event mask */
|
|
|
|
eventMask = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (stuff->valueMask & XSecurityEventMask) {
|
|
|
|
eventMask = *values++;
|
|
|
|
if (eventMask & ~XSecurityAllEventMasks) {
|
|
|
|
client->errorValue = eventMask;
|
|
|
|
return BadValue;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
protoname = (char *) &stuff[1];
|
2010-07-27 13:02:24 -06:00
|
|
|
protodata = protoname + bytes_to_int32(stuff->nbytesAuthProto);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* call os layer to generate the authorization */
|
|
|
|
|
|
|
|
authId = GenerateAuthorization(stuff->nbytesAuthProto, protoname,
|
2012-06-10 07:21:05 -06:00
|
|
|
stuff->nbytesAuthData, protodata,
|
|
|
|
&authdata_len, &pAuthdata);
|
|
|
|
if ((XID) ~0L == authId) {
|
|
|
|
err = SecurityErrorBase + XSecurityBadAuthorizationProtocol;
|
|
|
|
goto bailout;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now that we've added the auth, remember to remove it if we have to
|
|
|
|
* abort the request for some reason (like allocation failure)
|
|
|
|
*/
|
|
|
|
removeAuth = TRUE;
|
|
|
|
|
|
|
|
/* associate additional information with this auth ID */
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
pAuth = malloc(sizeof(SecurityAuthorizationRec));
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pAuth) {
|
|
|
|
err = BadAlloc;
|
|
|
|
goto bailout;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in the auth fields */
|
|
|
|
|
|
|
|
pAuth->id = authId;
|
|
|
|
pAuth->timeout = timeout;
|
|
|
|
pAuth->group = group;
|
|
|
|
pAuth->trustLevel = trustLevel;
|
2012-06-10 07:21:05 -06:00
|
|
|
pAuth->refcnt = 0; /* the auth was just created; nobody's using it yet */
|
2006-11-26 11:13:41 -07:00
|
|
|
pAuth->secondsRemaining = 0;
|
|
|
|
pAuth->timer = NULL;
|
|
|
|
pAuth->eventClients = NULL;
|
|
|
|
|
|
|
|
/* handle event selection */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (eventMask) {
|
|
|
|
err = SecurityEventSelectForAuthorization(pAuth, client, eventMask);
|
|
|
|
if (err != Success)
|
|
|
|
goto bailout;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!AddResource(authId, SecurityAuthorizationResType, pAuth)) {
|
|
|
|
err = BadAlloc;
|
|
|
|
goto bailout;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* start the timer ticking */
|
|
|
|
|
|
|
|
if (pAuth->timeout != 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityStartAuthorizationTimer(pAuth);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* tell client the auth id and data */
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
rep = (xSecurityGenerateAuthorizationReply) {
|
|
|
|
.type = X_Reply,
|
|
|
|
.sequenceNumber = client->sequence,
|
|
|
|
.length = bytes_to_int32(authdata_len),
|
|
|
|
.authId = authId,
|
|
|
|
.dataLength = authdata_len
|
|
|
|
};
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (client->swapped) {
|
|
|
|
swapl(&rep.length);
|
|
|
|
swaps(&rep.sequenceNumber);
|
|
|
|
swapl(&rep.authId);
|
|
|
|
swaps(&rep.dataLength);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
WriteToClient(client, SIZEOF(xSecurityGenerateAuthorizationReply), &rep);
|
2006-11-26 11:13:41 -07:00
|
|
|
WriteToClient(client, authdata_len, pAuthdata);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAudit
|
2016-05-29 06:02:34 -06:00
|
|
|
("client %d generated authorization %lu trust %d timeout %lu group %lu events %lu\n",
|
|
|
|
client->index, (unsigned long)pAuth->id, pAuth->trustLevel, (unsigned long)pAuth->timeout,
|
|
|
|
(unsigned long)pAuth->group, (unsigned long)eventMask);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* the request succeeded; don't call RemoveAuthorization or free pAuth */
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
bailout:
|
2006-11-26 11:13:41 -07:00
|
|
|
if (removeAuth)
|
2012-06-10 07:21:05 -06:00
|
|
|
RemoveAuthorization(stuff->nbytesAuthProto, protoname,
|
|
|
|
authdata_len, pAuthdata);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(pAuth);
|
2006-11-26 11:13:41 -07:00
|
|
|
return err;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* ProcSecurityGenerateAuthorization */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
ProcSecurityRevokeAuthorization(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xSecurityRevokeAuthorizationReq);
|
|
|
|
SecurityAuthorizationPtr pAuth;
|
2010-07-27 13:02:24 -06:00
|
|
|
int rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq);
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
rc = dixLookupResourceByType((void **) &pAuth, stuff->authId,
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAuthorizationResType, client,
|
|
|
|
DixDestroyAccess);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
FreeResource(stuff->authId, RT_NONE);
|
|
|
|
return Success;
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* ProcSecurityRevokeAuthorization */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
ProcSecurityDispatch(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xReq);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (stuff->data) {
|
|
|
|
case X_SecurityQueryVersion:
|
|
|
|
return ProcSecurityQueryVersion(client);
|
|
|
|
case X_SecurityGenerateAuthorization:
|
|
|
|
return ProcSecurityGenerateAuthorization(client);
|
|
|
|
case X_SecurityRevokeAuthorization:
|
|
|
|
return ProcSecurityRevokeAuthorization(client);
|
|
|
|
default:
|
|
|
|
return BadRequest;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* ProcSecurityDispatch */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
SProcSecurityQueryVersion(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xSecurityQueryVersionReq);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_SIZE_MATCH(xSecurityQueryVersionReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->majorVersion);
|
|
|
|
swaps(&stuff->minorVersion);
|
2006-11-26 11:13:41 -07:00
|
|
|
return ProcSecurityQueryVersion(client);
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* SProcSecurityQueryVersion */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
SProcSecurityGenerateAuthorization(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xSecurityGenerateAuthorizationReq);
|
|
|
|
CARD32 *values;
|
|
|
|
unsigned long nvalues;
|
2008-06-11 09:39:26 -06:00
|
|
|
int values_offset;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_AT_LEAST_SIZE(xSecurityGenerateAuthorizationReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->nbytesAuthProto);
|
|
|
|
swaps(&stuff->nbytesAuthData);
|
|
|
|
swapl(&stuff->valueMask);
|
2010-07-27 13:02:24 -06:00
|
|
|
values_offset = bytes_to_int32(stuff->nbytesAuthProto) +
|
2012-06-10 07:21:05 -06:00
|
|
|
bytes_to_int32(stuff->nbytesAuthData);
|
|
|
|
if (values_offset >
|
|
|
|
stuff->length - bytes_to_int32(sz_xSecurityGenerateAuthorizationReq))
|
|
|
|
return BadLength;
|
|
|
|
values = (CARD32 *) (&stuff[1]) + values_offset;
|
|
|
|
nvalues = (((CARD32 *) stuff) + stuff->length) - values;
|
2006-11-26 11:13:41 -07:00
|
|
|
SwapLongs(values, nvalues);
|
|
|
|
return ProcSecurityGenerateAuthorization(client);
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* SProcSecurityGenerateAuthorization */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
SProcSecurityRevokeAuthorization(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xSecurityRevokeAuthorizationReq);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2006-11-26 11:13:41 -07:00
|
|
|
REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->authId);
|
2006-11-26 11:13:41 -07:00
|
|
|
return ProcSecurityRevokeAuthorization(client);
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* SProcSecurityRevokeAuthorization */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
SProcSecurityDispatch(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xReq);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (stuff->data) {
|
|
|
|
case X_SecurityQueryVersion:
|
|
|
|
return SProcSecurityQueryVersion(client);
|
|
|
|
case X_SecurityGenerateAuthorization:
|
|
|
|
return SProcSecurityGenerateAuthorization(client);
|
|
|
|
case X_SecurityRevokeAuthorization:
|
|
|
|
return SProcSecurityRevokeAuthorization(client);
|
|
|
|
default:
|
|
|
|
return BadRequest;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
} /* SProcSecurityDispatch */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
SwapSecurityAuthorizationRevokedEvent(xSecurityAuthorizationRevokedEvent * from,
|
|
|
|
xSecurityAuthorizationRevokedEvent * to)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
to->type = from->type;
|
|
|
|
to->detail = from->detail;
|
|
|
|
cpswaps(from->sequenceNumber, to->sequenceNumber);
|
|
|
|
cpswapl(from->authId, to->authId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SecurityCheckDeviceAccess
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* client is the client attempting to access a device.
|
|
|
|
* dev is the device being accessed.
|
|
|
|
* fromRequest is TRUE if the device access is a direct result of
|
|
|
|
* the client executing some request and FALSE if it is a
|
|
|
|
* result of the server trying to send an event (e.g. KeymapNotify)
|
|
|
|
* to the client.
|
|
|
|
* Returns:
|
|
|
|
* TRUE if the device access should be allowed, else FALSE.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* An audit message is generated if access is denied.
|
|
|
|
*/
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityDevice(CallbackListPtr *pcbl, void *unused, void *calldata)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
XaceDeviceAccessRec *rec = calldata;
|
|
|
|
SecurityStateRec *subj, *obj;
|
|
|
|
Mask requested = rec->access_mode;
|
|
|
|
Mask allowed = SecurityDeviceMask;
|
|
|
|
|
|
|
|
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
|
|
|
|
obj = dixLookupPrivate(&serverClient->devPrivates, stateKey);
|
|
|
|
|
|
|
|
if (rec->dev != inputInfo.keyboard)
|
2012-06-10 07:21:05 -06:00
|
|
|
/* this extension only supports the core keyboard */
|
|
|
|
allowed = requested;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
if (SecurityDoCheck(subj, obj, requested, allowed) != Success) {
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAudit("Security denied client %d keyboard access on request "
|
|
|
|
"%s\n", rec->client->index,
|
|
|
|
SecurityLookupRequestName(rec->client));
|
|
|
|
rec->status = BadAccess;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* SecurityResource
|
2006-11-26 11:13:41 -07:00
|
|
|
*
|
|
|
|
* This function gets plugged into client->CheckAccess and is called from
|
|
|
|
* SecurityLookupIDByType/Class to determine if the client can access the
|
|
|
|
* resource.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* client is the client doing the resource access.
|
|
|
|
* id is the resource id.
|
|
|
|
* rtype is its type or class.
|
|
|
|
* access_mode represents the intended use of the resource; see
|
|
|
|
* resource.h.
|
2007-11-24 10:55:21 -07:00
|
|
|
* res is a pointer to the resource structure for this resource.
|
2006-11-26 11:13:41 -07:00
|
|
|
*
|
|
|
|
* Returns:
|
2007-11-24 10:55:21 -07:00
|
|
|
* If access is granted, the value of rval that was passed in, else FALSE.
|
2006-11-26 11:13:41 -07:00
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Disallowed resource accesses are audited.
|
|
|
|
*/
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityResource(CallbackListPtr *pcbl, void *unused, void *calldata)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
XaceResourceAccessRec *rec = calldata;
|
|
|
|
SecurityStateRec *subj, *obj;
|
|
|
|
int cid = CLIENT_ID(rec->id);
|
|
|
|
Mask requested = rec->access_mode;
|
|
|
|
Mask allowed = SecurityResourceMask;
|
|
|
|
|
|
|
|
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
|
|
|
|
|
|
|
|
/* disable background None for untrusted windows */
|
|
|
|
if ((requested & DixCreateAccess) && (rec->rtype == RT_WINDOW))
|
2012-06-10 07:21:05 -06:00
|
|
|
if (subj->haveState && subj->trustLevel != XSecurityClientTrusted)
|
|
|
|
((WindowPtr) rec->res)->forcedBG = TRUE;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* additional permissions for specific resource types */
|
|
|
|
if (rec->rtype == RT_WINDOW)
|
2012-06-10 07:21:05 -06:00
|
|
|
allowed |= SecurityWindowExtraMask;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* special checks for server-owned resources */
|
|
|
|
if (cid == 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (rec->rtype & RC_DRAWABLE)
|
|
|
|
/* additional operations allowed on root windows */
|
|
|
|
allowed |= SecurityRootWindowExtraMask;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
else if (rec->rtype == RT_COLORMAP)
|
|
|
|
/* allow access to default colormaps */
|
|
|
|
allowed = requested;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
else
|
|
|
|
/* allow read access to other server-owned resources */
|
|
|
|
allowed |= DixReadAccess;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
if (clients[cid] != NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
obj = dixLookupPrivate(&clients[cid]->devPrivates, stateKey);
|
|
|
|
if (SecurityDoCheck(subj, obj, requested, allowed) == Success)
|
|
|
|
return;
|
2010-12-05 08:36:02 -07:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2016-05-29 06:02:34 -06:00
|
|
|
SecurityAudit("Security: denied client %d access %lx to resource 0x%lx "
|
2012-06-10 07:21:05 -06:00
|
|
|
"of client %d on request %s\n", rec->client->index,
|
2016-05-29 06:02:34 -06:00
|
|
|
(unsigned long)requested, (unsigned long)rec->id, cid,
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityLookupRequestName(rec->client));
|
|
|
|
rec->status = BadAccess; /* deny access */
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityExtension(CallbackListPtr *pcbl, void *unused, void *calldata)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
XaceExtAccessRec *rec = calldata;
|
|
|
|
SecurityStateRec *subj;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (subj->haveState && subj->trustLevel == XSecurityClientTrusted)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
while (SecurityTrustedExtensions[i])
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!strcmp(SecurityTrustedExtensions[i++], rec->ext->name))
|
|
|
|
return;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
SecurityAudit("Security: denied client %d access to extension "
|
2012-06-10 07:21:05 -06:00
|
|
|
"%s on request %s\n",
|
|
|
|
rec->client->index, rec->ext->name,
|
|
|
|
SecurityLookupRequestName(rec->client));
|
2009-09-06 13:44:18 -06:00
|
|
|
rec->status = BadAccess;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityServer(CallbackListPtr *pcbl, void *unused, void *calldata)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
XaceServerAccessRec *rec = calldata;
|
|
|
|
SecurityStateRec *subj, *obj;
|
|
|
|
Mask requested = rec->access_mode;
|
|
|
|
Mask allowed = SecurityServerMask;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
|
|
|
|
obj = dixLookupPrivate(&serverClient->devPrivates, stateKey);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (SecurityDoCheck(subj, obj, requested, allowed) != Success) {
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAudit("Security: denied client %d access to server "
|
|
|
|
"configuration request %s\n", rec->client->index,
|
|
|
|
SecurityLookupRequestName(rec->client));
|
|
|
|
rec->status = BadAccess;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityClient(CallbackListPtr *pcbl, void *unused, void *calldata)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
XaceClientAccessRec *rec = calldata;
|
|
|
|
SecurityStateRec *subj, *obj;
|
|
|
|
Mask requested = rec->access_mode;
|
|
|
|
Mask allowed = SecurityClientMask;
|
|
|
|
|
|
|
|
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
|
|
|
|
obj = dixLookupPrivate(&rec->target->devPrivates, stateKey);
|
|
|
|
|
|
|
|
if (SecurityDoCheck(subj, obj, requested, allowed) != Success) {
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAudit("Security: denied client %d access to client %d on "
|
|
|
|
"request %s\n", rec->client->index, rec->target->index,
|
|
|
|
SecurityLookupRequestName(rec->client));
|
|
|
|
rec->status = BadAccess;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityProperty(CallbackListPtr *pcbl, void *unused, void *calldata)
|
2012-06-10 07:21:05 -06:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
XacePropertyAccessRec *rec = calldata;
|
|
|
|
SecurityStateRec *subj, *obj;
|
|
|
|
ATOM name = (*rec->ppProp)->propertyName;
|
|
|
|
Mask requested = rec->access_mode;
|
|
|
|
Mask allowed = SecurityResourceMask | DixReadAccess;
|
|
|
|
|
|
|
|
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
|
|
|
|
obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey);
|
|
|
|
|
|
|
|
if (SecurityDoCheck(subj, obj, requested, allowed) != Success) {
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAudit("Security: denied client %d access to property %s "
|
2016-05-29 06:02:34 -06:00
|
|
|
"(atom 0x%x) window 0x%lx of client %d on request %s\n",
|
2012-06-10 07:21:05 -06:00
|
|
|
rec->client->index, NameForAtom(name), name,
|
2016-05-29 06:02:34 -06:00
|
|
|
(unsigned long)rec->pWin->drawable.id, wClient(rec->pWin)->index,
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityLookupRequestName(rec->client));
|
|
|
|
rec->status = BadAccess;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
SecuritySend(CallbackListPtr *pcbl, void *unused, void *calldata)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
XaceSendAccessRec *rec = calldata;
|
|
|
|
SecurityStateRec *subj, *obj;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rec->client) {
|
2012-06-10 07:21:05 -06:00
|
|
|
int i;
|
|
|
|
|
|
|
|
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
|
|
|
|
obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey);
|
|
|
|
|
|
|
|
if (SecurityDoCheck(subj, obj, DixSendAccess, 0) == Success)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < rec->count; i++)
|
|
|
|
if (rec->events[i].u.u.type != UnmapNotify &&
|
|
|
|
rec->events[i].u.u.type != ConfigureRequest &&
|
|
|
|
rec->events[i].u.u.type != ClientMessage) {
|
|
|
|
|
|
|
|
SecurityAudit("Security: denied client %d from sending event "
|
2016-05-29 06:02:34 -06:00
|
|
|
"of type %s to window 0x%lx of client %d\n",
|
2012-06-10 07:21:05 -06:00
|
|
|
rec->client->index,
|
|
|
|
LookupEventName(rec->events[i].u.u.type),
|
2016-05-29 06:02:34 -06:00
|
|
|
(unsigned long)rec->pWin->drawable.id,
|
2012-06-10 07:21:05 -06:00
|
|
|
wClient(rec->pWin)->index);
|
|
|
|
rec->status = BadAccess;
|
|
|
|
return;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityReceive(CallbackListPtr *pcbl, void *unused, void *calldata)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
XaceReceiveAccessRec *rec = calldata;
|
|
|
|
SecurityStateRec *subj, *obj;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
|
|
|
|
obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (SecurityDoCheck(subj, obj, DixReceiveAccess, 0) == Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
SecurityAudit("Security: denied client %d from receiving an event "
|
2016-05-29 06:02:34 -06:00
|
|
|
"sent to window 0x%lx of client %d\n",
|
|
|
|
rec->client->index, (unsigned long)rec->pWin->drawable.id,
|
2012-06-10 07:21:05 -06:00
|
|
|
wClient(rec->pWin)->index);
|
2008-11-02 08:26:08 -07:00
|
|
|
rec->status = BadAccess;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* SecurityClientStateCallback
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* pcbl is &ClientStateCallback.
|
|
|
|
* nullata is NULL.
|
|
|
|
* calldata is a pointer to a NewClientInfoRec (include/dixstruct.h)
|
|
|
|
* which contains information about client state changes.
|
|
|
|
*
|
|
|
|
* Returns: nothing.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
2015-09-16 13:10:19 -06:00
|
|
|
*
|
2008-11-02 08:26:08 -07:00
|
|
|
* If a new client is connecting, its authorization ID is copied to
|
|
|
|
* client->authID. If this is a generated authorization, its reference
|
|
|
|
* count is bumped, its timer is cancelled if it was running, and its
|
|
|
|
* trustlevel is copied to TRUSTLEVEL(client).
|
2015-09-16 13:10:19 -06:00
|
|
|
*
|
2008-11-02 08:26:08 -07:00
|
|
|
* If a client is disconnecting and the client was using a generated
|
|
|
|
* authorization, the authorization's reference count is decremented, and
|
|
|
|
* if it is now zero, the timer for this authorization is started.
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
SecurityClientState(CallbackListPtr *pcbl, void *unused, void *calldata)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
NewClientInfoRec *pci = calldata;
|
|
|
|
SecurityStateRec *state;
|
|
|
|
SecurityAuthorizationPtr pAuth;
|
|
|
|
int rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
state = dixLookupPrivate(&pci->client->devPrivates, stateKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
switch (pci->client->clientState) {
|
|
|
|
case ClientStateInitial:
|
2012-06-10 07:21:05 -06:00
|
|
|
state->trustLevel = XSecurityClientTrusted;
|
|
|
|
state->authId = None;
|
|
|
|
state->haveState = TRUE;
|
2014-05-02 13:27:46 -06:00
|
|
|
state->live = FALSE;
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
case ClientStateRunning:
|
2012-06-10 07:21:05 -06:00
|
|
|
state->authId = AuthorizationIDOfClient(pci->client);
|
2014-09-27 11:52:59 -06:00
|
|
|
rc = dixLookupResourceByType((void **) &pAuth, state->authId,
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAuthorizationResType, serverClient,
|
|
|
|
DixGetAttrAccess);
|
|
|
|
if (rc == Success) {
|
|
|
|
/* it is a generated authorization */
|
|
|
|
pAuth->refcnt++;
|
2014-05-02 13:27:46 -06:00
|
|
|
state->live = TRUE;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pAuth->refcnt == 1 && pAuth->timer)
|
|
|
|
TimerCancel(pAuth->timer);
|
|
|
|
|
|
|
|
state->trustLevel = pAuth->trustLevel;
|
|
|
|
}
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
case ClientStateGone:
|
|
|
|
case ClientStateRetained:
|
2014-09-27 11:52:59 -06:00
|
|
|
rc = dixLookupResourceByType((void **) &pAuth, state->authId,
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityAuthorizationResType, serverClient,
|
|
|
|
DixGetAttrAccess);
|
2014-05-02 13:27:46 -06:00
|
|
|
if (rc == Success && state->live) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* it is a generated authorization */
|
|
|
|
pAuth->refcnt--;
|
2014-05-02 13:27:46 -06:00
|
|
|
state->live = FALSE;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pAuth->refcnt == 0)
|
|
|
|
SecurityStartAuthorizationTimer(pAuth);
|
|
|
|
}
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* SecurityResetProc
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* extEntry is the extension information for the security extension.
|
|
|
|
*
|
|
|
|
* Returns: nothing.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Performs any cleanup needed by Security at server shutdown time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
SecurityResetProc(ExtensionEntry * extEntry)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
/* Unregister callbacks */
|
|
|
|
DeleteCallback(&ClientStateCallback, SecurityClientState, NULL);
|
|
|
|
|
|
|
|
XaceDeleteCallback(XACE_EXT_DISPATCH, SecurityExtension, NULL);
|
|
|
|
XaceDeleteCallback(XACE_RESOURCE_ACCESS, SecurityResource, NULL);
|
|
|
|
XaceDeleteCallback(XACE_DEVICE_ACCESS, SecurityDevice, NULL);
|
|
|
|
XaceDeleteCallback(XACE_PROPERTY_ACCESS, SecurityProperty, NULL);
|
|
|
|
XaceDeleteCallback(XACE_SEND_ACCESS, SecuritySend, NULL);
|
|
|
|
XaceDeleteCallback(XACE_RECEIVE_ACCESS, SecurityReceive, NULL);
|
|
|
|
XaceDeleteCallback(XACE_CLIENT_ACCESS, SecurityClient, NULL);
|
|
|
|
XaceDeleteCallback(XACE_EXT_ACCESS, SecurityExtension, NULL);
|
|
|
|
XaceDeleteCallback(XACE_SERVER_ACCESS, SecurityServer, NULL);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* SecurityExtensionInit
|
|
|
|
*
|
|
|
|
* Arguments: none.
|
|
|
|
*
|
|
|
|
* Returns: nothing.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Enables the Security extension if possible.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2013-06-07 11:28:45 -06:00
|
|
|
SecurityExtensionInit(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
ExtensionEntry *extEntry;
|
2008-11-02 08:26:08 -07:00
|
|
|
int ret = TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
SecurityAuthorizationResType =
|
2012-06-10 07:21:05 -06:00
|
|
|
CreateNewResourceType(SecurityDeleteAuthorization,
|
|
|
|
"SecurityAuthorization");
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
RTEventClient =
|
2012-06-10 07:21:05 -06:00
|
|
|
CreateNewResourceType(SecurityDeleteAuthorizationEventClient,
|
|
|
|
"SecurityEventClient");
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (!SecurityAuthorizationResType || !RTEventClient)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
RTEventClient |= RC_NEVERRETAIN;
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* Allocate the private storage */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!dixRegisterPrivateKey
|
|
|
|
(stateKey, PRIVATE_CLIENT, sizeof(SecurityStateRec)))
|
|
|
|
FatalError("SecurityExtensionSetup: Can't allocate client private.\n");
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
/* Register callbacks */
|
|
|
|
ret &= AddCallback(&ClientStateCallback, SecurityClientState, NULL);
|
|
|
|
|
|
|
|
ret &= XaceRegisterCallback(XACE_EXT_DISPATCH, SecurityExtension, NULL);
|
|
|
|
ret &= XaceRegisterCallback(XACE_RESOURCE_ACCESS, SecurityResource, NULL);
|
|
|
|
ret &= XaceRegisterCallback(XACE_DEVICE_ACCESS, SecurityDevice, NULL);
|
|
|
|
ret &= XaceRegisterCallback(XACE_PROPERTY_ACCESS, SecurityProperty, NULL);
|
|
|
|
ret &= XaceRegisterCallback(XACE_SEND_ACCESS, SecuritySend, NULL);
|
|
|
|
ret &= XaceRegisterCallback(XACE_RECEIVE_ACCESS, SecurityReceive, NULL);
|
|
|
|
ret &= XaceRegisterCallback(XACE_CLIENT_ACCESS, SecurityClient, NULL);
|
|
|
|
ret &= XaceRegisterCallback(XACE_EXT_ACCESS, SecurityExtension, NULL);
|
|
|
|
ret &= XaceRegisterCallback(XACE_SERVER_ACCESS, SecurityServer, NULL);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!ret)
|
2012-06-10 07:21:05 -06:00
|
|
|
FatalError("SecurityExtensionSetup: Failed to register callbacks\n");
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
/* Add extension to server */
|
2006-11-26 11:13:41 -07:00
|
|
|
extEntry = AddExtension(SECURITY_EXTENSION_NAME,
|
2012-06-10 07:21:05 -06:00
|
|
|
XSecurityNumberEvents, XSecurityNumberErrors,
|
|
|
|
ProcSecurityDispatch, SProcSecurityDispatch,
|
2006-11-26 11:13:41 -07:00
|
|
|
SecurityResetProc, StandardMinorOpcode);
|
|
|
|
|
|
|
|
SecurityErrorBase = extEntry->errorBase;
|
|
|
|
SecurityEventBase = extEntry->eventBase;
|
|
|
|
|
|
|
|
EventSwapVector[SecurityEventBase + XSecurityAuthorizationRevoked] =
|
2012-06-10 07:21:05 -06:00
|
|
|
(EventSwapPtr) SwapSecurityAuthorizationRevokedEvent;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
SetResourceTypeErrorValue(SecurityAuthorizationResType,
|
|
|
|
SecurityErrorBase + XSecurityBadAuthorization);
|
2010-12-05 08:36:02 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* Label objects that were created before we could register ourself */
|
|
|
|
SecurityLabelInitial();
|
|
|
|
}
|