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

📄 tnc_compliance_funcs.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 2 页
字号:
/**
 * Vendor specific calls for TNC implementations to use.
 *
 * \file tnc_compliance_funcs.c
 *
 * Licensed under a dual GPL/BSD license.  (See LICENSE file for more info.)
 *
 * \author chris@open1x.org
 *
 * $Id: tnc_compliance_funcs.c,v 1.1.2.21 2008/01/29 18:31:52 chessing Exp $
 * $Date: 2008/01/29 18:31:52 $
 **/

#ifdef HAVE_TNC

#include <stdio.h>
#include <libtnc.h>
#include <tncifimc.h>

#ifdef WINDOWS
#include <windows.h>
#include "../../stdintwin.h"
#endif

#include "../../../lib/libxsupconfig/xsupconfig_structs.h"
#include "../../../lib/liblist/liblist.h"
#include "../../context.h"
#include "../../ipc_events.h"
#include "../../xsup_debug.h"
#include "../../xsup_common.h"
#include "../../ipc_events_index.h"
#include "../../wireless_sm.h"
#include "tnc_compliance_funcs.h"

#ifdef WINDOWS
#include "../../event_core_win.h"
#else
#include "../../event_core.h"
#endif

tnc_msg_batch *batch_ptr = NULL;

/**
 * \brief Determine the posture preferences for the current supplicant context.
 *
 * @param[in] imcID   The ID value that the IMC uses to track this instance.
 * @param[in] connectionID   The connection ID value that the IMC uses to track
 *                           this instance.
 * 
 * \retval uint32_t A 32 bit value that indicates the current settings for the 
 *                  posture set.  The flags are identified in tnc_compliance_options.h.
 **/
TNC_UInt32 TNC_28383_TNCC_Get_Posture_Preferences(TNC_IMCID imcID, TNC_ConnectionID connectionID)
{
	context *ctx = NULL;

	ctx = event_core_get_active_ctx();

	return ctx->prof->compliance;
}

/**
 * \brief Send an event notification to the UI.  These notifications should cause the UI
 *        to display a dialog box that contains the message, and the Ok button.
 *
 * @param[in] imcID   The ID that the IMC uses to track this instance.
 * @param[in] connectionID   The ID that the IMC uses to track this connection.
 * @param[in] oui   The IANA OUI number for the IMC making the call.
 * @param[in] notification   The notification number that will allow the UI to look
 *                           in a message catalog to find the proper string to display.
 **/
void TNC_28383_TNCC_Send_UI_Notification_by_ID(TNC_IMCID imcID, TNC_ConnectionID connectionID, TNC_UInt32 oui, TNC_UInt32 notification)
{
	ipc_events_imc_event(oui, notification);
}

/**
 * \brief Request that the UI display a message, with a set of yes/no buttons displayed.
 *        This will also register the callback that will be called when one of the
 *        yes/no buttons has been clicked.
 *
 * @param[in] imcID   The IMC ID that is used by the IMC to keep track of the connection.
 * @param[in] connectionID   The connectionID used by the IMC to keep track of the connection.
 * @param[in] oui   The OUI of the IMC that is making the request.  This is used by the
 *                  UI to determine which message catalog should be used.
 * @param[in] request   The request ID to use with the OUI to look up the message to display.
 * @param[in] callback   A pointer to the callback that should be called when the UI has
 *                       had a yes or no clicked.
 *
 * \retval 0 on success.
 * \retval !=0 on failure
 **/
TNC_UInt32 TNC_28383_TNCC_Request_Answer_From_UI_by_ID(TNC_IMCID imcID, 
						TNC_ConnectionID connectionID, TNC_UInt32 oui, TNC_UInt32 request, 
						void *callback)
{
	if (tnc_compliance_callbacks_add(imcID, connectionID, oui, request, callback) != 0)
	{
		debug_printf(DEBUG_NORMAL, "Couldn't request a TNC answer from the UI!\n");
		return TNC_RESULT_FATAL;
	}

	return TNC_RESULT_SUCCESS;
}

/**
 * \brief Write a log string to the supplicant's log file.  This string will *NOT* be
 *        passed up to the UI, and will *ONLY* be logged if TNC IMC debug logging is
 *        enabled.  As such, it should only be used for IMC debug messages.
 *
 * @param[in] imcID   The ID that the IMC uses to track this instance.
 * @param[in] logline   An ASCII string that will be written to the debug log.
 * @param[in] severity The TNC severity level which is used to determine how to log the message.
 **/
void TNC_28383_TNCC_debug_log(TNC_IMCID imcID, TNC_UInt32 severity, char *logline)
{
	char *temp = NULL;
	char imcn[100];

	sprintf((char *)&imcn, "%d", imcID);

	temp = Malloc(strlen(imcn) + strlen(logline) + 100);
	if (temp == NULL)
	{
		debug_printf(DEBUG_NORMAL, "IMC attempted to send us a log line, but we couldn't "
				"allocate memory to store it!\n");
		return;
	}

	sprintf(temp, "IMC ID : %s  Log Message : %s\n", imcn,
		logline);

	switch(severity)
	{
	case TNC_LOG_SEVERITY_ERR:
		{
			debug_printf(DEBUG_NORMAL | DEBUG_TNC_IMC | DEBUG_VERBOSE, "%s", logline);
		}break;
	case TNC_LOG_SEVERITY_WARNING:
	case TNC_LOG_SEVERITY_NOTICE:
	case TNC_LOG_SEVERITY_INFO:
        {
            // Only send INFO level information into the debug plugins.
            debug_printf(DEBUG_NULL, "%s", logline);
        }break;
	case TNC_LOG_SEVERITY_DEBUG:
	default:
		debug_printf(DEBUG_TNC_IMC | DEBUG_VERBOSE, "%s", logline);
	};

	FREE(temp);
}

/**
 * \brief Add a message to the UI request message queue.
 *
 * @param[in] imcID  The ID of the IMC requesting the addition to the batch.
 * @param[in] connectionID  The connection ID requesting the addition to the batch.
 * @param[in] oui   The OUI of the IMC that is making the request.  (Needed so that the UI knows
 *                  which message catalog to use.
 * @param[in] msgID   The message ID that the UI should use to locate the message in the catalog.
 * @param[in] attr   A string to send to the UI that the UI should just display.
 *
 * \retval 0 on success
 * \retval >0 on failure
 **/
TNC_UInt32 TNC_28383_TNCC_Add_To_Batch(TNC_IMCID imcID, TNC_ConnectionID connectionID, TNC_UInt32 oui, 
									  TNC_UInt32 msgID, TNC_BufferReference attr)
{
	tnc_msg_batch *cur = NULL;

	cur = Malloc(sizeof(tnc_msg_batch));
	if (cur == NULL)
	{
		debug_printf(DEBUG_NORMAL, "Couldn't allocate memory to store new TNC UI message batch node.\n");
		return TNC_RESULT_FATAL;
	}

	cur->imcID = imcID;
	cur->connectionID = connectionID;
	cur->msgid = msgID;
	cur->oui = oui;
	cur->parameter = _strdup(attr);
	cur->next = NULL;

	liblist_add_to_head((genlist **)&batch_ptr, (genlist *)cur);

	return TNC_RESULT_SUCCESS;
}

/**
 * \brief  The callback that is used to free the memory used by a single node.
 *
 * @param[in] node   The node to free the memory of.
 **/
node_delete_func tnc_compliance_funcs_delete_node(void **node)
{
	tnc_msg_batch *cur = NULL;

	cur = (*node);

	// We only need to free "parameter".  Everything else goes away when we free the node.
	FREE(cur->parameter);

	FREE((*node));
}

/**
 * \brief Actually send the message to the UI.
 * 
 * @param[in] imcID  The ID of the IMC requesting the addition to the batch.
 * @param[in] connectionID   The connection ID requesting that the data be sent.
 * @param[in] oui   The OUI number assigned to the IMC's developer company by IANA.
 * @param[in] msg   A message id provided by the IMC that will let the UI know to expect
 *                  a batch of messages.  (Must be unique!!)
 * @param[in] cb   The callback to call when the UI responds.  (If this is NULL then no callback
 *                 is expected.)
 *
 * \retval 0 on success
 * \retval !=0 on failure
 **/
TNC_UInt32 TNC_28383_TNCC_Send_Batch(TNC_IMCID imcID, TNC_ConnectionID connectionID, TNC_UInt32 oui,
							   TNC_UInt32 msg, callback *cb)
{
	if (tnc_compliance_callbacks_add(imcID, connectionID, oui, msg, cb) != 0)
	{
		debug_printf(DEBUG_NORMAL, "Couldn't add the callback needed to get an answer from the TNC "
				"batch message.\n");
		return TNC_RESULT_FATAL;	
	}

	ipc_events_send_tnc_batch(batch_ptr, imcID, connectionID, oui, msg);

⌨️ 快捷键说明

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