コード例 #1
0
ファイル: totemconfig.c プロジェクト: emrehe/corosync
static void totem_get_crypto_type(
	const struct objdb_iface_ver0 *objdb,
	hdb_handle_t object_totem_handle,
	struct totem_config *totem_config)
{
	const char *str;

	totem_config->crypto_accept = TOTEM_CRYPTO_ACCEPT_OLD;
	if (!objdb_get_string (objdb, object_totem_handle, "crypto_accept", &str)) {
		if (strcmp(str, "new") == 0) {
			totem_config->crypto_accept = TOTEM_CRYPTO_ACCEPT_NEW;
		}
	}

	totem_config->crypto_type = TOTEM_CRYPTO_SOBER;

#ifdef HAVE_LIBNSS
	/*
	 * We must set these even if the key does not exist.
	 * Encryption type can be set on-the-fly using CFG
	 */
	totem_config->crypto_crypt_type = CKM_AES_CBC_PAD;
	totem_config->crypto_sign_type = CKM_SHA256_RSA_PKCS;
#endif

	if (!objdb_get_string (objdb, object_totem_handle, "crypto_type", &str)) {
		if (strcmp(str, "sober") == 0) {
			return;
		}
#ifdef HAVE_LIBNSS
		if (strcmp(str, "nss") == 0) {
			totem_config->crypto_type = TOTEM_CRYPTO_NSS;

		}
#endif
	}
}
コード例 #2
0
ファイル: totemconfig.c プロジェクト: emrehe/corosync
static void totem_volatile_config_read (
	struct objdb_iface_ver0 *objdb,
	struct totem_config *totem_config,
	hdb_handle_t object_totem_handle)
{
	objdb_get_int (objdb,object_totem_handle, "token", &totem_config->token_timeout);

	objdb_get_int (objdb,object_totem_handle, "token_retransmit", &totem_config->token_retransmit_timeout);

	objdb_get_int (objdb,object_totem_handle, "hold", &totem_config->token_hold_timeout);

	objdb_get_int (objdb,object_totem_handle, "token_retransmits_before_loss_const", &totem_config->token_retransmits_before_loss_const);

	objdb_get_int (objdb,object_totem_handle, "join", &totem_config->join_timeout);
	objdb_get_int (objdb,object_totem_handle, "send_join", &totem_config->send_join_timeout);

	objdb_get_int (objdb,object_totem_handle, "consensus", &totem_config->consensus_timeout);

	objdb_get_int (objdb,object_totem_handle, "merge", &totem_config->merge_timeout);

	objdb_get_int (objdb,object_totem_handle, "downcheck", &totem_config->downcheck_timeout);

	objdb_get_int (objdb,object_totem_handle, "fail_recv_const", &totem_config->fail_to_recv_const);

	objdb_get_int (objdb,object_totem_handle, "seqno_unchanged_const", &totem_config->seqno_unchanged_const);

	objdb_get_int (objdb,object_totem_handle, "rrp_token_expired_timeout", &totem_config->rrp_token_expired_timeout);

	objdb_get_int (objdb,object_totem_handle, "rrp_problem_count_timeout", &totem_config->rrp_problem_count_timeout);

	objdb_get_int (objdb,object_totem_handle, "rrp_problem_count_threshold", &totem_config->rrp_problem_count_threshold);

	objdb_get_int (objdb,object_totem_handle, "rrp_autorecovery_check_timeout", &totem_config->rrp_autorecovery_check_timeout);

	objdb_get_int (objdb,object_totem_handle, "heartbeat_failures_allowed", &totem_config->heartbeat_failures_allowed);

	objdb_get_int (objdb,object_totem_handle, "max_network_delay", &totem_config->max_network_delay);

	objdb_get_int (objdb,object_totem_handle, "window_size", &totem_config->window_size);
	(void)objdb_get_string (objdb, object_totem_handle, "vsftype", &totem_config->vsf_type);

	objdb_get_int (objdb,object_totem_handle, "max_messages", &totem_config->max_messages);

	objdb_get_int (objdb,object_totem_handle, "miss_count_const", &totem_config->miss_count_const);
}
int openais_main_config_read (
	struct objdb_iface_ver0 *objdb,
	char **error_string,
	struct main_config *main_config)
{
	unsigned int object_service_handle;
	unsigned int object_logger_handle;
	char *value;
	char *error_reason = error_string_response;
	int i;

	memset (main_config, 0, sizeof (struct main_config));

	objdb->object_find_reset (OBJECT_PARENT_HANDLE);

	if (objdb->object_find (
		    OBJECT_PARENT_HANDLE,
		    "logging",
		    strlen ("logging"),
		    &object_service_handle) == 0) {

		if (!objdb_get_string (objdb,object_service_handle, "to_file", &value)) {
			if (strcmp (value, "yes") == 0) {
				main_config->logmode |= LOG_MODE_FILE;
			} else
			if (strcmp (value, "no") == 0) {
				main_config->logmode &= ~LOG_MODE_FILE;
			}
		}
		if (!objdb_get_string (objdb,object_service_handle, "to_syslog", &value)) {
			if (strcmp (value, "yes") == 0) {
				main_config->logmode |= LOG_MODE_SYSLOG;
			} else
			if (strcmp (value, "no") == 0) {
				main_config->logmode &= ~LOG_MODE_SYSLOG;
			}
		}
		if (!objdb_get_string (objdb,object_service_handle, "to_stderr", &value)) {
			if (strcmp (value, "yes") == 0) {
				main_config->logmode |= LOG_MODE_STDERR;
			} else
			if (strcmp (value, "no") == 0) {
				main_config->logmode &= ~LOG_MODE_STDERR;
			}
		}

		if (!objdb_get_string (objdb,object_service_handle, "debug", &value)) {
			if (strcmp (value, "on") == 0) {
				main_config->logmode |= LOG_MODE_DEBUG;
			} else
			if (strcmp (value, "off") == 0) {
				main_config->logmode &= ~LOG_MODE_DEBUG;
			} else {
				goto parse_error;
			}
		}
		if (!objdb_get_string (objdb,object_service_handle, "timestamp", &value)) {
			if (strcmp (value, "on") == 0) {
				main_config->logmode |= LOG_MODE_TIMESTAMP;
			} else
			if (strcmp (value, "off") == 0) {
				main_config->logmode &= ~LOG_MODE_TIMESTAMP;
			} else {
				goto parse_error;
			}
		}
		if (!objdb_get_string (objdb,object_service_handle, "logfile", &value)) {
			main_config->logfile = strdup (value);
		}

		if (!objdb_get_string (objdb,object_service_handle, "fileline", &value)) {
			if (strcmp (value, "on") == 0) {
				main_config->logmode |= LOG_MODE_FILELINE;
			} else
			if (strcmp (value, "off") == 0) {
				main_config->logmode &= ~LOG_MODE_FILELINE;
			} else {
				goto parse_error;
			}
		}

		if (!objdb_get_string (objdb,object_service_handle, "syslog_facility", &value)) {
			if (strcmp (value, "daemon") == 0) {
				main_config->syslog_facility = LOG_DAEMON;
			} else
			if (strcmp (value, "local0") == 0) {
				main_config->syslog_facility = LOG_LOCAL0;
			} else
			if (strcmp (value, "local1") == 0) {
				main_config->syslog_facility = LOG_LOCAL1;
			} else
			if (strcmp (value, "local2") == 0) {
				main_config->syslog_facility = LOG_LOCAL2;
			} else
			if (strcmp (value, "local3") == 0) {
				main_config->syslog_facility = LOG_LOCAL3;
			} else
			if (strcmp (value, "local4") == 0) {
				main_config->syslog_facility = LOG_LOCAL4;
			} else
			if (strcmp (value, "local5") == 0) {
				main_config->syslog_facility = LOG_LOCAL5;
			} else
			if (strcmp (value, "local6") == 0) {
				main_config->syslog_facility = LOG_LOCAL6;
			} else
			if (strcmp (value, "local7") == 0) {
				main_config->syslog_facility = LOG_LOCAL7;
			} else {
				error_reason = "unknown syslog facility specified";
				goto parse_error;
			}
		}

		while (	objdb->object_find (object_service_handle,
									"logger",
									strlen ("logger"),
									&object_logger_handle) == 0) {
			main_config->logger =
				realloc(main_config->logger,
						sizeof(struct logger_config) *
						(main_config->loggers + 1));
			i = main_config->loggers;
			main_config->loggers++;
			memset(&main_config->logger[i], 0, sizeof(struct logger_config));

			if (!objdb_get_string (objdb, object_logger_handle, "ident", &value)) {
				main_config->logger[i].ident = value;
			}
			else {
				error_reason = "ident required for logger directive";
				goto parse_error;
			}
			if (!objdb_get_string (objdb, object_logger_handle, "debug", &value)) {
				if (strcmp (value, "on") == 0) {
					main_config->logger[i].level = LOG_LEVEL_DEBUG;
				} else
				if (strcmp (value, "off") == 0) {
					main_config->logger[i].level &= ~LOG_LEVEL_DEBUG;
				} else {
					goto parse_error;
				}
			}
			if (!objdb_get_string (objdb, object_logger_handle, "tags", &value)) {
				char *token = strtok (value, "|");

				while (token != NULL) {
					if (strcmp (token, "enter") == 0) {
						main_config->logger[i].tags |= TAG_ENTER;
					} else if (strcmp (token, "leave") == 0) {
						main_config->logger[i].tags |= TAG_LEAVE;
					} else if (strcmp (token, "trace1") == 0) {
						main_config->logger[i].tags |= TAG_TRACE1;
					} else if (strcmp (token, "trace2") == 0) {
						main_config->logger[i].tags |= TAG_TRACE2;
					} else if (strcmp (token, "trace3") == 0) {
						main_config->logger[i].tags |= TAG_TRACE3;
					} else if (strcmp (token, "trace4") == 0) {
						main_config->logger[i].tags |= TAG_TRACE4;
					} else if (strcmp (token, "trace5") == 0) {
						main_config->logger[i].tags |= TAG_TRACE5;
					} else if (strcmp (token, "trace6") == 0) {
						main_config->logger[i].tags |= TAG_TRACE6;
					} else if (strcmp (token, "trace7") == 0) {
						main_config->logger[i].tags |= TAG_TRACE7;
					} else if (strcmp (token, "trace8") == 0) {
						main_config->logger[i].tags |= TAG_TRACE8;
					} else {
						error_reason = "bad tags value";
						goto parse_error;
					}

					token = strtok(NULL, "|");
				}
			}
		}
	}

	objdb->object_find_reset (OBJECT_PARENT_HANDLE);
	if (objdb->object_find (
		    OBJECT_PARENT_HANDLE,
		    "aisexec",
		    strlen ("aisexec"),
		    &object_service_handle) == 0) {

		if (!objdb_get_string (objdb,object_service_handle, "user", &value)) {
			main_config->user = strdup(value);
		}
		if (!objdb_get_string (objdb,object_service_handle, "group", &value)) {
			main_config->group = strdup(value);
		}
	}

	/* Default user/group */
	if (main_config->user == NULL) {
		main_config->user = "******";
	}

	if (main_config->group == NULL) {
		main_config->group = "ais";
	}

	if ((main_config->logmode & LOG_MODE_FILE) && main_config->logfile == 0) {
		error_reason = "logmode set to 'file' but no logfile specified";
		goto parse_error;
	}

	if (!main_config->syslog_facility)
		main_config->syslog_facility = LOG_DAEMON;

	return 0;

parse_error:
	snprintf (error_string_response, sizeof(error_string_response),
		 "parse error in config: %s.\n",
		 error_reason);

	*error_string = error_string_response;
	return (-1);
}
コード例 #4
0
ファイル: totemconfig.c プロジェクト: emrehe/corosync
int totem_config_keyread (
	struct objdb_iface_ver0 *objdb,
	struct totem_config *totem_config,
	const char **error_string)
{
	int got_key = 0;
	const char *key_location = NULL;
	hdb_handle_t object_totem_handle;
	int res;

	memset (totem_config->private_key, 0, 128);
	totem_config->private_key_len = 128;

	if (totem_config->secauth == 0) {
		return (0);
	}

	res = totem_handle_find (objdb, &object_totem_handle);
	if (res == -1) {
		return (-1);
	}
	/* objdb may store the location of the key file */
	if (!objdb_get_string (objdb,object_totem_handle, "keyfile", &key_location)
	    && key_location) {
		res = read_keyfile(key_location, totem_config, error_string);
		if (res)  {
			goto key_error;
		}
		got_key = 1;
	} else { /* Or the key itself may be in the objdb */
		char *key = NULL;
		size_t key_len;
		res = objdb->object_key_get (object_totem_handle,
			"key",
			strlen ("key"),
			(void *)&key,
			&key_len);

		if (res == 0 && key) {
			if (key_len > sizeof (totem_config->private_key)) {
				goto key_error;
			}
			memcpy(totem_config->private_key, key, key_len);
			totem_config->private_key_len = key_len;
			got_key = 1;
		}
	}

	/* In desperation we read the default filename */
	if (!got_key) {
		const char *filename = getenv("COROSYNC_TOTEM_AUTHKEY_FILE");
		if (!filename)
			filename = COROSYSCONFDIR "/authkey";
		res = read_keyfile(filename, totem_config, error_string);
		if (res)
			goto key_error;

	}

	return (0);

key_error:
	*error_string = error_string_response;
	return (-1);

}
コード例 #5
0
ファイル: totemconfig.c プロジェクト: emrehe/corosync
extern int totem_config_read (
	struct objdb_iface_ver0 *objdb,
	struct totem_config *totem_config,
	const char **error_string)
{
	int res = 0;
	hdb_handle_t object_totem_handle;
	hdb_handle_t object_interface_handle;
	hdb_handle_t object_member_handle;
	const char *str;
	unsigned int ringnumber = 0;
	hdb_handle_t object_find_interface_handle;
	hdb_handle_t object_find_member_handle;
	const char *transport_type;
	int member_count = 0;

	res = totem_handle_find (objdb, &object_totem_handle);
	if (res == -1) {
printf ("couldn't find totem handle\n");
		return (-1);
	}

	memset (totem_config, 0, sizeof (struct totem_config));
	totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
	if (totem_config->interfaces == 0) {
		*error_string = "Out of memory trying to allocate ethernet interface storage area";
		return -1;
	}

	memset (totem_config->interfaces, 0,
		sizeof (struct totem_interface) * INTERFACE_MAX);

	totem_config->secauth = 1;

	strcpy (totem_config->rrp_mode, "none");

	if (!objdb_get_string (objdb, object_totem_handle, "version", &str)) {
		if (strcmp (str, "2") == 0) {
			totem_config->version = 2;
		}
	}
	if (!objdb_get_string (objdb, object_totem_handle, "secauth", &str)) {
		if (strcmp (str, "on") == 0) {
			totem_config->secauth = 1;
		}
		if (strcmp (str, "off") == 0) {
			totem_config->secauth = 0;
		}
	}

	if (totem_config->secauth == 1) {
		totem_get_crypto_type(objdb, object_totem_handle, totem_config);
	}

	if (!objdb_get_string (objdb, object_totem_handle, "rrp_mode", &str)) {
		strcpy (totem_config->rrp_mode, str);
	}

	/*
	 * Get interface node id
	 */
	objdb_get_int (objdb, object_totem_handle, "nodeid", &totem_config->node_id);

	totem_config->clear_node_high_bit = 0;
	if (!objdb_get_string (objdb,object_totem_handle, "clear_node_high_bit", &str)) {
		if (strcmp (str, "yes") == 0) {
			totem_config->clear_node_high_bit = 1;
		}
	}

	objdb_get_int (objdb,object_totem_handle, "threads", &totem_config->threads);


	objdb_get_int (objdb,object_totem_handle, "netmtu", &totem_config->net_mtu);

	/*
	 * Get things that might change in the future
	 */
	totem_volatile_config_read (objdb, totem_config, object_totem_handle);

	objdb->object_find_create (
		object_totem_handle,
		"interface",
		strlen ("interface"),
		&object_find_interface_handle);

	while (objdb->object_find_next (
		object_find_interface_handle,
		&object_interface_handle) == 0) {

		member_count = 0;

		objdb_get_int (objdb, object_interface_handle, "ringnumber", &ringnumber);

		/*
		 * Get interface multicast address
		 */
		if (!objdb_get_string (objdb, object_interface_handle, "mcastaddr", &str)) {
			res = totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr, str, 0);
		}
		totem_config->broadcast_use = 0;
		if (!objdb_get_string (objdb, object_interface_handle, "broadcast", &str)) {
			if (strcmp (str, "yes") == 0) {
				totem_config->broadcast_use = 1;
				totemip_parse (
					&totem_config->interfaces[ringnumber].mcast_addr,
					"255.255.255.255", 0);
			}
		}

		/*
		 * Get mcast port
		 */
		if (!objdb_get_string (objdb, object_interface_handle, "mcastport", &str)) {
			totem_config->interfaces[ringnumber].ip_port = atoi (str);
		}

		/*
		 * Get the bind net address
		 */
		if (!objdb_get_string (objdb, object_interface_handle, "bindnetaddr", &str)) {

			res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, str,
					     totem_config->interfaces[ringnumber].mcast_addr.family);
		}

		/*
		 * Get the TTL
		 */
		totem_config->interfaces[ringnumber].ttl = 1;
		if (!objdb_get_string (objdb, object_interface_handle, "ttl", &str)) {
			totem_config->interfaces[ringnumber].ttl = atoi (str);
		}

		objdb->object_find_create (
			object_interface_handle,
			"member",
			strlen ("member"),
			&object_find_member_handle);

		while (objdb->object_find_next (
			object_find_member_handle,
			&object_member_handle) == 0) {

			if (!objdb_get_string (objdb, object_member_handle, "memberaddr", &str)) {
				res = totemip_parse (&totem_config->interfaces[ringnumber].member_list[member_count++], str, 0);
			}
		
		}
		totem_config->interfaces[ringnumber].member_count = member_count;
		totem_config->interface_count++;
	}

	objdb->object_find_destroy (object_find_interface_handle);

	add_totem_config_notification(objdb, totem_config, object_totem_handle);

	totem_config->transport_number = TOTEM_TRANSPORT_UDP;
	(void)objdb_get_string (objdb, object_totem_handle, "transport", &transport_type);

	if (transport_type) {
		if (strcmp (transport_type, "udpu") == 0) {
			totem_config->transport_number = TOTEM_TRANSPORT_UDPU;
		}
	}
	if (transport_type) {
		if (strcmp (transport_type, "iba") == 0) {
			totem_config->transport_number = TOTEM_TRANSPORT_RDMA;
		}
	}

	return 0;
}