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

📄 radpwtst.c

📁 RADIUS协议的认证计费服务
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * 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 * */static char     rcsid[] = "$Id: radpwtst.c,v 1.1.1.1 2001/08/10 20:49:29 bonze Exp $";#include	<sys/types.h>#include	<sys/socket.h>#include	<sys/param.h>#include	<netinet/in.h>#include	<sys/time.h>#include	<sys/signal.h>#ifdef	aix#include	<sys/termio.h>#else	/* aix */#include	<sys/termios.h>#endif	/* aix */#ifdef	SVR4#include	<sys/systeminfo.h>#endif	/* SVR4 */#include	<netdb.h>#include	<pwd.h>#include	<stdio.h>#include	<stdlib.h>#include	<unistd.h>#include	"radius.h"#ifndef RESPONSE_TIMEOUT#define RESPONSE_TIMEOUT 3#endif#ifndef MAX_RETRIES#define MAX_RETRIES	10#endifUINT2           send_buffer_size = RAD_SEND_BUFFER_SIZE;char            recv_buffer[RAD_RECV_BUFFER_SIZE];char            send_buffer[RAD_SEND_BUFFER_SIZE];char            ourhostname[MAXHOSTNAMELEN];char           *progname;char           *radius_dir;int             debug_flag = 0;int             dumpcore = 0;int             file_logging = 2;   /* 0 => syslog, 1 => logfile, 2 => stderr */int             zap_logfile = 0;int             authfile_cnt = 0;int             clients_cnt = 0;int             users_cnt = 0;time_t          birthdate;AATVPTR		rad_authen_aatv = (AATV *) NULL;AATVPTR         rad_ipc_aatv = (AATV *) NULL;AATV           *authtype_tv[PW_AUTH_MAX + 1];FILE           *ddt = NULL;FILE           *msgfd = 0;extern void     dir_init();static void     radpwtst_usage ();typedef struct string_list_struct{	struct string_list_struct *next;	char                      *str;} string_list;static char *rad_getpass (prompt)char           *prompt;{	int             ch;	char           *p;	FILE           *infp;	FILE           *outfp;	sigset_t        newset;	sigset_t        oldset;#ifdef	TCSAFLUSHtypedef	struct termios  TERM_STRUCT;#define	GET_TTY(x,y)    tcgetattr(x,y)#define	SET_TTY(x,y)    tcsetattr(x,TCSAFLUSH,y)#else	/* TCSAFLUSH */typedef	struct termio   TERM_STRUCT;#define	GET_TTY(x,y)    ioctl(x,TCGETA,y)#define	SET_TTY(x,y)    ioctl(x,TCSETAF,y)#endif	/* TCSAFLUSH */	TERM_STRUCT     term;	TERM_STRUCT     termsave;	static char     buf[AUTH_PASS_LEN + 1];	infp = stdin;	outfp = stderr;	sigemptyset (&newset);  /* block SIGINT and SIGTSTP, save signal mask */	sigaddset (&newset, SIGINT);	sigaddset (&newset, SIGTSTP);	sigprocmask (SIG_BLOCK, &newset, &oldset);	GET_TTY(fileno(infp), &termsave);	term = termsave;			/* copy the entire structure */	term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); /* turn off echoing */	SET_TTY(fileno(infp), &term);	fputs (prompt, outfp);	rewind (outfp);				/* implied flush */	p = buf;	while (((ch = getc (infp)) != EOF) && (ch != '\n'))	{		if (p < buf + AUTH_PASS_LEN)		{			*p++ = ch;		}	}	*p = '\0';				/* null terminated password */	write (fileno (outfp), "\n", 1);	/* echo one newline */	SET_TTY(fileno(infp), &termsave);	sigprocmask (SIG_SETMASK, &oldset, NULL);	return (buf);} /* end of rad_getpass () */intmain (argc, argv)int             argc;char           *argv[];{	int             acks = 0;	/* ACKs to ignore */	int             result;	int             retries;	int             new_old;	int             zero = 0;	char           *clear_pw = (char *) NULL;	char           *client_name = (char *) NULL;  	char	       *ptr;	string_list    *vplist = NULL;  /* For '-:' option(s) */	string_list   **vpnext = &vplist; /* For '-:' option */	char            passwd[AUTH_PASS_LEN + 1];	char            msg[4096]; /* big enough to hold several messages */	SEND_DATA       data;	/*	 *	Determine what program we're running as...	 *	Strip off the path (if any).	 */	progname = *argv;	for (ptr = progname; *ptr != '\0'; ptr++)	{		if (*ptr == '/')		{			progname = ptr + 1;		}	}	/* Set up some defaults */	data.version = 0;	data.server = "";	/* SendServer picks server, if need be */	radius_dir = "";	/* SendServer picks directory, if need be */	data.timeout = RESPONSE_TIMEOUT;	data.user_file = (char *) NULL;	data.send_pairs = NULL_VP;	data.receive_pairs = NULL_VP;	data.group = (char *) NULL;	data.arades = 0;	data.challenge = 0;	data.password = (char *) NULL;	data.user_name = (char *) NULL;	data.client_id = 0;	retries = MAX_RETRIES;	/* Try for response this many times */	new_old = 0;		/* Assume old style */	data.ustype = 0;	data.fptype = 0;	/* by default */	data.svc_port = 0;	/* Late binding */	if (strcmp (progname, "radsend") == 0)	{		data.code = PW_ACCESS_REQUEST;		data.port_num = -1; /* Don't let send_server() force to one */		data.ustype = -1;		data.client_id = (UINT4) -1;		new_old = 1;		/* New style, where that counts. */	}	else	{		data.port_num = 1; /* Just default to port number one here */		if (strcmp (progname, "radacct") == 0)		{			data.code = PW_ACCOUNTING_REQUEST;		}		else /* radpwtst, classic. */		{			data.code = PW_ACCESS_REQUEST;		}	}#ifdef	SVR4	if (sysinfo (SI_HOSTNAME, ourhostname, sizeof (ourhostname)) < 0)	{		perror ("SI_HOSTNAME");		exit (-1);	}#else	/* Assume BSD */	if (gethostname (ourhostname, sizeof (ourhostname)) < 0)	{		perror ("gethostname");		exit (-1);	}#endif	/* SVR4 */	/* Check command args */	while (--argc > 0 && *(*++argv) == '-')	{		/* switch on char. after "-" */		ptr = *argv + 1;		switch (*ptr++)		{		    case 'a':	/* "ACKs to ignore" */			if (--argc <= 0)			{				printf ("bad or no count of ACKs to ignore\n");				radpwtst_usage ();			}			argv++;			acks = atoi (*argv);			break;		    case 'c':	/* "Packet Code" */			if (--argc == 0)			{				radpwtst_usage ();				printf ("packet code\n");			}			argv++;			data.code = atoi (*argv);			break;		    case 'd':	/* "Directory" */			if (--argc == 0)			{				radpwtst_usage ();				printf ("directory\n");			}			argv++;			radius_dir = *argv;	/* Use specified directory */			break;		    case 'f':	/* "Users" file */			if (--argc == 0)			{				radpwtst_usage ();				printf ("users file\n");			}			argv++;			data.user_file = *argv;			break;		    case 'g':	/* "Users" group */			if (--argc == 0)			{				radpwtst_usage ();				printf ("users group\n");			}			argv++;			data.group = *argv;			break;		    case 'h':	/* "Help" message */			radpwtst_usage ();			argv++;			break;		    case 'i':   /* Client-Id */			if (--argc == 0)			{				radpwtst_usage ();			}			argv++;			client_name = *argv;			break;		    case 'l':	/* async-line */			if (--argc == 0)			{				radpwtst_usage ();				printf ("async-line\n");			}			argv++;			sscanf (*argv, "%u", &data.port_num);			break;		    case 'n':			new_old = 1;			break;		    case 'p':	/* UDP-port */			if (--argc == 0)			{				radpwtst_usage ();				printf ("udp port\n");			}			argv++;			sscanf (*argv, "%u", &data.svc_port);			break;		    case 'r':   /* Retries */			if (--argc == 0)			{				radpwtst_usage ();				printf ("retries\n");			}			argv++;			sscanf (*argv, "%u", &retries);			break;		    case 's':	/* "Server name" */			if (--argc == 0)			{				radpwtst_usage ();				printf ("server\n");			}			argv++;			data.server = *argv;			break;		    case 't':   /* Timeout */			if (--argc == 0)			{				radpwtst_usage ();				printf ("timeout\n");			}			argv++;			sscanf (*argv, "%u", &data.timeout);			break;		    case 'u':	/* "Service Type" */			if (--argc == 0)			{				radpwtst_usage ();				printf ("service type\n");			}			argv++;			if (strcasecmp (*argv, "auth") == 0)			{				if (new_old == 1) /* new style */				{					data.ustype = PW_AUTHENTICATE_ONLY;				}				else /* old style */				{					data.ustype = PW_OUTBOUND_USER;				}			}#ifdef ASCEND

⌨️ 快捷键说明

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