[PATCH] cleanup patches
Volker Lendecke
Volker.Lendecke at SerNet.DE
Wed Dec 3 09:19:45 MST 2014
Hi!
Attached find a few innocent cleanup patches from my notify
branch.
I'd appreciate review&push!
Thanks,
Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From c3964f42b9e54293293436f4dba0945516784816 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 21 Nov 2014 16:20:10 +0100
Subject: [PATCH 01/10] ctdbd_conn: Accept msgs to all registered srvids
register_with_ctdbd tells ctdbd_conn what we listen on. Avoid having to
explicitly filter.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ctdbd_conn.c | 43 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index a26f410..5dc007b 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -54,6 +54,7 @@ struct ctdbd_connection {
uint32_t reqid;
uint32_t our_vnn;
uint64_t rand_srvid;
+ uint64_t *srvids;
int fd;
struct tevent_fd *fde;
@@ -109,10 +110,43 @@ static void ctdb_packet_dump(struct ctdb_req_header *hdr)
NTSTATUS register_with_ctdbd(struct ctdbd_connection *conn, uint64_t srvid)
{
+ NTSTATUS status;
int cstatus;
- return ctdbd_control(conn, CTDB_CURRENT_NODE,
- CTDB_CONTROL_REGISTER_SRVID, srvid, 0,
- tdb_null, NULL, NULL, &cstatus);
+ size_t num_srvids;
+ uint64_t *tmp;
+
+ status = ctdbd_control(conn, CTDB_CURRENT_NODE,
+ CTDB_CONTROL_REGISTER_SRVID, srvid, 0,
+ tdb_null, NULL, NULL, &cstatus);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ num_srvids = talloc_array_length(conn->srvids);
+
+ tmp = talloc_realloc(conn, conn->srvids, uint64_t,
+ num_srvids + 1);
+ if (tmp == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ conn->srvids = tmp;
+
+ conn->srvids[num_srvids] = srvid;
+ return NT_STATUS_OK;
+}
+
+static bool ctdb_is_our_srvid(struct ctdbd_connection *conn, uint64_t srvid)
+{
+ size_t i, num_srvids;
+
+ num_srvids = talloc_array_length(conn->srvids);
+
+ for (i=0; i<num_srvids; i++) {
+ if (srvid == conn->srvids[i]) {
+ return true;
+ }
+ }
+ return false;
}
/*
@@ -661,8 +695,7 @@ static NTSTATUS ctdb_handle_message(struct messaging_context *msg_ctx,
return NT_STATUS_OK;
}
- /* only messages to our pid or the broadcast are valid here */
- if (msg->srvid != getpid() && msg->srvid != MSG_SRVID_SAMBA) {
+ if (!ctdb_is_our_srvid(conn, msg->srvid)) {
DEBUG(0,("Got unexpected message with srvid=%llu\n",
(unsigned long long)msg->srvid));
return NT_STATUS_OK;
--
1.7.9.5
From 29c29d750e6f1c2d6cc91e7827f81c368112c1bd Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 3 Dec 2014 15:54:19 +0100
Subject: [PATCH 02/10] lib: Fix signed/unsigned comparisons
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/util/data_blob.c | 4 ++--
lib/util/util.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/util/data_blob.c b/lib/util/data_blob.c
index 1b0e6ab..4723669 100644
--- a/lib/util/data_blob.c
+++ b/lib/util/data_blob.c
@@ -135,7 +135,7 @@ print the data_blob as hex string
**/
_PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
{
- int i;
+ size_t i;
char *hex_string;
hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1);
@@ -155,7 +155,7 @@ _PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *
_PUBLIC_ char *data_blob_hex_string_upper(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)
{
- int i;
+ size_t i;
char *hex_string;
hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1);
diff --git a/lib/util/util.c b/lib/util/util.c
index 157a4aa..562f7df 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -732,7 +732,7 @@ _PUBLIC_ void dump_data_pw(const char *msg, const uint8_t * data, size_t len)
*/
_PUBLIC_ bool all_zero(const uint8_t *ptr, size_t size)
{
- int i;
+ size_t i;
if (!ptr) return true;
for (i=0;i<size;i++) {
if (ptr[i]) return false;
--
1.7.9.5
From d6ebf3a98423dedaf78a2042717e8373edb10fe5 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 3 Dec 2014 16:02:35 +0100
Subject: [PATCH 03/10] ctdb: ctdb_protocol.h references struct sockaddr
Signed-off-by: Volker Lendecke <vl at samba.org>
---
ctdb/include/ctdb_protocol.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/ctdb/include/ctdb_protocol.h b/ctdb/include/ctdb_protocol.h
index 725e426..db365b4 100644
--- a/ctdb/include/ctdb_protocol.h
+++ b/ctdb/include/ctdb_protocol.h
@@ -20,6 +20,8 @@
#ifndef _CTDB_PROTOCOL_H
#define _CTDB_PROTOCOL_H
+#include <sys/socket.h>
+
/* location of daemon socket, set at configure time */
#ifdef SOCKPATH
#define CTDB_SOCKET SOCKPATH
--
1.7.9.5
From 4a43a431c5a817ffcc8076635f3047b0f80c88e0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Nov 2014 13:33:06 +0000
Subject: [PATCH 04/10] lib: Split out sys_[read|write] & friends
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/proto.h | 5 --
source3/lib/recvfile.c | 1 +
source3/lib/sys_rw.c | 101 ++++++++++++++++++++++++++
source3/lib/sys_rw.h | 36 +++++++++
source3/lib/system.c | 90 -----------------------
source3/lib/util.c | 1 +
source3/lib/util_file.c | 1 +
source3/lib/util_sock.c | 1 +
source3/lib/util_transfer_file.c | 1 +
source3/libsmb/unexpected.c | 1 +
source3/modules/vfs_aio_fork.c | 1 +
source3/modules/vfs_aio_linux.c | 1 +
source3/modules/vfs_aio_posix.c | 1 +
source3/modules/vfs_default.c | 1 +
source3/modules/vfs_fruit.c | 1 +
source3/printing/print_cups.c | 1 +
source3/rpc_server/samr/srv_samr_chgpasswd.c | 1 +
source3/smbd/scavenger.c | 1 +
source3/winbindd/winbindd_dual.c | 1 +
source3/wscript_build | 7 +-
20 files changed, 158 insertions(+), 96 deletions(-)
create mode 100644 source3/lib/sys_rw.c
create mode 100644 source3/lib/sys_rw.h
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 82e1032..68a3053 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -242,11 +242,6 @@ int sys_set_nfs_quota(const char *path, const char *bdev,
/* The following definitions come from lib/system.c */
-ssize_t sys_read(int fd, void *buf, size_t count);
-ssize_t sys_write(int fd, const void *buf, size_t count);
-ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt);
-ssize_t sys_pread(int fd, void *buf, size_t count, off_t off);
-ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off);
ssize_t sys_send(int s, const void *msg, size_t len, int flags);
ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
int sys_fcntl_ptr(int fd, int cmd, void *arg);
diff --git a/source3/lib/recvfile.c b/source3/lib/recvfile.c
index 273c51f..403d5e8 100644
--- a/source3/lib/recvfile.c
+++ b/source3/lib/recvfile.c
@@ -25,6 +25,7 @@
#include "includes.h"
#include "system/filesys.h"
+#include "lib/sys_rw.h"
/* Do this on our own in TRANSFER_BUF_SIZE chunks.
* It's safe to make direct syscalls to lseek/write here
diff --git a/source3/lib/sys_rw.c b/source3/lib/sys_rw.c
new file mode 100644
index 0000000..6d8f149
--- /dev/null
+++ b/source3/lib/sys_rw.c
@@ -0,0 +1,101 @@
+/*
+ * 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.h"
+
+/*******************************************************************
+A read wrapper that will deal with EINTR/EWOULDBLOCK
+********************************************************************/
+
+ssize_t sys_read(int fd, void *buf, size_t count)
+{
+ ssize_t ret;
+
+ do {
+ ret = read(fd, buf, count);
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
+ errno == EWOULDBLOCK));
+
+ return ret;
+}
+
+/*******************************************************************
+A write wrapper that will deal with EINTR/EWOULDBLOCK.
+********************************************************************/
+
+ssize_t sys_write(int fd, const void *buf, size_t count)
+{
+ ssize_t ret;
+
+ do {
+ ret = write(fd, buf, count);
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
+ errno == EWOULDBLOCK));
+
+ return ret;
+}
+
+/*******************************************************************
+A writev wrapper that will deal with EINTR.
+********************************************************************/
+
+ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt)
+{
+ ssize_t ret;
+
+ do {
+ ret = writev(fd, iov, iovcnt);
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
+ errno == EWOULDBLOCK));
+
+ return ret;
+}
+
+/*******************************************************************
+A pread wrapper that will deal with EINTR
+********************************************************************/
+
+ssize_t sys_pread(int fd, void *buf, size_t count, off_t off)
+{
+ ssize_t ret;
+
+ do {
+ ret = pread(fd, buf, count, off);
+ } while (ret == -1 && errno == EINTR);
+ return ret;
+}
+
+/*******************************************************************
+A write wrapper that will deal with EINTR
+********************************************************************/
+
+ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off)
+{
+ ssize_t ret;
+
+ do {
+ ret = pwrite(fd, buf, count, off);
+ } while (ret == -1 && errno == EINTR);
+ return ret;
+}
diff --git a/source3/lib/sys_rw.h b/source3/lib/sys_rw.h
new file mode 100644
index 0000000..ee1584e
--- /dev/null
+++ b/source3/lib/sys_rw.h
@@ -0,0 +1,36 @@
+/*
+ * 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_H__
+#define __LIB_SYS_RW_H__
+
+#include <unistd.h>
+
+struct iovec;
+
+ssize_t sys_read(int fd, void *buf, size_t count);
+ssize_t sys_write(int fd, const void *buf, size_t count);
+ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt);
+ssize_t sys_pread(int fd, void *buf, size_t count, off_t off);
+ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off);
+
+#endif
diff --git a/source3/lib/system.c b/source3/lib/system.c
index 6478e6f..7531d77 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -50,96 +50,6 @@
expansions/etc make sense to the OS should be acceptable to Samba.
*/
-
-
-/*******************************************************************
-A read wrapper that will deal with EINTR.
-********************************************************************/
-
-ssize_t sys_read(int fd, void *buf, size_t count)
-{
- ssize_t ret;
-
- do {
- ret = read(fd, buf, count);
- } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-
- return ret;
-}
-
-/*******************************************************************
-A write wrapper that will deal with EINTR.
-********************************************************************/
-
-ssize_t sys_write(int fd, const void *buf, size_t count)
-{
- ssize_t ret;
-
- do {
- ret = write(fd, buf, count);
- } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-
- return ret;
-}
-
-/*******************************************************************
-A writev wrapper that will deal with EINTR.
-********************************************************************/
-
-ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt)
-{
- ssize_t ret;
-
-#if 0
- /* Try to confuse write_data_iov a bit */
- if ((random() % 5) == 0) {
- return sys_write(fd, iov[0].iov_base, iov[0].iov_len);
- }
- if (iov[0].iov_len > 1) {
- return sys_write(fd, iov[0].iov_base,
- (random() % (iov[0].iov_len-1)) + 1);
- }
-#endif
-
- do {
- ret = writev(fd, iov, iovcnt);
- } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-
- return ret;
-}
-
-/*******************************************************************
-A pread wrapper that will deal with EINTR
-********************************************************************/
-
-#if defined(HAVE_PREAD)
-ssize_t sys_pread(int fd, void *buf, size_t count, off_t off)
-{
- ssize_t ret;
-
- do {
- ret = pread(fd, buf, count, off);
- } while (ret == -1 && errno == EINTR);
- return ret;
-}
-#endif
-
-/*******************************************************************
-A write wrapper that will deal with EINTR
-********************************************************************/
-
-#if defined(HAVE_PWRITE)
-ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off)
-{
- ssize_t ret;
-
- do {
- ret = pwrite(fd, buf, count, off);
- } while (ret == -1 && errno == EINTR);
- return ret;
-}
-#endif
-
/*******************************************************************
A send wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
********************************************************************/
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 7b2afa8..49eef50 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -31,6 +31,7 @@
#include <ccan/hash/hash.h>
#include "libcli/security/security.h"
#include "serverid.h"
+#include "lib/sys_rw.h"
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c
index 8319f04..27a078f 100644
--- a/source3/lib/util_file.c
+++ b/source3/lib/util_file.c
@@ -18,6 +18,7 @@
*/
#include "includes.h"
+#include "lib/sys_rw.h"
/**
Load from a pipe into memory.
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index d865ffb..2bed9a9 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -28,6 +28,7 @@
#include "../lib/util/tevent_unix.h"
#include "../lib/util/tevent_ntstatus.h"
#include "../lib/tsocket/tsocket.h"
+#include "lib/sys_rw.h"
const char *client_addr(int fd, char *addr, size_t addrlen)
{
diff --git a/source3/lib/util_transfer_file.c b/source3/lib/util_transfer_file.c
index 00a2c9d..d415d7f 100644
--- a/source3/lib/util_transfer_file.c
+++ b/source3/lib/util_transfer_file.c
@@ -22,6 +22,7 @@
#include <includes.h>
#include "transfer_file.h"
+#include "lib/sys_rw.h"
/****************************************************************************
Transfer some data between two fd's.
diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c
index 2c01bb7..ee1c360 100644
--- a/source3/libsmb/unexpected.c
+++ b/source3/libsmb/unexpected.c
@@ -22,6 +22,7 @@
#include "../lib/util/tevent_ntstatus.h"
#include "lib/async_req/async_sock.h"
#include "libsmb/nmblib.h"
+#include "lib/sys_rw.h"
static const char *nmbd_socket_dir(void)
{
diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c
index 12e6f80..c2148a1 100644
--- a/source3/modules/vfs_aio_fork.c
+++ b/source3/modules/vfs_aio_fork.c
@@ -26,6 +26,7 @@
#include "smbd/globals.h"
#include "lib/async_req/async_sock.h"
#include "lib/util/tevent_unix.h"
+#include "lib/sys_rw.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_aio_linux.c b/source3/modules/vfs_aio_linux.c
index 6188975..6c97592 100644
--- a/source3/modules/vfs_aio_linux.c
+++ b/source3/modules/vfs_aio_linux.c
@@ -24,6 +24,7 @@
#include "smbd/smbd.h"
#include "smbd/globals.h"
#include "lib/util/tevent_unix.h"
+#include "lib/sys_rw.h"
#include <sys/eventfd.h>
#include <libaio.h>
diff --git a/source3/modules/vfs_aio_posix.c b/source3/modules/vfs_aio_posix.c
index 3629541..ef5f706 100644
--- a/source3/modules/vfs_aio_posix.c
+++ b/source3/modules/vfs_aio_posix.c
@@ -24,6 +24,7 @@
#include "smbd/smbd.h"
#include "smbd/globals.h"
#include "lib/util/tevent_unix.h"
+#include "lib/sys_rw.h"
#include <aio.h>
/* The signal we'll use to signify aio done. */
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index 2ac7100..ab2ba89 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -32,6 +32,7 @@
#include "lib/util/tevent_unix.h"
#include "lib/asys/asys.h"
#include "lib/util/tevent_ntstatus.h"
+#include "lib/sys_rw.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS
diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index da1ec7f..69d025a 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -28,6 +28,7 @@
#include "smbd/globals.h"
#include "messages.h"
#include "libcli/security/security.h"
+#include "lib/sys_rw.h"
/*
* Enhanced OS X and Netatalk compatibility
diff --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c
index 0ec71ab..68f367c 100644
--- a/source3/printing/print_cups.c
+++ b/source3/printing/print_cups.c
@@ -26,6 +26,7 @@
#include "printing.h"
#include "printing/pcap.h"
#include "librpc/gen_ndr/ndr_printcap.h"
+#include "lib/sys_rw.h"
#ifdef HAVE_CUPS
#include <cups/cups.h>
diff --git a/source3/rpc_server/samr/srv_samr_chgpasswd.c b/source3/rpc_server/samr/srv_samr_chgpasswd.c
index 684ccee..e899306 100644
--- a/source3/rpc_server/samr/srv_samr_chgpasswd.c
+++ b/source3/rpc_server/samr/srv_samr_chgpasswd.c
@@ -54,6 +54,7 @@
#include "rpc_server/samr/srv_samr_util.h"
#include "passdb.h"
#include "auth.h"
+#include "lib/sys_rw.h"
#ifndef ALLOW_CHANGE_PASSWORD
#if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
diff --git a/source3/smbd/scavenger.c b/source3/smbd/scavenger.c
index 122305e..013b4d2 100644
--- a/source3/smbd/scavenger.c
+++ b/source3/smbd/scavenger.c
@@ -26,6 +26,7 @@
#include "smbd/scavenger.h"
#include "locking/proto.h"
#include "lib/util/util_process.h"
+#include "lib/sys_rw.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_SCAVENGER
diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c
index f71d111..b9c110f 100644
--- a/source3/winbindd/winbindd_dual.c
+++ b/source3/winbindd/winbindd_dual.c
@@ -38,6 +38,7 @@
#include "messages.h"
#include "../lib/util/tevent_unix.h"
#include "lib/param/loadparm.h"
+#include "lib/sys_rw.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_WINBIND
diff --git a/source3/wscript_build b/source3/wscript_build
index 7b5130d..9be5e0d 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -261,6 +261,11 @@ bld.SAMBA3_SUBSYSTEM('KRBCLIENT',
source='libads/kerberos.c libads/ads_status.c',
public_deps='krb5samba k5crypto gssapi LIBTSOCKET CLDAP LIBNMB')
+bld.SAMBA3_LIBRARY('sys_rw',
+ source='lib/sys_rw.c',
+ deps='replace',
+ private_library=True)
+
bld.SAMBA3_SUBSYSTEM('samba3util',
source='''lib/system.c
lib/sendfile.c
@@ -272,7 +277,7 @@ bld.SAMBA3_SUBSYSTEM('samba3util',
lib/util_sock.c
lib/util_transfer_file.c
lib/sock_exec.c''',
- deps='ndr samba-security NDR_SECURITY samba-util util_tdb ccan-hash')
+ deps='ndr samba-security NDR_SECURITY samba-util util_tdb ccan-hash sys_rw')
if bld.CONFIG_GET("CTDB_CFLAGS") and bld.CONFIG_GET("CTDB_INCLUDE"):
SAMBA_CLUSTER_SUPPORT_SOURCES='''
--
1.7.9.5
From 7501575aa77ffe3ce1ae9e7962263fdee017a432 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Nov 2014 14:06:49 +0000
Subject: [PATCH 05/10] lib: read_data->read_data_ntstatus
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/proto.h | 2 +-
source3/lib/ctdbd_conn.c | 6 +++---
source3/lib/util_sock.c | 2 +-
source3/nmbd/asyncdns.c | 4 ++--
source3/smbd/notify_inotify.c | 2 +-
source3/smbd/reply.c | 3 ++-
source3/winbindd/winbindd_dual.c | 5 +++--
7 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 68a3053..dcecf74 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -565,7 +565,7 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
size_t mincnt, size_t maxcnt,
unsigned int time_out,
size_t *size_ret);
-NTSTATUS read_data(int fd, char *buffer, size_t N);
+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 iov_buflen(const struct iovec *iov, int iovlen);
uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt);
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 5dc007b..7bdb376 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -379,7 +379,7 @@ static NTSTATUS ctdb_read_packet(int fd, TALLOC_CTX *mem_ctx,
}
}
- status = read_data(fd, (char *)&msglen, sizeof(msglen));
+ status = read_data_ntstatus(fd, (char *)&msglen, sizeof(msglen));
if (!NT_STATUS_IS_OK(status)) {
return status;
}
@@ -396,8 +396,8 @@ static NTSTATUS ctdb_read_packet(int fd, TALLOC_CTX *mem_ctx,
req->length = msglen;
- status = read_data(fd, ((char *)req) + sizeof(msglen),
- msglen - sizeof(msglen));
+ status = read_data_ntstatus(fd, ((char *)req) + sizeof(msglen),
+ msglen - sizeof(msglen));
if (!NT_STATUS_IS_OK(status)) {
return status;
}
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 2bed9a9..d93e22d 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -197,7 +197,7 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
on socket calls.
****************************************************************************/
-NTSTATUS read_data(int fd, char *buffer, size_t N)
+NTSTATUS read_data_ntstatus(int fd, char *buffer, size_t N)
{
return read_fd_with_timeout(fd, buffer, N, N, 0, NULL);
}
diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c
index 90340ef..4468c7b 100644
--- a/source3/nmbd/asyncdns.c
+++ b/source3/nmbd/asyncdns.c
@@ -90,7 +90,7 @@ static void asyncdns_process(void)
while (1) {
NTSTATUS status;
- status = read_data(fd_in, (char *)&r, sizeof(r));
+ status = read_data_ntstatus(fd_in, (char *)&r, sizeof(r));
if (!NT_STATUS_IS_OK(status)) {
break;
@@ -219,7 +219,7 @@ void run_dns_queue(struct messaging_context *msg)
start_async_dns(msg);
}
- status = read_data(fd_in, (char *)&r, sizeof(r));
+ status = read_data_ntstatus(fd_in, (char *)&r, sizeof(r));
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("read from child failed: %s\n", nt_errstr(status)));
diff --git a/source3/smbd/notify_inotify.c b/source3/smbd/notify_inotify.c
index efb659f..5ec6178 100644
--- a/source3/smbd/notify_inotify.c
+++ b/source3/smbd/notify_inotify.c
@@ -216,7 +216,7 @@ static void inotify_handler(struct tevent_context *ev, struct tevent_fd *fde,
if (e == NULL) return;
((uint8_t *)e)[bufsize] = '\0';
- status = read_data(in->fd, (char *)e0, bufsize);
+ status = read_data_ntstatus(in->fd, (char *)e0, bufsize);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("Failed to read all inotify data - %s\n",
nt_errstr(status)));
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 9b3ed65..83369f8 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -4361,7 +4361,8 @@ void reply_writebraw(struct smb_request *req)
(int)tcount,(int)nwritten,(int)numtowrite));
}
- status = read_data(xconn->transport.sock, buf+4, numtowrite);
+ status = read_data_ntstatus(xconn->transport.sock, buf+4,
+ numtowrite);
if (!NT_STATUS_IS_OK(status)) {
/* Try and give an error message
diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c
index b9c110f..43a27b3 100644
--- a/source3/winbindd/winbindd_dual.c
+++ b/source3/winbindd/winbindd_dual.c
@@ -53,7 +53,7 @@ static NTSTATUS child_read_request(int sock, struct winbindd_request *wreq)
{
NTSTATUS status;
- status = read_data(sock, (char *)wreq, sizeof(*wreq));
+ status = read_data_ntstatus(sock, (char *)wreq, sizeof(*wreq));
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("child_read_request: read_data failed: %s\n",
nt_errstr(status)));
@@ -76,7 +76,8 @@ static NTSTATUS child_read_request(int sock, struct winbindd_request *wreq)
/* Ensure null termination */
wreq->extra_data.data[wreq->extra_len] = '\0';
- status = read_data(sock, wreq->extra_data.data, wreq->extra_len);
+ status = read_data_ntstatus(sock, wreq->extra_data.data,
+ wreq->extra_len);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("Could not read extra data: %s\n",
nt_errstr(status)));
--
1.7.9.5
From 764bfa8707768d7a995c6ef19b03e4f789a1358d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Nov 2014 14:21:17 +0000
Subject: [PATCH 06/10] lib: Split out iov_buf[len]
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/proto.h | 3 +-
source3/lib/iov_buf.c | 65 ++++++++++++++++++++++++++++++++++++++++++
source3/lib/iov_buf.h | 29 +++++++++++++++++++
source3/lib/messages.c | 1 +
source3/lib/messages_ctdbd.c | 1 +
source3/lib/util_sock.c | 44 +---------------------------
source3/wscript_build | 7 ++++-
7 files changed, 104 insertions(+), 46 deletions(-)
create mode 100644 source3/lib/iov_buf.c
create mode 100644 source3/lib/iov_buf.h
diff --git a/source3/include/proto.h b/source3/include/proto.h
index dcecf74..d9815f4 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -566,9 +566,8 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf,
unsigned int time_out,
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 iov_buflen(const struct iovec *iov, int iovlen);
-uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt);
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,
diff --git a/source3/lib/iov_buf.c b/source3/lib/iov_buf.c
new file mode 100644
index 0000000..dd99da3
--- /dev/null
+++ b/source3/lib/iov_buf.c
@@ -0,0 +1,65 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba system utilities
+ * Copyright (C) Volker Lendecke 2014
+ *
+ * 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 "iov_buf.h"
+
+ssize_t iov_buflen(const struct iovec *iov, int iovcnt)
+{
+ size_t buflen = 0;
+ int i;
+
+ for (i=0; i<iovcnt; i++) {
+ size_t thislen = iov[i].iov_len;
+ size_t tmp = buflen + thislen;
+
+ if ((tmp < buflen) || (tmp < thislen)) {
+ /* overflow */
+ return -1;
+ }
+ buflen = tmp;
+ }
+ return buflen;
+}
+
+uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt)
+{
+ int i;
+ ssize_t buflen;
+ uint8_t *buf, *p;
+
+ buflen = iov_buflen(iov, iovcnt);
+ if (buflen == -1) {
+ return NULL;
+ }
+ buf = talloc_array(mem_ctx, uint8_t, buflen);
+ if (buf == NULL) {
+ return NULL;
+ }
+
+ p = buf;
+ for (i=0; i<iovcnt; i++) {
+ size_t len = iov[i].iov_len;
+
+ memcpy(p, iov[i].iov_base, len);
+ p += len;
+ }
+ return buf;
+}
diff --git a/source3/lib/iov_buf.h b/source3/lib/iov_buf.h
new file mode 100644
index 0000000..a884bdb
--- /dev/null
+++ b/source3/lib/iov_buf.h
@@ -0,0 +1,29 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba system utilities
+ * Copyright (C) Volker Lendecke 2014
+ *
+ * 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_IOV_BUF_H__
+#define __LIB_IOV_BUF_H__
+
+#include <unistd.h>
+#include <talloc.h>
+
+ssize_t iov_buflen(const struct iovec *iov, int iovlen);
+uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt);
+
+#endif
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index d4c580f..5b4daa2 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -52,6 +52,7 @@
#include "lib/util/tevent_unix.h"
#include "lib/background.h"
#include "lib/messages_dgm.h"
+#include "lib/iov_buf.h"
struct messaging_callback {
struct messaging_callback *prev, *next;
diff --git a/source3/lib/messages_ctdbd.c b/source3/lib/messages_ctdbd.c
index eb7e929..59f5976 100644
--- a/source3/lib/messages_ctdbd.c
+++ b/source3/lib/messages_ctdbd.c
@@ -20,6 +20,7 @@
#include "includes.h"
#include "messages.h"
#include "util_tdb.h"
+#include "lib/iov_buf.h"
/*
* It is not possible to include ctdb.h and tdb_compat.h (included via
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index d93e22d..163045a 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -29,6 +29,7 @@
#include "../lib/util/tevent_ntstatus.h"
#include "../lib/tsocket/tsocket.h"
#include "lib/sys_rw.h"
+#include "lib/iov_buf.h"
const char *client_addr(int fd, char *addr, size_t addrlen)
{
@@ -202,49 +203,6 @@ NTSTATUS read_data_ntstatus(int fd, char *buffer, size_t N)
return read_fd_with_timeout(fd, buffer, N, N, 0, NULL);
}
-ssize_t iov_buflen(const struct iovec *iov, int iovcnt)
-{
- size_t buflen = 0;
- int i;
-
- for (i=0; i<iovcnt; i++) {
- size_t thislen = iov[i].iov_len;
- size_t tmp = buflen + thislen;
-
- if ((tmp < buflen) || (tmp < thislen)) {
- /* overflow */
- return -1;
- }
- buflen = tmp;
- }
- return buflen;
-}
-
-uint8_t *iov_buf(TALLOC_CTX *mem_ctx, const struct iovec *iov, int iovcnt)
-{
- int i;
- ssize_t buflen;
- uint8_t *buf, *p;
-
- buflen = iov_buflen(iov, iovcnt);
- if (buflen == -1) {
- return NULL;
- }
- buf = talloc_array(mem_ctx, uint8_t, buflen);
- if (buf == NULL) {
- return NULL;
- }
-
- p = buf;
- for (i=0; i<iovcnt; i++) {
- size_t len = iov[i].iov_len;
-
- memcpy(p, iov[i].iov_base, len);
- p += len;
- }
- return buf;
-}
-
/****************************************************************************
Write all data from an iov array
NB. This can be called with a non-socket fd, don't add dependencies
diff --git a/source3/wscript_build b/source3/wscript_build
index 9be5e0d..ba2e9e4d 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -266,6 +266,11 @@ bld.SAMBA3_LIBRARY('sys_rw',
deps='replace',
private_library=True)
+bld.SAMBA3_LIBRARY('iov_buf',
+ source='lib/iov_buf.c',
+ deps='replace talloc',
+ private_library=True)
+
bld.SAMBA3_SUBSYSTEM('samba3util',
source='''lib/system.c
lib/sendfile.c
@@ -277,7 +282,7 @@ bld.SAMBA3_SUBSYSTEM('samba3util',
lib/util_sock.c
lib/util_transfer_file.c
lib/sock_exec.c''',
- deps='ndr samba-security NDR_SECURITY samba-util util_tdb ccan-hash sys_rw')
+ deps='ndr samba-security NDR_SECURITY samba-util util_tdb ccan-hash sys_rw iov_buf')
if bld.CONFIG_GET("CTDB_CFLAGS") and bld.CONFIG_GET("CTDB_INCLUDE"):
SAMBA_CLUSTER_SUPPORT_SOURCES='''
--
1.7.9.5
From 6201ebc3de734a3ad685cbe6e8fb7575b07e6cd8 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Nov 2014 14:25:56 +0000
Subject: [PATCH 07/10] lib: Split out write_data[_iov]
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/proto.h | 2 -
source3/lib/ctdbd_conn.c | 1 +
source3/lib/sys_rw_data.c | 107 ++++++++++++++++++++++++++++
source3/lib/sys_rw_data.h | 33 +++++++++
source3/lib/util.c | 1 +
source3/lib/util_sock.c | 82 +--------------------
source3/modules/vfs_aio_fork.c | 1 +
source3/modules/vfs_preopen.c | 1 +
source3/modules/vfs_smb_traffic_analyzer.c | 1 +
source3/nmbd/asyncdns.c | 1 +
source3/printing/printing.c | 1 +
source3/smbd/process.c | 1 +
source3/smbd/reply.c | 1 +
source3/smbd/smb2_read.c | 1 +
source3/torture/torture.c | 1 +
source3/utils/smbfilter.c | 1 +
source3/winbindd/winbindd_dual.c | 1 +
source3/wscript_build | 4 +-
18 files changed, 156 insertions(+), 85 deletions(-)
create mode 100644 source3/lib/sys_rw_data.c
create mode 100644 source3/lib/sys_rw_data.h
diff --git a/source3/include/proto.h b/source3/include/proto.h
index d9815f4..82b2fb5 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 7bdb376..c41ec53 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 0000000..f7bedb3
--- /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 0000000..fc97573
--- /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 49eef50..b64b32b 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 163045a..682d964 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 c2148a1..39334bc 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 612b025..cc38a90 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 92a1762..06ff1f6 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 4468c7b..5973c8e 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 5d053cc..61afa28 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 c7f0e9a..a761669 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 83369f8..e7b12a5 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 470e496..4e974a2 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 f90f882..2714655 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 e06fee6..ff966a8 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 43a27b3..35838e6 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 ba2e9e4d..575fa82 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -262,8 +262,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',
--
1.7.9.5
From ea4082f26e0947e3ed29c7a6027760fb0363c1a7 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Nov 2014 14:29:26 +0000
Subject: [PATCH 08/10] lib: Make write_data take a const void *
This aligns it with write(2)
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/sys_rw_data.c | 2 +-
source3/lib/sys_rw_data.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/source3/lib/sys_rw_data.c b/source3/lib/sys_rw_data.c
index f7bedb3..e4f9a16 100644
--- a/source3/lib/sys_rw_data.c
+++ b/source3/lib/sys_rw_data.c
@@ -97,7 +97,7 @@ ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt)
on socket calls.
****************************************************************************/
-ssize_t write_data(int fd, const char *buffer, size_t n)
+ssize_t write_data(int fd, const void *buffer, size_t n)
{
struct iovec iov;
diff --git a/source3/lib/sys_rw_data.h b/source3/lib/sys_rw_data.h
index fc97573..5d1995b 100644
--- a/source3/lib/sys_rw_data.h
+++ b/source3/lib/sys_rw_data.h
@@ -28,6 +28,6 @@
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);
+ssize_t write_data(int fd, const void *buffer, size_t n);
#endif
--
1.7.9.5
From 0f24c4569c3d7334a0f5cda5b6be3ca7652b43d3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Nov 2014 14:35:14 +0000
Subject: [PATCH 09/10] lib: Add a simple read_data call without NTSTATUS
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/sys_rw_data.c | 22 ++++++++++++++++++++++
source3/lib/sys_rw_data.h | 1 +
2 files changed, 23 insertions(+)
diff --git a/source3/lib/sys_rw_data.c b/source3/lib/sys_rw_data.c
index e4f9a16..353dbe7 100644
--- a/source3/lib/sys_rw_data.c
+++ b/source3/lib/sys_rw_data.c
@@ -105,3 +105,25 @@ ssize_t write_data(int fd, const void *buffer, size_t n)
iov.iov_len = n;
return write_data_iov(fd, &iov, 1);
}
+
+/*
+ * Blocking read n bytes from a fd
+ */
+
+ssize_t read_data(int fd, void *buffer, size_t n)
+{
+ ssize_t nread;
+
+ nread = 0;
+
+ while (nread < n) {
+ ssize_t ret;
+ ret = sys_read(fd, ((char *)buffer) + nread, n - nread);
+ if (ret <= 0) {
+ return ret;
+ }
+ nread += ret;
+ }
+
+ return nread;
+}
diff --git a/source3/lib/sys_rw_data.h b/source3/lib/sys_rw_data.h
index 5d1995b..bda3795 100644
--- a/source3/lib/sys_rw_data.h
+++ b/source3/lib/sys_rw_data.h
@@ -29,5 +29,6 @@ struct iovec;
ssize_t write_data_iov(int fd, const struct iovec *iov, int iovcnt);
ssize_t write_data(int fd, const void *buffer, size_t n);
+ssize_t read_data(int fd, void *buffer, size_t n);
#endif
--
1.7.9.5
From 0c773c9f506bf3f4a09947e6584c61fd6ef994a9 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 19 Nov 2014 14:41:42 +0000
Subject: [PATCH 10/10] smbd: Use read_data() in notify_inotify
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/smbd/notify_inotify.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/source3/smbd/notify_inotify.c b/source3/smbd/notify_inotify.c
index 5ec6178..4b8d4a4 100644
--- a/source3/smbd/notify_inotify.c
+++ b/source3/smbd/notify_inotify.c
@@ -24,6 +24,7 @@
#include "includes.h"
#include "../librpc/gen_ndr/notify.h"
#include "smbd/smbd.h"
+#include "lib/sys_rw_data.h"
#ifdef HAVE_INOTIFY
@@ -198,7 +199,7 @@ static void inotify_handler(struct tevent_context *ev, struct tevent_fd *fde,
int bufsize = 0;
struct inotify_event *e0, *e;
uint32_t prev_cookie=0;
- NTSTATUS status;
+ ssize_t ret;
/*
we must use FIONREAD as we cannot predict the length of the
@@ -216,10 +217,10 @@ static void inotify_handler(struct tevent_context *ev, struct tevent_fd *fde,
if (e == NULL) return;
((uint8_t *)e)[bufsize] = '\0';
- status = read_data_ntstatus(in->fd, (char *)e0, bufsize);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0,("Failed to read all inotify data - %s\n",
- nt_errstr(status)));
+ ret = read_data(in->fd, e0, bufsize);
+ if (ret != bufsize) {
+ DEBUG(0, ("Failed to read all inotify data - %s\n",
+ strerror(errno)));
talloc_free(e0);
/* the inotify fd will now be out of sync,
* can't keep reading data off it */
--
1.7.9.5
More information about the samba-technical
mailing list