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

📄 xsupconfcheck.c

📁 Linux上的802.1x 的supplicant的实现。很多supplicant程序都是基于它开发的
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <strings.h>#include "xsupconfig.h"#include "xsupconfcheck.h"#ifdef USE_EFENCE#include <efence.h>#endif/****************************************************************** * * Do anything necessary to set up the library. * ******************************************************************/int xsupconfcheck_init(){  return 0;}/***************************************************************** * * Add an error to the list.  This function should only be used inside this * library!! * *****************************************************************/void xsupconfcheck_add_log(cerrs **errors, char *line, ...){  va_list ap;  cerrs *cur;  char errorline[2048];  if ((*errors) == NULL)    {      *errors = NULL;      *errors = (cerrs *)malloc(sizeof(cerrs));      if (!(*errors)) return;      cur = *errors;    } else {      cur = *errors;      while (cur->next) cur = cur->next;            cur->next = (cerrs *)malloc(sizeof(cerrs));      if (!cur->next) return;      cur = cur->next;    }  // At this point, cur should point to some memory space that needs to be  // populated.  va_start(ap, line);    vsnprintf((char *)&errorline, 2048, line, ap);  cur->line = strdup(errorline);  cur->next = NULL;}/***************************************************************** * * Check the global settings to verify that the needed settings are in place. * *****************************************************************/int xsupconfcheck_check_globals(struct config_globals *globals, 				cerrs **errors){  int retval = 0;  if (!globals)    {      xsupconfcheck_add_log(errors, "No global values to check!\n");      return -1;    }  // In the globals, we only need the default_net and allowed_nets to be set.  if (!globals->default_net)    {      xsupconfcheck_add_log(errors, "No 'default_netname' is configured.\n");      retval = -1;    }  return retval;}/***************************************************************** * * Verify that we have valid keys set for the static WEP method. * *****************************************************************/int xsupconfcheck_check_static_wep_method(struct config_static_wep *wep,					  char *netname, cerrs **errors){  int retval = 0;  int len;  if ((wep->tx_key < 1) || (wep->tx_key > 4))    {      xsupconfcheck_add_log(errors, "In network clause '%s', the static WEP"			    " key index is invalid.\n");      retval = -1;    } else {      // We can't check for the validity of a key, if the index is wrong,      // since we mostly care about the key that is defined by the index value.      if (!wep->key[wep->tx_key])	{	  xsupconfcheck_add_log(errors, "In network clause '%s', the static "				"key pointed to by the 'tx_key' setting is "				"empty.\n", netname);	} else {	  // Make sure the length of the key is valid.  It should be either	  // 10, or 26 characters.  (The key is represented by a string of	  // hex digits.	  len = strlen((char *)wep->key[wep->tx_key]);	  if ((len != 26) && (len != 10))	    {	      xsupconfcheck_add_log(errors, "In network clause '%s', the "				    "static key pointed to by the tx_key (%d)"				    "setting has an invalid length.\n",				    netname, wep->tx_key);	      retval = -1;	    }	}    }        return retval;}/***************************************************************** * * Verify that we have valid keys set for the initial WEP method. * *****************************************************************/int xsupconfcheck_check_initial_wep_method(struct config_static_wep *wep,					   char *netname, cerrs **errors){  int retval = 0;  int len;  if ((wep->tx_key < 1) || (wep->tx_key > 4))    {      xsupconfcheck_add_log(errors, "In network clause '%s', the initial WEP"			    " key index is invalid.\n");      retval = -1;    } else {      // We can't check for the validity of a key, if the index is wrong,      // since we mostly care about the key that is defined by the index value.      if (!wep->key[wep->tx_key])	{	  xsupconfcheck_add_log(errors, "In network clause '%s', the initial "				"WEP key pointed to by the 'tx_key' setting is"				" empty.\n", netname);	} else {	  // Make sure the length of the key is valid.  It should be either	  // 10, or 26 characters.  (The key is represented by a string of	  // hex digits.	  len = strlen((char *)wep->key[wep->tx_key]);	  if ((len != 26) && (len != 10))	    {	      xsupconfcheck_add_log(errors, "In network clause '%s', the "				    "initial WEP key pointed to by the tx_key "				    "(%d) setting has an invalid length.\n",				    netname, wep->tx_key);	      retval = -1;	    }	}    }        return retval;}/***************************************************************** * * Verify that there are valid settings for WPA_PSK. * *****************************************************************/int xsupconfcheck_check_wpa_psk(struct config_wpa_psk *psk, char *netname,				cerrs **errors){  int retval = 0;  if ((!psk->key) && (!psk->hex_key))    {      xsupconfcheck_add_log(errors, "WPA-PSK needs either a 'key', or "			    "'hex_key' in network clause '%s'.\n", netname);      retval = -1;    }  return retval;}/***************************************************************** * * Check the configuration options for EAP-MD5. * *****************************************************************/int xsupconfcheck_check_eap_md5(struct config_eap_md5 *md5, char *netname, 				cerrs **errors){  int retval = 0;  // For EAP-MD5, we don't need anything defined.  The only thing that matters  // is that we have a password, and if we don't currently have one, we will  // ask a GUI to provide one for us.  return retval;}/***************************************************************** * * Check the configuration options for EAP-OTP. * *****************************************************************/int xsupconfcheck_check_eap_otp(struct config_eap_otp *otp, char *netname, 				cerrs **errors){  int retval = 0;  // For EAP-OTP, we don't need anything defined.  The only thing that matters  // is that we have a password, and if we don't currently have one, we will  // ask a GUI to provide one for us.  return retval;}/***************************************************************** * * Check the configuration options for EAP-GTC. * *****************************************************************/int xsupconfcheck_check_eap_gtc(struct config_eap_otp *gtc, char *netname, 				cerrs **errors){  int retval = 0;  // For EAP-GTC, we don't need anything defined.  The only thing that matters  // is that we have a password, and if we don't currently have one, we will  // ask a GUI to provide one for us.  return retval;}/***************************************************************** * * Verify that the configuration information we have for EAP-TLS contains  * enough information to complete a configuration. * *****************************************************************/int xsupconfcheck_check_eap_tls(struct config_eap_tls *tls, char *netname,				cerrs **errors){  int retval = 0;  if (!tls->user_cert)    {      xsupconfcheck_add_log(errors, "In network clause '%s', EAP-TLS requires"			    " a 'user_cert' option.\n", netname);      retval = -1;    }  if ((!tls->root_cert) && (!tls->root_dir))    {      xsupconfcheck_add_log(errors, "In network clause '%s', EAP-TLS requires"			    " either a 'root_cert' or 'root_dir' setting.",			    netname);      retval = -1;    }  if (!tls->user_key)    {      xsupconfcheck_add_log(errors, "In network clause '%s', EAP-TLS requires"			    " a 'user_key' setting.  (It may be the same"			    " file as the 'user_cert'.)\n", netname);      retval = -1;    }  return retval;}/***************************************************************** * * Check the configuration options for LEAP. * *****************************************************************/int xsupconfcheck_check_eap_leap(struct config_eap_leap *leap, char *netname, 				 cerrs **errors){  int retval = 0;  // For LEAP, we don't need anything defined.  The only thing that matters  // is that we have a password, and if we don't currently have one, we will  // ask a GUI to provide one for us.  return retval;}/***************************************************************** * * Check the configuration options for EAP-MSCHAPv2. * *****************************************************************/int xsupconfcheck_check_eap_mschapv2(struct config_eap_mschapv2 *mscv2, 				     char *netname, cerrs **errors){  int retval = 0;  // For EAP-MSCHAPv2, we don't need anything defined.  The only thing that   // matters is that we have a password, and if we don't currently have one,   // will ask a GUI to provide one for us.  return retval;}/***************************************************************** * * Check the configuration options for EAP-SIM. * *****************************************************************/int xsupconfcheck_check_eap_sim(struct config_eap_sim *sim, char *netname, 				cerrs **errors){  int retval = 0;  // For EAP-SIM, we don't need anything defined.  The only thing that matters  // is that we have a password, and if we don't currently have one, we will  // ask a GUI to provide one for us.  return retval;}/***************************************************************** * * Check the configuration options for EAP-AKA. * *****************************************************************/int xsupconfcheck_check_eap_aka(struct config_eap_aka *aka, char *netname, 				cerrs **errors){  int retval = 0;    // For EAP-AKA, we don't need anything defined.  The only thing that matters  // is that we have a password, and if we don't currently have one, we will  // ask a GUI to provide one for us.    return retval;}/******************************************************************** * * Check the PEAP phase 2 methods. * ********************************************************************/int xsupconfcheck_check_peap_phase2(struct config_eap_method *phase2,				    char *netname, cerrs **errors){  int retval = 0;  struct config_eap_method *cur;    cur = phase2;

⌨️ 快捷键说明

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