[PATCH] Fix shared object clashes - read_data()

Uri Simchoni uri at samba.org
Thu Jan 21 18:30:42 UTC 2016



On 01/21/2016 08:11 PM, Jeremy Allison wrote:
> On Thu, Jan 21, 2016 at 12:39:26PM +0200, Alexander Bokovoy wrote:
>> On Thu, 21 Jan 2016, Uri Simchoni wrote:
>>> I also suppose that having a shared library with read_data() in it is asking
>>> for trouble (and the linux loader doesn't seem to support the notion of
>>> private shared libs, so the fact that it's private doesn't really help
>>> here).
>>>
>>> Thanks,
>>> Uri
>>>
>> Can we rename read_data to something more unique? 
> Nah, we've been using read_data() forever (longer than
> gnutls has been in existence :-).
>
>
Well, it's not gnutls that has read_data(), it's some library (libtspi, 
part of trousers package) that gnutls build in FC22 pulls in.

Attached is a patchset that renames read_data(), write_data(), and 
write_data_iov() (and fixes one bug that was found in apparently unused 
code).

I'm for renaming because although we (samba developers) view read_data 
as an internal function, the linux dynamic loader doesn't seem to think 
so. Maybe there's some technology (linker namespaces?) that can fix 
this. But I'm not religious about it - the wscript-only fix seems good 
enough for this particular case, and adding the dependency seems 
justified even without the Fedora issue.

Uri.
-------------- next part --------------
>From 0c827f531cbc4d8b5c932e107fd500111630226c Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 21 Jan 2016 11:14:36 +0200
Subject: [PATCH v2 1/5] build: fix ldbsearch panic on FC22

add dependency that fixes ldbsearch panic due to conflict -
function read_data() is implemented both by libtspi.so.1, which
is a dependency of gnutls on FC22, and by an internal samba
shared lib.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/dsdb/samdb/ldb_modules/wscript_build_server | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source4/dsdb/samdb/ldb_modules/wscript_build_server b/source4/dsdb/samdb/ldb_modules/wscript_build_server
index b54d27f..8fa9939 100755
--- a/source4/dsdb/samdb/ldb_modules/wscript_build_server
+++ b/source4/dsdb/samdb/ldb_modules/wscript_build_server
@@ -325,7 +325,7 @@ bld.SAMBA_MODULE('ldb_acl',
 	init_function='ldb_acl_module_init',
 	module_init_name='ldb_init_module',
 	internal_module=False,
-	deps='talloc samba-security samdb DSDB_MODULE_HELPERS krb5samba'
+	deps='talloc samba-util samba-security samdb DSDB_MODULE_HELPERS krb5samba'
 	)
 
 
-- 
2.4.3


>From e3cf5458f7dad0b15436fc415a0d05f32889435c Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 21 Jan 2016 13:18:20 +0200
Subject: [PATCH v2 2/5] dbwrap_file: fix use of read_data()

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/dbwrap/dbwrap_file.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/dbwrap/dbwrap_file.c b/lib/dbwrap/dbwrap_file.c
index a3b1737..46e62c8 100644
--- a/lib/dbwrap/dbwrap_file.c
+++ b/lib/dbwrap/dbwrap_file.c
@@ -171,7 +171,7 @@ static struct db_record *db_file_fetch_locked(struct db_context *db,
 	result->value.dptr = NULL;
 
 	if (statbuf.st_ex_size != 0) {
-		NTSTATUS status;
+		ssize_t read_bytes;
 
 		result->value.dsize = statbuf.st_ex_size;
 		result->value.dptr = talloc_array(result, uint8_t,
@@ -182,11 +182,10 @@ static struct db_record *db_file_fetch_locked(struct db_context *db,
 			return NULL;
 		}
 
-		status = read_data(file->fd, (char *)result->value.dptr,
-				  result->value.dsize);
-		if (!NT_STATUS_IS_OK(status)) {
-			DEBUG(3, ("read_data failed: %s\n",
-				  nt_errstr(status)));
+		read_bytes = read_data(file->fd, (char *)result->value.dptr,
+				       result->value.dsize);
+		if (read_bytes != result->value.dsize) {
+			DEBUG(3, ("read_data failed: %s\n", strerror(errno)));
 			TALLOC_FREE(result);
 			return NULL;
 		}
-- 
2.4.3


>From f7c192750cfca4ad924c7d8e95e2a2042d269037 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 21 Jan 2016 13:12:54 +0200
Subject: [PATCH v2 3/5] lib: rename read_data() -> samba_sys_read_data()

read_data is likelier to clash with other libraries.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/dbwrap/dbwrap_file.c      | 7 ++++---
 lib/util/genrand.c            | 2 +-
 lib/util/sys_rw_data.c        | 2 +-
 lib/util/sys_rw_data.h        | 2 +-
 source3/lib/ctdbd_conn.c      | 6 +++---
 source3/smbd/notify_inotify.c | 2 +-
 source3/smbd/scavenger.c      | 2 +-
 7 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/lib/dbwrap/dbwrap_file.c b/lib/dbwrap/dbwrap_file.c
index 46e62c8..e997f98 100644
--- a/lib/dbwrap/dbwrap_file.c
+++ b/lib/dbwrap/dbwrap_file.c
@@ -182,10 +182,11 @@ static struct db_record *db_file_fetch_locked(struct db_context *db,
 			return NULL;
 		}
 
-		read_bytes = read_data(file->fd, (char *)result->value.dptr,
-				       result->value.dsize);
+		read_bytes = samba_sys_read_data(
+		    file->fd, (char *)result->value.dptr, result->value.dsize);
 		if (read_bytes != result->value.dsize) {
-			DEBUG(3, ("read_data failed: %s\n", strerror(errno)));
+			DEBUG(3, ("samba_sys_read_data failed: %s\n",
+				  strerror(errno)));
 			TALLOC_FREE(result);
 			return NULL;
 		}
diff --git a/lib/util/genrand.c b/lib/util/genrand.c
index a775535..906a1ce 100644
--- a/lib/util/genrand.c
+++ b/lib/util/genrand.c
@@ -45,7 +45,7 @@ _PUBLIC_ void generate_random_buffer(uint8_t *out, int len)
 
 	open_urandom();
 
-	rw_ret = read_data(urand_fd, out, len);
+	rw_ret = samba_sys_read_data(urand_fd, out, len);
 	if (rw_ret != len) {
 		abort();
 	}
diff --git a/lib/util/sys_rw_data.c b/lib/util/sys_rw_data.c
index de71716..f2fe0c8 100644
--- a/lib/util/sys_rw_data.c
+++ b/lib/util/sys_rw_data.c
@@ -98,7 +98,7 @@ ssize_t write_data(int fd, const void *buffer, size_t n)
  * Blocking read n bytes from a fd
  */
 
-ssize_t read_data(int fd, void *buffer, size_t n)
+ssize_t samba_sys_read_data(int fd, void *buffer, size_t n)
 {
 	ssize_t nread;
 
diff --git a/lib/util/sys_rw_data.h b/lib/util/sys_rw_data.h
index bda3795..8ce88b6 100644
--- a/lib/util/sys_rw_data.h
+++ b/lib/util/sys_rw_data.h
@@ -29,6 +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);
+ssize_t samba_sys_read_data(int fd, void *buffer, size_t n);
 
 #endif
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 04f6f2f..b4e5834 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -312,7 +312,7 @@ static int ctdb_read_packet(int fd, int timeout, TALLOC_CTX *mem_ctx,
 		}
 	}
 
-	nread = read_data(fd, &msglen, sizeof(msglen));
+	nread = samba_sys_read_data(fd, &msglen, sizeof(msglen));
 	if (nread == -1) {
 		return errno;
 	}
@@ -332,8 +332,8 @@ static int ctdb_read_packet(int fd, int timeout, TALLOC_CTX *mem_ctx,
 
 	req->length = msglen;
 
-	nread = read_data(fd, ((char *)req) + sizeof(msglen),
-			  msglen - sizeof(msglen));
+	nread = samba_sys_read_data(fd, ((char *)req) + sizeof(msglen),
+				    msglen - sizeof(msglen));
 	if (nread == -1) {
 		TALLOC_FREE(req);
 		return errno;
diff --git a/source3/smbd/notify_inotify.c b/source3/smbd/notify_inotify.c
index 78fb654..9cfe620 100644
--- a/source3/smbd/notify_inotify.c
+++ b/source3/smbd/notify_inotify.c
@@ -221,7 +221,7 @@ static void inotify_handler(struct tevent_context *ev, struct tevent_fd *fde,
 	if (e == NULL) return;
 	((uint8_t *)e)[bufsize] = '\0';
 
-	ret = read_data(in->fd, e0, bufsize);
+	ret = samba_sys_read_data(in->fd, e0, bufsize);
 	if (ret != bufsize) {
 		DEBUG(0, ("Failed to read all inotify data - %s\n",
 			  strerror(errno)));
diff --git a/source3/smbd/scavenger.c b/source3/smbd/scavenger.c
index 9f58f62..25674aa 100644
--- a/source3/smbd/scavenger.c
+++ b/source3/smbd/scavenger.c
@@ -167,7 +167,7 @@ static bool scavenger_wait_hello(int fd, struct server_id *child)
 	struct server_id_buf tmp;
 	ssize_t ret;
 
-	ret = read_data(fd, child, sizeof(struct server_id));
+	ret = samba_sys_read_data(fd, child, sizeof(struct server_id));
 	if (ret == -1) {
 		DEBUG(2, ("Failed to read from pipe: %s\n",
 			  strerror(errno)));
-- 
2.4.3


>From c169f9ed6387242ecec5fd94d7e38e0a2e5c390e Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 21 Jan 2016 13:34:01 +0200
Subject: [PATCH v2 4/5] lib rename write_data() -> samba_sys_write_data()

Avoid possible name clashes with other libraries

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/dbwrap/dbwrap_file.c       |  6 ++++--
 lib/util/sys_rw_data.c         |  2 +-
 lib/util/sys_rw_data.h         |  2 +-
 source3/lib/util.c             |  9 +++++----
 source3/lib/util_sock.c        |  2 +-
 source3/modules/vfs_aio_fork.c |  4 ++--
 source3/modules/vfs_preopen.c  |  4 ++--
 source3/nmbd/asyncdns.c        |  5 +++--
 source3/printing/printing.c    |  2 +-
 source3/smbd/process.c         |  2 +-
 source3/smbd/reply.c           | 46 ++++++++++++++++++++++++------------------
 source3/smbd/scavenger.c       |  2 +-
 source3/smbd/smb2_read.c       | 13 ++++++------
 source3/utils/smbfilter.c      |  3 ++-
 14 files changed, 57 insertions(+), 45 deletions(-)

diff --git a/lib/dbwrap/dbwrap_file.c b/lib/dbwrap/dbwrap_file.c
index e997f98..79df2d3 100644
--- a/lib/dbwrap/dbwrap_file.c
+++ b/lib/dbwrap/dbwrap_file.c
@@ -205,8 +205,10 @@ static NTSTATUS db_file_store_root(int fd, TDB_DATA data)
 		return map_nt_error_from_unix(errno);
 	}
 
-	if (write_data(fd, (char *)data.dptr, data.dsize) != data.dsize) {
-		DEBUG(3, ("write_data failed: %s\n", strerror(errno)));
+	if (samba_sys_write_data(fd, (char *)data.dptr, data.dsize) !=
+	    data.dsize) {
+		DEBUG(3,
+		      ("samba_sys_write_data failed: %s\n", strerror(errno)));
 		return map_nt_error_from_unix(errno);
 	}
 
diff --git a/lib/util/sys_rw_data.c b/lib/util/sys_rw_data.c
index f2fe0c8..a7136f5 100644
--- a/lib/util/sys_rw_data.c
+++ b/lib/util/sys_rw_data.c
@@ -85,7 +85,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 void *buffer, size_t n)
+ssize_t samba_sys_write_data(int fd, const void *buffer, size_t n)
 {
 	struct iovec iov;
 
diff --git a/lib/util/sys_rw_data.h b/lib/util/sys_rw_data.h
index 8ce88b6..124c5b7 100644
--- a/lib/util/sys_rw_data.h
+++ b/lib/util/sys_rw_data.h
@@ -28,7 +28,7 @@
 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 samba_sys_write_data(int fd, const void *buffer, size_t n);
 ssize_t samba_sys_read_data(int fd, void *buffer, size_t n);
 
 #endif
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 2895c14..0961436 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -359,13 +359,14 @@ ssize_t write_data_at_offset(int fd, const char *buffer, size_t N, off_t pos)
 	ssize_t ret;
 
 	if (pos == (off_t)-1) {
-		return write_data(fd, buffer, N);
+		return samba_sys_write_data(fd, buffer, N);
 	}
 #if defined(HAVE_PWRITE) || defined(HAVE_PRWITE64)
 	while (total < N) {
 		ret = sys_pwrite(fd,buffer + total,N - total, pos);
 		if (ret == -1 && errno == ESPIPE) {
-			return write_data(fd, buffer + total,N - total);
+			return samba_sys_write_data(fd, buffer + total,
+						    N - total);
 		}
 		if (ret == -1) {
 			DEBUG(0,("write_data_at_offset: write failure. Error = %s\n", strerror(errno) ));
@@ -379,13 +380,13 @@ ssize_t write_data_at_offset(int fd, const char *buffer, size_t N, off_t pos)
 	}
 	return (ssize_t)total;
 #else
-	/* Use lseek and write_data. */
+	/* Use lseek and samba_sys_write_data. */
 	if (lseek(fd, pos, SEEK_SET) == -1) {
 		if (errno != ESPIPE) {
 			return -1;
 		}
 	}
-	return write_data(fd, buffer, N);
+	return samba_sys_write_data(fd, buffer, N);
 #endif
 }
 
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 0e1a66c..996b941 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -214,7 +214,7 @@ bool send_keepalive(int client)
 	buf[0] = NBSSkeepalive;
 	buf[1] = buf[2] = buf[3] = 0;
 
-	return(write_data(client,(char *)buf,4) == 4);
+	return (samba_sys_write_data(client, (char *)buf, 4) == 4);
 }
 
 /****************************************************************************
diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c
index 472ef0c..4aacef6 100644
--- a/source3/modules/vfs_aio_fork.c
+++ b/source3/modules/vfs_aio_fork.c
@@ -381,8 +381,8 @@ static void aio_child_loop(int sockfd, struct mmap_area *map)
 		 */
 		close(fd);
 
-		ret = write_data(sockfd, (char *)&ret_struct,
-				 sizeof(ret_struct));
+		ret = samba_sys_write_data(sockfd, (char *)&ret_struct,
+					   sizeof(ret_struct));
 		if (ret != sizeof(ret_struct)) {
 			DEBUG(10, ("could not write ret_struct: %s\n",
 				   strerror(errno)));
diff --git a/source3/modules/vfs_preopen.c b/source3/modules/vfs_preopen.c
index b67aad8..ed55fd0 100644
--- a/source3/modules/vfs_preopen.c
+++ b/source3/modules/vfs_preopen.c
@@ -96,8 +96,8 @@ static void preopen_queue_run(struct preopen_state *state)
 		*pdelimiter = delimiter;
 
 		to_write = talloc_get_size(state->template_fname);
-		written = write_data(state->helpers[helper].fd,
-				     state->template_fname, to_write);
+		written = samba_sys_write_data(state->helpers[helper].fd,
+					       state->template_fname, to_write);
 		state->helpers[helper].busy = true;
 
 		if (written != to_write) {
diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c
index b4532fa..de7bd18 100644
--- a/source3/nmbd/asyncdns.c
+++ b/source3/nmbd/asyncdns.c
@@ -100,7 +100,8 @@ static void asyncdns_process(void)
 		pull_ascii_nstring( qname, sizeof(qname), r.name.name);
 		r.result.s_addr = interpret_addr(qname);
 
-		if (write_data(fd_out, (char *)&r, sizeof(r)) != sizeof(r))
+		if (samba_sys_write_data(fd_out, (char *)&r, sizeof(r)) !=
+		    sizeof(r))
 			break;
 	}
 
@@ -198,7 +199,7 @@ static bool write_child(struct packet_struct *p)
 
 	r.name = p->packet.nmb.question.question_name;
 
-	return write_data(fd_out, (char *)&r, sizeof(r)) == sizeof(r);
+	return samba_sys_write_data(fd_out, (char *)&r, sizeof(r)) == sizeof(r);
 }
 
 /***************************************************************************
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index e7e6c6d..5223204 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -2490,7 +2490,7 @@ ssize_t print_job_write(struct tevent_context *ev,
 		goto err_out;
 	}
 
-	return_code = write_data(pjob->fd, buf, size);
+	return_code = samba_sys_write_data(pjob->fd, buf, size);
 	if (return_code > 0) {
 		pjob->size += size;
 		pjob_store(ev, msg_ctx, sharename, jobid, pjob);
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 79ca91f..f0c4627 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -248,7 +248,7 @@ bool srv_send_smb(struct smbXsrv_connection *xconn, char *buffer,
 
 	len = smb_len_large(buf_out) + 4;
 
-	ret = write_data(xconn->transport.sock, buf_out, len);
+	ret = samba_sys_write_data(xconn->transport.sock, buf_out, len);
 	if (ret <= 0) {
 		int saved_errno = errno;
 		/*
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 77d5b6e..1f611a1 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -3287,14 +3287,15 @@ ssize_t fake_sendfile(struct smbXsrv_connection *xconn, files_struct *fsp,
 			memset(buf + ret, '\0', cur_read - ret);
 		}
 
-		ret = write_data(xconn->transport.sock, buf, cur_read);
+		ret =
+		    samba_sys_write_data(xconn->transport.sock, buf, cur_read);
 		if (ret != cur_read) {
 			int saved_errno = errno;
 			/*
 			 * Try and give an error message saying what
 			 * client failed.
 			 */
-			DEBUG(0, ("write_data failed for client %s. "
+			DEBUG(0, ("samba_sys_write_data failed for client %s. "
 				  "Error %s\n",
 				  smbXsrv_connection_dbg(xconn),
 				  strerror(saved_errno)));
@@ -3362,14 +3363,16 @@ ssize_t sendfile_short_send(struct smbXsrv_connection *xconn,
 			ssize_t ret;
 
 			to_write = MIN(SHORT_SEND_BUFSIZE, smb_maxcnt - nread);
-			ret = write_data(xconn->transport.sock, buf, to_write);
+			ret = samba_sys_write_data(xconn->transport.sock, buf,
+						   to_write);
 			if (ret != to_write) {
 				int saved_errno = errno;
 				/*
 				 * Try and give an error message saying what
 				 * client failed.
 				 */
-				DEBUG(0, ("write_data failed for client %s. "
+				DEBUG(0, ("samba_sys_write_data failed for "
+					  "client %s. "
 					  "Error %s\n",
 					  smbXsrv_connection_dbg(xconn),
 					  strerror(saved_errno)));
@@ -3395,16 +3398,16 @@ static void reply_readbraw_error(struct smbXsrv_connection *xconn)
 	SIVAL(header,0,0);
 
 	smbd_lock_socket(xconn);
-	if (write_data(xconn->transport.sock,header,4) != 4) {
+	if (samba_sys_write_data(xconn->transport.sock, header, 4) != 4) {
 		int saved_errno = errno;
 		/*
 		 * Try and give an error message saying what
 		 * client failed.
 		 */
-		DEBUG(0, ("write_data failed for client %s. "
-			  "Error %s\n",
-			  smbXsrv_connection_dbg(xconn),
-			  strerror(saved_errno)));
+		DEBUG(0,
+		      ("samba_sys_write_data failed for client %s. "
+		       "Error %s\n",
+		       smbXsrv_connection_dbg(xconn), strerror(saved_errno)));
 		errno = saved_errno;
 
 		fail_readraw();
@@ -3526,15 +3529,16 @@ normal_readbraw:
 	}
 
 	_smb_setlen(outbuf,ret);
-	if (write_data(xconn->transport.sock, outbuf, 4+ret) != 4+ret) {
+	if (samba_sys_write_data(xconn->transport.sock, outbuf, 4 + ret) !=
+	    4 + ret) {
 		int saved_errno = errno;
 		/*
 		 * Try and give an error message saying what
 		 * client failed.
 		 */
-		DEBUG(0, ("write_data failed for client %s. Error %s\n",
-			  smbXsrv_connection_dbg(xconn),
-			  strerror(saved_errno)));
+		DEBUG(0,
+		      ("samba_sys_write_data failed for client %s. Error %s\n",
+		       smbXsrv_connection_dbg(xconn), strerror(saved_errno)));
 		errno = saved_errno;
 
 		fail_readraw();
@@ -4078,19 +4082,21 @@ normal_read:
 		setup_readX_header(req, (char *)headerbuf, smb_maxcnt);
 
 		/* Send out the header. */
-		ret = write_data(xconn->transport.sock, (char *)headerbuf,
-				 sizeof(headerbuf));
+		ret =
+		    samba_sys_write_data(xconn->transport.sock,
+					 (char *)headerbuf, sizeof(headerbuf));
 		if (ret != sizeof(headerbuf)) {
 			saved_errno = errno;
 			/*
 			 * Try and give an error message saying what
 			 * client failed.
 			 */
-			DEBUG(0,("send_file_readX: write_data failed for file "
-				 "%s (%s) for client %s. Terminating\n",
-				 fsp_str_dbg(fsp),
-				 smbXsrv_connection_dbg(xconn),
-				 strerror(saved_errno)));
+			DEBUG(0,
+			      ("send_file_readX: samba_sys_write_data failed "
+			       "for file "
+			       "%s (%s) for client %s. Terminating\n",
+			       fsp_str_dbg(fsp), smbXsrv_connection_dbg(xconn),
+			       strerror(saved_errno)));
 			errno = saved_errno;
 			exit_server_cleanly("send_file_readX sendfile failed");
 		}
diff --git a/source3/smbd/scavenger.c b/source3/smbd/scavenger.c
index 25674aa..0a6b58b 100644
--- a/source3/smbd/scavenger.c
+++ b/source3/smbd/scavenger.c
@@ -147,7 +147,7 @@ static bool scavenger_say_hello(int fd, struct server_id self)
 	ssize_t ret;
 	struct server_id_buf tmp;
 
-	ret = write_data(fd, &self, sizeof(self));
+	ret = samba_sys_write_data(fd, &self, sizeof(self));
 	if (ret == -1) {
 		DEBUG(2, ("Failed to write to pipe: %s\n", strerror(errno)));
 		return false;
diff --git a/source3/smbd/smb2_read.c b/source3/smbd/smb2_read.c
index 89527f3..028a976 100644
--- a/source3/smbd/smb2_read.c
+++ b/source3/smbd/smb2_read.c
@@ -269,14 +269,15 @@ static int smb2_sendfile_send_data(struct smbd_smb2_read_state *state)
 
 normal_read:
 	/* Send out the header. */
-	ret = write_data(xconn->transport.sock,
-			 (const char *)hdr->data, hdr->length);
+	ret = samba_sys_write_data(xconn->transport.sock,
+				   (const char *)hdr->data, hdr->length);
 	if (ret != hdr->length) {
 		saved_errno = errno;
-		DEBUG(0,("smb2_sendfile_send_data: write_data failed for file "
-			 "%s (%s) for client %s. Terminating\n",
-			 fsp_str_dbg(fsp), strerror(saved_errno),
-			 smbXsrv_connection_dbg(xconn)));
+		DEBUG(0, ("smb2_sendfile_send_data: samba_sys_write_data "
+			  "failed for file "
+			  "%s (%s) for client %s. Terminating\n",
+			  fsp_str_dbg(fsp), strerror(saved_errno),
+			  smbXsrv_connection_dbg(xconn)));
 		*pstatus = map_nt_error_from_unix_common(saved_errno);
 		return 0;
 	}
diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c
index 9068448..7aab982 100644
--- a/source3/utils/smbfilter.c
+++ b/source3/utils/smbfilter.c
@@ -163,7 +163,8 @@ static bool send_smb(int fd, char *buffer)
         len = smb_len(buffer) + 4;
 
 	while (nwritten < len) {
-		ret = write_data(fd,buffer+nwritten,len - nwritten);
+		ret =
+		    samba_sys_write_data(fd, buffer + nwritten, len - nwritten);
 		if (ret <= 0) {
 			DEBUG(0,("Error writing %d bytes to client. %d. (%s)\n",
 				(int)len,(int)ret, strerror(errno) ));
-- 
2.4.3


>From 2eb35856ef19ee3c65038237bc4d78dd58895166 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 21 Jan 2016 13:37:58 +0200
Subject: [PATCH v2 5/5] lib: rename write_data_iov to samba_sys_write_data_iov

Avoid possible name clashes with other libs.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/util/sys_rw_data.c           |  5 +++--
 lib/util/sys_rw_data.h           |  2 +-
 source3/lib/ctdbd_conn.c         | 25 +++++++++++++++----------
 source3/torture/torture.c        |  2 +-
 source3/winbindd/winbindd_dual.c |  2 +-
 5 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/lib/util/sys_rw_data.c b/lib/util/sys_rw_data.c
index a7136f5..6f7e52a 100644
--- a/lib/util/sys_rw_data.c
+++ b/lib/util/sys_rw_data.c
@@ -32,7 +32,8 @@
  on socket calls.
 ****************************************************************************/
 
-ssize_t write_data_iov(int fd, const struct iovec *orig_iov, int iovcnt)
+ssize_t samba_sys_write_data_iov(int fd, const struct iovec *orig_iov,
+				 int iovcnt)
 {
 	ssize_t to_send;
 	ssize_t thistime;
@@ -91,7 +92,7 @@ ssize_t samba_sys_write_data(int fd, const void *buffer, size_t n)
 
 	iov.iov_base = discard_const_p(void, buffer);
 	iov.iov_len = n;
-	return write_data_iov(fd, &iov, 1);
+	return samba_sys_write_data_iov(fd, &iov, 1);
 }
 
 /*
diff --git a/lib/util/sys_rw_data.h b/lib/util/sys_rw_data.h
index 124c5b7..4f150a5 100644
--- a/lib/util/sys_rw_data.h
+++ b/lib/util/sys_rw_data.h
@@ -27,7 +27,7 @@
 
 struct iovec;
 
-ssize_t write_data_iov(int fd, const struct iovec *iov, int iovcnt);
+ssize_t samba_sys_write_data_iov(int fd, const struct iovec *iov, int iovcnt);
 ssize_t samba_sys_write_data(int fd, const void *buffer, size_t n);
 ssize_t samba_sys_read_data(int fd, void *buffer, size_t n);
 
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index b4e5834..6c0fd07 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -621,9 +621,10 @@ int ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
 	iov2[0].iov_len = offsetof(struct ctdb_req_message_old, data);
 	memcpy(&iov2[1], iov, iovlen * sizeof(struct iovec));
 
-	nwritten = write_data_iov(conn->fd, iov2, iovlen+1);
+	nwritten = samba_sys_write_data_iov(conn->fd, iov2, iovlen + 1);
 	if (nwritten == -1) {
-		DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno)));
+		DEBUG(3, ("samba_sys_write_data_iov failed: %s\n",
+			  strerror(errno)));
 		cluster_fatal("cluster dispatch daemon msg write error\n");
 	}
 
@@ -667,9 +668,10 @@ static int ctdbd_control(struct ctdbd_connection *conn,
 	iov[1].iov_base = data.dptr;
 	iov[1].iov_len = data.dsize;
 
-	nwritten = write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
+	nwritten = samba_sys_write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
 	if (nwritten == -1) {
-		DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno)));
+		DEBUG(3, ("samba_sys_write_data_iov failed: %s\n",
+			  strerror(errno)));
 		cluster_fatal("cluster dispatch daemon msg write error\n");
 	}
 
@@ -782,9 +784,10 @@ bool ctdb_processes_exist(struct ctdbd_connection *conn,
 		iov[1].iov_base = &pid;
 		iov[1].iov_len = sizeof(pid);
 
-		nwritten = write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
+		nwritten =
+		    samba_sys_write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
 		if (nwritten == -1) {
-			DEBUG(10, ("write_data_iov failed: %s\n",
+			DEBUG(10, ("samba_sys_write_data_iov failed: %s\n",
 				   strerror(errno)));
 			goto fail;
 		}
@@ -944,9 +947,10 @@ int ctdbd_migrate(struct ctdbd_connection *conn, uint32_t db_id, TDB_DATA key)
 	iov[1].iov_base = key.dptr;
 	iov[1].iov_len = key.dsize;
 
-	nwritten = write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
+	nwritten = samba_sys_write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
 	if (nwritten == -1) {
-		DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno)));
+		DEBUG(3, ("samba_sys_write_data_iov failed: %s\n",
+			  strerror(errno)));
 		cluster_fatal("cluster dispatch daemon msg write error\n");
 	}
 
@@ -1003,9 +1007,10 @@ int ctdbd_parse(struct ctdbd_connection *conn, uint32_t db_id,
 	iov[1].iov_base = key.dptr;
 	iov[1].iov_len = key.dsize;
 
-	nwritten = write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
+	nwritten = samba_sys_write_data_iov(conn->fd, iov, ARRAY_SIZE(iov));
 	if (nwritten == -1) {
-		DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno)));
+		DEBUG(3, ("samba_sys_write_data_iov failed: %s\n",
+			  strerror(errno)));
 		cluster_fatal("cluster dispatch daemon msg write error\n");
 	}
 
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 6c34e4c..17775d6 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -223,7 +223,7 @@ static bool cli_bad_session_request(int fd,
 	_smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len);
 	SCVAL(len_buf,0,0x81);
 
-	len = write_data_iov(fd, iov, 3);
+	len = samba_sys_write_data_iov(fd, iov, 3);
 	if (len == -1) {
 		goto fail;
 	}
diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c
index 17a89a7..6e729e1 100644
--- a/source3/winbindd/winbindd_dual.c
+++ b/source3/winbindd/winbindd_dual.c
@@ -103,7 +103,7 @@ static NTSTATUS child_write_response(int sock, struct winbindd_response *wrsp)
 
 	DEBUG(10, ("Writing %d bytes to parent\n", (int)wrsp->length));
 
-	if (write_data_iov(sock, iov, iov_count) != wrsp->length) {
+	if (samba_sys_write_data_iov(sock, iov, iov_count) != wrsp->length) {
 		DEBUG(0, ("Could not write result\n"));
 		return NT_STATUS_INVALID_HANDLE;
 	}
-- 
2.4.3



More information about the samba-technical mailing list