libcli/util: add tstream_full_request_u32 and tstream_full_request_u16
authorRalph Boehme <slow@samba.org>
Wed, 21 Sep 2016 21:27:14 +0000 (14:27 -0700)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 25 Oct 2023 22:23:38 +0000 (22:23 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
libcli/util/tstream.c
libcli/util/tstream.h

index dd830e2aa442d36afb2028599abebaa60a70c298..b4317f23ade162966a0b3aa80997156363a55a5b 100644 (file)
@@ -175,3 +175,30 @@ NTSTATUS tstream_read_pdu_blob_recv(struct tevent_req *req,
        return NT_STATUS_OK;
 }
 
+NTSTATUS tstream_full_request_u32(struct tstream_context *stream,
+                                 void *private_data,
+                                 DATA_BLOB blob, size_t *size)
+{
+       if (blob.length < 4) {
+               return STATUS_MORE_ENTRIES;
+       }
+       *size = 4 + RIVAL(blob.data, 0);
+       if (*size > blob.length) {
+               return STATUS_MORE_ENTRIES;
+       }
+       return NT_STATUS_OK;
+}
+
+NTSTATUS tstream_full_request_u16(struct tstream_context *stream,
+                                 void *private_data,
+                                 DATA_BLOB blob, size_t *size)
+{
+       if (blob.length < 2) {
+               return STATUS_MORE_ENTRIES;
+       }
+       *size = 2 + RSVAL(blob.data, 0);
+       if (*size > blob.length) {
+               return STATUS_MORE_ENTRIES;
+       }
+       return NT_STATUS_OK;
+}
index 3bf80f0e9256bf1435ebfd0cefbd06cee109e9f4..6d30e04c70adc9e579361cd47be433748ea7bdb0 100644 (file)
@@ -90,4 +90,31 @@ NTSTATUS tstream_read_pdu_blob_recv(struct tevent_req *req,
                                    TALLOC_CTX *mem_ctx,
                                    DATA_BLOB *pdu_blob);
 
+/**
+ * @brief Get a PDU size with a 32 bit size header field
+ *
+ * Work out if a packet is complete for protocols that use a 32 bit
+ * network byte order length.
+ *
+ * @see tstream_read_pdu_blob_send()
+ * @see tstream_read_pdu_blob_recv()
+ */
+NTSTATUS tstream_full_request_u32(struct tstream_context *stream,
+                                 void *private_data,
+                                 DATA_BLOB blob, size_t *size);
+
+/**
+ * @brief Get a PDU size with a 16 bit size header field
+ *
+ * Work out if a packet is complete for protocols that use a 16 bit
+ * network byte order length.
+ *
+ * @see tstream_read_pdu_blob_send()
+ * @see tstream_read_pdu_blob_recv()
+ */
+NTSTATUS tstream_full_request_u16(struct tstream_context *stream,
+                                 void *private_data,
+                                 DATA_BLOB blob, size_t *size);
+
+
 #endif /* _LIBCLI_UTIL_TSTREAM_H_ */