Xext: selinux: use REPLY_*() macros for preparing / sending replies

Use the new macros for preparing and sending replies to clients.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-07-08 17:27:02 +02:00
parent 105ee0f8ac
commit a9f50509bc

View File

@ -69,19 +69,13 @@ static int
ProcSELinuxQueryVersion(ClientPtr client)
{
SELinuxQueryVersionReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.server_major = SELINUX_MAJOR_VERSION,
.server_minor = SELINUX_MINOR_VERSION
};
if (client->swapped) {
swaps(&rep.sequenceNumber);
swapl(&rep.length);
swaps(&rep.server_major);
swaps(&rep.server_minor);
}
WriteToClient(client, sizeof(rep), &rep);
return Success;
REPLY_FIELD_CARD16(server_major);
REPLY_FIELD_CARD16(server_minor);
REPLY_SEND_RET_SUCCESS();
}
static int
@ -97,20 +91,11 @@ SELinuxSendContextReply(ClientPtr client, security_id_t sid)
}
SELinuxGetContextReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.length = bytes_to_int32(len),
.context_len = len
};
if (client->swapped) {
swapl(&rep.length);
swaps(&rep.sequenceNumber);
swapl(&rep.context_len);
}
WriteToClient(client, sizeof(SELinuxGetContextReply), &rep);
WriteToClient(client, len, ctx);
REPLY_FIELD_CARD32(context_len);
REPLY_SEND_EXTRA(ctx, len);
freecon(ctx);
return Success;
}
@ -361,18 +346,15 @@ SELinuxSendItemsToClient(ClientPtr client, SELinuxListItemRec * items,
/* Fill in the buffer */
for (k = 0; k < count; k++) {
buf[pos] = items[k].id;
if (client->swapped)
swapl(buf + pos);
REPLY_BUF_CARD32(buf + pos, 1);
pos++;
buf[pos] = items[k].octx_len * 4;
if (client->swapped)
swapl(buf + pos);
REPLY_BUF_CARD32(buf + pos, 1);
pos++;
buf[pos] = items[k].dctx_len * 4;
if (client->swapped)
swapl(buf + pos);
REPLY_BUF_CARD32(buf + pos, 1);
pos++;
memcpy((char *) (buf + pos), items[k].octx, strlen(items[k].octx) + 1);
@ -384,20 +366,11 @@ SELinuxSendItemsToClient(ClientPtr client, SELinuxListItemRec * items,
sendreply: ;
/* Send reply to client */
SELinuxListItemsReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.length = size,
.count = count
};
if (client->swapped) {
swapl(&rep.length);
swaps(&rep.sequenceNumber);
swapl(&rep.count);
}
WriteToClient(client, sizeof(SELinuxListItemsReply), &rep);
WriteToClient(client, size * 4, buf);
REPLY_FIELD_CARD32(count);
REPLY_SEND_EXTRA(buf, size * sizeof(CARD32));
/* Free stuff and return */
SELinuxFreeItems(items, count);