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

📄 xsupgui_request2.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 2 页
字号:
/**
 * Licensed under a dual GPL/BSD license. (See LICENSE file for more info.)
 *
 * \file xsupgui_request2.c
 *
 * \author chris@open1x.org
 *
 * $Id: xsupgui_request2.c,v 1.1.2.13 2008/01/21 22:51:44 chessing Exp $
 * $Date: 2008/01/21 22:51:44 $
 **/

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

#include "xsupgui.h"
#include "../libxsupconfig/xsupconfig_structs.h"
#include "xsupgui_request.h"
#include "xsupgui_xml_common.h"

/**
 *  \brief Request that the supplicant reload it's configuration file.
 *
 *  \retval REQUEST_SUCCESS on success 
 *  \retval REQUEST_TIMEOUT on timeout
 *  \retval >299 on other error
 **/
int xsupgui_request_reload_config()
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL;
	int done = REQUEST_SUCCESS, err = 0;

	doc = xsupgui_xml_common_build_msg();
	if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;

	n = xmlDocGetRootElement(doc);
	if (n == NULL) 
	{
		done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
		goto reload_config_done;
	}

	if (xmlNewChild(n, NULL, "Reload_Configuration", NULL) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		goto reload_config_done;
	}

	err = xsupgui_request_send(doc, &retdoc);
	if (err != REQUEST_SUCCESS)
	{
		done = err;
		goto reload_config_done;
	}

	// Otherwise, parse it and see if we got what we wanted.
	err = xsupgui_request_check_exceptions(retdoc);
	if (err != 0) 
	{
		done = err;
		goto reload_config_done;
	}

	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
		goto reload_config_done;
	}

	// If we get here, then we know that the document passed the
	// validation tests imposed.  So, we need to see if we got the result 
	// we wanted.
	n = n->children;
	if (xsupgui_request_find_node(n, "ACK") != NULL)
	{
		done = REQUEST_SUCCESS;
	}
	else
	{
		done = IPC_ERROR_NOT_ACK;
	}

reload_config_done:
	if (doc != NULL) xmlFreeDoc(doc);
	if (retdoc != NULL) xmlFreeDoc(retdoc);

	return done;
}

/**
 *  \brief Request that the supplicant terminate itself.
 *
 *  \retval REQUEST_SUCCESS on success 
 *  \retval REQUEST_TIMEOUT on timeout
 *  \retval >299 on other error
 **/
int xsupgui_request_terminate()
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL;
	int done = 0, err = 0;

	doc = xsupgui_xml_common_build_msg();
	if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;

	n = xmlDocGetRootElement(doc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
		goto terminate_done;
	}

	if (xmlNewChild(n, NULL, "Terminate", NULL) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		goto terminate_done;
	}

	err = xsupgui_request_send(doc, &retdoc);
	if (err != REQUEST_SUCCESS)
	{
		done = err;
		goto terminate_done;
	}

	// Otherwise, parse it and see if we got what we wanted.
	err = xsupgui_request_check_exceptions(retdoc);
	if (err != 0) 
	{
		done = err;
		goto terminate_done;
	}

	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
		goto terminate_done;
	}

	// If we get here, then we know that the document passed the
	// validation tests imposed.  So, we need to see if we got the result 
	// we wanted.
	n = n->children;
	if (xsupgui_request_find_node(n, "ACK") != NULL)
	{
		done = REQUEST_SUCCESS;
	}
	else
	{
		done = IPC_ERROR_NOT_ACK;
	}

terminate_done:
	if (doc != NULL) xmlFreeDoc(doc);
	if (retdoc != NULL) xmlFreeDoc(retdoc);

	return done;
}

/**
 *  \brief Tell Xsupplicant to pause an interface. 
 *
 *  This will kick the statemachine in to a "STOPPED" state.  When
 *  the statemachine is stopped, any connection that is currently in
 *  use will continue to exist.  If the authenticator asks the 
 *  supplicant to reauthenticate, or rekey, the supplicant will ignore it.
 *  So, in general, you should send a logoff and/or disassociate before
 *  pausing the interface.
 *
 * @param[in] device  The OS specific name of the device to pause.
 *
 * \retval REQUEST_SUCCESS on success 
 * \retval REQUEST_TIMEOUT on timeout
 * \retval >299 on other error
 **/
int xsupgui_request_stop(char *device)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	int done = 0, err = 0;
	char *temp = NULL;

	if (device == NULL) return IPC_ERROR_INVALID_PARAMETERS;

	doc = xsupgui_xml_common_build_msg();
	if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;

	n = xmlDocGetRootElement(doc);
	if (n == NULL) 
	{
		done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
		goto request_stop;
	}

	t = xmlNewChild(n, NULL, "Request_Stop", NULL);
	if (t == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		goto request_stop;
	}

	xsupgui_xml_common_convert_amp(device, &temp);
	if (xmlNewChild(t, NULL, "Interface", temp) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_INT_NODE;
		free(temp);
		goto request_stop;
	}
	free(temp);

	err = xsupgui_request_send(doc, &retdoc);
	if (err != REQUEST_SUCCESS)
	{
		done = err;
		goto request_stop;
	}

	// Otherwise, parse it and see if we got what we wanted.
	err = xsupgui_request_check_exceptions(retdoc);
	if (err != 0) 
	{
		done = err;
		goto request_stop;
	}

	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
		goto request_stop;
	}

	// If we get here, then we know that the document passed the
	// validation tests imposed.  So, we need to see if we got the result 
	// we wanted.
	n = n->children;
	if (xsupgui_request_find_node(n, "ACK") != NULL)
	{
		done = REQUEST_SUCCESS;
	}
	else
	{
		done = IPC_ERROR_NOT_ACK;
	}

request_stop:
	if (doc != NULL) xmlFreeDoc(doc);
	if (retdoc != NULL) xmlFreeDoc(retdoc);

	return done;
}

/**
 *  \brief Request that the supplicant send a LOGOFF.
 *
 *  @param[in] device  The OS specific name of the device that we want to have send a 
 *                     LOGOFF.
 *
 *  \retval REQUEST_SUCCESS on success 
 *  \retval REQUEST_TIMEOUT on timeout
 *  \retval >299 on other error
 *
 *  \warning Sending a LOGOFF message will not cause all authentications to stop.  It will
 *           only terminate the currently authenticated session.  In general, the 
 *           authenticator will attempt to start another authentication shortly after 
 *           getting a LOGOFF message.  If it is the intent to stop future authentications,
 *           you should request that the interface go in to a "stopped" state.
 **/
int xsupgui_request_logoff(char *device)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	int done = 0, err = 0;
	char *temp = NULL;

	doc = xsupgui_xml_common_build_msg();
	if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;

	n = xmlDocGetRootElement(doc);
	if (n == NULL) 
	{
		done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
		goto request_logoff;
	}

	t = xmlNewChild(n, NULL, "Request_Logoff", NULL);
	if (t == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		goto request_logoff;
	}

	xsupgui_xml_common_convert_amp(device, &temp);
	if (xmlNewChild(t, NULL, "Interface", temp) == NULL)
	{
		done = IPC_ERROR_INVALID_PARAMETERS;
		free(temp);
		goto request_logoff;
	}
	free(temp);

	err = xsupgui_request_send(doc, &retdoc);
	if (err != REQUEST_SUCCESS)
	{
		done = err;
		goto request_logoff;
	}

	// Otherwise, parse it and see if we got what we wanted.
	err = xsupgui_request_check_exceptions(retdoc);
	if (err != 0) 
	{
		done = err;
		goto request_logoff;
	}

	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
		goto request_logoff;
	}

	// If we get here, then we know that the document passed the
	// validation tests imposed.  So, we need to see if we got the result 
	// we wanted.
	n = n->children;
	if (xsupgui_request_find_node(n, "ACK") != NULL)
	{
		done = REQUEST_SUCCESS;
	}
	else
	{
		done = IPC_ERROR_NOT_ACK;
	}

request_logoff:
	if (doc != NULL) xmlFreeDoc(doc);
	if (retdoc != NULL) xmlFreeDoc(retdoc);

	return done;
}

/**
 *  \brief Request the state of the 802.1X state machine on a given interface.
 *
 *  @param[in] device   The OS specific device name that we want to know the 802.1X state
 *                      machine state for.
 *  @param[out] state   The current state of the 802.1X state machine.
 *
 *  \retval REQUEST_SUCCESS on success 
 *  \retval REQUEST_TIMEOUT on timeout
 *  \retval >299 on other error
 **/
int xsupgui_request_get_1x_state(char *device, int *state)
{
	return xsupgui_request_get_some_value(device, "Get_1X_State", "dot1X_State", "State", state);
}

/**
 *  \brief Request the state of the EAP state machine on a given interface.
 *
 *  @param[in] device   The OS specific name of the device to get the EAP state machine
 *                      state from.
 *  @param[out] state   The current state of the EAP state machine.
 *
 *  \retval REQUEST_SUCCESS on success 
 *  \retval REQUEST_TIMEOUT on timeout
 *  \retval >299 on other error
 **/
int xsupgui_request_get_eap_state(char *device, int *state)
{
	return xsupgui_request_get_some_value(device, "Get_EAP_State", "EAP_State", "State", state);
}

/**
 *  \brief Request the state of the 802.1X backend state machine on a given interface.
 *
 *  @param[in] device   The OS specific name of the device to get the 802.1X backend state
 *                      machine state from.
 *  @param[out] state   The current state of the 802.1X backend state machine.
 *
 *  \retval REQUEST_SUCCESS on success 
 *  \retval REQUEST_TIMEOUT on timeout
 *  \retval >299 on other error
 **/
int xsupgui_request_get_backend_state(char *device, int *state)
{
	return xsupgui_request_get_some_value(device, "Get_Backend_State", "Backend_State", "State", state);
}

/**
 *  \brief Request the state of the physical interface state machine on a given interface.
 *
 *  @param[in] device   The OS specific device name to get the physical state machine state
 *                      from.
 *  @param[out] state   The current state of the physical interface state machine.
 *
 *  \retval REQUEST_SUCCESS on success 
 *  \retval REQUEST_TIMEOUT on timeout
 *  \retval >299 on other error
 **/
int xsupgui_request_get_physical_state(char *device, int *state)
{
	return xsupgui_request_get_some_value(device, "Get_Physical_State", "Physical_State", "State", state);
}

/**
 *  \brief Request the pairwise key type in use on a given interface.
 *
 *  @param[in] device   The OS specific device name that we want to know the pairwise key 
 *                      type for.
 *  @param[out] keytype   The pairwise key type that is in use.
 *
 *  \retval REQUEST_SUCCESS on success 
 *  \retval REQUEST_TIMEOUT on timeout
 *  \retval >299 on other error
 **/
int xsupgui_request_get_pairwise_key_type(char *device, int *keytype)
{
	return xsupgui_request_get_some_value(device, "Get_Pairwise_Key_Type", "Pairwise_Key_Type", "Key_Type", keytype);
}

/**
 *  \brief Request the group key type in use on a given interface.
 *
 *  @param[in] device   The OS specific device name that we want to know the group key
 *                      type for.
 *  @param[out] keytype   The group key type that is in use.
 *
 *  \retval REQUEST_SUCCESS on success 
 *  \retval REQUEST_TIMEOUT on timeout
 *  \retval >299 on other error
 **/
int xsupgui_request_get_group_key_type(char *device, int *keytype)
{
	return xsupgui_request_get_some_value(device, "Get_Group_Key_Type", "Group_Key_Type", "Key_Type", keytype);
}

/**
 * \brief Request EAP type in use on a given interface.
 *
 * @param[in] device   The OS specific device name that we want to know the EAP type that
 *                     was used to authenticate.
 * @param[out] eaptype   The EAP method that is in use on the requested interface.
 *
 * \retval REQUEST_SUCCESS on success 
 * \retval REQUEST_TIMEOUT on timeout
 * \retval >299 on other error
 **/
int xsupgui_request_get_eap_type_in_use(char *device, int *eaptype)
{
	return xsupgui_request_get_some_value(device, "Get_EAP_Type_In_Use", "EAP_Type_In_Use", "EAP_Type", eaptype);
}

/**
 *  \brief Request IP information in use on a given interface.
 *
 *  @param[in] device   The OS specific device name to get the IP address information for.
 *  @param[out] info   A structure that contains the IP address, netmask, gateway, and
 *                     other IP information for the interface.
 *
 *  \retval REQUEST_SUCCESS on success
 *  \retval REQUEST_TIMEOUT on timeout
 *  \retval >299 on other error
 **/
int xsupgui_request_get_ip_info(char *device, ipinfo_type **info)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;

⌨️ 快捷键说明

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