Blob Blame History Raw
From 3b0e48c33c6b43688ff46fed576266cfe6362595 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Thu, 8 Oct 2020 13:25:17 +0200
Subject: [PATCH 21/27] packet: add sss_packet_set_body

Reviewed-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Sumit Bose <sbose@redhat.com>
---
 src/responder/common/responder_packet.c | 19 +++++++++++++++++++
 src/responder/common/responder_packet.h |  5 +++++
 2 files changed, 24 insertions(+)

diff --git a/src/responder/common/responder_packet.c b/src/responder/common/responder_packet.c
index ab15b1dac..f56d92276 100644
--- a/src/responder/common/responder_packet.c
+++ b/src/responder/common/responder_packet.c
@@ -302,6 +302,25 @@ void sss_packet_get_body(struct sss_packet *packet, uint8_t **body, size_t *blen
     *blen = sss_packet_get_len(packet) - SSS_NSS_HEADER_SIZE;
 }
 
+errno_t sss_packet_set_body(struct sss_packet *packet,
+                            uint8_t *body,
+                            size_t blen)
+{
+    uint8_t *pbody;
+    size_t plen;
+    errno_t ret;
+
+    ret = sss_packet_grow(packet, blen);
+    if (ret != EOK) {
+        return ret;
+    }
+
+    sss_packet_get_body(packet, &pbody, &plen);
+    memcpy(pbody, body, blen);
+
+    return EOK;
+}
+
 void sss_packet_set_error(struct sss_packet *packet, int error)
 {
     SAFEALIGN_SETMEM_UINT32(packet->buffer + SSS_PACKET_ERR_OFFSET, error,
diff --git a/src/responder/common/responder_packet.h b/src/responder/common/responder_packet.h
index afceb4aae..509a22a9a 100644
--- a/src/responder/common/responder_packet.h
+++ b/src/responder/common/responder_packet.h
@@ -42,4 +42,9 @@ uint32_t sss_packet_get_status(struct sss_packet *packet);
 void sss_packet_get_body(struct sss_packet *packet, uint8_t **body, size_t *blen);
 void sss_packet_set_error(struct sss_packet *packet, int error);
 
+/* Grow packet and set its body. */
+errno_t sss_packet_set_body(struct sss_packet *packet,
+                            uint8_t *body,
+                            size_t blen);
+
 #endif /* __SSSSRV_PACKET_H__ */
-- 
2.21.3