cs_error_t icmap_get_string(const char *key_name, char **str) { cs_error_t res; size_t str_len; icmap_value_types_t type; res = icmap_get(key_name, NULL, &str_len, &type); if (res != CS_OK || type != ICMAP_VALUETYPE_STRING) { if (res == CS_OK) { res = CS_ERR_INVALID_PARAM; } goto return_error; } *str = malloc(str_len); if (*str == NULL) { res = CS_ERR_NO_MEMORY; goto return_error; } res = icmap_get(key_name, *str, &str_len, &type); if (res != CS_OK) { free(*str); goto return_error; } return (CS_OK); return_error: return (res); }
int totem_config_keyread ( struct totem_config *totem_config, const char **error_string) { int got_key = 0; char *key_location = NULL; int res; size_t key_len; memset (totem_config->private_key, 0, 128); totem_config->private_key_len = 128; if (strcmp(totem_config->crypto_cipher_type, "none") == 0 && strcmp(totem_config->crypto_hash_type, "none") == 0) { return (0); } /* cmap may store the location of the key file */ if (icmap_get_string("totem.keyfile", &key_location) == CS_OK) { res = read_keyfile(key_location, totem_config, error_string); free(key_location); if (res) { goto key_error; } got_key = 1; } else { /* Or the key itself may be in the cmap */ if (icmap_get("totem.key", NULL, &key_len, NULL) == CS_OK) { if (key_len > sizeof (totem_config->private_key)) { sprintf(error_string_response, "key is too long"); goto key_error; } if (icmap_get("totem.key", totem_config->private_key, &key_len, NULL) == CS_OK) { totem_config->private_key_len = key_len; got_key = 1; } else { sprintf(error_string_response, "can't store private key"); goto key_error; } } } /* 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); }
static void member_object_joined (unsigned int nodeid) { char member_ip[ICMAP_KEYNAME_MAXLEN]; char member_join_count[ICMAP_KEYNAME_MAXLEN]; char member_status[ICMAP_KEYNAME_MAXLEN]; snprintf(member_ip, ICMAP_KEYNAME_MAXLEN, "runtime.totem.pg.mrp.srp.members.%u.ip", nodeid); snprintf(member_join_count, ICMAP_KEYNAME_MAXLEN, "runtime.totem.pg.mrp.srp.members.%u.join_count", nodeid); snprintf(member_status, ICMAP_KEYNAME_MAXLEN, "runtime.totem.pg.mrp.srp.members.%u.status", nodeid); if (icmap_get(member_ip, NULL, NULL, NULL) == CS_OK) { icmap_inc(member_join_count); icmap_set_string(member_status, "joined"); } else { icmap_set_string(member_ip, (char*)api->totem_ifaces_print (nodeid)); icmap_set_uint32(member_join_count, 1); icmap_set_string(member_status, "joined"); } log_printf (LOGSYS_LEVEL_DEBUG, "Member joined: %s", api->totem_ifaces_print (nodeid)); }
static cs_error_t icmap_get_int( const char *key_name, void *value, icmap_value_types_t type) { char key_value[16]; size_t key_size; cs_error_t err; icmap_value_types_t key_type; key_size = sizeof(key_value); memset(key_value, 0, key_size); err = icmap_get(key_name, key_value, &key_size, &key_type); if (err != CS_OK) return (err); if (key_type != type) { return (CS_ERR_INVALID_PARAM); } memcpy(value, key_value, icmap_get_valuetype_len(key_type)); return (CS_OK); }