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

📄 xsupconfig.c

📁 Linux上的802.1x 的supplicant的实现。很多supplicant程序都是基于它开发的
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************* * Implementation for parsing configuration file, and storing needed data. * * Licensed under a dual GPL/BSD license.  (See LICENSE file for more info.) * * File: xsupconfig.c * * Authors: Chris.Hessing@utah.edu * * $Id: xsupconfig.c,v 1.20 2006/06/13 18:02:56 chessing Exp $ * $Date: 2006/06/13 18:02:56 $ * $Log: xsupconfig.c,v $ * Revision 1.20  2006/06/13 18:02:56  chessing * Fixed a problem that would result in a segfault if a HUP was received.  Created stub functions for implementation of EAP-TNC to support Trusted Network Connect. * * Revision 1.19  2006/06/05 19:56:42  chessing * Fixed a 16k memory leak in the config parse code.  Cleaned up some of the TLS code. * * Revision 1.18  2006/06/02 21:49:18  chessing * More memory leak cleanups, and another patch from Carsten. * * Revision 1.17  2006/06/01 22:49:49  galimorerpg * Converted all instances of u_char to uint8_t * Fixed a bad #include in the generic frame handler. * * Revision 1.16  2006/05/31 05:10:51  chessing * Beginnings of EAP-TTLS-EAP-MD5, and added internet draft for EAP-TTLS to doc/standards. * * Revision 1.15  2006/05/30 23:40:23  chessing * Small patches/additions and addition to the readme file that contains a link to the location of libtnc. * * Revision 1.14  2006/05/30 04:33:19  chessing * Some small updates for the GUI code. * * Revision 1.13  2006/05/26 22:04:58  chessing * Fixed some memory access errors, and cleaned up some wext stuff that was causing issues with the madwifi driver in wext mode. * * Revision 1.12  2006/05/18 20:40:19  chessing * More work on the GUI interface.  The advanced button in the configuration tab is now complete. * * Revision 1.11  2006/05/17 22:18:10  chessing * A couple of small changes to Xsupplicant, and some major changes to the GUI configuration/monitor tool. * * Revision 1.10  2006/05/13 05:56:44  chessing * Removed last pieces of code that relied on SIGALRM.  Active scan timeout is now configurable so that people that wish to hammer on their cards now have the option to do that. ;) * * Revision 1.9  2006/04/17 03:56:23  chessing * Added some support to enable/disable TNC support both via the configuration file, and via IPC. * * Revision 1.8  2006/04/06 06:39:47  chessing * A few fixes for bugs found at Interop's Hot Stage.  We now work with madwifi-ng. * * Revision 1.7  2006/03/21 18:22:09  chessing * Fixes to EAP-AKA code.  Changed a few defaults to disable Xsupplicant based roaming, and passive scanning for this release.  (It would currently cause more problems than it would solve. * * Revision 1.6  2006/02/23 22:26:50  chessing * Fix for bug id #1415020.  'Building Xsupplicant 1.2.3 Fails on FC4'. * * Revision 1.5  2006/01/03 04:02:35  chessing * Added the ability to store the PEAP password in a hashed format.  (Basically, an MS-CHAPv1 hash.)  Also added an 'ntpwdhash' program to the tools directory that will convert a cleartext password in to a hash that can be copied to the configuration file. * * Revision 1.4  2005/11/16 02:18:37  chessing * Updates to the config writing library.  The config-parser tool has been modified to be able to parse a config, and rewrite it. * * Revision 1.3  2005/11/10 04:56:54  chessing * Added patch from Ben Gardner to add support for setting a specific WEP key prior to attempting to associte.  (With a few slight modifications by me to make it fit in the current CVS code, and get it supported in config-parse.)  Added patch from Pekka Savola to fix some header ordering issues, and a potential buffer overflow. * * Revision 1.2  2005/10/17 03:56:52  chessing * Updates to the libxsupconfig library.  It no longer relies on other source from the main tree, so it can be used safely in other code with problems. * * Revision 1.1  2005/10/17 00:15:55  chessing * Moved the config parsing routines out to a new library called libxsupconfig.a, so that it will be easier to create third-party tools that can easily parse a config. * * Revision 1.82  2005/09/14 03:34:54  chessing * Small cosmetic changes.  Default association mode is now auto instead of manual. Fixes for bug IDs #1290449 & #1290323. * * Revision 1.81  2005/09/14 02:50:44  chessing * Major updates.  Auto association now works.  Started to rewrite the rtnetlink pieces using iwlib from the wireless tools to avoid compatibility issues.  As a result, getting the WPA and RSN IEs via the IWEVGENIE event no longer works for some reason, but the old style using IWEVCUSTOM events should still work like a champ. * * Revision 1.80  2005/09/08 16:27:01  chessing * Some small updates to the new state machine code.  First attempt at an auto association mode.  (It mostly works. ;) * * Revision 1.79  2005/09/05 01:00:34  chessing * Major overhaul to most of the state machines in Xsupplicant.  Also added additional error messages to the TLS functions to try to debug the one of the problems reported on the list.  Basic testing shows this new code to be more stable than previous code, but it needs more testing. * * Revision 1.78  2005/08/25 03:34:05  chessing * Removed a bunch of functions from config.c that could be handled better in other ways. * * Revision 1.77  2005/08/25 02:20:20  chessing * Some cleanup in xsup_debug.c, added the ability to wait for an interface to come up if it is down when Xsupplicant is started.  Roughed in the ability to choose between having Xsupplicant auto associate you, or allow you to set the ssid manually.  The stale key timer can now be set in the config file.  The association timeout can be set in the config file, and will also be used once the functionality is in place to attempt to guess the key settings needed for association, as well as the functionality to auto associate. * * Revision 1.76  2005/08/21 18:12:12  chessing * Added the ability to reload our configuration using a HUP.  Cleaned up a bunch of memory leaks in the config parse code. * * Revision 1.75  2005/08/20 19:06:52  chessing * Patch from Carsten Grohmann to fix a few things in xsup_get_state.c.  Also added the ability to define an empty network clause, that will set the card in to encryption disabled mode.  From there, anything short of changing the SSID will be ignored by Xsupplicant. * * Revision 1.74  2005/08/18 03:19:04  chessing * Added the ability to define an SSID with static WEP keys.  When we switch to a network that has this type of configuration we will set the keys, and stop the various association timers. * * Revision 1.73  2005/08/12 03:34:06  chessing * Fix to the TLS implementation, should help avoid some of the weird 'block cipher pad' errors.  Also includes a partial implementation of the ability to use static WEP keys based on the SSID in use. * * Revision 1.72  2005/08/09 01:39:13  chessing * Cleaned out old commit notes from the released version.  Added a few small features including the ability to disable the friendly warnings that are spit out.  (Such as the warning that is displayed when keys aren't rotated after 10 minutes.)  We should also be able to start when the interface is down.  Last, but not least, we can handle empty network configs.  (This may be useful for situations where there isn't a good reason to have a default network defined.) * * *******************************************************************/#include <stdlib.h>#include <strings.h>#include <string.h>#include <stdio.h>#include <sys/types.h>#include "xsup_err.h"#include "xsupconfig.h"#ifdef USE_EFENCE#include <efence.h>#endifstruct config_data *config_info = NULL; // the configuration data structurestruct config_network *current_network_data = NULL;  // Point to the config                                                     // data we currently are                                                     // using.extern FILE *yyin;extern int config_linenum;extern int yyparse(void);extern int yycleanup(void);#define FREE_STRING(x) if (x != NULL) {free(x); x = NULL;}/**************************************** * * Load all of the configuration information in to memory.  We should * set a flag to make sure that we have loaded the config before we * call config_build(). * ****************************************/int config_setup(char *path_to_config){  /* Make sure we got a parameter */  if (path_to_config == NULL) {    return XECONFIGFILEFAIL;  }  /* check to see if we can really open this file */  yyin = fopen(path_to_config, "r");  if (yyin == NULL) {    return XECONFIGFILEFAIL;  }  /* check to see if the configuration is already set */  if (config_info) {      return XECONFIGALREADYLOADED;  }  /* parse the file */  if (config_parse() != XENONE) {    delete_config_data(&config_info);    return XECONFIGPARSEFAIL;  }  // set the file name  if (config_info)    config_info->config_fname = strdup(path_to_config);  return XENONE;}/***************************************************************** * * Return the pointer to config_info. * *****************************************************************/struct config_data *config_get_config_info(){  return config_info;}/***************************************************************** * *  Create a fresh config in memory with nothing other than a *  default network name. * *  NOTE: THIS FUNCTION SHOULD *NEVER* BE CALLED INSIDE OF XSUPPLICANT!! *  IT IS PROVIDED SO THAT GUI INTERFACES CAN HAVE A File|New.. OPTION! * *****************************************************************/void config_create_new_config(){  initialize_config_data(&config_info);  config_info->config_fname = NULL;   // We don't know what the file name will be.  // Populate the globals  initialize_config_globals(&(config_info->globals));  // Populate our 'default' network.  initialize_config_network(&(config_info->networks));  config_info->globals->default_net = strdup("default");  config_info->networks->name = strdup("default");}/***************************************************************** * * Given the network name 'matchname', find the network, and return the * network priority that was assigned to it. * *****************************************************************/uint8_t config_get_network_priority(char *matchname){  struct config_network *cur;  if (!matchname)    {      printf("Looking for NULL network priority!?  (It is likely that the"	     " scan results were truncated for some reason.)\n");      return 0xff;    }  // Start at the top of the list.  cur = config_info->networks;  while ((cur != NULL) && (strcmp(cur->name, matchname) != 0))    {      cur = cur->next;    }  if (!cur) return 0xff;  return cur->priority;}/*********************************************************** * * Given a network name, find the configuration information in memory. * ***********************************************************/struct config_network *config_find_network(struct config_network *nethead, 					   char *matchname){  struct config_network *cur;  cur = nethead;  if ((nethead == NULL) || (matchname == NULL))    {      return NULL;    }  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 = nethead;  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;}/**************************************** * * Return our root network data structure. * ****************************************/struct config_network *config_get_root_network_config(){  return config_info->networks;}/**************************************** * * Remove a network from our list. * ****************************************/int config_delete_net(char *netname){  struct config_network *cur, *prev;  if (strcmp(config_info->networks->name, netname) == 0)    {      // The first one is the one we want to remove.      cur = config_info->networks;      config_info->networks = cur->next;      // Then, delete everything in that network.      delete_config_single_network(&cur);      return XENONE;    }  // Otherwise, it will be somewhere else.  cur = config_info->networks->next;  prev = config_info->networks;  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_network(&cur);      return XENONE;    }    return XENOTHING_TO_DO;}/**************************************** * * Return our current network data structure. * ****************************************/struct config_network *config_get_network_config(){  return current_network_data;}/**************************************** * * Set our current network data structure. * ****************************************/void config_set_network_config(struct config_network *newnet){  current_network_data = newnet;}/***************************************************************************** * * Get a pointer to the config global information.  This pointer should * *NEVER* be freed by any callers, or things will break!!!!!! * *****************************************************************************/struct config_globals *config_get_globals(){  if (config_info == NULL)    {      return NULL;    }  return config_info->globals;}/************************************ * * Clean up any memory that we have used to store the configuration information *  ************************************/void config_destroy(){  /* close the input file */  if (yyin)    fclose(yyin);  /* see if there really is something to cleanup */  delete_config_data(&config_info);}/************************************ * * Temporary test function for parsing * ************************************/int config_parse(){  if (yyparse() != XENONE) {    return XECONFIGPARSEFAIL;  }  return XENONE;}/************************************* * * Functions to call when the program terminates. * *************************************/void config_terminate(){  yycleanup();}//****************************************// CONFIG QUERIES//****************************************/****************************************** * * See if the network config is currently in memory * ******************************************/int config_contains_network(char *netname) {  if (!config_info || !config_info->networks)    return FALSE;  return config_network_contains_net(config_info->networks, netname);}/****************************************** * * See if network config is  allowed *  ******************************************/int config_allows_network(struct config_data *conf, char *netname){  struct config_string_list *current;  // make sure we have a config and globals  if (!conf || !conf->globals)    return FALSE;  current = conf->globals->allowed_nets;    // lack of an allowed list means all nets are allowed  if (current == NULL)     return TRUE;  if (config_string_list_contains_string(current, netname))    return TRUE;  return FALSE;}//**********************************************// Private functions for config parsing. Do // not call these from outside config code//**********************************************  /*********************/ /* CONFIG_STATIC_WEP *//*********************/void delete_config_static_wep(struct config_static_wep **tmp_static_wep){  int i;  if ((*tmp_static_wep) == NULL)    return;  for (i=1;i<5;i++)    {      FREE_STRING((*tmp_static_wep)->key[i]);    }  free(*tmp_static_wep);  *tmp_static_wep = NULL;}void initialize_config_static_wep(struct config_static_wep **tmp_static_wep){  if (*tmp_static_wep != NULL) {    delete_config_static_wep(tmp_static_wep);  }

⌨️ 快捷键说明

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