/* * _cb_cerebrod_alternate_hostname * * callback function that parses and stores cerebrod alternate hostname * * Returns 0 on success, -1 on error */ static int _cb_cerebrod_alternate_hostname(conffile_t cf, struct conffile_data *data, char *optionname, int option_type, void *option_ptr, int option_data, void *app_ptr, int app_data) { struct cerebro_config *conf; char *p; if (!option_ptr) { conffile_seterrnum(cf, CONFFILE_ERR_PARAMETERS); return -1; } conf = (struct cerebro_config *)option_ptr; if (strlen(data->string) > CEREBRO_MAX_HOSTNAME_LEN) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_OVERFLOW_ARGLEN); return -1; } strcpy(conf->cerebrod_alternate_hostname, data->string); /* shorten hostname if necessary */ if ((p = strchr(conf->cerebrod_alternate_hostname, '.'))) *p = '\0'; conf->cerebrod_alternate_hostname_flag++; return 0; }
/* * _cb_cerebro_event_server * * callback function that parses and stores cerebrod event servers to * connect to. * * Returns 0 on success, -1 on error */ static int _cb_cerebro_event_server(conffile_t cf, struct conffile_data *data, char *optionname, int option_type, void *option_ptr, int option_data, void *app_ptr, int app_data) { struct cerebro_config *conf; if (!option_ptr) { conffile_seterrnum(cf, CONFFILE_ERR_PARAMETERS); return -1; } conf = (struct cerebro_config *)option_ptr; /* arg1 - required - ip/hostname - 0.0.0.0 for default * arg2 - optional - port - 0 for default */ if (data->stringlist_len > 0) { int index = conf->cerebro_event_server_len; if (data->stringlist_len > 2) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_ARG_TOOMANY); return -1; } if (strlen(data->stringlist[0]) > CEREBRO_MAX_HOSTNAME_LEN) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_OVERFLOW_ARGLEN); return -1; } strcpy(conf->cerebro_event_server[index].hostname, data->stringlist[0]); if (data->stringlist_len > 1) { int port; char *endptr; port = strtol(data->stringlist[1], &endptr, 0); if (endptr != (data->stringlist[1] + strlen(data->stringlist[1]))) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_ARG_INVALID); return -1; } conf->cerebro_event_server[index].port = port; } else conf->cerebro_event_server[index].port = CEREBRO_CONFIG_PORT_DEFAULT; conf->cerebro_event_server_len++; } return 0; }
int interpret_config_parse_strtoul (conffile_t cf, const char *str, uint32_t max, uint32_t *value) { char *endptr = NULL; assert (cf); assert (str); assert (value); errno = 0; (*value) = strtoul (str, &endptr, 0); if (errno || endptr[0] != '\0' || (*value) > max) { conffile_seterrnum (cf, CONFFILE_ERR_PARSE_ARG_INVALID); return (-1); } return (0); }
/* * _cb_cerebrod_forward_host_accept * * callback function that parses and stores cerebrod forward host * accept configuration. * * Returns 0 on success, -1 on error */ static int _cb_cerebrod_forward_host_accept(conffile_t cf, struct conffile_data *data, char *optionname, int option_type, void *option_ptr, int option_data, void *app_ptr, int app_data) { struct cerebro_config *conf; if (!option_ptr) { conffile_seterrnum(cf, CONFFILE_ERR_PARAMETERS); return -1; } conf = (struct cerebro_config *)option_ptr; if (data->stringlist_len > 0) { int i; for (i = 0; i < data->stringlist_len; i++) { if (conf->cerebrod_forward_host_accept_len >= CEREBRO_CONFIG_FORWARD_HOST_ACCEPT_MAX) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_ARG_TOOMANY); return -1; } if (strlen(data->stringlist[i]) > CEREBRO_CONFIG_HOST_INPUT_MAX) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_OVERFLOW_ARGLEN); return -1; } strcpy(conf->cerebrod_forward_host_accept[conf->cerebrod_forward_host_accept_len], data->stringlist[i]); conf->cerebrod_forward_host_accept_len++; } } return 0; }
/* * _cb_heartbeat_freq * * conffile callback function that parses and stores heartbeat * configuration data * * Returns 0 on success, -1 on error */ static int _cb_cerebrod_heartbeat_freq(conffile_t cf, struct conffile_data *data, char *optionname, int option_type, void *option_ptr, int option_data, void *app_ptr, int app_data) { struct cerebro_config *conf; if (!option_ptr) { conffile_seterrnum(cf, CONFFILE_ERR_PARAMETERS); return -1; } conf = (struct cerebro_config *)option_ptr; if (data->intlist_len == 1) { conf->cerebrod_heartbeat_frequency_min = data->intlist[0]; conf->cerebrod_heartbeat_frequency_max = data->intlist[0]; } else if (data->intlist_len == 2) { if (data->intlist[0] > data->intlist[1]) { conffile_seterrnum(cf, CONFFILE_ERR_PARAMETERS); return -1; } conf->cerebrod_heartbeat_frequency_min = data->intlist[0]; conf->cerebrod_heartbeat_frequency_max = data->intlist[1]; } else { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_ARG_TOOMANY); return -1; } return 0; }
int interpret_config_parse_state (conffile_t cf, char *option_string) { assert (cf); assert (option_string); if (!strcasecmp (option_string, "Nominal")) return (IPMI_INTERPRET_STATE_NOMINAL); else if (!strcasecmp (option_string, "Warning")) return (IPMI_INTERPRET_STATE_WARNING); else if (!strcasecmp (option_string, "Critical")) return (IPMI_INTERPRET_STATE_CRITICAL); conffile_seterrnum (cf, CONFFILE_ERR_PARSE_ARG_INVALID); return (-1); }
int interpret_config_parse_manufactuer_id_product_id (conffile_t cf, const char *str, struct ipmi_interpret_config_file_ids ids[IPMI_INTERPRET_CONFIG_FILE_MANUFACTURER_ID_MAX], unsigned int *ids_count) { char *tmpstr = NULL; char *manufacturer_id_ptr; char *manufacturer_id_lasts; unsigned int i; int rv = -1; assert (cf); assert (str); assert (ids_count); (*ids_count) = 0; if (!(tmpstr = strdup (str))) { conffile_seterrnum (cf, CONFFILE_ERR_OUTMEM); goto cleanup; } manufacturer_id_ptr = strtok_r (tmpstr, ",", &manufacturer_id_lasts); while (manufacturer_id_ptr && (*ids_count) < IPMI_INTERPRET_CONFIG_FILE_MANUFACTURER_ID_MAX) { char *product_ids_ptr; char *ptr; uint32_t tmp; if (!(ptr = strchr (manufacturer_id_ptr, ':'))) { conffile_seterrnum (cf, CONFFILE_ERR_PARSE_ARG_INVALID); goto cleanup; } (*ptr) = '\0'; product_ids_ptr = ptr + 1; if (interpret_config_parse_strtoul (cf, manufacturer_id_ptr, 0x00FFFFFF, /* 24 bit manufacturer ID */ &tmp) < 0) goto cleanup; ids[(*ids_count)].manufacturer_id = tmp; if ((ptr = strchr (product_ids_ptr, '-'))) { char *product_id1_ptr; char *product_id2_ptr; uint16_t product_id1; uint16_t product_id2; product_id1_ptr = product_ids_ptr; (*ptr) = '\0'; product_id2_ptr = ptr + 1; if (interpret_config_parse_strtoul (cf, product_id1_ptr, USHRT_MAX, &tmp) < 0) goto cleanup; product_id1 = tmp; if (interpret_config_parse_strtoul (cf, product_id2_ptr, USHRT_MAX, &tmp) < 0) goto cleanup; product_id2 = tmp; if (product_id1 > product_id2) { conffile_seterrnum (cf, CONFFILE_ERR_PARSE_ARG_INVALID); return (-1); } if ((product_id2 - product_id1 + 1) > IPMI_INTERPRET_CONFIG_FILE_PRODUCT_ID_MAX) { conffile_seterrnum (cf, CONFFILE_ERR_PARSE_ARG_TOOMANY); return (-1); } for (i = 0; i < (product_id2 - product_id1 + 1) ; i++) ids[(*ids_count)].product_ids[i] = product_id1 + i; ids[(*ids_count)].product_ids_count = product_id2 - product_id1 + 1; } else if ((ptr = strchr (product_ids_ptr, '+'))) { unsigned int index = 0; uint16_t product_id; while ((ptr = strchr (product_ids_ptr, '+')) && index < IPMI_INTERPRET_CONFIG_FILE_PRODUCT_ID_MAX) { char *product_id_ptr; product_id_ptr = product_ids_ptr; (*ptr) = '\0'; product_ids_ptr = ptr + 1; if (interpret_config_parse_strtoul (cf, product_id_ptr, USHRT_MAX, &tmp) < 0) goto cleanup; product_id = tmp; ids[(*ids_count)].product_ids[index] = product_id; index++; } if (interpret_config_parse_strtoul (cf, product_ids_ptr, USHRT_MAX, &tmp) < 0) goto cleanup; product_id = tmp; ids[(*ids_count)].product_ids[index] = product_id; index++; ids[(*ids_count)].product_ids_count = index; } else { if (interpret_config_parse_strtoul (cf, product_ids_ptr, USHRT_MAX, &tmp) < 0) goto cleanup; ids[(*ids_count)].product_ids[0] = tmp; ids[(*ids_count)].product_ids_count = 1; } (*ids_count)++; manufacturer_id_ptr = strtok_r (NULL, ",", &manufacturer_id_lasts); } rv = 0; cleanup: free (tmpstr); return (rv); }
/* * _cb_cerebrod_module_exclude * * callback function that parses and stores cerebrod module exclude * configuration. * * Returns 0 on success, -1 on error */ static int _cb_cerebrod_module_exclude(conffile_t cf, struct conffile_data *data, char *optionname, int option_type, void *option_ptr, int option_data, void *app_ptr, int app_data) { struct cerebro_config *conf; if (!option_ptr) { conffile_seterrnum(cf, CONFFILE_ERR_PARAMETERS); return -1; } conf = (struct cerebro_config *)option_ptr; if (data->stringlist_len > 0) { int i; for (i = 0; i < data->stringlist_len; i++) { if (strlen(data->stringlist[i]) > CEREBRO_MAX_MODULE_NAME_LEN) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_OVERFLOW_ARGLEN); return -1; } /* achu: passing char[][] as pointer is badness, play it safe */ if (!strcasecmp(optionname, "cerebrod_metric_module_exclude")) { if (conf->cerebrod_metric_module_exclude_len >= CEREBRO_CONFIG_METRIC_MODULE_EXCLUDE_MAX) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_ARG_TOOMANY); return -1; } strcpy(conf->cerebrod_metric_module_exclude[conf->cerebrod_metric_module_exclude_len], data->stringlist[i]); conf->cerebrod_metric_module_exclude_len++; } else if (!strcasecmp(optionname, "cerebrod_monitor_module_exclude")) { if (conf->cerebrod_monitor_module_exclude_len >= CEREBRO_CONFIG_MONITOR_MODULE_EXCLUDE_MAX) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_ARG_TOOMANY); return -1; } strcpy(conf->cerebrod_monitor_module_exclude[conf->cerebrod_monitor_module_exclude_len], data->stringlist[i]); conf->cerebrod_monitor_module_exclude_len++; } else if (!strcasecmp(optionname, "cerebrod_event_module_exclude")) { if (conf->cerebrod_event_module_exclude_len >= CEREBRO_CONFIG_EVENT_MODULE_EXCLUDE_MAX) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_ARG_TOOMANY); return -1; } strcpy(conf->cerebrod_event_module_exclude[conf->cerebrod_event_module_exclude_len], data->stringlist[i]); conf->cerebrod_event_module_exclude_len++; } } } return 0; }
/* * _cb_cerebrod_forward_message_config * * callback function that parses and stores cerebrod forward message * configuration. * * Returns 0 on success, -1 on error */ static int _cb_cerebrod_forward_message_config(conffile_t cf, struct conffile_data *data, char *optionname, int option_type, void *option_ptr, int option_data, void *app_ptr, int app_data) { struct cerebro_config *conf; if (!option_ptr) { conffile_seterrnum(cf, CONFFILE_ERR_PARAMETERS); return -1; } conf = (struct cerebro_config *)option_ptr; /* arg1 - required - destination ip - 0.0.0.0 for default * arg2 - optional - destination port - 0 for default * arg3 - optional - source port - 0 for default * arg4 - optional - source_network_interface - 0.0.0.0 for default * arg5 - optional - list host specific for forwarding * arg6 ... */ if (data->stringlist_len > 0) { int index = conf->cerebrod_forward_message_config_len; if (data->stringlist_len > (4 + CEREBRO_CONFIG_FORWARD_HOST_MAX)) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_ARG_TOOMANY); return -1; } if (strlen(data->stringlist[0]) > CEREBRO_MAX_HOSTNAME_LEN) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_OVERFLOW_ARGLEN); return -1; } strcpy(conf->cerebrod_forward_message_config[index].ip, data->stringlist[0]); if (data->stringlist_len > 1) { int port; char *endptr; port = strtol(data->stringlist[1], &endptr, 0); if (endptr != (data->stringlist[1] + strlen(data->stringlist[1]))) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_ARG_INVALID); return -1; } conf->cerebrod_forward_message_config[index].destination_port = port; } else conf->cerebrod_forward_message_config[index].destination_port = CEREBRO_CONFIG_PORT_DEFAULT; if (data->stringlist_len > 2) { int port; char *endptr; port = strtol(data->stringlist[2], &endptr, 0); if (endptr != (data->stringlist[2] + strlen(data->stringlist[2]))) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_ARG_INVALID); return -1; } conf->cerebrod_forward_message_config[index].source_port = port; } else conf->cerebrod_forward_message_config[index].source_port = CEREBRO_CONFIG_PORT_DEFAULT; if (data->stringlist_len > 3) { if (strlen(data->stringlist[3]) > CEREBRO_MAX_HOSTNAME_LEN) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_OVERFLOW_ARGLEN); return -1; } strcpy(conf->cerebrod_forward_message_config[index].network_interface, data->stringlist[3]); } else strcpy(conf->cerebrod_forward_message_config[index].network_interface, CEREBRO_CONFIG_IP_DEFAULT); if (data->stringlist_len > 4) { int i; for (i = 4; i < data->stringlist_len; i++) { int host_index = conf->cerebrod_forward_message_config[index].host_len; if (strlen(data->stringlist[i]) > CEREBRO_CONFIG_HOST_INPUT_MAX) { conffile_seterrnum(cf, CONFFILE_ERR_PARSE_OVERFLOW_ARGLEN); return -1; } strcpy(conf->cerebrod_forward_message_config[index].host[host_index], data->stringlist[i]); conf->cerebrod_forward_message_config[index].host_len++; } } conf->cerebrod_forward_message_config_len++; } return 0; }