From a9f50509bc3589103f5814981de34317f6e617fb Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 8 Jul 2024 17:27:02 +0200 Subject: [PATCH] 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 --- Xext/xselinux_ext.c | 49 ++++++++++----------------------------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/Xext/xselinux_ext.c b/Xext/xselinux_ext.c index e8035e574..6c6444b06 100644 --- a/Xext/xselinux_ext.c +++ b/Xext/xselinux_ext.c @@ -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);