/* return -1 on failout error, 0 on invalid data */ static int _sel_parse_err_handle (pstdout_state_t pstate, ipmi_sel_ctx_t sel_ctx, int debug, const char *func) { assert (sel_ctx); assert (func); if (ipmi_sel_ctx_errnum (sel_ctx) == IPMI_SEL_ERR_INVALID_SEL_ENTRY) { /* most likely bad event data from remote system or user input */ if (debug) PSTDOUT_FPRINTF (pstate, stderr, "Invalid data\n"); return (0); } PSTDOUT_FPRINTF (pstate, stderr, "%s: %s\n", func, ipmi_sel_ctx_errormsg (sel_ctx)); return (-1); }
int event_load_event_state_config_file (pstdout_state_t pstate, ipmi_interpret_ctx_t interpret_ctx, const char *event_state_config_file) { if (event_state_config_file) { if (ipmi_interpret_load_sel_config (interpret_ctx, event_state_config_file) < 0) { if (ipmi_interpret_ctx_errnum (interpret_ctx) == IPMI_INTERPRET_ERR_SEL_CONFIG_FILE_DOES_NOT_EXIST) PSTDOUT_FPRINTF (pstate, stderr, "event state config file '%s' does not exist\n", event_state_config_file); else if (ipmi_interpret_ctx_errnum (interpret_ctx) == IPMI_INTERPRET_ERR_SEL_CONFIG_FILE_PARSE) PSTDOUT_FPRINTF (pstate, stderr, "event state config file '%s' parse error\n", event_state_config_file); else PSTDOUT_FPRINTF (pstate, stderr, "ipmi_interpret_load_sel_config: %s\n", ipmi_interpret_ctx_errormsg (interpret_ctx)); return (-1); } } else { if (ipmi_interpret_load_sel_config (interpret_ctx, NULL) < 0) { if (ipmi_interpret_ctx_errnum (interpret_ctx) == IPMI_INTERPRET_ERR_SEL_CONFIG_FILE_PARSE) PSTDOUT_FPRINTF (pstate, stderr, "event state config file parse error\n"); else PSTDOUT_FPRINTF (pstate, stderr, "ipmi_interpret_load_sel_config: %s\n", ipmi_interpret_ctx_errormsg (interpret_ctx)); return (-1); } } return (0); }
ipmi_ctx_t ipmi_open (const char *progname, const char *hostname, struct common_cmd_args *common_args, pstdout_state_t pstate) { ipmi_ctx_t ipmi_ctx = NULL; unsigned int workaround_flags = 0; assert (progname); assert (common_args); if (!(ipmi_ctx = ipmi_ctx_create ())) { PSTDOUT_FPRINTF (pstate, stderr, "ipmi_ctx_create: %s", strerror (errno)); goto cleanup; } if (hostname && strcasecmp (hostname, "localhost") != 0 && strcmp (hostname, "127.0.0.1") != 0) { if (common_args->driver_type == IPMI_DEVICE_LAN_2_0) { parse_get_freeipmi_outofband_2_0_flags (common_args->workaround_flags_outofband_2_0, &workaround_flags); if (ipmi_ctx_open_outofband_2_0 (ipmi_ctx, hostname, common_args->username, common_args->password, (common_args->k_g_len) ? common_args->k_g : NULL, (common_args->k_g_len) ? common_args->k_g_len : 0, common_args->privilege_level, common_args->cipher_suite_id, common_args->session_timeout, common_args->retransmission_timeout, workaround_flags, (common_args->debug) ? IPMI_FLAGS_DEBUG_DUMP : IPMI_FLAGS_DEFAULT) < 0) { if (ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_USERNAME_INVALID || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_PASSWORD_INVALID || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_K_G_INVALID || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_PRIVILEGE_LEVEL_INSUFFICIENT || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_PRIVILEGE_LEVEL_CANNOT_BE_OBTAINED || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_AUTHENTICATION_TYPE_UNAVAILABLE || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_CIPHER_SUITE_ID_UNAVAILABLE || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_PASSWORD_VERIFICATION_TIMEOUT || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_HOSTNAME_INVALID || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_IPMI_2_0_UNAVAILABLE || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_CONNECTION_TIMEOUT) PSTDOUT_FPRINTF (pstate, stderr, "%s: %s\n", progname, ipmi_ctx_errormsg (ipmi_ctx)); else PSTDOUT_FPRINTF (pstate, stderr, "ipmi_ctx_open_outofband_2_0: %s\n", ipmi_ctx_errormsg (ipmi_ctx)); goto cleanup; } } else { parse_get_freeipmi_outofband_flags (common_args->workaround_flags_outofband, &workaround_flags); if (ipmi_ctx_open_outofband (ipmi_ctx, hostname, common_args->username, common_args->password, common_args->authentication_type, common_args->privilege_level, common_args->session_timeout, common_args->retransmission_timeout, workaround_flags, (common_args->debug) ? IPMI_FLAGS_DEBUG_DUMP : IPMI_FLAGS_DEFAULT) < 0) { if (ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_USERNAME_INVALID || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_PASSWORD_INVALID || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_PRIVILEGE_LEVEL_INSUFFICIENT || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_PRIVILEGE_LEVEL_CANNOT_BE_OBTAINED || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_AUTHENTICATION_TYPE_UNAVAILABLE || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_PASSWORD_VERIFICATION_TIMEOUT || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_HOSTNAME_INVALID || ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_CONNECTION_TIMEOUT) PSTDOUT_FPRINTF (pstate, stderr, "%s: %s\n", progname, ipmi_ctx_errormsg (ipmi_ctx)); else PSTDOUT_FPRINTF (pstate, stderr, "ipmi_ctx_open_outofband: %s\n", ipmi_ctx_errormsg (ipmi_ctx)); goto cleanup; } } } else { if (!ipmi_is_root ()) { PSTDOUT_FPRINTF (pstate, stderr, "%s: %s\n", progname, ipmi_ctx_strerror (IPMI_ERR_PERMISSION)); goto cleanup; } parse_get_freeipmi_inband_flags (common_args->workaround_flags_inband, &workaround_flags); if (common_args->driver_type == IPMI_DEVICE_UNKNOWN) { int ret; if ((ret = ipmi_ctx_find_inband (ipmi_ctx, NULL, common_args->disable_auto_probe, common_args->driver_address, common_args->register_spacing, common_args->driver_device, workaround_flags, (common_args->debug) ? IPMI_FLAGS_DEBUG_DUMP : IPMI_FLAGS_DEFAULT)) < 0) { PSTDOUT_FPRINTF (pstate, stderr, "ipmi_ctx_find_inband: %s\n", ipmi_ctx_errormsg (ipmi_ctx)); goto cleanup; } if (!ret) { PSTDOUT_FPRINTF (pstate, stderr, "could not find inband device"); goto cleanup; } } else { if (ipmi_ctx_open_inband (ipmi_ctx, common_args->driver_type, common_args->disable_auto_probe, common_args->driver_address, common_args->register_spacing, common_args->driver_device, workaround_flags, (common_args->debug) ? IPMI_FLAGS_DEBUG_DUMP : IPMI_FLAGS_DEFAULT) < 0) { if (ipmi_ctx_errnum (ipmi_ctx) == IPMI_ERR_DEVICE_NOT_FOUND) PSTDOUT_FPRINTF (pstate, stderr, "%s: %s\n", progname, ipmi_ctx_errormsg (ipmi_ctx)); else PSTDOUT_FPRINTF (pstate, stderr, "ipmi_ctx_open_inband: %s\n", ipmi_ctx_errormsg (ipmi_ctx)); goto cleanup; } } } if (common_args->target_channel_number_is_set || common_args->target_slave_address_is_set) { if (ipmi_ctx_set_target (ipmi_ctx, common_args->target_channel_number_is_set ? &common_args->target_channel_number : NULL, common_args->target_slave_address_is_set ? &common_args->target_slave_address : NULL) < 0) { PSTDOUT_FPRINTF (pstate, stderr, "ipmi_ctx_set_target: %s\n", ipmi_ctx_errormsg (ipmi_ctx)); goto cleanup; } } return (ipmi_ctx); cleanup: ipmi_ctx_close (ipmi_ctx); ipmi_ctx_destroy (ipmi_ctx); return (NULL); }