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

📄 testrad.c

📁 vxworks下radius协议栈 的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* testrad.c *//* Test file to test RADIUS authentication and accounting requests 	*//* Copyright 1984 - 2000 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history____________________Date	Init	Comment052401	tk	Add SERVER_DESTROY_TEST flag to test server deletion.020801	tk	Add rad() and radany() functions.013101	tk	add run_auth_mservers and run_acct_mservers functions to test retransmission		multiple servers.  Add code in auth and acct request to display IP address		of server to send to.122100	md  	merged from visual source safe*//************************************************************************//*	Copyright (C) 1993 - 1999 RouterWare, Inc.   						*//*	Unpublished - rights reserved under the Copyright Laws of the		*//*	United States.  Use, duplication, or disclosure by the 				*//*	Government is subject to restrictions as set forth in 				*//*	subparagraph (c)(1)(ii) of the Rights in Technical Data and 		*//*	Computer Software clause at 252.227-7013.							*//*	RouterWare, Inc., 3961 MacArthur Suite 212 Newport Beach, CA 92660	*//************************************************************************/#if 0#define SERVER_DESTROY_TEST	/* to test server deletion */#endif#include <netinet\in.h>#include <logLib.h>#include "radius.h"#include "testrad.h"static int test_count = 0;/**********************************************************************************************************/void radius_send_test_authentication_request (	UINT test_request_counter, 	bool any_server,	RADIUS_SERVER_HANDLE	server_handle){	ULONG nas_address = swap_long(0xC0A88602);	BYTE* bp_nas_address;	unsigned char	nas_id = 1;	BYTE* bp_nas_id = (BYTE*) (&nas_id);	ULONG value;	RADIUS_ATTRIBUTE_LIST_HANDLE attribute_list_handle;	RADIUS_REQUEST_HANDLE request_handle;	RADIUS_REQUEST_CALLBACKS *p_callbacks;	BYTE* bp_username;	BYTE* bp_user_password = test_password;	BYTE* ip_string = (BYTE *)malloc(18);				/* the user password should match the password configured for the user in the			   RADIUS server */#if defined (__RADIUS_TEST_APP_USE_PAP__)	/* PAP authentication */#else		/* CHAP authentication */		int i;	int challenge[4];	/* for storing the 16 octet random challenge */	BYTE *bp_chap_challenge;							BYTE *bp_chap = (BYTE *)calloc (1, 17);#endif	RW_CONTAINER_ITERATOR server_iterator;	RADIUS_SERVER	*p_server;	struct	in_addr	inetAddr;	/*	server_handle = radius_find_server_with_specified_parameters ("192.168.254.65", 1812, RADIUS_AUTHENTICATION_SERVER_TYPE);	server_handle = radius_find_server_with_specified_parameters ("192.168.134.3", 1645, RADIUS_AUTHENTICATION_SERVER_TYPE);*/	request_handle = radiustest_get_entry();	p_callbacks = (RADIUS_REQUEST_CALLBACKS*) malloc (sizeof (RADIUS_REQUEST_CALLBACKS));		p_callbacks->fptr_radius_normal_callback = radius_fake_response;	p_callbacks->fptr_radius_error_callback = radius_fake_error_callback;	attribute_list_handle = radius_create_attribute_list ();		bp_username = test_username_array [test_request_counter - 1];	radius_add_attribute_to_list (attribute_list_handle, RADIUS_USER_NAME, strlen (bp_username), bp_username);		radius_add_attribute_to_list (attribute_list_handle, RADIUS_NAS_IDENTIFIER, 10, "vxWorksLAC");		#if defined (__RADIUS_TEST_APP_USE_PAP__)	radius_add_attribute_to_list (attribute_list_handle, RADIUS_USER_PASSWORD, strlen (bp_user_password), bp_user_password);#else /* CHAP */	srand( (unsigned)time( NULL ) );	for ( i = 0; i < 4; i ++)		{		challenge[i] = rand ();		}	bp_chap_challenge = (BYTE *) calloc (1, 1 + strlen (bp_user_password) + 16);	if (bp_chap_challenge == NULL)		{		exit (1);		}	memcpy (bp_chap_challenge, bp_nas_id, 1);	memcpy ((bp_chap_challenge + 1), bp_user_password, strlen (bp_user_password));	memcpy ((bp_chap_challenge + 1 +  strlen (bp_user_password)), (BYTE *)&challenge, 16);		radius_add_attribute_to_list (attribute_list_handle, RADIUS_CHAP_CHALLENGE, 16, (BYTE *)&challenge);		memcpy (bp_chap, bp_nas_id, 1);		MD_string( bp_chap_challenge, 1 + strlen (bp_user_password) + 16, bp_chap + 1, MD5);	radius_add_attribute_to_list (attribute_list_handle, RADIUS_CHAP_PASSWORD, 17, bp_chap);	free(bp_chap);	free(bp_chap_challenge);#endif	bp_nas_address = (BYTE*)(&nas_address);	radius_add_attribute_to_list (attribute_list_handle, RADIUS_NAS_IP_ADDRESS, 4, bp_nas_address);	radius_request[request_handle] = attribute_list_handle;	radius_printf(RADIUS_DATA_PRINTF, "Auth: request_handle = %x\n", request_handle);	radius_printf(RADIUS_DATA_PRINTF, "Auth: attribute_handle = %x\n", attribute_list_handle);	/* display the server IP address */	server_iterator = (RW_CONTAINER_ITERATOR) server_handle;	p_server = (RADIUS_SERVER*) rw_container_at (server_iterator);	radius_util_serialize_ulong(p_server->ip_address, (BYTE *)&value);	inetAddr.s_addr = value;	inet_ntoa_b(inetAddr, ip_string);	radius_printf(RADIUS_DATA_PRINTF, "Sending authentication request to server %s\n", ip_string);	free(ip_string);	if (any_server == false)	    radius_server_request (server_handle, request_handle, p_callbacks, RADIUS_ACCESS_REQUEST, attribute_list_handle);	else	    radius_any_server_request (server_handle, request_handle, p_callbacks, RADIUS_ACCESS_REQUEST, attribute_list_handle);		free (p_callbacks);}		 /************************************************************************/static void radius_fake_response (RADIUS_REQUEST_HANDLE request_handle, enum RADIUS_CODE code, RADIUS_ATTRIBUTE_LIST_HANDLE response_attr_handle){	RADIUS_ATTRIBUTE_LIST_HANDLE	request_attr_handle;	radius_printf (RADIUS_DATA_PRINTF, "Callback Normal Case.\n");	radius_printf (RADIUS_DATA_PRINTF, "Request Handle: %d\t, RADIUS Code: %d\t, Attribute List handle: %x\n", request_handle, code, response_attr_handle);	if ((request_attr_handle = radiustest_get_attribute_handle(request_handle)) == NULL)	{		printf("Error: Can't find request attribute list from request handle\n");	}	radiustest_free_attrib_lists (request_attr_handle, response_attr_handle);		radius_request[request_handle] = NULL;		test_count++;	logMsg("Reply received count = %d\n", test_count, 0,0,0,0,0);}	/************************************************************************/static void radius_fake_error_callback (RADIUS_REQUEST_HANDLE request_handle, enum RADIUS_ERROR_CALLBACK_CODE error_code){	RADIUS_ATTRIBUTE_LIST_HANDLE	request_attr_handle;	printf ("Callback Error Case.\n");	printf ("Request Handle: %d\t, Error Code: %d\n", request_handle, error_code);	if ((request_attr_handle = radiustest_get_attribute_handle(request_handle)) == NULL)	{		printf("Error: Can't find request attribute list from request handle\n");	}	radiustest_free_attrib_lists (request_attr_handle, NULL);		radius_request[request_handle] = NULL;		test_count++;	logMsg("Error reply received count!!!! = %d\n", test_count, 0,0,0,0,0);}	/************************************************************************** This following routine sends an accounting request to the RADIUS server.*************************************************************************/  /************************************************************************* *  Additional accounting request types can be specified here.  *  Note when the ACCT_DELAY_TIME type is set, the RADIUS client will treat *  this as a special case in that it will update the packet identifier *  and create a new authenticator for each retransmitted packet (RFC 2139).*  For other requests, the Client will assign the same identifier and *  authenticator to the retransmitted packets as the original request packet.  *************************************************************************//* comment out the accounting request types you don't want to test */#define	ACCT_DELAY_TIME bool radius_send_test_accounting_request (	enum RADIUS_ACCOUNTING_STATUS_TYPES type, 	UINT test_request_counter, 	bool any_server,	RADIUS_SERVER_HANDLE	server_handle){/*	RADIUS_SERVER_HANDLE server_handle;*/	RADIUS_ATTRIBUTE_LIST_HANDLE attribute_list_handle;	RADIUS_REQUEST_HANDLE request_handle;	RADIUS_REQUEST_CALLBACKS *p_callbacks;	BYTE bp_session_id[16];	BYTE* bp_username;	BYTE* ip_string = (BYTE *)malloc(18);	ULONG value;	RW_CONTAINER_ITERATOR server_iterator;	RADIUS_SERVER	*p_server;	struct	in_addr	inetAddr;/*	server_handle = radius_find_server_with_specified_parameters ("192.168.134.3", 1646, RADIUS_ACCOUNTING_SERVER_TYPE);*/		sprintf (bp_session_id, "S-%d", test_request_counter);	request_handle = radiustest_get_entry();	attribute_list_handle = radius_create_attribute_list ();	p_callbacks = (RADIUS_REQUEST_CALLBACKS*) malloc (sizeof (RADIUS_REQUEST_CALLBACKS));		p_callbacks->fptr_radius_normal_callback = radius_fake_response;	p_callbacks->fptr_radius_error_callback = radius_fake_error_callback;		bp_username = test_username_array [test_request_counter - 1];	radius_add_attribute_to_list (attribute_list_handle, RADIUS_USER_NAME, strlen (bp_username), bp_username);	if (type == RADIUS_ACCOUNTING_START)		{		radius_util_serialize_ulong ((ULONG) RADIUS_ACCOUNTING_START, (BYTE*)&value);		radius_add_attribute_to_list (attribute_list_handle, RADIUS_ACCT_STATUS_TYPE, 4,  (BYTE*) &value);#ifdef	ACCT_DELAY_TIME		radius_util_serialize_ulong (0, (BYTE*)&value);		radius_add_attribute_to_list (attribute_list_handle, RADIUS_ACCT_DELAY_TIME, 4,  (BYTE*) &value);#endif		radius_add_attribute_to_list (attribute_list_handle, RADIUS_ACCT_SESSION_ID, 10, bp_session_id);		radius_util_serialize_ulong (0xCC1FBA62, (BYTE*)&value);		radius_add_attribute_to_list (attribute_list_handle, RADIUS_NAS_IP_ADDRESS, 4, (BYTE*) &value);		}	else /* RADIUS_ACCOUNTING_STOP */		{		radius_util_serialize_ulong ((ULONG) RADIUS_ACCOUNTING_STOP, (BYTE*)&value);		radius_add_attribute_to_list (attribute_list_handle, RADIUS_ACCT_STATUS_TYPE, 4, (BYTE*) &value);		radius_add_attribute_to_list (attribute_list_handle, RADIUS_ACCT_SESSION_ID, 10, bp_session_id);				radius_util_serialize_ulong (232, (BYTE*)&value);		radius_add_attribute_to_list (attribute_list_handle, RADIUS_ACCT_INPUT_OCTETS, 4, (BYTE*) &value);				radius_util_serialize_ulong ((ULONG) RADIUS_ACCOUNTING_TERMINATION_USER_REQUEST, (BYTE*)&value);		radius_add_attribute_to_list (attribute_list_handle, RADIUS_ACCT_TERMINATE_CAUSE, 4, (BYTE*) &value);		radius_util_serialize_ulong ((ULONG) 0xCC1FBA62,(BYTE*) &value);		radius_add_attribute_to_list (attribute_list_handle, RADIUS_NAS_IP_ADDRESS, 4, (BYTE*) &value);		}	radius_request[request_handle] = attribute_list_handle;	radius_printf(RADIUS_DATA_PRINTF, "Acct: request_handle = %x\n", request_handle);	radius_printf(RADIUS_DATA_PRINTF, "Acct: attribute_handle = %x\n", attribute_list_handle);	/* display the server IP address */		server_iterator = (RW_CONTAINER_ITERATOR) server_handle;	p_server = (RADIUS_SERVER*) rw_container_at (server_iterator);	radius_util_serialize_ulong(p_server->ip_address, (BYTE *)&value);	inetAddr.s_addr = value; 	inet_ntoa_b(inetAddr, ip_string);	radius_printf(RADIUS_DATA_PRINTF, "Sending accounting request to server %s\n", ip_string);	free(ip_string);	if (any_server == false)	    radius_server_request (server_handle, request_handle, p_callbacks, RADIUS_ACCOUNTING_REQUEST, attribute_list_handle);	else	    radius_any_server_request (server_handle, request_handle, p_callbacks, RADIUS_ACCOUNTING_REQUEST, attribute_list_handle);	free(p_callbacks);	return (true);}/************************************************************************* Routine to initialize radius test************************************************************************/void radiustest_initialize(){	int	i=0;	while (i < RADIUS_MAX_REQUESTS)		{		radius_request[i++] = NULL;		}}/************************************************************************* Find an available request entry************************************************************************/int radiustest_get_entry(){	int	i = 0;	while (i < RADIUS_MAX_REQUESTS)	{		if (radius_request[i] == NULL)			{			return(i);			}		else			{			i++;			}	}	printf("No more entry available!\n");	return (-1);}/************************************************************************* Get the request attribute list handle given the request handle************************************************************************/RADIUS_ATTRIBUTE_LIST_HANDLE radiustest_get_attribute_handle(RADIUS_REQUEST_HANDLE req){	if (req < RADIUS_MAX_REQUESTS)		{		return (radius_request[req]);		}	return(NULL);}

⌨️ 快捷键说明

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