struct ipmi_config_section *
ipmi_config_core_sections_create (ipmi_config_state_data_t *state_data)
{
  struct ipmi_config_section *sections = NULL;
  struct ipmi_config_section *section = NULL;
  uint8_t number_of_users;
  unsigned int userindex;
  int channelindex;

  assert (state_data);

  if (load_lan_channel_numbers (state_data) == IPMI_CONFIG_ERR_FATAL_ERROR)
    return (NULL);
  
  if (load_serial_channel_numbers (state_data) == IPMI_CONFIG_ERR_FATAL_ERROR)
    return (NULL);

  if (load_sol_channel_numbers (state_data) == IPMI_CONFIG_ERR_FATAL_ERROR)
    return (NULL);

  if (_get_number_of_users (state_data, &number_of_users) != IPMI_CONFIG_ERR_SUCCESS)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "Unable to get Number of Users\n");
      return (NULL);
    }
 
  if (state_data->prog_data->args->verbose_count
      && state_data->lan_channel_numbers_count > 1)
    {
      state_data->lan_base_config_flags = IPMI_CONFIG_DO_NOT_CHECKOUT;
      state_data->lan_channel_config_flags = 0;
    }
  else
    {
      state_data->lan_base_config_flags = 0;
      state_data->lan_channel_config_flags = IPMI_CONFIG_DO_NOT_CHECKOUT;
    }

  if (state_data->prog_data->args->verbose_count
      && state_data->serial_channel_numbers_count > 1)
    {
      state_data->serial_base_config_flags = IPMI_CONFIG_DO_NOT_CHECKOUT;
      state_data->serial_channel_config_flags = 0;
    }
  else
    {
      state_data->serial_base_config_flags = 0;
      state_data->serial_channel_config_flags = IPMI_CONFIG_DO_NOT_CHECKOUT;
    }

  if (state_data->prog_data->args->verbose_count
      && state_data->sol_channel_numbers_unique_count > 1)
    {
      state_data->sol_base_config_flags = IPMI_CONFIG_DO_NOT_CHECKOUT;
      state_data->sol_channel_config_flags = 0;
    }
  else
    {
      state_data->sol_base_config_flags = 0;
      state_data->sol_channel_config_flags = IPMI_CONFIG_DO_NOT_CHECKOUT;
    }

  /* User Section(s) */

  for (userindex = 0; userindex < number_of_users; userindex++)
    {
      if (!(section = ipmi_config_core_user_section_get (state_data, userindex + 1)))
        goto cleanup;
      if (ipmi_config_section_append (&sections, section) < 0)
        goto cleanup;
    }

  /* Lan_Channel Section(s) */

  if (!(section = ipmi_config_core_lan_channel_section_get (state_data,
							    state_data->lan_base_config_flags,
							    -1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->lan_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->lan_channel_numbers_count; channelindex++)
        {
          if (!(section = ipmi_config_core_lan_channel_section_get (state_data,
								    state_data->lan_channel_config_flags,
								    channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }

  /* Lan_Conf Section(s) */

  if (!(section = ipmi_config_core_lan_conf_section_get (state_data,
							 state_data->lan_base_config_flags,
							 -1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->lan_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->lan_channel_numbers_count; channelindex++)
        {
          if (!(section = ipmi_config_core_lan_conf_section_get (state_data,
								 state_data->lan_channel_config_flags,
								 channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }

  /* Lan_Conf_Auth Section(s) */

  if (!(section = ipmi_config_core_lan_conf_auth_section_get (state_data,
							      state_data->lan_base_config_flags,
							      -1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->lan_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->lan_channel_numbers_count; channelindex++)
        {
          if (!(section = ipmi_config_core_lan_conf_auth_section_get (state_data,
								      state_data->lan_channel_config_flags,
								      channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }

  /* Lan_Conf_Security_Keys Section(s) */

  if (!(section = ipmi_config_core_lan_conf_security_keys_section_get (state_data,
								       state_data->lan_base_config_flags,
								       -1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->lan_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->lan_channel_numbers_count; channelindex++)
        {
          if (!(section = ipmi_config_core_lan_conf_security_keys_section_get (state_data,
									       state_data->lan_channel_config_flags,
									       channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }

  /* Lan_Conf_User_Security Section(s) */

  if (!(section = ipmi_config_core_lan_conf_user_security_section_get (state_data,
								       state_data->lan_base_config_flags,
								       -1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->lan_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->lan_channel_numbers_count; channelindex++)
        {
          if (!(section = ipmi_config_core_lan_conf_user_security_section_get (state_data,
									       state_data->lan_channel_config_flags,
									       channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }

  /* Lan_Conf_Misc Section(s) */

  if (!(section = ipmi_config_core_lan_conf_misc_section_get (state_data,
							      state_data->lan_base_config_flags,
							      -1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->lan_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->lan_channel_numbers_count; channelindex++)
        {
          if (!(section = ipmi_config_core_lan_conf_misc_section_get (state_data,
								      state_data->lan_channel_config_flags,
								      channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }

  /* Rmcpplus_Conf_Privilege Section(s) */
 
  if (!(section = ipmi_config_core_rmcpplus_conf_privilege_section_get (state_data,
									state_data->lan_base_config_flags,
									-1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->lan_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->lan_channel_numbers_count; channelindex++)
        {
          if (!(section = ipmi_config_core_rmcpplus_conf_privilege_section_get (state_data,
										state_data->lan_channel_config_flags,
										channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }

  /* Serial_Channel Section(s) */

  if (!(section = ipmi_config_core_serial_channel_section_get (state_data,
							       state_data->serial_base_config_flags,
							       -1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->serial_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->serial_channel_numbers_count; channelindex++)
        {
          if (!(section = ipmi_config_core_serial_channel_section_get (state_data,
								       state_data->serial_channel_config_flags,
								       channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }

  /* Serial_Conf Section(s) */

  if (!(section = ipmi_config_core_serial_conf_section_get (state_data,
							    state_data->serial_base_config_flags,
							    -1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->serial_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->serial_channel_numbers_count; channelindex++)
        {
          if (!(section = ipmi_config_core_serial_conf_section_get (state_data,
								    state_data->serial_channel_config_flags,
								    channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }

  /* PEF Conf Section */

  if (!(section = ipmi_config_core_pef_conf_section_get (state_data)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  /* SOL_Conf Section(s) */

  if (!(section = ipmi_config_core_sol_conf_section_get (state_data,
							 state_data->sol_base_config_flags,
							 -1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->sol_channel_numbers_unique_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->sol_channel_numbers_unique_count; channelindex++)
        {
          if (!(section = ipmi_config_core_sol_conf_section_get (state_data,
								 state_data->sol_channel_config_flags,
								 channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }
  
  /* Misc Section */

  if (!(section = ipmi_config_core_misc_section_get (state_data)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  return (sections);

 cleanup:
  ipmi_config_sections_destroy (sections);
  return (NULL);
}
struct config_section *
ipmi_pef_config_alert_policy_table_section_get (ipmi_pef_config_state_data_t *state_data, unsigned int num)
{
  struct config_section *section = NULL;
  char section_name[CONFIG_MAX_SECTION_NAME_LEN];
  char description[CONFIG_MAX_DESCRIPTION_LEN];

  assert (state_data);
  assert (num);

  snprintf (section_name, CONFIG_MAX_SECTION_NAME_LEN, "Alert_Policy_%u", num);

  if (!(section = config_section_create (state_data->pstate,
                                         section_name,
                                         NULL,
                                         NULL,
                                         0,
                                         NULL,
                                         NULL)))
    goto cleanup;

  if (config_section_add_key (state_data->pstate,
                              section,
                              "Policy_Type",
                              "Possible values: Always_Send_To_This_Destination/Proceed_To_Next_Entry/Do_Not_Proceed_Any_More_Entries/Proceed_To_Next_Entry_Different_Channel/Proceed_To_Next_Entry_Different_Destination_Type",
                              0,
                              policy_type_checkout,
                              policy_type_commit,
                              policy_type_validate) < 0)
    goto cleanup;

  if (config_section_add_key (state_data->pstate,
                              section,
                              "Policy_Enabled",
                              "Possible values: Yes/No",
                              0,
                              policy_enabled_checkout,
                              policy_enabled_commit,
                              config_yes_no_validate) < 0)
    goto cleanup;

  if (config_section_add_key (state_data->pstate,
                              section,
                              "Policy_Number",
                              "Give a valid number",
                              0,
                              policy_number_checkout,
                              policy_number_commit,
                              config_number_range_four_bits) < 0)
    goto cleanup;

  if (config_section_add_key (state_data->pstate,
                              section,
                              "Destination_Selector",
                              "Give a valid number",
                              0,
                              destination_selector_checkout,
                              destination_selector_commit,
                              config_number_range_four_bits) < 0)
    goto cleanup;

  if (!state_data->lan_channel_numbers_loaded)
    {
      if (load_lan_channel_numbers (state_data) != CONFIG_ERR_SUCCESS)
	goto cleanup;
    }

  if (state_data->lan_channel_numbers_count > 0)
    {
      char tempbuf[CONFIG_MAX_DESCRIPTION_LEN];
      int i;

      snprintf (description,
		CONFIG_MAX_DESCRIPTION_LEN,
		"Give a valid number (LAN = %u",
		state_data->lan_channel_numbers[0]);

      for (i = 1; i < state_data->lan_channel_numbers_count; i++)
	{
	  snprintf (tempbuf,
		    CONFIG_MAX_DESCRIPTION_LEN,
		    ", %u",
		    state_data->lan_channel_numbers[i]);
	  
	  strcat (description, tempbuf);
	}

      strcat (description, ")");
    }
  else
    snprintf (description,
	      CONFIG_MAX_DESCRIPTION_LEN,
	      "Give a valid number");

  if (config_section_add_key (state_data->pstate,
                              section,
                              "Channel_Number",
                              description,
                              0,
                              channel_number_checkout,
                              channel_number_commit,
                              config_number_range_four_bits) < 0)
    goto cleanup;

  if (config_section_add_key (state_data->pstate,
                              section,
                              "Alert_String_Set_Selector",
                              "Give a valid number",
                              0,
                              alert_string_set_selector_checkout,
                              alert_string_set_selector_commit,
                              config_number_range_seven_bits) < 0)
    goto cleanup;

  if (config_section_add_key (state_data->pstate,
                              section,
                              "Event_Specific_Alert_String",
                              "Possible values: Yes/No",
                              0,
                              event_specific_alert_string_checkout,
                              event_specific_alert_string_commit,
                              config_yes_no_validate) < 0)
    goto cleanup;

  return (section);

 cleanup:
  if (section)
    config_section_destroy (section);
  return (NULL);
}
struct ipmi_config_section *
ipmi_config_pef_sections_create (ipmi_config_state_data_t *state_data)
{
  struct ipmi_config_section *sections = NULL;
  struct ipmi_config_section *section = NULL;
  uint8_t number_of_lan_alert_destinations = 0;
  uint8_t number_of_alert_strings = 0;
  uint8_t number_of_alert_policy_entries = 0;
  uint8_t number_of_event_filters = 0;
  unsigned int i;
  int channelindex;

  assert (state_data);

  if (load_lan_channel_numbers (state_data) == IPMI_CONFIG_ERR_FATAL_ERROR) 
    return (NULL);

  if (_get_number_of_lan_alert_destinations (state_data,
					     &number_of_lan_alert_destinations) != IPMI_CONFIG_ERR_SUCCESS)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "Unable to get Number of Alert Destinations\n");
      return (NULL);
    }

  if (_get_number_of_alert_policy_entries (state_data,
					   &number_of_alert_policy_entries) != IPMI_CONFIG_ERR_SUCCESS)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "Unable to get Number of Alert Policy Entries\n");
      return (NULL);
    }

  if (_get_number_of_alert_strings (state_data,
				    &number_of_alert_strings) != IPMI_CONFIG_ERR_SUCCESS)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "Unable to get Number of Alert Strings\n");
      return (NULL);
    }

  if (_get_number_of_event_filters (state_data,
				    &number_of_event_filters) != IPMI_CONFIG_ERR_SUCCESS)
    {
      pstdout_fprintf (state_data->pstate,
                       stderr,
                       "Unable to get Number of Event Filters\n");
      return (NULL);
    }

  if (state_data->prog_data->args->verbose_count
      && state_data->lan_channel_numbers_count > 1)
    {
      state_data->lan_base_config_flags = IPMI_CONFIG_DO_NOT_CHECKOUT;
      state_data->lan_channel_config_flags = 0;
    }
  else
    {
      state_data->lan_base_config_flags = 0;
      state_data->lan_channel_config_flags = IPMI_CONFIG_DO_NOT_CHECKOUT;
    }

  /* PEF_Conf Section */

  if (!(section = ipmi_config_pef_pef_conf_section_get (state_data)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  /* Community_String Section(s) */

  if (!(section = ipmi_config_pef_community_string_section_get (state_data,
								state_data->lan_base_config_flags,
								-1)))
    goto cleanup;
  if (ipmi_config_section_append (&sections, section) < 0)
    goto cleanup;

  if (state_data->lan_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->lan_channel_numbers_count; channelindex++)
        {
          if (!(section = ipmi_config_pef_community_string_section_get (state_data,
									state_data->lan_channel_config_flags,
									channelindex)))
            goto cleanup;
          if (ipmi_config_section_append (&sections, section) < 0)
            goto cleanup;
        }
    }

  /* Lan_Alert_Destination Section(s) */


  for (i = 0; i <= number_of_lan_alert_destinations; i++)
    {
      if (!(section = ipmi_config_pef_lan_alert_destination_section_get (state_data,
									 i,
									 state_data->lan_base_config_flags,
									 -1)))
        goto cleanup;
      if (ipmi_config_section_append (&sections, section) < 0)
        goto cleanup;
    }

  if (state_data->lan_channel_numbers_count > 1)
    {
      for (channelindex = 0; channelindex < state_data->lan_channel_numbers_count; channelindex++)
        {
	  for (i = 0; i < number_of_lan_alert_destinations; i++)
	    {
	      if (!(section = ipmi_config_pef_lan_alert_destination_section_get (state_data,
										 i + 1,
										 state_data->lan_channel_config_flags,
										 channelindex)))
		goto cleanup;
	      if (ipmi_config_section_append (&sections, section) < 0)
		goto cleanup;
	    }
        }
    }

  /* Alert_String Section(s) */

  for (i = 0; i <= number_of_alert_strings; i++)
    {
      if (!(section = ipmi_config_pef_alert_string_section_get (state_data, i)))
        goto cleanup;
      if (ipmi_config_section_append (&sections, section) < 0)
        goto cleanup;
    }

  /* Alert_Policy Section(s) */

  for (i = 0; i < number_of_alert_policy_entries; i++)
    {
      if (!(section = ipmi_config_pef_alert_policy_table_section_get (state_data, i + 1)))
        goto cleanup;
      if (ipmi_config_section_append (&sections, section) < 0)
        goto cleanup;
    }

  /* Event_Filter Section(s) */

  for (i = 0; i < number_of_event_filters; i++)
    {
      if (!(section = ipmi_config_pef_event_filter_table_section_get (state_data, i + 1)))
        goto cleanup;
      if (ipmi_config_section_append (&sections, section) < 0)
        goto cleanup;
    }

  return (sections);

 cleanup:
  ipmi_config_sections_destroy (sections);
  return (NULL);
}