Sfoglia il codice sorgente

qdevice-net: Support tls required and fix leaks

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Jan Friesse 10 anni fa
parent
commit
954e05a058
2 ha cambiato i file con 32 aggiunte e 16 eliminazioni
  1. 30 16
      qdevices/qdevice-net-instance.c
  2. 2 0
      qdevices/qnet-config.h

+ 30 - 16
qdevices/qdevice-net-instance.c

@@ -169,17 +169,24 @@ qdevice_net_instance_init_from_cmap(struct qdevice_instance *instance)
 	/*
 	 * Check tls
 	 */
+	tls_supported = QDEVICE_NET_DEFAULT_TLS_SUPPORTED;
+
 	if (cmap_get_string(cmap_handle, "quorum.device.net.tls", &str) == CS_OK) {
 		if ((i = utils_parse_bool_str(str)) == -1) {
-			free(str);
-			qdevice_log(LOG_ERR, "quorum.device.net.tls value is not valid.");
-			return (-1);
-		}
+			if (strcasecmp(str, "required") != 0) {
+				free(str);
+				qdevice_log(LOG_ERR, "quorum.device.net.tls value is not valid.");
 
-		if (i == 1) {
-			tls_supported = TLV_TLS_SUPPORTED;
+				goto error_free_instance;
+			} else {
+				tls_supported = TLV_TLS_REQUIRED;
+			}
 		} else {
-			tls_supported = TLV_TLS_UNSUPPORTED;
+			if (i == 1) {
+				tls_supported = TLV_TLS_SUPPORTED;
+			} else {
+				tls_supported = TLV_TLS_UNSUPPORTED;
+			}
 		}
 
 		free(str);
@@ -190,20 +197,19 @@ qdevice_net_instance_init_from_cmap(struct qdevice_instance *instance)
 	 */
 	if (cmap_get_string(cmap_handle, "quorum.device.net.host", &str) != CS_OK) {
 		qdevice_log(LOG_ERR, "Qdevice net daemon address is not defined (quorum.device.net.host)");
-		return (-1);
+		goto error_free_instance;
 	}
 	host_addr = str;
 
 	if (cmap_get_string(cmap_handle, "quorum.device.net.port", &str) == CS_OK) {
 		host_port = strtol(str, &ep, 10);
 
+		free(str);
 
 		if (host_port <= 0 || host_port > ((uint16_t)~0) || *ep != '\0') {
 			qdevice_log(LOG_ERR, "quorum.device.net.port must be in range 0-65535");
-			return (-1);
+			goto error_free_host_addr;
 		}
-
-		free(str);
 	} else {
 		host_port = QNETD_DEFAULT_HOST_PORT;
 	}
@@ -213,7 +219,7 @@ qdevice_net_instance_init_from_cmap(struct qdevice_instance *instance)
 	 */
 	if (cmap_get_string(cmap_handle, "totem.cluster_name", &str) != CS_OK) {
 		qdevice_log(LOG_ERR, "Cluster name (totem.cluster_name) has to be defined.");
-		return (-1);
+		goto error_free_host_addr;
 	}
 	cluster_name = str;
 
@@ -242,7 +248,7 @@ qdevice_net_instance_init_from_cmap(struct qdevice_instance *instance)
 		} else {
 			qdevice_log(LOG_ERR, "Unknown decision algorithm %s", str);
 			free(str);
-			return (-1);
+			goto error_free_cluster_name;
 		}
 
 		free(str);
@@ -265,7 +271,7 @@ qdevice_net_instance_init_from_cmap(struct qdevice_instance *instance)
 			if (li <= 0 || li > ((uint32_t)~0) || *ep != '\0') {
 				qdevice_log(LOG_ERR, "tie_breaker must be lowest|highest|valid_node_id");
 				free(str);
-				return (-1);
+				goto error_free_cluster_name;
 			}
 
 			tie_breaker.mode = TLV_TIE_BREAKER_MODE_NODE_ID;
@@ -286,7 +292,7 @@ qdevice_net_instance_init_from_cmap(struct qdevice_instance *instance)
 			qdevice_log(LOG_ERR, "connect_timeout must be valid number in range <%lu,%lu>",
 			    QDEVICE_NET_MIN_CONNECT_TIMEOUT, QDEVICE_NET_MAX_CONNECT_TIMEOUT);
 			free(str);
-			return (-1);
+			goto error_free_cluster_name;
 		}
 
 		connect_timeout = li;
@@ -306,11 +312,19 @@ qdevice_net_instance_init_from_cmap(struct qdevice_instance *instance)
 	    host_addr, host_port, cluster_name, &tie_breaker, connect_timeout,
 	    instance->cmap_poll_fd, instance->votequorum_poll_fd) == -1) {
 		qdevice_log(LOG_ERR, "Can't initialize qdevice-net instance");
-		return (-1);
+		goto error_free_instance;
 	}
 
 	net_instance->qdevice_instance_ptr = instance;
 	instance->model_data = net_instance;
 
 	return (0);
+
+error_free_cluster_name:
+	free(cluster_name);
+error_free_host_addr:
+	free(host_addr);
+error_free_instance:
+	free(net_instance);
+	return (-1);
 }

+ 2 - 0
qdevices/qnet-config.h

@@ -79,6 +79,8 @@ extern "C" {
 
 #define QDEVICE_NET_DEFAULT_ALGORITHM		TLV_DECISION_ALGORITHM_TYPE_TEST
 
+#define QDEVICE_NET_DEFAULT_TLS_SUPPORTED	TLV_TLS_SUPPORTED
+
 #define QNETD_DEFAULT_TIE_BREAKER_MODE		TLV_TIE_BREAKER_MODE_LOWEST
 #define QDEVICE_NET_DEFAULT_TIE_BREAKER_MODE	QNETD_DEFAULT_TIE_BREAKER_MODE