[SCM] Samba Shared Repository - branch master updated

Amitay Isaacs amitay at samba.org
Fri Jul 27 06:43:02 UTC 2018


The branch, master has been updated
       via  e7ef0c9 ctdb-common: Drop unused function mkdir_p_or_die()
       via  77242e7 ctdb-common: Drop function parse_ip_mask() and supporting functions
       via  b1fed7e ctdb-daemon: Switch to using ctdb_sock_addr_mask_from_string()
       via  efaa769 ctdb-tools: Switch to using ctdb_sock_addr_mask_from_string()
       via  4a1fb72 ctdb-protocol: Add function ctdb_sock_addr_mask_from_string()
       via  3b56f20 ctdb-protocol: Fix compilation issue with strncpy()
       via  5dd84bf ctdb-common: Fix compilation issue with strncpy()
      from  2dffcde smbd: Remove "share_mode_entry->lease"

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit e7ef0c97e981ff6097eeca5b7ecf5136955b23fe
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Jun 8 18:48:07 2018 +1000

    ctdb-common: Drop unused function mkdir_p_or_die()
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    
    Autobuild-User(master): Amitay Isaacs <amitay at samba.org>
    Autobuild-Date(master): Fri Jul 27 08:42:20 CEST 2018 on sn-devel-144

commit 77242e7631514b80a84146b2f4f232dab28d978b
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Jun 8 07:33:32 2018 +1000

    ctdb-common: Drop function parse_ip_mask() and supporting functions
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit b1fed7e14c7e2bdfa88f8e502d5256c555dcae90
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Jun 8 07:27:07 2018 +1000

    ctdb-daemon: Switch to using ctdb_sock_addr_mask_from_string()
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit efaa7690d01faa1f24c21920666f644c9d42ca11
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Jun 8 07:26:51 2018 +1000

    ctdb-tools: Switch to using ctdb_sock_addr_mask_from_string()
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 4a1fb7296ca1c32fbb85ade2d5f104690b83929b
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Jun 8 07:13:25 2018 +1000

    ctdb-protocol: Add function ctdb_sock_addr_mask_from_string()
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 3b56f2002a35b55b46958178c79aee519f0c5880
Author: Martin Schwenke <martin at meltin.net>
Date:   Thu Jul 26 11:01:30 2018 +1000

    ctdb-protocol: Fix compilation issue with strncpy()
    
    When configured with --picky-developer and using -O3 with gcc 8.1:
    
    ../protocol/protocol_util.c: In function ‘ctdb_sock_addr_from_string’:
    ../protocol/protocol_util.c:282:2: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
      strncpy(s, str, len+1);
      ^~~~~~~~~~~~~~~~~~~~~~
    ../protocol/protocol_util.c:277:8: note: length computed here
      len = strlen(str);
            ^~~~~~~~~~~
    
    Use strlcpy() instead and check the result.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13545
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 5dd84bf5d73e4afab094834bc317da7884b9b9b3
Author: Martin Schwenke <martin at meltin.net>
Date:   Thu Jul 26 11:00:28 2018 +1000

    ctdb-common: Fix compilation issue with strncpy()
    
    When configured with --picky-developer and using -O3 with gcc 8.1:
    
    ../common/system_socket.c: In function ‘parse_ip_mask’:
    ../common/system_socket.c:229:2: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
      strncpy(s, str, len+1);
      ^~~~~~~~~~~~~~~~~~~~~~
    ../common/system_socket.c:223:8: note: length computed here
      len = strlen(str);
            ^~~~~~~~~~~
    
    Use strlcpy() instead and check the result.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13545
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

-----------------------------------------------------------------------

Summary of changes:
 ctdb/common/system.c                |  14 ----
 ctdb/common/system.h                |   2 -
 ctdb/common/system_socket.c         | 137 ------------------------------------
 ctdb/common/system_socket.h         |   5 --
 ctdb/protocol/protocol_util.c       |  45 +++++++++++-
 ctdb/protocol/protocol_util.h       |   3 +
 ctdb/server/ctdb_takeover.c         |  17 ++++-
 ctdb/tests/src/protocol_util_test.c |  35 +++++++++
 ctdb/tools/ctdb.c                   |   3 +-
 9 files changed, 97 insertions(+), 164 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ctdb/common/system.c b/ctdb/common/system.c
index a95f314..51149ed 100644
--- a/ctdb/common/system.c
+++ b/ctdb/common/system.c
@@ -143,20 +143,6 @@ void lockdown_memory(bool valgrinding)
 #endif
 }
 
-void mkdir_p_or_die(const char *dir, int mode)
-{
-	int ret;
-
-	ret = mkdir_p(dir, mode);
-	if (ret != 0) {
-		DEBUG(DEBUG_ALERT,
-		      ("ctdb exiting with error: "
-		       "failed to create directory \"%s\" (%s)\n",
-		       dir, strerror(errno)));
-		exit(1);
-	}
-}
-
 void ctdb_wait_for_process_to_exit(pid_t pid)
 {
 	while (kill(pid, 0) == 0 || errno != ESRCH) {
diff --git a/ctdb/common/system.h b/ctdb/common/system.h
index 8d558e2..042e7cc 100644
--- a/ctdb/common/system.h
+++ b/ctdb/common/system.h
@@ -29,8 +29,6 @@ void reset_scheduler(void);
 
 void lockdown_memory(bool valgrinding);
 
-void mkdir_p_or_die(const char *dir, int mode);
-
 void ctdb_wait_for_process_to_exit(pid_t pid);
 
 bool ctdb_sys_check_iface_exists(const char *iface);
diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c
index d8627fd..562b2bf 100644
--- a/ctdb/common/system_socket.c
+++ b/ctdb/common/system_socket.c
@@ -112,143 +112,6 @@ bool ctdb_sys_have_ip(ctdb_sock_addr *_addr)
 	return ret == 0;
 }
 
-static bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin)
-{
-	sin->sin_family = AF_INET;
-	sin->sin_port   = htons(port);
-
-	if (inet_pton(AF_INET, s, &sin->sin_addr) != 1) {
-		DBG_ERR("Failed to translate %s into sin_addr\n", s);
-		return false;
-	}
-
-#ifdef HAVE_SOCK_SIN_LEN
-	sin->sin_len = sizeof(*sin);
-#endif
-	return true;
-}
-
-static bool parse_ipv6(const char *s,
-		       const char *ifaces,
-		       unsigned port,
-		       ctdb_sock_addr *saddr)
-{
-	saddr->ip6.sin6_family   = AF_INET6;
-	saddr->ip6.sin6_port     = htons(port);
-	saddr->ip6.sin6_flowinfo = 0;
-	saddr->ip6.sin6_scope_id = 0;
-
-	if (inet_pton(AF_INET6, s, &saddr->ip6.sin6_addr) != 1) {
-		DBG_ERR("Failed to translate %s into sin6_addr\n", s);
-		return false;
-	}
-
-	if (ifaces && IN6_IS_ADDR_LINKLOCAL(&saddr->ip6.sin6_addr)) {
-		if (strchr(ifaces, ',')) {
-			DBG_ERR("Link local address %s "
-				"is specified for multiple ifaces %s\n",
-				s, ifaces);
-			return false;
-		}
-		saddr->ip6.sin6_scope_id = if_nametoindex(ifaces);
-	}
-
-#ifdef HAVE_SOCK_SIN6_LEN
-	saddr->ip6.sin6_len = sizeof(*saddr);
-#endif
-	return true;
-}
-
-static bool parse_ip(const char *addr,
-		     const char *ifaces,
-		     unsigned port,
-		     ctdb_sock_addr *saddr)
-{
-	char *p;
-	bool ret;
-
-	ZERO_STRUCTP(saddr); /* valgrind :-) */
-
-	/*
-	 * IPv4 or IPv6 address?
-	 *
-	 * Use rindex() because we need the right-most ':' below for
-	 * IPv4-mapped IPv6 addresses anyway...
-	 */
-	p = rindex(addr, ':');
-	if (p == NULL) {
-		ret = parse_ipv4(addr, port, &saddr->ip);
-	} else {
-		uint8_t ipv4_mapped_prefix[12] = {
-			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff
-		};
-
-		ret = parse_ipv6(addr, ifaces, port, saddr);
-		if (! ret) {
-			return ret;
-		}
-
-		/*
-		 * Check for IPv4-mapped IPv6 address
-		 * (e.g. ::ffff:192.0.2.128) - reparse as IPv4 if
-		 * necessary
-		 */
-		if (memcmp(&saddr->ip6.sin6_addr.s6_addr[0],
-			   ipv4_mapped_prefix,
-			   sizeof(ipv4_mapped_prefix)) == 0) {
-			/* Reparse as IPv4 */
-			ret = parse_ipv4(p+1, port, &saddr->ip);
-		}
-	}
-
-	return ret;
-}
-
-/*
- * Parse an ip/mask pair
- */
-bool parse_ip_mask(const char *str,
-		   const char *ifaces,
-		   ctdb_sock_addr *addr,
-		   unsigned *mask)
-{
-	char *p;
-	char s[64]; /* Much longer than INET6_ADDRSTRLEN */
-	char *endp = NULL;
-	ssize_t len;
-	bool ret;
-
-	ZERO_STRUCT(*addr);
-
-	len = strlen(str);
-	if (len >= sizeof(s)) {
-		DBG_ERR("Address %s is unreasonably long\n", str);
-		return false;
-	}
-
-	strncpy(s, str, len+1);
-
-	p = rindex(s, '/');
-	if (p == NULL) {
-		DBG_ERR("Address %s does not contain a mask\n", s);
-		return false;
-	}
-
-	*mask = strtoul(p+1, &endp, 10);
-	if (endp == NULL || *endp != 0) {
-		/* trailing garbage */
-		DBG_ERR("Trailing garbage after the mask in %s\n", s);
-		return false;
-	}
-	*p = 0;
-
-
-	/* now is this a ipv4 or ipv6 address ?*/
-	ret = parse_ip(s, ifaces, 0, addr);
-
-	return ret;
-}
-
 /*
  * simple TCP checksum - assumes data is multiple of 2 bytes long
  */
diff --git a/ctdb/common/system_socket.h b/ctdb/common/system_socket.h
index eb2c6f7..065c53c 100644
--- a/ctdb/common/system_socket.h
+++ b/ctdb/common/system_socket.h
@@ -24,11 +24,6 @@
 
 bool ctdb_sys_have_ip(ctdb_sock_addr *addr);
 
-bool parse_ip_mask(const char *str,
-		   const char *ifaces,
-		   ctdb_sock_addr *addr,
-		   unsigned *mask);
-
 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
 
 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c
index c75555f..69bd67b 100644
--- a/ctdb/protocol/protocol_util.c
+++ b/ctdb/protocol/protocol_util.c
@@ -274,13 +274,11 @@ int ctdb_sock_addr_from_string(const char *str,
 
 	/* Parse out port number and then IP address */
 
-	len = strlen(str);
+	len = strlcpy(s, str, sizeof(s));
 	if (len >= sizeof(s)) {
 		return EINVAL;
 	}
 
-	strncpy(s, str, len+1);
-
 	p = rindex(s, ':');
 	if (p == NULL) {
 		return EINVAL;
@@ -300,6 +298,47 @@ int ctdb_sock_addr_from_string(const char *str,
 	return ret;
 }
 
+int ctdb_sock_addr_mask_from_string(const char *str,
+				    ctdb_sock_addr *addr,
+				    unsigned int *mask)
+{
+	char *p;
+	char s[64]; /* Much longer than INET6_ADDRSTRLEN */
+	unsigned int m;
+	char *endp = NULL;
+	ssize_t len;
+	bool ret;
+
+	if (addr == NULL || mask == NULL) {
+		return EINVAL;
+	}
+
+	len = strlcpy(s, str, sizeof(s));
+	if (len >= sizeof(s)) {
+		return EINVAL;
+	}
+
+	p = rindex(s, '/');
+	if (p == NULL) {
+		return EINVAL;
+	}
+
+	m = strtoul(p+1, &endp, 10);
+	if (endp == p+1 || *endp != '\0') {
+		/* Empty string or trailing garbage */
+		return EINVAL;
+	}
+
+	*p = '\0';
+	ret = ip_from_string(s, addr);
+
+	if (ret == 0) {
+		*mask = m;
+	}
+
+	return ret;
+}
+
 unsigned int ctdb_sock_addr_port(ctdb_sock_addr *addr)
 {
 	switch (addr->sa.sa_family) {
diff --git a/ctdb/protocol/protocol_util.h b/ctdb/protocol/protocol_util.h
index 66a4913..fa7189c 100644
--- a/ctdb/protocol/protocol_util.h
+++ b/ctdb/protocol/protocol_util.h
@@ -41,6 +41,9 @@ const char *ctdb_sock_addr_to_string(TALLOC_CTX *mem_ctx,
 				     ctdb_sock_addr *addr, bool with_port);
 int ctdb_sock_addr_from_string(const char *str,
 			       ctdb_sock_addr *addr, bool with_port);
+int ctdb_sock_addr_mask_from_string(const char *str,
+				    ctdb_sock_addr *addr,
+				    unsigned int *mask);
 unsigned int ctdb_sock_addr_port(ctdb_sock_addr *addr);
 void ctdb_sock_addr_set_port(ctdb_sock_addr *addr, unsigned int port);
 int ctdb_sock_addr_cmp_ip(const ctdb_sock_addr *addr1,
diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c
index 3f5536d..95663af 100644
--- a/ctdb/server/ctdb_takeover.c
+++ b/ctdb/server/ctdb_takeover.c
@@ -33,6 +33,8 @@
 #include "lib/util/sys_rw.h"
 #include "lib/util/util_process.h"
 
+#include "protocol/protocol_util.h"
+
 #include "ctdb_private.h"
 #include "ctdb_client.h"
 
@@ -1156,6 +1158,7 @@ int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses)
 		const char *addrstr;
 		const char *ifaces;
 		char *tok, *line;
+		int ret;
 
 		line = lines[i];
 		while ((*line == ' ') || (*line == '\t')) {
@@ -1179,11 +1182,21 @@ int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses)
 		}
 		ifaces = tok;
 
-		if (!addrstr || !parse_ip_mask(addrstr, ifaces, &addr, &mask)) {
-			DEBUG(DEBUG_CRIT,("Badly formed line %u in public address list\n", i+1));
+		if (addrstr == NULL) {
+			D_ERR("Badly formed line %u in public address list\n",
+			      i+1);
 			talloc_free(lines);
 			return -1;
 		}
+
+		ret = ctdb_sock_addr_mask_from_string(addrstr, &addr, &mask);
+		if (ret != 0) {
+			D_ERR("Badly formed line %u in public address list\n",
+			      i+1);
+			talloc_free(lines);
+			return -1;
+		}
+
 		if (ctdb_add_public_address(ctdb, &addr, mask, ifaces, check_addresses)) {
 			DEBUG(DEBUG_CRIT,("Failed to add line %u to the public address list\n", i+1));
 			talloc_free(lines);
diff --git a/ctdb/tests/src/protocol_util_test.c b/ctdb/tests/src/protocol_util_test.c
index eb7eb0f..9b4729e 100644
--- a/ctdb/tests/src/protocol_util_test.c
+++ b/ctdb/tests/src/protocol_util_test.c
@@ -73,6 +73,36 @@ static void test_sock_addr_cmp(const char *ip1, const char *ip2,
 }
 
 /*
+ * Test parsing of IP/mask, conversion to string
+ */
+
+static void test_sock_addr_mask_from_string(const char *ip_mask)
+{
+	ctdb_sock_addr sa;
+	unsigned mask;
+	const char *s, *t;
+	int ret;
+
+	ret = ctdb_sock_addr_mask_from_string(ip_mask, &sa, &mask);
+	assert(ret == 0);
+	s = ctdb_sock_addr_to_string(NULL, &sa, false);
+	assert(s != NULL);
+	t = talloc_asprintf(s, "%s/%u", s, mask);
+	assert(strcmp(ip_mask, t) == 0);
+	talloc_free(discard_const(s));
+}
+
+static void test_sock_addr_mask_from_string_bad(const char *ip_mask)
+{
+	ctdb_sock_addr sa;
+	unsigned mask;
+	int ret;
+
+	ret = ctdb_sock_addr_mask_from_string(ip_mask, &sa, &mask);
+	assert(ret == EINVAL);
+}
+
+/*
  * Test parsing of connection, conversion to string
  */
 
@@ -324,6 +354,11 @@ int main(int argc, char *argv[])
 	test_sock_addr_cmp("fe80::6af7:28ff:fefa:d136:123",
 			   "fe80::6af7:28ff:fefa:d136:122" , true, 1);
 
+	test_sock_addr_mask_from_string("127.0.0.1/8");
+	test_sock_addr_mask_from_string("::1/128");
+	test_sock_addr_mask_from_string("fe80::6af7:28ff:fefa:d136/64");
+	test_sock_addr_mask_from_string_bad("127.0.0.1");
+
 	test_connection_to_string("127.0.0.1:12345 127.0.0.2:54321");
 	test_connection_to_string("fe80::6af7:28ff:fefa:d137:12345 "
 				  "fe80::6af7:28ff:fefa:d138:54321");
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index 9d5d7b8..771632c 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -3849,7 +3849,8 @@ static int control_addip(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 		usage("addip");
 	}
 
-	if (! parse_ip_mask(argv[0], argv[1], &addr, &mask)) {
+	ret = ctdb_sock_addr_mask_from_string(argv[0], &addr, &mask);
+	if (ret != 0) {
 		fprintf(stderr, "Invalid IP/Mask %s\n", argv[0]);
 		return 1;
 	}


-- 
Samba Shared Repository



More information about the samba-cvs mailing list