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