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

📄 fsm.c

📁 RADIUS协议的认证计费服务
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright [C] The Regents of the University of Michigan and Merit Network, * Inc. 1992, 1993, 1994, 1995, 1996, 1997, 1998 All Rights Reserved * * Permission to use, copy, and modify this software and its documentation  * for any purpose and without fee is hereby granted, provided:  * * 1) that the above copyright notice and this permission notice appear in all *    copies of the software and derivative works or modified versions thereof,  * * 2) that both the copyright notice and this permission and disclaimer notice  *    appear in all supporting documentation, and  * * 3) that all derivative works made from this material are returned to the *    Regents of the University of Michigan and Merit Network, Inc. with *    permission to copy, to display, to distribute, and to make derivative *    works from the provided material in whole or in part for any purpose. * * Users of this code are requested to notify Merit Network, Inc. of such use * by sending email to aaa-admin@merit.edu * * Please also use aaa-admin@merit.edu to inform Merit Network, Inc of any * derivative works. * * Distribution of this software or derivative works or the associated * documentation is not allowed without an additional license. * * Licenses for other uses are available on an individually negotiated * basis.  Contact aaa-license@merit.edu for more information. * * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE REGENTS OF THE * UNIVERSITY OF MICHIGAN AND MERIT NETWORK, INC. DO NOT WARRANT THAT THE * FUNCTIONS CONTAINED IN THE SOFTWARE WILL MEET LICENSEE'S REQUIREMENTS OR * THAT OPERATION WILL BE UNINTERRUPTED OR ERROR FREE.  The Regents of the * University of Michigan and Merit Network, Inc. shall not be liable for any * special, indirect, incidental or consequential damages with respect to any * claim by Licensee or any third party arising from use of the software. * * Merit AAA Server Support * Merit Network, Inc. * 4251 Plymouth Road, Suite C. * Ann Arbor, Michigan, USA 48105-2785 * * attn:  John Vollbrecht * voice: 734-764-9430 * fax:   734-647-3185 * email: aaa-admin@merit.edu * *//*  * * Public entry points in this file: * * init_fsm * */static char     rcsid[] = "$Id: fsm.c,v 1.1.1.1 2001/08/10 20:49:28 bonze Exp $";#include	<sys/types.h>#include	<sys/param.h>#include	<sys/stat.h>#include	<netinet/in.h>#include	<stdio.h>#include	<syslog.h>#include	<ctype.h>#include 	<string.h>#include	"radius.h"extern int      debug_flag;    /* values > 0 allow various debug output */extern FILE    *ddt;extern char    *radius_dir;extern char    *fsm_id;static FSM_ENT **fsm;          /* pointer to FSM table */static FSM_ENT **default_fsm;  /* pointer to default action table */static int      add_state PROTO((STATELIST *, char *, u_int, int));static int      enum_event PROTO((char *));static int      extra_stuff PROTO((char *, int *, char **));static NAME_LIST *find_state PROTO((STATELIST *, char *));static void     rad_fsmdelete PROTO((int));static int      rad_fsminit PROTO((char*, FSM_ENT ***, char *));/* *	Default Action Table */static char    *default_actions =		/* MUST NOT HAVE FSMID */{"Start:\n\	*.*.DUP			REDO		Same\n\	*.*.FATAL		FATAL_LOG	End\n\	*.*.TIMEOUT		TIMEOUT		End\n\	*.*.ABORT		NULL		End\n\	*.*.RETRY_LIMIT		FAIL		ReplyHold\n\\n\ReplyHold:\n\	*.*.ACK			REPLY		Unlimit\n\	*.*.NAK			REPLY		Unlimit\n\\n\Unlimit:\n\	*.*.ACK			RETRY_LIMIT	Hold		XVALUE=0\n\	*.*.NAK			RETRY_LIMIT	Hold		XVALUE=0\n\\n\Hold:\n\	*.*.TIMEOUT		NULL		End\n\\n\End:"};#ifdef	MERIT_LAS/* *	Standard LAS State Machine Table when there is no FSM configuration file */#ifdef USR_CCAstatic char    *standard_fsm ={"%FSMID USR_STD_LAS\n\Start:\n\        *.+AUTHENTICATE.ACK     AUTHENTICATE    REPLYhold\n\        *.+AUTHEN.ACK           AUTHENTICATE    REPLYhold\n\        *.+AUTH_ONLY.ACK        AUTHENTICATE    REPLYhold\n\        *.+ACCT.ACK             ACCT            REPLYhold\n\        *.+MGT_POLL.ACK         SRV_STATUS      REPLYhold\n\        *.+IPALLOC.ACK          IPPOOL          REPLYhold\n\        *.+IPRELEASE.ACK        IPPOOL          REPLYhold\n\        *.+RF_REQ.ACK           RES_FREE_REQ    End\n\        *.+RF_RESP.ACK          RES_FREE_RESP   End\n\        *.+RQ_REQ.ACK           FWD_TO_NAS      End\n\        *.+RQ_RESP.ACK          RES_QRY_RESP    RQwait\n\        *.+NAS_REB_REQ.ACK      NAS_REB         End\n\        *.+NAS_REB_RESP.ACK     NULL            End\n\        *.+EVENT_REQUEST.ACK    NULL            End\n\        *.+TERM_SESSION.ACK     NULL            End\n\        *.*.NAK                 REPLY           End\n\\n\REPLYhold:\n\        *.*.ACK                 REPLY           Hold\n\        *.*.NAK                 REPLY           Hold\n\        *.*.ACC_CHAL            REPLY           Hold\n\\n\RQwait:\n\        Start.RES_QRY_RESP.ACK  NULL            Start\n\        Start.RES_QRY_RESP.DONE NULL            End\n\        Start.RES_QRY_RESP.NAK  NULL            End\n\\n\Hold:\n\        *.*.TIMEOUT             NULL            End\n\        *.*.TIMER               NULL            End\n\\n\End:"};#else  /* USR_CCA *//* *	Standard LAS State Machine Table when there is no FSM configuration file */static char    *standard_fsm ={"%FSMID STD_LAS\n\Start:\n\        *.+AUTHEN.ACK           AUTHENTICATE    REPLYhold\n\        *.+AUTH_ONLY.ACK        AUTHENTICATE    REPLYhold\n\        *.+AUTHENTICATE.ACK     AUTHENTICATE    REPLYhold\n\        *.+ACCT.ACK             ACCT            REPLYhold\n\        *.+IPALLOC.ACK          IPPOOL          REPLYhold\n\        *.+IPRELEASE.ACK        IPPOOL          REPLYhold\n\        *.+MGT_POLL.ACK         SRV_STATUS      REPLYhold\n\        *.+EVENT_REQUEST.ACK    NULL            End\n\        *.+TERM_SESSION.ACK     NULL            End\n\        *.*.NAK                 REPLY           End\n\\n\REPLYhold:\n\        *.*.ACK                 REPLY           Hold\n\        *.*.NAK                 REPLY           Hold\n\        *.*.ACC_CHAL            REPLY           Hold\n\\n\Hold:\n\        *.*.TIMEOUT             NULL            End\n\\n\End:"};#endif  /* USR_CCA */#else	/* MERIT_LAS *//* *	Standard State Machine Table when there is no FSM configuration file */#ifdef USR_CCAstatic char    *standard_fsm ={"%FSMID USR_STD\n\Start:\n\        *.+AUTHEN.ACK           AUTHENTICATE    REPLYhold\n\        *.+AUTH_ONLY.ACK        AUTHENTICATE    REPLYhold\n\        *.+ACCT.ACK             ACCT            REPLYhold\n\        *.+MGT_POLL.ACK         SRV_STATUS      REPLYhold\n\        *.+IPALLOC.ACK          IPPOOL          REPLYhold\n\        *.+IPRELEASE.ACK        IPPOOL          REPLYhold\n\        *.+RF_REQ.ACK           RES_FREE_REQ    End\n\        *.+RF_RESP.ACK          RES_FREE_RESP   End\n\        *.+RQ_REQ.ACK           FWD_TO_NAS      End\n\        *.+RQ_RESP.ACK          RES_QRY_RESP    RQwait\n\        *.+NAS_REB_REQ.ACK      NAS_REB         End\n\        *.+NAS_REB_RESP.ACK     NULL            End\n\        *.+EVENT_REQUEST.ACK    NULL            End\n\        *.+TERM_SESSION.ACK     NULL            End\n\        *.*.NAK                 REPLY           End\n\\n\REPLYhold:\n\        *.*.ACK                 REPLY           Hold\n\        *.*.NAK                 REPLY           Hold\n\        *.*.ACC_CHAL            REPLY           Hold\n\\n\RQwait:\n\        Start.RES_QRY_RESP.ACK  NULL            Start\n\        Start.RES_QRY_RESP.DONE NULL            End\n\        Start.RES_QRY_RESP.NAK  NULL            End\n\\n\Hold:\n\        *.*.TIMEOUT             NULL            End\n\        *.*.TIMER               NULL            End\n\\n\End:"};#else  /* USR_CCA *//* *	Standard State Machine Table when there is no FSM configuration file */static char    *standard_fsm ={"%FSMID STD\n\Start:\n\        *.+AUTHEN.ACK           AUTHENTICATE    REPLYhold\n\        *.+AUTH_ONLY.ACK        AUTHENTICATE    REPLYhold\n\        *.+ACCT.ACK             ACCT            REPLYhold\n\        *.+MGT_POLL.ACK         SRV_STATUS      REPLYhold\n\        *.+IPALLOC.ACK          IPPOOL          REPLYhold\n\        *.+IPRELEASE.ACK        IPPOOL          REPLYhold\n\        *.+EVENT_REQUEST.ACK    NULL            End\n\        *.+TERM_SESSION.ACK     NULL            End\n\        *.*.NAK                 REPLY           End\n\\n\REPLYhold:\n\        *.*.ACK                 REPLY           Hold\n\        *.*.NAK                 REPLY           Hold\n\        *.*.ACC_CHAL            REPLY           Hold\n\\n\Hold:\n\        *.*.TIMEOUT             NULL            End\n\\n\End:"};#endif  /* USR_CCA */#endif	/* MERIT_LAS *//************************************************************************* * *	Function: add_state * *	Purpose: Add a state name and flag to the list. *		 Assign the next available state number to it. * *	Returns: The (new) next available state number to use. * *************************************************************************/static intadd_state (list, name, flag, num)STATELIST      *list;		/* list of states names */char           *name;		/* name of the new state */u_int           flag;		/* flag (seen/defined) for the new state */int             num;		/* next available state number to use */{	NAME_LIST      *node;	static char    *func = "add_state";	dprintf(4, (LOG_DAEMON, LOG_DEBUG, "%s: entered", func));	if (num >= ST_RESERVED)	{		logit (LOG_DAEMON, LOG_DEBUG, "%s: FSM size (%d) too large\n",			func, num);		exit (-14);	}	/* make sure we'll have enough space in the FSM array */	if (list->nst >= list->maxst)	{		dprintf(1, (LOG_DAEMON, LOG_DEBUG,			"%s: growing FSM size by 8", func));		list->maxst += 8;		fsm = (FSM_ENT **) realloc (fsm,					    (list->maxst) * sizeof (FSM_ENT *));	}	/* append new state to states list */	if ((node = (NAME_LIST *) malloc (sizeof (NAME_LIST)))							== (NAME_LIST *) NULL)	{		logit (LOG_DAEMON, LOG_ALERT, "%s: FATAL out of memory", func);		abort ();	}	node->name = add_string (name, ASIS);	node->num = num;	node->flag = (u_char) flag;	node->next = list->states;	list->states = node;	list->nst++;	dprintf(4, (LOG_DAEMON, LOG_DEBUG,		"%s: added '%s' as state %d with flag %s", func,		(name == (char *) NULL) ? "?" : name,		num, ((u_char) flag == ST_SEEN) ? "ST_SEEN" : "ST_DEFINED"));	num++;	return num;} /* end of add_state () *//************************************************************************* * *	Function: enum_event * *	Purpose: Enumerate a event (from string to number). *		 Note: These numbers are taken from #defines in radius.h * *	Returns: <number> of the event, *		 -2 if the event is not valid. * *************************************************************************/static intenum_event (pevent)char           *pevent;{	typedef struct	{		char *ev_name;		int   ev_value;	} event_map_t;	static event_map_t events[] =	{		{ EN_NAK,		EV_NAK			},		{ EN_ACK,		EV_ACK			},		{ EN_ERROR,		EV_ERROR		},		{ EN_WAIT,		EV_WAIT			},		{ EN_FATAL,		EV_FATAL		},		{ EN_DUP_REQ,		EV_DUP_REQ		},		{ EN_TIMER,		EV_TIMER		},		{ EN_TIMEOUT,		EV_TIMEOUT		},		{ EN_ABORT,		EV_ABORT		},		{ EN_NEW_AUTHEN,	EV_NEW_AUTHEN		},		{ EN_NEW_ACCT,		EV_NEW_ACCT		},		{ EN_NEW_PASSWD,	EV_NEW_PASSWD		},		{ EN_RE_ACCESS,		EV_RE_ACCESS		},		{ EN_ACC_CHAL,		EV_ACC_CHAL		},		{ EN_MGT_POLL,		EV_MGT_POLL		},		{ EN_AUTH_ONLY,		EV_AUTH_ONLY		},		{ EN_ACCT_START,	EV_ACCT_START		},		{ EN_ACCT_STOP,		EV_ACCT_STOP		},		{ EN_ACCT_ALIVE,	EV_ACCT_ALIVE		},		{ EN_ACCT_MODEM_START,	EV_ACCT_MODEM_START	},		{ EN_ACCT_MODEM_STOP,	EV_ACCT_MODEM_STOP	},		{ EN_ACCT_CANCEL,	EV_ACCT_CANCEL		},		{ EN_ACCT_ON,		EV_ACCT_ON		},		{ EN_ACCT_OFF,		EV_ACCT_OFF		},		{ EN_ACCT_DUP,		EV_ACCT_DUP		},		{ EN_RC1,		EV_RC1			},		{ EN_RC2,		EV_RC2			},		{ EN_RC3,		EV_RC3			},		{ EN_RC4,		EV_RC4			},		{ EN_RC5,		EV_RC5			},		{ EN_RC6,		EV_RC6			},		{ EN_RC7,		EV_RC7			},		{ EN_RC8,		EV_RC8			},		{ EN_RC9,		EV_RC9			},		{ EN_RC10,		EV_RC10			},		{ EN_RC11,		EV_RC11			},		{ EN_RC12,		EV_RC12			},		{ EN_RC13,		EV_RC13			},		{ EN_RC14,		EV_RC14			},		{ EN_RC15,		EV_RC15			},		{ EN_RC16,		EV_RC16			},		{ EN_RC17,		EV_RC17			},		{ EN_RC18,		EV_RC18			},		{ EN_RC19,		EV_RC19			},		{ EN_RC20,		EV_RC20			},		{ EN_RC21,		EV_RC21			},		{ EN_PW_EXPIRED,	EV_PW_EXPIRED		},		{ EN_RETRY_LIMIT,	EV_RETRY_LIMIT		},#ifdef USR_CCA		{ EN_RF_REQ,		EV_RF_REQ		},		{ EN_RQ_REQ,		EV_RQ_REQ		},		{ EN_RQ_RESP,		EV_RQ_RESP		},		{ EN_DONE,		EV_DONE			},		{ EN_NAS_REB_REQ,	EV_NAS_REB_REQ		},		{ EN_NAS_REB_RESP,	EV_NAS_REB_RESP		},		{ EN_RF_RESP,		EV_RF_RESP		},#endif	/* USR_CCA */		{ NULL,			-2			} /* EOL */	};	int             i;	static char    *func = "enum_event";

⌨️ 快捷键说明

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