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

📄 xsupconfwrite_eap.c

📁 linux 下通过802.1认证的安装包
💻 C
字号:
/**
 * Implementation for converting variables that make up the <EAP> section
 * to the libxml2 format that can be written to disk, or manipulated in other ways.
 *
 * Licensed under a dual GPL/BSD license.  (See LICENSE file for more info.)
 *
 * \file xsupconfwrite_eap.c
 *
 * \author chris@open1x.org
 *
 * $Id: xsupconfwrite_eap.c,v 1.1.2.5 2007/04/08 04:09:29 chessing Exp $
 * $Date: 2007/04/08 04:09:29 $
 **/

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>

#include <string.h>
#include <libxml/parser.h>

#ifndef WINDOWS
#include <stdint.h>
#endif

#include "../libxsupconfig/xsupconfig_structs.h"
#include "../../src/xsup_common.h"
#include "../libxsupconfig/xsupconfig.h"
#include "../libxsupconfig/xsupconfig_vars.h"
#include "xsupconfwrite_pwd_only.h"
#include "xsupconfwrite_eap_tls.h"
#include "xsupconfwrite_eap_sim.h"
#include "xsupconfwrite_eap_aka.h"
#include "xsupconfwrite_eap_mschapv2.h"
#include "xsupconfwrite_eap_tnc.h"
#include "xsupconfwrite_eap_ttls.h"
#include "xsupconfwrite_eap_peap.h"
#include "xsupconfwrite_eap_fast.h"
#include "xsupconfwrite.h"

// Uncomment the #define below to enable textual debug output.
 #define WRITE_EAP_CONFIG 1


/**
 * \brief Create the <EAP> block for the configuration file in a format
 *        that libxml2 can understand.
 *
 * @param[in] method  A config_eap_method structure that contains all of the
 *                    variables that we want to convert to XML.
 * @param[in] write_all   If set to TRUE, we will write all of the configuration
 *                        options to the XML node tree, no matter if their values
 *                        are set to the default or not.
 *
 * \retval NULL on error
 * \retval xmlNodePtr containing the <EAP> tree in a format that is used by 
 *         libxml2.
 **/
xmlNodePtr xsupconfwrite_eap_create_tree(struct config_eap_method *method, 
										 char write_all)
{
	xmlNodePtr eapnode = NULL;
	xmlNodePtr eapdata = NULL;
		
	if (method == NULL) return NULL;

	// Create the root node for the <EAP> block.
	eapnode = xmlNewNode(NULL, "EAP");
	if (eapnode == NULL)
	{
#ifdef WRITE_EAP_CONFIG
		printf("Couldn't allocate memory to store <EAP> block!\n");
#endif
		return NULL;
	}

	switch (method->method_num)
	{
	case EAP_TYPE_MD5:
		eapdata = xsupconfwrite_pwd_only_create_tree("MD5", method->method_data, write_all); 
  	    break;

	case EAP_TYPE_OTP:
		eapdata = xmlNewNode(NULL, "Type");
		if (eapdata != NULL)
		{
			xmlNodeAddContent(eapdata, "OTP");
		}
		break;

	case EAP_TYPE_GTC:
		eapdata = xsupconfwrite_pwd_only_create_tree("GTC", method->method_data, write_all);
		break;

	case EAP_TYPE_TLS:
		eapdata = xsupconfwrite_eap_tls_create_tree(method->method_data, write_all);
		break;

	case EAP_TYPE_LEAP:
		eapdata = xsupconfwrite_pwd_only_create_tree("LEAP", method->method_data, write_all);
		break;

	case EAP_TYPE_SIM:
		eapdata = xsupconfwrite_eap_sim_create_tree(method->method_data, write_all);
		break;

	case EAP_TYPE_TTLS:
		eapdata = xsupconfwrite_eap_ttls_create_tree(method->method_data, write_all);
		break;

	case EAP_TYPE_AKA:
		eapdata = xsupconfwrite_eap_aka_create_tree(method->method_data, write_all);
		break;

	case EAP_TYPE_PEAP:
		eapdata = xsupconfwrite_eap_peap_create_tree(method->method_data, write_all);
		break;

	case EAP_TYPE_MSCHAPV2:
		eapdata = xsupconfwrite_eap_mschapv2_create_tree(method->method_data, write_all);
		break;

	case EAP_TYPE_TNC:
		eapdata = xsupconfwrite_eap_tnc_create_tree(method->method_data, write_all);
		break;

	case EAP_TYPE_FAST:
		eapdata = xsupconfwrite_eap_fast_create_tree(method->method_data, write_all);
		break;

	default:
		// Unknown!  Return an error.
		xmlFreeNode(eapnode);
		return NULL;
		break;
	}

	if (eapdata == NULL)
	{
#ifdef WRITE_EAP_DEBUG
		printf("Couldn't create EAP method node!\n");
#endif
		xmlFreeNode(eapnode);
		return NULL;
	}

	if (xmlAddChild(eapnode, eapdata) == NULL)
	{
#ifdef WRITE_EAP_DEBUG
		printf("Couldn't add EAP child node to <EAP> block!\n");
#endif
		xmlFreeNode(eapnode);
		return NULL;
	}

	return eapnode;
}

⌨️ 快捷键说明

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