lib/util: add and use iov_concat
authorRalph Boehme <slow@samba.org>
Wed, 22 Feb 2017 16:21:15 +0000 (17:21 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 18 Apr 2017 20:54:15 +0000 (22:54 +0200)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/util/iov_buf.c
lib/util/iov_buf.h
lib/util/wscript_build
libcli/smb/smbXcli_base.c

index d260b2fea86100fe025963a30ebb93d4d07fe76c..592bc5d04986d0b2a00cb039d584d632d16764ab 100644 (file)
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/filesys.h"
 #include "iov_buf.h"
+#include <talloc.h>
 
 ssize_t iov_buflen(const struct iovec *iov, int iovcnt)
 {
@@ -90,3 +91,23 @@ bool iov_advance(struct iovec **iov, int *iovcnt, size_t n)
        *iovcnt = cnt;
        return true;
 }
+
+uint8_t *iov_concat(TALLOC_CTX *mem_ctx, const struct iovec *iov, int count)
+{
+       ssize_t buflen;
+       uint8_t *buf;
+
+       buflen = iov_buflen(iov, count);
+       if (buflen == -1) {
+               return NULL;
+       }
+
+       buf = talloc_array(mem_ctx, uint8_t, buflen);
+       if (buf == NULL) {
+               return NULL;
+       }
+
+       iov_buf(iov, count, buf, buflen);
+
+       return buf;
+}
index 8f0ca266da9439740d6eab537fde6d2c4396eec3..79b81b84779b662c255d0c0bf684fdd4914f3828 100644 (file)
 #ifndef __LIB_IOV_BUF_H__
 #define __LIB_IOV_BUF_H__
 
-#include <unistd.h>
-#include <stdint.h>
-#include <stdbool.h>
+#include "replace.h"
+#include <talloc.h>
 
 ssize_t iov_buflen(const struct iovec *iov, int iovlen);
 ssize_t iov_buf(const struct iovec *iov, int iovcnt,
                uint8_t *buf, size_t buflen);
 bool iov_advance(struct iovec **iov, int *iovcnt, size_t n);
+uint8_t *iov_concat(TALLOC_CTX *mem_ctx, const struct iovec *iov, int count);
 
 #endif
index 91505eb1b44b796f49ce0fb98d82fa4ba16c1f63..d09394736ac584fd596dbd80421cb87731309872 100644 (file)
@@ -78,6 +78,7 @@ bld.SAMBA_SUBSYSTEM('samba-util-core',
 
 bld.SAMBA_LIBRARY('iov_buf',
                   source='iov_buf.c',
+                  deps='talloc',
                   local_include=False,
                   private_library=True)
 
index 1fcf11e6c93d6a6642ab85a4c424e656af1379bb..1ec11a9dec49979899dc5b2adf2a40be908fbfba 100644 (file)
@@ -1343,28 +1343,6 @@ static size_t smbXcli_iov_len(const struct iovec *iov, int count)
        return ret;
 }
 
-static uint8_t *smbXcli_iov_concat(TALLOC_CTX *mem_ctx,
-                                  const struct iovec *iov,
-                                  int count)
-{
-       ssize_t buflen;
-       uint8_t *buf;
-
-       buflen = iov_buflen(iov, count);
-       if (buflen == -1) {
-               return NULL;
-       }
-
-       buf = talloc_array(mem_ctx, uint8_t, buflen);
-       if (buf == NULL) {
-               return NULL;
-       }
-
-       iov_buf(iov, count, buf, buflen);
-
-       return buf;
-}
-
 static void smb1cli_req_flags(enum protocol_types protocol,
                              uint32_t smb1_capabilities,
                              uint8_t smb_command,
@@ -1647,7 +1625,7 @@ static NTSTATUS smb1cli_conn_signv(struct smbXcli_conn *conn,
 
        frame = talloc_stackframe();
 
-       buf = smbXcli_iov_concat(frame, &iov[1], iov_count - 1);
+       buf = iov_concat(frame, &iov[1], iov_count - 1);
        if (buf == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -1739,7 +1717,7 @@ static NTSTATUS smb1cli_req_writev_submit(struct tevent_req *req,
        if (common_encryption_on(state->conn->smb1.trans_enc)) {
                char *buf, *enc_buf;
 
-               buf = (char *)smbXcli_iov_concat(talloc_tos(), iov, iov_count);
+               buf = (char *)iov_concat(talloc_tos(), iov, iov_count);
                if (buf == NULL) {
                        return NT_STATUS_NO_MEMORY;
                }