2010-07-27 13:02:24 -06:00
|
|
|
/************************************************************
|
|
|
|
|
|
|
|
Author: Eamon Walsh <ewalsh@tycho.nsa.gov>
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
this permission notice appear in supporting documentation. 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
|
|
|
|
AUTHOR 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.
|
|
|
|
|
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "selection.h"
|
|
|
|
#include "inputstr.h"
|
|
|
|
#include "windowstr.h"
|
|
|
|
#include "propertyst.h"
|
|
|
|
#include "extnsionst.h"
|
2013-06-07 11:28:45 -06:00
|
|
|
#include "extinit.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "xselinuxint.h"
|
|
|
|
|
|
|
|
#define CTX_DEV offsetof(SELinuxSubjectRec, dev_create_sid)
|
|
|
|
#define CTX_WIN offsetof(SELinuxSubjectRec, win_create_sid)
|
|
|
|
#define CTX_PRP offsetof(SELinuxSubjectRec, prp_create_sid)
|
|
|
|
#define CTX_SEL offsetof(SELinuxSubjectRec, sel_create_sid)
|
|
|
|
#define USE_PRP offsetof(SELinuxSubjectRec, prp_use_sid)
|
|
|
|
#define USE_SEL offsetof(SELinuxSubjectRec, sel_use_sid)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
security_context_t octx;
|
|
|
|
security_context_t dctx;
|
|
|
|
CARD32 octx_len;
|
|
|
|
CARD32 dctx_len;
|
|
|
|
CARD32 id;
|
|
|
|
} SELinuxListItemRec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extension Dispatch
|
|
|
|
*/
|
|
|
|
|
|
|
|
static security_context_t
|
|
|
|
SELinuxCopyContext(char *ptr, unsigned len)
|
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
security_context_t copy = malloc(len + 1);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!copy)
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
2010-07-27 13:02:24 -06:00
|
|
|
strncpy(copy, ptr, len);
|
|
|
|
copy[len] = '\0';
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcSELinuxQueryVersion(ClientPtr client)
|
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
SELinuxQueryVersionReply rep = {
|
|
|
|
.type = X_Reply,
|
|
|
|
.sequenceNumber = client->sequence,
|
|
|
|
.length = 0,
|
|
|
|
.server_major = SELINUX_MAJOR_VERSION,
|
|
|
|
.server_minor = SELINUX_MINOR_VERSION
|
|
|
|
};
|
2010-07-27 13:02:24 -06:00
|
|
|
if (client->swapped) {
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&rep.sequenceNumber);
|
|
|
|
swapl(&rep.length);
|
|
|
|
swaps(&rep.server_major);
|
|
|
|
swaps(&rep.server_minor);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
WriteToClient(client, sizeof(rep), &rep);
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SELinuxSendContextReply(ClientPtr client, security_id_t sid)
|
|
|
|
{
|
|
|
|
SELinuxGetContextReply rep;
|
|
|
|
security_context_t ctx = NULL;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
if (sid) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (avc_sid_to_context_raw(sid, &ctx) < 0)
|
|
|
|
return BadValue;
|
|
|
|
len = strlen(ctx) + 1;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
rep = (SELinuxGetContextReply) {
|
|
|
|
.type = X_Reply,
|
|
|
|
.sequenceNumber = client->sequence,
|
|
|
|
.length = bytes_to_int32(len),
|
|
|
|
.context_len = len
|
|
|
|
};
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (client->swapped) {
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&rep.length);
|
|
|
|
swaps(&rep.sequenceNumber);
|
|
|
|
swapl(&rep.context_len);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
WriteToClient(client, sizeof(SELinuxGetContextReply), &rep);
|
2010-07-27 13:02:24 -06:00
|
|
|
WriteToClient(client, len, ctx);
|
|
|
|
freecon(ctx);
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcSELinuxSetCreateContext(ClientPtr client, unsigned offset)
|
|
|
|
{
|
|
|
|
PrivateRec **privPtr = &client->devPrivates;
|
|
|
|
security_id_t *pSid;
|
|
|
|
security_context_t ctx = NULL;
|
|
|
|
char *ptr;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
REQUEST(SELinuxSetCreateContextReq);
|
|
|
|
REQUEST_FIXED_SIZE(SELinuxSetCreateContextReq, stuff->context_len);
|
|
|
|
|
|
|
|
if (stuff->context_len > 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ctx = SELinuxCopyContext((char *) (stuff + 1), stuff->context_len);
|
|
|
|
if (!ctx)
|
|
|
|
return BadAlloc;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr = dixLookupPrivate(privPtr, subjectKey);
|
2012-06-10 07:21:05 -06:00
|
|
|
pSid = (security_id_t *) (ptr + offset);
|
2010-07-27 13:02:24 -06:00
|
|
|
*pSid = NULL;
|
|
|
|
|
|
|
|
rc = Success;
|
|
|
|
if (stuff->context_len > 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (security_check_context_raw(ctx) < 0 ||
|
|
|
|
avc_context_to_sid_raw(ctx, pSid) < 0)
|
|
|
|
rc = BadValue;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(ctx);
|
2010-07-27 13:02:24 -06:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcSELinuxGetCreateContext(ClientPtr client, unsigned offset)
|
|
|
|
{
|
|
|
|
security_id_t *pSid;
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetCreateContextReq);
|
|
|
|
|
|
|
|
if (offset == CTX_DEV)
|
2012-06-10 07:21:05 -06:00
|
|
|
ptr = dixLookupPrivate(&serverClient->devPrivates, subjectKey);
|
2010-07-27 13:02:24 -06:00
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
ptr = dixLookupPrivate(&client->devPrivates, subjectKey);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pSid = (security_id_t *) (ptr + offset);
|
2010-07-27 13:02:24 -06:00
|
|
|
return SELinuxSendContextReply(client, *pSid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcSELinuxSetDeviceContext(ClientPtr client)
|
|
|
|
{
|
|
|
|
security_context_t ctx;
|
|
|
|
security_id_t sid;
|
|
|
|
DeviceIntPtr dev;
|
|
|
|
SELinuxSubjectRec *subj;
|
|
|
|
SELinuxObjectRec *obj;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
REQUEST(SELinuxSetContextReq);
|
|
|
|
REQUEST_FIXED_SIZE(SELinuxSetContextReq, stuff->context_len);
|
|
|
|
|
|
|
|
if (stuff->context_len < 1)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadLength;
|
|
|
|
ctx = SELinuxCopyContext((char *) (stuff + 1), stuff->context_len);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!ctx)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadAlloc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
rc = dixLookupDevice(&dev, stuff->id, client, DixManageAccess);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
goto out;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (security_check_context_raw(ctx) < 0 ||
|
2012-06-10 07:21:05 -06:00
|
|
|
avc_context_to_sid_raw(ctx, &sid) < 0) {
|
|
|
|
rc = BadValue;
|
|
|
|
goto out;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
subj = dixLookupPrivate(&dev->devPrivates, subjectKey);
|
|
|
|
subj->sid = sid;
|
|
|
|
obj = dixLookupPrivate(&dev->devPrivates, objectKey);
|
|
|
|
obj->sid = sid;
|
|
|
|
|
|
|
|
rc = Success;
|
2012-06-10 07:21:05 -06:00
|
|
|
out:
|
2010-12-05 08:36:02 -07:00
|
|
|
free(ctx);
|
2010-07-27 13:02:24 -06:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcSELinuxGetDeviceContext(ClientPtr client)
|
|
|
|
{
|
|
|
|
DeviceIntPtr dev;
|
|
|
|
SELinuxSubjectRec *subj;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
REQUEST(SELinuxGetContextReq);
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetContextReq);
|
|
|
|
|
|
|
|
rc = dixLookupDevice(&dev, stuff->id, client, DixGetAttrAccess);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
subj = dixLookupPrivate(&dev->devPrivates, subjectKey);
|
|
|
|
return SELinuxSendContextReply(client, subj->sid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcSELinuxGetDrawableContext(ClientPtr client)
|
|
|
|
{
|
|
|
|
DrawablePtr pDraw;
|
|
|
|
PrivateRec **privatePtr;
|
|
|
|
SELinuxObjectRec *obj;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
REQUEST(SELinuxGetContextReq);
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetContextReq);
|
|
|
|
|
2011-04-02 10:08:38 -06:00
|
|
|
rc = dixLookupDrawable(&pDraw, stuff->id, client, 0, DixGetAttrAccess);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-04-02 10:08:38 -06:00
|
|
|
if (pDraw->type == DRAWABLE_PIXMAP)
|
2012-06-10 07:21:05 -06:00
|
|
|
privatePtr = &((PixmapPtr) pDraw)->devPrivates;
|
2010-07-27 13:02:24 -06:00
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
privatePtr = &((WindowPtr) pDraw)->devPrivates;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
obj = dixLookupPrivate(privatePtr, objectKey);
|
|
|
|
return SELinuxSendContextReply(client, obj->sid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-27 11:52:59 -06:00
|
|
|
ProcSELinuxGetPropertyContext(ClientPtr client, void *privKey)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
WindowPtr pWin;
|
|
|
|
PropertyPtr pProp;
|
|
|
|
SELinuxObjectRec *obj;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
REQUEST(SELinuxGetPropertyContextReq);
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetPropertyContextReq);
|
|
|
|
|
|
|
|
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetPropAccess);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
rc = dixLookupProperty(&pProp, pWin, stuff->property, client,
|
2012-06-10 07:21:05 -06:00
|
|
|
DixGetAttrAccess);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
obj = dixLookupPrivate(&pProp->devPrivates, privKey);
|
|
|
|
return SELinuxSendContextReply(client, obj->sid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-27 11:52:59 -06:00
|
|
|
ProcSELinuxGetSelectionContext(ClientPtr client, void *privKey)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
Selection *pSel;
|
|
|
|
SELinuxObjectRec *obj;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
REQUEST(SELinuxGetContextReq);
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetContextReq);
|
|
|
|
|
|
|
|
rc = dixLookupSelection(&pSel, stuff->id, client, DixGetAttrAccess);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
obj = dixLookupPrivate(&pSel->devPrivates, privKey);
|
|
|
|
return SELinuxSendContextReply(client, obj->sid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcSELinuxGetClientContext(ClientPtr client)
|
|
|
|
{
|
|
|
|
ClientPtr target;
|
|
|
|
SELinuxSubjectRec *subj;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
REQUEST(SELinuxGetContextReq);
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetContextReq);
|
|
|
|
|
|
|
|
rc = dixLookupClient(&target, stuff->id, client, DixGetAttrAccess);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
subj = dixLookupPrivate(&target->devPrivates, subjectKey);
|
|
|
|
return SELinuxSendContextReply(client, subj->sid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
SELinuxPopulateItem(SELinuxListItemRec * i, PrivateRec ** privPtr, CARD32 id,
|
|
|
|
int *size)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
SELinuxObjectRec *obj = dixLookupPrivate(privPtr, objectKey);
|
|
|
|
SELinuxObjectRec *data = dixLookupPrivate(privPtr, dataKey);
|
|
|
|
|
|
|
|
if (avc_sid_to_context_raw(obj->sid, &i->octx) < 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadValue;
|
2010-07-27 13:02:24 -06:00
|
|
|
if (avc_sid_to_context_raw(data->sid, &i->dctx) < 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadValue;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
i->id = id;
|
|
|
|
i->octx_len = bytes_to_int32(strlen(i->octx) + 1);
|
|
|
|
i->dctx_len = bytes_to_int32(strlen(i->dctx) + 1);
|
|
|
|
|
|
|
|
*size += i->octx_len + i->dctx_len + 3;
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
SELinuxFreeItems(SELinuxListItemRec * items, int count)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
int k;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
for (k = 0; k < count; k++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
freecon(items[k].octx);
|
|
|
|
freecon(items[k].dctx);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(items);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
SELinuxSendItemsToClient(ClientPtr client, SELinuxListItemRec * items,
|
|
|
|
int size, int count)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int rc, k, pos = 0;
|
2010-07-27 13:02:24 -06:00
|
|
|
SELinuxListItemsReply rep;
|
|
|
|
CARD32 *buf;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
buf = calloc(size, sizeof(CARD32));
|
2010-07-27 13:02:24 -06:00
|
|
|
if (size && !buf) {
|
2012-06-10 07:21:05 -06:00
|
|
|
rc = BadAlloc;
|
|
|
|
goto out;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the buffer */
|
|
|
|
for (k = 0; k < count; k++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
buf[pos] = items[k].id;
|
|
|
|
if (client->swapped)
|
|
|
|
swapl(buf + pos);
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
buf[pos] = items[k].octx_len * 4;
|
|
|
|
if (client->swapped)
|
|
|
|
swapl(buf + pos);
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
buf[pos] = items[k].dctx_len * 4;
|
|
|
|
if (client->swapped)
|
|
|
|
swapl(buf + pos);
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
memcpy((char *) (buf + pos), items[k].octx, strlen(items[k].octx) + 1);
|
|
|
|
pos += items[k].octx_len;
|
|
|
|
memcpy((char *) (buf + pos), items[k].dctx, strlen(items[k].dctx) + 1);
|
|
|
|
pos += items[k].dctx_len;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send reply to client */
|
2013-06-07 11:28:45 -06:00
|
|
|
rep = (SELinuxListItemsReply) {
|
|
|
|
.type = X_Reply,
|
|
|
|
.sequenceNumber = client->sequence,
|
|
|
|
.length = size,
|
|
|
|
.count = count
|
|
|
|
};
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (client->swapped) {
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&rep.length);
|
|
|
|
swaps(&rep.sequenceNumber);
|
|
|
|
swapl(&rep.count);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
WriteToClient(client, sizeof(SELinuxListItemsReply), &rep);
|
|
|
|
WriteToClient(client, size * 4, buf);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/* Free stuff and return */
|
2010-12-05 08:36:02 -07:00
|
|
|
rc = Success;
|
|
|
|
free(buf);
|
2012-06-10 07:21:05 -06:00
|
|
|
out:
|
2010-07-27 13:02:24 -06:00
|
|
|
SELinuxFreeItems(items, count);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcSELinuxListProperties(ClientPtr client)
|
|
|
|
{
|
|
|
|
WindowPtr pWin;
|
|
|
|
PropertyPtr pProp;
|
|
|
|
SELinuxListItemRec *items;
|
|
|
|
int rc, count, size, i;
|
|
|
|
CARD32 id;
|
|
|
|
|
|
|
|
REQUEST(SELinuxGetContextReq);
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetContextReq);
|
|
|
|
|
|
|
|
rc = dixLookupWindow(&pWin, stuff->id, client, DixListPropAccess);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/* Count the number of properties and allocate items */
|
|
|
|
count = 0;
|
|
|
|
for (pProp = wUserProps(pWin); pProp; pProp = pProp->next)
|
2012-06-10 07:21:05 -06:00
|
|
|
count++;
|
2010-12-05 08:36:02 -07:00
|
|
|
items = calloc(count, sizeof(SELinuxListItemRec));
|
2010-07-27 13:02:24 -06:00
|
|
|
if (count && !items)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadAlloc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/* Fill in the items and calculate size */
|
|
|
|
i = 0;
|
|
|
|
size = 0;
|
|
|
|
for (pProp = wUserProps(pWin); pProp; pProp = pProp->next) {
|
2012-06-10 07:21:05 -06:00
|
|
|
id = pProp->propertyName;
|
|
|
|
rc = SELinuxPopulateItem(items + i, &pProp->devPrivates, id, &size);
|
|
|
|
if (rc != Success) {
|
|
|
|
SELinuxFreeItems(items, count);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
i++;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return SELinuxSendItemsToClient(client, items, size, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcSELinuxListSelections(ClientPtr client)
|
|
|
|
{
|
|
|
|
Selection *pSel;
|
|
|
|
SELinuxListItemRec *items;
|
|
|
|
int rc, count, size, i;
|
|
|
|
CARD32 id;
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetCreateContextReq);
|
|
|
|
|
|
|
|
/* Count the number of selections and allocate items */
|
|
|
|
count = 0;
|
|
|
|
for (pSel = CurrentSelections; pSel; pSel = pSel->next)
|
2012-06-10 07:21:05 -06:00
|
|
|
count++;
|
2010-12-05 08:36:02 -07:00
|
|
|
items = calloc(count, sizeof(SELinuxListItemRec));
|
2010-07-27 13:02:24 -06:00
|
|
|
if (count && !items)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadAlloc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/* Fill in the items and calculate size */
|
|
|
|
i = 0;
|
|
|
|
size = 0;
|
|
|
|
for (pSel = CurrentSelections; pSel; pSel = pSel->next) {
|
2012-06-10 07:21:05 -06:00
|
|
|
id = pSel->selection;
|
|
|
|
rc = SELinuxPopulateItem(items + i, &pSel->devPrivates, id, &size);
|
|
|
|
if (rc != Success) {
|
|
|
|
SELinuxFreeItems(items, count);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
i++;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return SELinuxSendItemsToClient(client, items, size, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcSELinuxDispatch(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xReq);
|
|
|
|
switch (stuff->data) {
|
|
|
|
case X_SELinuxQueryVersion:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxQueryVersion(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetDeviceCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxSetCreateContext(client, CTX_DEV);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetDeviceCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, CTX_DEV);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetDeviceContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxSetDeviceContext(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetDeviceContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetDeviceContext(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetDrawableCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxSetCreateContext(client, CTX_WIN);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetDrawableCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, CTX_WIN);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetDrawableContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetDrawableContext(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetPropertyCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxSetCreateContext(client, CTX_PRP);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetPropertyCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, CTX_PRP);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetPropertyUseContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxSetCreateContext(client, USE_PRP);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetPropertyUseContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, USE_PRP);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetPropertyContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetPropertyContext(client, objectKey);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetPropertyDataContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetPropertyContext(client, dataKey);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxListProperties:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxListProperties(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetSelectionCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxSetCreateContext(client, CTX_SEL);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetSelectionCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, CTX_SEL);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetSelectionUseContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxSetCreateContext(client, USE_SEL);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetSelectionUseContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, USE_SEL);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetSelectionContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetSelectionContext(client, objectKey);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetSelectionDataContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetSelectionContext(client, dataKey);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxListSelections:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxListSelections(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetClientContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetClientContext(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadRequest;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
static int _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcSELinuxQueryVersion(ClientPtr client)
|
|
|
|
{
|
|
|
|
return ProcSELinuxQueryVersion(client);
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
static int _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcSELinuxSetCreateContext(ClientPtr client, unsigned offset)
|
|
|
|
{
|
|
|
|
REQUEST(SELinuxSetCreateContextReq);
|
|
|
|
|
|
|
|
REQUEST_AT_LEAST_SIZE(SELinuxSetCreateContextReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->context_len);
|
2010-07-27 13:02:24 -06:00
|
|
|
return ProcSELinuxSetCreateContext(client, offset);
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
static int _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcSELinuxSetDeviceContext(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(SELinuxSetContextReq);
|
|
|
|
|
|
|
|
REQUEST_AT_LEAST_SIZE(SELinuxSetContextReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->id);
|
|
|
|
swapl(&stuff->context_len);
|
2010-07-27 13:02:24 -06:00
|
|
|
return ProcSELinuxSetDeviceContext(client);
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
static int _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcSELinuxGetDeviceContext(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(SELinuxGetContextReq);
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetContextReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->id);
|
2010-07-27 13:02:24 -06:00
|
|
|
return ProcSELinuxGetDeviceContext(client);
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
static int _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcSELinuxGetDrawableContext(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(SELinuxGetContextReq);
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetContextReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->id);
|
2010-07-27 13:02:24 -06:00
|
|
|
return ProcSELinuxGetDrawableContext(client);
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
static int _X_COLD
|
2014-09-27 11:52:59 -06:00
|
|
|
SProcSELinuxGetPropertyContext(ClientPtr client, void *privKey)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
REQUEST(SELinuxGetPropertyContextReq);
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetPropertyContextReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->window);
|
|
|
|
swapl(&stuff->property);
|
2010-07-27 13:02:24 -06:00
|
|
|
return ProcSELinuxGetPropertyContext(client, privKey);
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
static int _X_COLD
|
2014-09-27 11:52:59 -06:00
|
|
|
SProcSELinuxGetSelectionContext(ClientPtr client, void *privKey)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
REQUEST(SELinuxGetContextReq);
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetContextReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->id);
|
2010-07-27 13:02:24 -06:00
|
|
|
return ProcSELinuxGetSelectionContext(client, privKey);
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
static int _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcSELinuxListProperties(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(SELinuxGetContextReq);
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetContextReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->id);
|
2010-07-27 13:02:24 -06:00
|
|
|
return ProcSELinuxListProperties(client);
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
static int _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcSELinuxGetClientContext(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(SELinuxGetContextReq);
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(SELinuxGetContextReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&stuff->id);
|
2010-07-27 13:02:24 -06:00
|
|
|
return ProcSELinuxGetClientContext(client);
|
|
|
|
}
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
static int _X_COLD
|
2010-07-27 13:02:24 -06:00
|
|
|
SProcSELinuxDispatch(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xReq);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
switch (stuff->data) {
|
|
|
|
case X_SELinuxQueryVersion:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxQueryVersion(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetDeviceCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxSetCreateContext(client, CTX_DEV);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetDeviceCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, CTX_DEV);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetDeviceContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxSetDeviceContext(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetDeviceContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxGetDeviceContext(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetDrawableCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxSetCreateContext(client, CTX_WIN);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetDrawableCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, CTX_WIN);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetDrawableContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxGetDrawableContext(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetPropertyCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxSetCreateContext(client, CTX_PRP);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetPropertyCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, CTX_PRP);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetPropertyUseContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxSetCreateContext(client, USE_PRP);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetPropertyUseContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, USE_PRP);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetPropertyContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxGetPropertyContext(client, objectKey);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetPropertyDataContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxGetPropertyContext(client, dataKey);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxListProperties:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxListProperties(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetSelectionCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxSetCreateContext(client, CTX_SEL);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetSelectionCreateContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, CTX_SEL);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxSetSelectionUseContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxSetCreateContext(client, USE_SEL);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetSelectionUseContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxGetCreateContext(client, USE_SEL);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetSelectionContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxGetSelectionContext(client, objectKey);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetSelectionDataContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxGetSelectionContext(client, dataKey);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxListSelections:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcSELinuxListSelections(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_SELinuxGetClientContext:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcSELinuxGetClientContext(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadRequest;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extension Setup / Teardown
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
SELinuxResetProc(ExtensionEntry * extEntry)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
SELinuxFlaskReset();
|
|
|
|
SELinuxLabelReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-07 11:28:45 -06:00
|
|
|
SELinuxExtensionInit(void)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
ExtensionEntry *extEntry;
|
|
|
|
|
|
|
|
/* Check SELinux mode on system, configuration file, and boolean */
|
|
|
|
if (!is_selinux_enabled()) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_INFO, "SELinux: Disabled on system\n");
|
|
|
|
return;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
if (selinuxEnforcingState == SELINUX_MODE_DISABLED) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_INFO, "SELinux: Disabled in configuration file\n");
|
|
|
|
return;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
if (!security_get_boolean_active("xserver_object_manager")) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LogMessage(X_INFO, "SELinux: Disabled by boolean\n");
|
2010-07-27 13:02:24 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up XACE hooks */
|
|
|
|
SELinuxLabelInit();
|
|
|
|
SELinuxFlaskInit();
|
|
|
|
|
|
|
|
/* Add extension to server */
|
|
|
|
extEntry = AddExtension(SELINUX_EXTENSION_NAME,
|
2012-06-10 07:21:05 -06:00
|
|
|
SELinuxNumberEvents, SELinuxNumberErrors,
|
|
|
|
ProcSELinuxDispatch, SProcSELinuxDispatch,
|
|
|
|
SELinuxResetProc, StandardMinorOpcode);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|