lib: Split out write_data[_iov]
authorVolker Lendecke <vl@samba.org>
Wed, 19 Nov 2014 14:25:56 +0000 (14:25 +0000)
committerJeremy Allison <jra@samba.org>
Sat, 6 Dec 2014 23:12:07 +0000 (00:12 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
18 files changed:
source3/include/proto.h
source3/lib/ctdbd_conn.c
source3/lib/sys_rw_data.c [new file with mode: 0644]
source3/lib/sys_rw_data.h [new file with mode: 0644]
source3/lib/util.c
source3/lib/util_sock.c
source3/modules/vfs_aio_fork.c
source3/modules/vfs_preopen.c
source3/modules/vfs_smb_traffic_analyzer.c
source3/nmbd/asyncdns.c
source3/printing/printing.c
source3/smbd/process.c
source3/smbd/reply.c
source3/smbd/smb2_read.c
source3/torture/torture.c
source3/utils/smbfilter.c
source3/winbindd/winbindd_dual.c
source3/wscript_build

index d9815f49f164a774e6b99cb169af64afede7bbf5..82b2fb5b31005c26b8a07495422973c77d86abc0 100644 (file)
@@ -567,8 +567,6 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
                                  size_t *size_ret);
 NTSTATUS read_data_ntstatus(int fd, char *buffer, size_t N);
 
-ssize_t write_data(int fd, const char *buffer, size_t N);
-ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt);
 bool send_keepalive(int client);
 NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf,
                                          unsigned int timeout,
index 7bdb37664f8d0ebc9509a99d11aeba09a46e56af..c41ec530a7b336727e17d8f76e37430ea16dc81b 100644 (file)
@@ -23,6 +23,7 @@
 #include "serverid.h"
 #include "ctdbd_conn.h"
 #include "system/select.h"
+#include "lib/sys_rw_data.h"
 
 #include "messages.h"
 
diff --git a/source3/lib/sys_rw_data.c b/source3/lib/sys_rw_data.c
new file mode 100644 (file)
index 0000000..f7bedb3
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba system utilities
+ * Copyright (C) Andrew Tridgell 1992-1998
+ * Copyright (C) Jeremy Allison  1998-2005
+ * Copyright (C) Timur Bakeyev        2005
+ * Copyright (C) Bjoern Jacke    2006-2007
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "system/filesys.h"
+#include "lib/sys_rw_data.h"
+#include "lib/sys_rw.h"
+#include "lib/iov_buf.h"
+
+/****************************************************************************
+ Write all data from an iov array
+ NB. This can be called with a non-socket fd, don't add dependencies
+ on socket calls.
+****************************************************************************/
+
+ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt)
+{
+       ssize_t to_send;
+       ssize_t thistime;
+       size_t sent;
+       struct iovec iov_copy[iovcnt];
+       struct iovec *iov;
+
+       to_send = iov_buflen(orig_iov, iovcnt);
+       if (to_send == -1) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       thistime = sys_writev(fd, orig_iov, iovcnt);
+       if ((thistime <= 0) || (thistime == to_send)) {
+               return thistime;
+       }
+       sent = thistime;
+
+       /*
+        * We could not send everything in one call. Make a copy of iov that
+        * we can mess with. We keep a copy of the array start in iov_copy for
+        * the TALLOC_FREE, because we're going to modify iov later on,
+        * discarding elements.
+        */
+
+       memcpy(iov_copy, orig_iov, sizeof(struct iovec) * iovcnt);
+       iov = iov_copy;
+
+       while (sent < to_send) {
+               /*
+                * We have to discard "thistime" bytes from the beginning
+                * iov array, "thistime" contains the number of bytes sent
+                * via writev last.
+                */
+               while (thistime > 0) {
+                       if (thistime < iov[0].iov_len) {
+                               char *new_base =
+                                       (char *)iov[0].iov_base + thistime;
+                               iov[0].iov_base = (void *)new_base;
+                               iov[0].iov_len -= thistime;
+                               break;
+                       }
+                       thistime -= iov[0].iov_len;
+                       iov += 1;
+                       iovcnt -= 1;
+               }
+
+               thistime = sys_writev(fd, iov, iovcnt);
+               if (thistime <= 0) {
+                       break;
+               }
+               sent += thistime;
+       }
+
+       return sent;
+}
+
+/****************************************************************************
+ Write data to a fd.
+ NB. This can be called with a non-socket fd, don't add dependencies
+ on socket calls.
+****************************************************************************/
+
+ssize_t write_data(int fd, const char *buffer, size_t n)
+{
+       struct iovec iov;
+
+       iov.iov_base = discard_const_p(void, buffer);
+       iov.iov_len = n;
+       return write_data_iov(fd, &iov, 1);
+}
diff --git a/source3/lib/sys_rw_data.h b/source3/lib/sys_rw_data.h
new file mode 100644 (file)
index 0000000..fc97573
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba system utilities
+ * Copyright (C) Andrew Tridgell 1992-1998
+ * Copyright (C) Jeremy Allison  1998-2005
+ * Copyright (C) Timur Bakeyev        2005
+ * Copyright (C) Bjoern Jacke    2006-2007
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LIB_SYS_RW_DATA_H__
+#define __LIB_SYS_RW_DATA_H__
+
+#include <unistd.h>
+
+struct iovec;
+
+ssize_t write_data_iov(int fd, const struct iovec *iov, int iovcnt);
+ssize_t write_data(int fd, const char *buffer, size_t n);
+
+#endif
index 49eef505ad329df888661e5ef3f06ba8db0dacec..b64b32b9a792088f2af409c889cfae2d50b3f392 100644 (file)
@@ -32,6 +32,7 @@
 #include "libcli/security/security.h"
 #include "serverid.h"
 #include "lib/sys_rw.h"
+#include "lib/sys_rw_data.h"
 
 #ifdef HAVE_SYS_PRCTL_H
 #include <sys/prctl.h>
index 163045a8a2c043a72652fdb7777c2890bbdcedd6..682d964b30c8eee95fa7c9d467ed3ad0076625b7 100644 (file)
@@ -29,7 +29,7 @@
 #include "../lib/util/tevent_ntstatus.h"
 #include "../lib/tsocket/tsocket.h"
 #include "lib/sys_rw.h"
-#include "lib/iov_buf.h"
+#include "lib/sys_rw_data.h"
 
 const char *client_addr(int fd, char *addr, size_t addrlen)
 {
@@ -203,86 +203,6 @@ NTSTATUS read_data_ntstatus(int fd, char *buffer, size_t N)
        return read_fd_with_timeout(fd, buffer, N, N, 0, NULL);
 }
 
-/****************************************************************************
- Write all data from an iov array
- NB. This can be called with a non-socket fd, don't add dependencies
- on socket calls.
-****************************************************************************/
-
-ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt)
-{
-       ssize_t to_send;
-       ssize_t thistime;
-       size_t sent;
-       struct iovec iov_copy[iovcnt];
-       struct iovec *iov;
-
-       to_send = iov_buflen(orig_iov, iovcnt);
-       if (to_send == -1) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       thistime = sys_writev(fd, orig_iov, iovcnt);
-       if ((thistime <= 0) || (thistime == to_send)) {
-               return thistime;
-       }
-       sent = thistime;
-
-       /*
-        * We could not send everything in one call. Make a copy of iov that
-        * we can mess with. We keep a copy of the array start in iov_copy for
-        * the TALLOC_FREE, because we're going to modify iov later on,
-        * discarding elements.
-        */
-
-       memcpy(iov_copy, orig_iov, sizeof(struct iovec) * iovcnt);
-       iov = iov_copy;
-
-       while (sent < to_send) {
-               /*
-                * We have to discard "thistime" bytes from the beginning
-                * iov array, "thistime" contains the number of bytes sent
-                * via writev last.
-                */
-               while (thistime > 0) {
-                       if (thistime < iov[0].iov_len) {
-                               char *new_base =
-                                       (char *)iov[0].iov_base + thistime;
-                               iov[0].iov_base = (void *)new_base;
-                               iov[0].iov_len -= thistime;
-                               break;
-                       }
-                       thistime -= iov[0].iov_len;
-                       iov += 1;
-                       iovcnt -= 1;
-               }
-
-               thistime = sys_writev(fd, iov, iovcnt);
-               if (thistime <= 0) {
-                       break;
-               }
-               sent += thistime;
-       }
-
-       return sent;
-}
-
-/****************************************************************************
- Write data to a fd.
- NB. This can be called with a non-socket fd, don't add dependencies
- on socket calls.
-****************************************************************************/
-
-ssize_t write_data(int fd, const char *buffer, size_t N)
-{
-       struct iovec iov;
-
-       iov.iov_base = discard_const_p(void, buffer);
-       iov.iov_len = N;
-       return write_data_iov(fd, &iov, 1);
-}
-
 /****************************************************************************
  Send a keepalive packet (rfc1002).
 ****************************************************************************/
index c2148a104fb8f100ed5376ff09a76c927fba6de2..39334bc33a52ae964bab8a83bb2b0282a397f6d5 100644 (file)
@@ -27,6 +27,7 @@
 #include "lib/async_req/async_sock.h"
 #include "lib/util/tevent_unix.h"
 #include "lib/sys_rw.h"
+#include "lib/sys_rw_data.h"
 
 #if !defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) && !defined(HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS)
 # error Can not pass file descriptors
index 612b0252e220e5aa097fdf27d6c7c6e0ea751784..cc38a90d7c1871f638efe4d464dd96e562f9950d 100644 (file)
@@ -21,6 +21,7 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "smbd/smbd.h"
+#include "lib/sys_rw_data.h"
 
 struct preopen_state;
 
index 92a176265b4be5070de4e6a80ab7de0248ffb14d..06ff1f6956da98179ecc7a826d54bdc2305845bb 100644 (file)
@@ -29,6 +29,7 @@
 #include "../librpc/gen_ndr/ndr_netlogon.h"
 #include "auth.h"
 #include "../lib/tsocket/tsocket.h"
+#include "lib/sys_rw_data.h"
 
 /* abstraction for the send_over_network function */
 enum sock_type {INTERNET_SOCKET = 0, UNIX_DOMAIN_SOCKET};
index 4468c7ba5d49cb48540a21aea2a7985bddf51620..5973c8efc06669051a7a4764fe3395bd6d6ca802 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "includes.h"
 #include "nmbd/nmbd.h"
+#include "lib/sys_rw_data.h"
 
 /***************************************************************************
   Add a DNS result to the name cache.
index 5d053cc71ea8fce991fe92a868680c3e12499493..61afa2881f081a31818c5268a979d302df8a792d 100644 (file)
@@ -36,6 +36,7 @@
 #include "messages.h"
 #include "util_tdb.h"
 #include "lib/param/loadparm.h"
+#include "lib/sys_rw_data.h"
 
 extern struct current_user current_user;
 extern userdom_struct current_user_info;
index c7f0e9ade9ad2717d27d49b54162440deaf431fe..a761669aefa73d3d0b9f7a0d4ec810671b999528 100644 (file)
@@ -39,6 +39,7 @@
 #include "../libcli/security/dom_sid.h"
 #include "../libcli/security/security_token.h"
 #include "lib/id_cache.h"
+#include "lib/sys_rw_data.h"
 #include "serverid.h"
 #include "system/threads.h"
 
index cd13d68092dbb8c06dd51efe4f1a5fdd96960ee9..0b6c1024481fc31f7a173cfc338489eb678ca69c 100644 (file)
@@ -43,6 +43,7 @@
 #include "../lib/tsocket/tsocket.h"
 #include "lib/tevent_wait.h"
 #include "libcli/smb/smb_signing.h"
+#include "lib/sys_rw_data.h"
 
 /****************************************************************************
  Ensure we check the path in *exactly* the same way as W2K for a findfirst/findnext
index 470e496631e8707833f5d55ee72e6a8534c2934a..4e974a2eee1c5ac0f258338a6068e552c8f36935 100644 (file)
@@ -26,6 +26,7 @@
 #include "libcli/security/security.h"
 #include "../lib/util/tevent_ntstatus.h"
 #include "rpc_server/srv_pipe_hnd.h"
+#include "lib/sys_rw_data.h"
 
 static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
                                              struct tevent_context *ev,
index f90f882093f56944868cc665b96e1b2a43c8b3ea..27146555d105a1abdf921a4e9e8933bb428a9948 100644 (file)
@@ -41,6 +41,7 @@
 #include "util_tdb.h"
 #include "../libcli/smb/read_smb.h"
 #include "../libcli/smb/smbXcli_base.h"
+#include "lib/sys_rw_data.h"
 
 extern char *optarg;
 extern int optind;
index e06fee6b9ad78c172af240f2d6fd62f730ccded6..ff966a8c592fc54842206352ad28feb5d1e39db7 100644 (file)
@@ -22,6 +22,7 @@
 #include "system/select.h"
 #include "../lib/util/select.h"
 #include "libsmb/nmblib.h"
+#include "lib/sys_rw_data.h"
 
 #define SECURITY_MASK 0
 #define SECURITY_SET  0
index 43a27b3f4da6e45dd9427ea3eb556cabfcf59dc6..35838e6a15e41b97be7f06c6cdd8e233d841ae6c 100644 (file)
@@ -39,6 +39,7 @@
 #include "../lib/util/tevent_unix.h"
 #include "lib/param/loadparm.h"
 #include "lib/sys_rw.h"
+#include "lib/sys_rw_data.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
index 591b1be77e3bcb74b3e78e7a7e13b0f01ceeb43b..18f6b6db7c58065c552dcd30117e6292a3b7813c 100755 (executable)
@@ -254,8 +254,8 @@ bld.SAMBA3_SUBSYSTEM('KRBCLIENT',
                      public_deps='krb5samba k5crypto gssapi LIBTSOCKET CLDAP LIBNMB')
 
 bld.SAMBA3_LIBRARY('sys_rw',
-                   source='lib/sys_rw.c',
-                   deps='replace',
+                   source='lib/sys_rw.c lib/sys_rw_data.c',
+                   deps='replace iov_buf',
                    private_library=True)
 
 bld.SAMBA3_LIBRARY('iov_buf',