⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsupconfig.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 5 页
字号:
 * @param[in] matchname   The name of the connection to locate the configuration for.
 *
 * \retval ptr  A pointer to the connection information, or NULL on failure.
 **/
struct config_connection *config_find_connection(char *matchname)
{
  struct config_connection *cur;

  TRACE

  cur = conf_connections;

  if ((matchname == NULL) && (forced_profile == NULL))
    {
		debug_printf(DEBUG_CONFIG_PARSE, "No configuration name provided, and no forced profile provided!\n");
      return NULL;
    }

  // If we have a forced profile, then look for it first.
  if (forced_profile != NULL)
    {
      while ((cur != NULL) && (strcmp(cur->name, forced_profile) != 0))
	{
	  cur = cur->next;
	}

      // If a forced profile is defined, and not found, then we still
      // need to return.
      return cur;
    }

  while ((cur != NULL) && (strcmp(cur->name, matchname) != 0))
    {
      cur = cur->next;
    }
  
  // If we got a match, return it.
  if (cur != NULL)
    {
      return cur;
    }
  
  // Otherwise, look against the essid.
  cur = conf_connections;

  while (cur != NULL)
  {
    if ((cur->ssid == NULL) || (strcmp(cur->ssid,matchname) != 0)) 
	{
	  cur = cur->next;
	} else {
  	  break;
	}
  }
  
  // Do we have a match on ssid?
  if (cur != NULL)
  {
	return cur;
  }

  return NULL;
}

/**
 * \brief Free a single profile.
 *
 * @param[in] prof   A pointer to the profile that we want to free.
 *
 * \retval XENONE on success
 * \retval XEMALLOC on failure
 **/
int delete_config_single_profile(struct config_profiles **prof)
{
  struct config_profiles *cur;

  if (prof == NULL) return XEMALLOC;

  if ((*prof) == NULL) return XEMALLOC;

  cur = (*prof);

  FREE_STRING(cur->name);
  FREE_STRING(cur->identity);
  FREE_STRING(cur->temp_password);
  FREE_STRING(cur->temp_username);
  delete_config_eap_method(&cur->method);

  free((*prof));

  return XENONE;
}

/** 
 * \brief Remove a profile from out linked list.
 * 
 * @param[in] profname  The name of the profile that we want to remove from 
 *                      the list.
 *
 * \retval XENONE on success
 * \retval XENOTHING_TO_DO if the connection didn't exist.
 **/
int config_delete_profile(char *profname)
{
  struct config_profiles *cur, *prev;

  TRACE

	if (profname == NULL) return XENOTHING_TO_DO;

	if (conf_profiles == NULL) return XENOTHING_TO_DO;

    if (strcmp(conf_profiles->name, profname) == 0)
      {
	// The first one is the one we want to remove.
	cur = conf_profiles;
	conf_profiles = cur->next;

	// Then, delete everything in that network.
	delete_config_single_profile(&cur);

	return XENONE;
      }

  // Otherwise, it will be somewhere else.
  cur = conf_profiles->next;
  prev = conf_profiles;

  while ((cur) && (strcmp(cur->name, profname) != 0))
    {
      cur = cur->next;
      prev = prev->next;
    }

  if ((cur) && (strcmp(cur->name, profname) == 0))
    {
      // We found the network to delete.
      prev->next = cur->next;

      delete_config_single_profile(&cur);
      return XENONE;
    }

  return XENOTHING_TO_DO;
}

/**
 * \brief Remove a connection from our linked list.
 *
 * @param[in] netname  The name of the connection to remove from the list.
 *
 * \retval XENONE on success
 * \retval XENOTHING_TO_DO if the connection didn't exist.
 **/
int config_delete_connection(char *netname)
{
  struct config_connection *cur, *prev;

  TRACE

  if (netname == NULL) return XENOTHING_TO_DO;

  if (conf_connections == NULL) return XENOTHING_TO_DO;

  if (strcmp(conf_connections->name, netname) == 0)
    {
      // The first one is the one we want to remove.
      cur = conf_connections;
      conf_connections = cur->next;

      // Then, delete everything in that network.
      delete_config_single_connection(&cur);

      return XENONE;
    }

  // Otherwise, it will be somewhere else.
  cur = conf_connections->next;
  prev = conf_connections;

  while ((cur) && (strcmp(cur->name, netname) != 0))
    {
      cur = cur->next;
      prev = prev->next;
    }

  if ((cur) && (strcmp(cur->name, netname) == 0))
    {
      // We found the network to delete.
      prev->next = cur->next;

      delete_config_single_connection(&cur);
      return XENONE;
    }
  
  return XENOTHING_TO_DO;
}

/**
 * \brief Remove an interface from our linked list.
 *
 * @param[in] intdesc  The description of the interface to remove from the list.
 *
 * \retval XENONE on success
 * \retval XENOTHING_TO_DO if the interface didn't exist.
 **/
int config_delete_interface(char *intdesc)
{
  struct xsup_interfaces *cur, *prev;

  TRACE

  if (conf_devices == NULL) return XENOTHING_TO_DO;

  cur = conf_devices->interf;

  if (cur == NULL) return XENOTHING_TO_DO;

  if (strcmp(cur->description, intdesc) == 0)
    {
      // The first one is the one we want to remove.
		conf_devices->interf = cur->next;

      // Then, delete everything in that network.
      delete_config_interface(&cur);

      return XENONE;
    }

  // Otherwise, it will be somewhere else.
  prev = cur;
  cur = cur->next;

  while ((cur) && (strcmp(cur->description, intdesc) != 0))
    {
      cur = cur->next;
      prev = prev->next;
    }

  if ((cur) && (strcmp(cur->description, intdesc) == 0))
    {
      // We found the network to delete.
      prev->next = cur->next;

      delete_config_interface(&cur);
      return XENONE;
    }
  
  return XENOTHING_TO_DO;
}

/**
 * \brief Remove a trusted server from our linked list.
 *
 * @param[in] svrname  The name of the trusted server to remove from the list.
 *
 * \retval XENONE on success
 * \retval XENOTHING_TO_DO if the server didn't exist.
 **/
int config_delete_trusted_server(char *svrname)
{
  struct config_trusted_server *cur, *prev;

  TRACE

  if (svrname == NULL) return XENOTHING_TO_DO;

  if (conf_trusted_servers == NULL) return XENOTHING_TO_DO;

  cur = conf_trusted_servers->servers;

  if (cur == NULL) return XENOTHING_TO_DO;

  if (strcmp(cur->name, svrname) == 0)
    {
      // The first one is the one we want to remove.
	  conf_trusted_servers->servers = cur->next;

      // Then, delete everything in that network.
      delete_config_trusted_server(&cur);

      return XENONE;
    }

  // Otherwise, it will be somewhere else.
  prev = cur;
  cur = cur->next;

  while ((cur) && (strcmp(cur->name, svrname) != 0))
    {
      cur = cur->next;
      prev = prev->next;
    }

  if ((cur) && (strcmp(cur->name, svrname) == 0))
    {
      // We found the one to delete.
      prev->next = cur->next;

      delete_config_trusted_server(&cur);
      return XENONE;
    }
  
  return XENOTHING_TO_DO;
}


/**
 * \brief Get a pointer to the config global information.  
 *
 * \retval ptr   Pointer to the structure that contains the variable
 *               settings from the <Globals> section of the configuration.
 *
 * \warning This pointer should *NEVER* be freed by any callers, or things will break!!!!!!
 **/
struct config_globals *config_get_globals()
{
	TRACE
  return conf_globals;
}

/**
 *  \brief Get a pointer to the information about the interfaces that we loaded
 *         from the configuration file.
 *
 *  \retval ptr   Pointer to the structure that contains the interfaces
 *                that were defined in the <Interface> section of the
 *                <Device> block.
 *
 *  \warning This pointer should *NEVER* be freed by any callers, or things will break!
 **/
struct xsup_interfaces *config_get_config_ints()
{
	TRACE

	// If we don't have any devices in the config file, then say so. ;)
	if (conf_devices == NULL) return NULL;

	return conf_devices->interf;
}

/**
 *  \brief Get the phase 2 password from TTLS.
 *
 *  @param[in] ttls   A pointer to the TTLS configuration structure that
 *                    contains the password you would like to find.
 *
 *  \retval password  The password from the phase 2 section of the
 *                    TTLS configuration.
 *  \retval NULL  Failure
 **/
char *config_get_ttls_pwd(struct config_eap_ttls *ttls)
{
	if (((struct config_pwd_only *)(ttls->phase2_data)) == NULL) return NULL;

	switch (ttls->phase2_type)
	{
	case TTLS_PHASE2_PAP:
		return ((struct config_pwd_only *)(ttls->phase2_data))->password;
		break;

	case TTLS_PHASE2_CHAP:
		return ((struct config_pwd_only *)(ttls->phase2_data))->password;
		break;

	case TTLS_PHASE2_MSCHAP:
		return ((struct config_pwd_only *)(ttls->phase2_data))->password;
		break;

	case TTLS_PHASE2_MSCHAPV2:
		return ((struct config_pwd_only *)(ttls->phase2_data))->password;
		break;

	case TTLS_PHASE2_EAP:
		return config_get_pwd_from_profile(ttls->phase2_data);
		break;

	case TTLS_PHASE2_UNDEFINED:
	default:
	  return NULL;
	  break;
	}

	return NULL;
}

/**
 *  \brief Get the password for an EAP method that is buried in a
 *         config_eap_method struct.
 *
 *  @param[in] meth   A structure that contains the EAP method configuration
 *                    data, and an integer that identifies the EAP method.
 *
 *  \retval ptr   The password from the EAP method specified by 'meth'.
 **/
char *config_get_pwd_from_profile(struct config_eap_method *meth)
{
	switch (meth->method_num)
	{
	case EAP_TYPE_MD5:
	case EAP_TYPE_GTC:
	case EAP_TYPE_LEAP:
		return ((struct config_pwd_only *)(meth->method_data))->password;
		break;

	case EAP_TYPE_OTP:
		return NULL;         // No password here.
		break;

	case EAP_TYPE_TLS:
		return ((struct config_eap_tls *)(meth->method_data))->user_key_pass;
		break;

	case EAP_TYPE_SIM:
		return ((struct config_eap_sim *)(meth->method_data))->password;
		break;

	case EAP_TYPE_TTLS:
		return config_get_ttls_pwd(((struct config_eap_ttls *)(meth->method_data)));
		break;	

	case EAP_TYPE_AKA:
		return ((struct config_eap_aka *)(meth->method_data))->password;
		break;

	case EAP_TYPE_PEAP:
		return config_get_pwd_from_profile((((struct config_eap_peap *)(meth->method_data))->phase2));
		break;

	case EAP_TYPE_MSCHAPV2:
		return ((struct config_eap_mschapv2 *)(meth->method_data))->password;
		break;

	case EAP_TYPE_FAST:
		return config_get_pwd_from_profile((((struct config_eap_fast *)(meth->method_data))->phase2));
		break;
	}

	return NULL;
}

/**
 *  \brief Get the inner username for an EAP method that is buried in a
 *         config_eap_method struct.
 *
 *  @param[in] meth   A structure that contains the EAP method configuration
 *                    data, and an integer that identifies the EAP method.
 *
 *  \retval ptr   The password from the EAP method specified by 'meth'.
 **/
char *config_get_inner_user_from_profile(struct config_eap_method *meth)
{
	switch (meth->method_num)
	{
	case EAP_TYPE_TTLS:
		return ((struct config_eap_ttls *)(meth->method_data))->inner_id;
		break;	

	case EAP_TYPE_PEAP:
		return ((struct config_eap_peap *)(meth->method_data))->identity;
		break;

	case EAP_TYPE_FAST:
		return ((struct config_eap_fast *)(meth->method_data))->innerid;
		break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -