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

📄 xsupconfwrite_connection.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 2 页
字号:
/**
 * Implementation for converting variables that make up the <Connection> 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_connection.c
 *
 * \author chris@open1x.org
 *
 * $Id: xsupconfwrite_connection.c,v 1.1.2.13 2007/07/21 11:42:50 cgrohmann Exp $
 * $Date: 2007/07/21 11:42:50 $
 **/

#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.h"

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

/**
 * \brief Create the <IPv4_Configuration> block for the configuration file in a format
 *        that libxml2 can understand.
 *
 * @param[in] ipdata  A config_ip_data 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 <IPv4_Configuration> tree in a format that is used by 
 *         libxml2.
 **/
xmlNodePtr xsupconfwrite_connection_ipdata(struct config_ip_data *ipdata, 
												char write_all)
{
	xmlNodePtr ipNode = NULL;
	char static_temp[50];
	char *temp = NULL;
	int i;
	
	if (ipdata == NULL) return NULL;

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

	if ((write_all == TRUE) || (ipdata->type != 0))
	{
		switch (ipdata->type)
		{
		default:
		case 0:
			temp = _strdup("DHCP");
			break;

		case 1:
			temp = _strdup("STATIC");
			break;
		}

		if (xmlNewChild(ipNode, NULL, "Type", temp) == NULL)
		{
#ifdef WRITE_CONNECTION_CONFIG
			printf("Couldn't create <Type> node!\n");
#endif
			xmlFreeNode(ipNode);
			free(temp);
			return NULL;
		}

		free(temp);
		temp = NULL;
	}

	if ((write_all == TRUE) || (ipdata->ipaddr != NULL))
	{
		if (xmlNewChild(ipNode, NULL, "IP_Address", ipdata->ipaddr) == NULL)
		{
#ifdef WRITE_CONNECTION_CONFIG
			printf("Couldn't create <IP_Address> node!\n");
#endif
			xmlFreeNode(ipNode);
			return NULL;
		}
	}

	if ((write_all == TRUE) || (ipdata->netmask != NULL))
	{
		if (xmlNewChild(ipNode, NULL, "Netmask", ipdata->netmask) == NULL)
		{
#ifdef WRITE_CONNECTION_CONFIG
			printf("Couldn't create <Netmask> node!\n");
#endif
			xmlFreeNode(ipNode);
			return NULL;
		}
	}

	if ((write_all == TRUE) || (ipdata->gateway != NULL))
	{
		if (xmlNewChild(ipNode, NULL, "Gateway", ipdata->gateway) == NULL)
		{
#ifdef WRITE_CONNECTION_CONFIG
			printf("Couldn't create <Gateway> node!\n");
#endif
			xmlFreeNode(ipNode);
			return NULL;
		}
	}

	if ((write_all == TRUE) || (ipdata->dns1 != NULL))
	{
		if (xmlNewChild(ipNode, NULL, "DNS1", ipdata->dns1) == NULL)
		{
#ifdef WRITE_CONNECTION_CONFIG
			printf("Couldn't create <DNS1> node!\n");
#endif
			xmlFreeNode(ipNode);
			return NULL;
		}
	}

	if ((write_all == TRUE) || (ipdata->dns2 != NULL))
	{
		if (xmlNewChild(ipNode, NULL, "DNS2", ipdata->dns2) == NULL)
		{
#ifdef WRITE_CONNECTION_CONFIG
			printf("Couldn't create <DNS2> node!\n");
#endif
			xmlFreeNode(ipNode);
			return NULL;
		}
	}

	if ((write_all == TRUE) || (ipdata->dns3 != NULL))
	{
		if (xmlNewChild(ipNode, NULL, "DNS3", ipdata->dns3) == NULL)
		{
#ifdef WRITE_CONNECTION_CONFIG
			printf("Couldn't create <DNS3> node!\n");
#endif
			xmlFreeNode(ipNode);
			return NULL;
		}
	}

	if ((write_all == TRUE) || (ipdata->renew_on_reauth == TRUE))
	{
		if (ipdata->renew_on_reauth == TRUE)
		{
			if (xmlNewChild(ipNode, NULL, "Renew_DHCP_on_Reauthentication", "yes") == NULL)
			{
#ifdef WRITE_CONNECTION_CONFIG
				printf("Couldn't create <Renew_DHCP_on_Reauthentication> node!\n");
#endif
				xmlFreeNode(ipNode);
				return NULL;
			}
		}
		else
		{
			if (xmlNewChild(ipNode, NULL, "Renew_DHCP_on_Reauthentication", "no") == NULL)
			{
#ifdef WRITE_CONNECTION_CONFIG
				printf("Couldn't create <Renew_DHCP_on_Reauthentication> node!\n");
#endif
				xmlFreeNode(ipNode);
				return NULL;
			}
		}
	}

	if ((write_all == TRUE) || (ipdata->search_domain != NULL))
	{
		if (xmlNewChild(ipNode, NULL, "Search_Domain", ipdata->search_domain) == NULL)
		{
#ifdef WRITE_CONNECTION_CONFIG
			printf("Couldn't create <Search_Domain> node!\n");
#endif
			xmlFreeNode(ipNode);
			return NULL;
		}
	}

	return ipNode;
}


/**
 * \brief Create the <Association> block for the configuration file in a format
 *        that libxml2 can understand.
 *
 * @param[in] assoc  A config_association 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 <Association> tree in a format that is used by 
 *         libxml2.
 **/
xmlNodePtr xsupconfwrite_connection_association(struct config_association *assoc, 
												char write_all)
{
	xmlNodePtr assocNode = NULL;
	char static_temp[50];
	char *temp = NULL;
	uint16_t ressize;
	int i;
	
	if (assoc == NULL) return NULL;

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

	if ((write_all == TRUE) || (assoc->association_type != ASSOC_AUTO))
	{
		switch (assoc->association_type)
		{
		default:
		case ASSOC_AUTO:
			temp = _strdup("auto");
			break;

		case ASSOC_OPEN:
			temp = _strdup("open");
			break;

		case ASSOC_SHARED:
			temp = _strdup("shared");
			break;

		case ASSOC_LEAP:
			temp = _strdup("leap");
			break;

		case ASSOC_WPA:
			temp = _strdup("wpa");
			break;

		case ASSOC_WPA2:
			temp = _strdup("wpa2");
			break;
		}

		if (xmlNewChild(assocNode, NULL, "Type", temp) == NULL)
		{
#ifdef WRITE_CONNECTION_CONFIG
			printf("Couldn't create <Type> node!\n");
#endif
			xmlFreeNode(assocNode);
			free(temp);
			return NULL;
		}

		free(temp);
		temp = NULL;
	}

	if ((write_all == TRUE) || ((assoc->auth_type != AUTH_EAP) && (assoc->auth_type != AUTH_UNKNOWN)))
	{
		switch (assoc->auth_type)
		{
		case AUTH_NONE:
			temp = _strdup("NONE");
			break;

		case AUTH_PSK:
			temp = _strdup("PSK");
			break;

		default:
		case AUTH_EAP:
			temp = _strdup("EAP");
			break;
		}

		if (xmlNewChild(assocNode, NULL, "Authentication", temp) == NULL)
		{
#ifdef WRITE_CONNECTION_CONFIG
			printf("Couldn't create <Authentication> node!\n");
#endif
			free(temp);
			xmlFreeNode(assocNode);
			return NULL;
		}

		free(temp);
	}

	// Don't check write_all here.  The absence of this tag means that it should
	// be automagically figured out.
	if (assoc->pairwise_keys != 0)
	{
		if (assoc->pairwise_keys & CRYPT_FLAGS_WEP40)
		{
			if (xmlNewChild(assocNode, NULL, "Pairwise_Key_Type", "wep40") == NULL)
			{
#ifdef WRITE_CONNECTION_CONFIG
				printf("Couldn't create <Pairwise_Key_Type> node!\n");
#endif
				xmlFreeNode(assocNode);
				return NULL;
			}
		}

		if (assoc->pairwise_keys & CRYPT_FLAGS_TKIP)
		{
			if (xmlNewChild(assocNode, NULL, "Pairwise_Key_Type", "tkip") == NULL)
			{
#ifdef WRITE_CONNECTION_CONFIG
				printf("Couldn't create <Pairwise_Key_Type> node!\n");
#endif
				xmlFreeNode(assocNode);
				return NULL;
			}
		}

		if (assoc->pairwise_keys & CRYPT_FLAGS_WRAP)
		{
			if (xmlNewChild(assocNode, NULL, "Pairwise_Key_Type", "wrap") == NULL)
			{
#ifdef WRITE_CONNECTION_CONFIG
				printf("Couldn't create <Pairwise_Key_Type> node!\n");
#endif
				xmlFreeNode(assocNode);
				return NULL;
			}
		}

		if (assoc->pairwise_keys & CRYPT_FLAGS_CCMP)
		{
			if (xmlNewChild(assocNode, NULL, "Pairwise_Key_Type", "ccmp") == NULL)
			{
#ifdef WRITE_CONNECTION_CONFIG
				printf("Couldn't create <Pairwise_Key_Type> node!\n");
#endif
				xmlFreeNode(assocNode);

⌨️ 快捷键说明

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