diff options
author | Volker Lendecke <vl@samba.org> | 2014-11-19 14:25:56 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2014-12-07 00:12:07 +0100 |
commit | 0013001e702a091b102c3a9a531d12e1d8d97828 (patch) | |
tree | bb3707402337503a55b8e63f83e531c065971173 /source3 | |
parent | 214fc09a3443ab62772666a985975fa548b215fa (diff) | |
download | samba-0013001e702a091b102c3a9a531d12e1d8d97828.tar.gz samba-0013001e702a091b102c3a9a531d12e1d8d97828.tar.xz samba-0013001e702a091b102c3a9a531d12e1d8d97828.zip |
lib: Split out write_data[_iov]
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/proto.h | 2 | ||||
-rw-r--r-- | source3/lib/ctdbd_conn.c | 1 | ||||
-rw-r--r-- | source3/lib/sys_rw_data.c | 107 | ||||
-rw-r--r-- | source3/lib/sys_rw_data.h | 33 | ||||
-rw-r--r-- | source3/lib/util.c | 1 | ||||
-rw-r--r-- | source3/lib/util_sock.c | 82 | ||||
-rw-r--r-- | source3/modules/vfs_aio_fork.c | 1 | ||||
-rw-r--r-- | source3/modules/vfs_preopen.c | 1 | ||||
-rw-r--r-- | source3/modules/vfs_smb_traffic_analyzer.c | 1 | ||||
-rw-r--r-- | source3/nmbd/asyncdns.c | 1 | ||||
-rw-r--r-- | source3/printing/printing.c | 1 | ||||
-rw-r--r-- | source3/smbd/process.c | 1 | ||||
-rw-r--r-- | source3/smbd/reply.c | 1 | ||||
-rw-r--r-- | source3/smbd/smb2_read.c | 1 | ||||
-rw-r--r-- | source3/torture/torture.c | 1 | ||||
-rw-r--r-- | source3/utils/smbfilter.c | 1 | ||||
-rw-r--r-- | source3/winbindd/winbindd_dual.c | 1 | ||||
-rwxr-xr-x | source3/wscript_build | 4 |
18 files changed, 156 insertions, 85 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index d9815f49f1..82b2fb5b31 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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, diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c index 7bdb37664f..c41ec530a7 100644 --- a/source3/lib/ctdbd_conn.c +++ b/source3/lib/ctdbd_conn.c @@ -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 index 0000000000..f7bedb3740 --- /dev/null +++ b/source3/lib/sys_rw_data.c @@ -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 index 0000000000..fc97573dcb --- /dev/null +++ b/source3/lib/sys_rw_data.h @@ -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 diff --git a/source3/lib/util.c b/source3/lib/util.c index 49eef505ad..b64b32b9a7 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -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> diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 163045a8a2..682d964b30 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -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) { @@ -204,86 +204,6 @@ NTSTATUS read_data_ntstatus(int fd, char *buffer, size_t N) } /**************************************************************************** - 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). ****************************************************************************/ diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c index c2148a104f..39334bc33a 100644 --- a/source3/modules/vfs_aio_fork.c +++ b/source3/modules/vfs_aio_fork.c @@ -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 diff --git a/source3/modules/vfs_preopen.c b/source3/modules/vfs_preopen.c index 612b0252e2..cc38a90d7c 100644 --- a/source3/modules/vfs_preopen.c +++ b/source3/modules/vfs_preopen.c @@ -21,6 +21,7 @@ #include "includes.h" #include "system/filesys.h" #include "smbd/smbd.h" +#include "lib/sys_rw_data.h" struct preopen_state; diff --git a/source3/modules/vfs_smb_traffic_analyzer.c b/source3/modules/vfs_smb_traffic_analyzer.c index 92a176265b..06ff1f6956 100644 --- a/source3/modules/vfs_smb_traffic_analyzer.c +++ b/source3/modules/vfs_smb_traffic_analyzer.c @@ -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}; diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 4468c7ba5d..5973c8efc0 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -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. diff --git a/source3/printing/printing.c b/source3/printing/printing.c index 5d053cc71e..61afa2881f 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -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; diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c7f0e9ade9..a761669aef 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -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" diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index cd13d68092..0b6c102448 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -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 diff --git a/source3/smbd/smb2_read.c b/source3/smbd/smb2_read.c index 470e496631..4e974a2eee 100644 --- a/source3/smbd/smb2_read.c +++ b/source3/smbd/smb2_read.c @@ -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, diff --git a/source3/torture/torture.c b/source3/torture/torture.c index f90f882093..27146555d1 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -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; diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index e06fee6b9a..ff966a8c59 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -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 diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c index 43a27b3f4d..35838e6a15 100644 --- a/source3/winbindd/winbindd_dual.c +++ b/source3/winbindd/winbindd_dual.c @@ -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 diff --git a/source3/wscript_build b/source3/wscript_build index 591b1be77e..18f6b6db7c 100755 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -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', |