diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/proto.h | 3 | ||||
-rw-r--r-- | source3/lib/iov_buf.c | 65 | ||||
-rw-r--r-- | source3/lib/iov_buf.h | 29 | ||||
-rw-r--r-- | source3/lib/messages.c | 1 | ||||
-rw-r--r-- | source3/lib/messages_ctdbd.c | 1 | ||||
-rw-r--r-- | source3/lib/util_sock.c | 44 | ||||
-rwxr-xr-x | source3/wscript_build | 7 |
7 files changed, 104 insertions, 46 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index dcecf74a86..d9815f49f1 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 0000000000..dd99da3625 --- /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 0000000000..a884bdbe0e --- /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 d4c580fdd2..5b4daa2932 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 eb7e929fc3..59f5976da0 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 d93e22d702..163045a8a2 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 787c4e2551..591b1be77e 100755 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -258,6 +258,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 @@ -269,7 +274,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=''' |