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

📄 builddbm.c

📁 RADIUS协议的认证计费服务
💻 C
字号:
/* * *	RADIUS *	Remote Authentication Dial In User Service * * *	Livingston Enterprises, Inc. *	6920 Koll Center Parkway *	Pleasanton, CA   94566 * *	Copyright 1992 Livingston Enterprises, Inc. * *	Permission to use, copy, modify, and distribute this software for any *	purpose and without fee is hereby granted, provided that this *	copyright and permission notice appear on all copies and supporting *	documentation, the name of Livingston Enterprises, Inc. not be used *	in advertising or publicity pertaining to distribution of the *	program without specific prior permission, and notice be given *	in supporting documentation that copying and distribution is by *	permission of Livingston Enterprises, Inc. * *	Livingston Enterprises, Inc. makes no representations about *	the suitability of this software for any purpose.  It is *	provided "as is" without express or implied warranty. * *      Copyright (c) 1996 Ascend Communications, Inc. *      All rights reserved. * *      Permission to copy, display, distribute and make derivative works *      from this material in whole or in part for any purpose is granted *      provided that the above copyright notice and this paragraph are *      duplicated in all copies.  THIS SOFTWARE IS PROVIDED "AS IS" AND *      WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, WITHOUT *      LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *      FOR A PARTICULAR PURPOSE. * *//* * 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: builddbm.c,v 1.1.1.1 2001/08/10 20:49:27 bonze Exp $";static char     sccsid[] =		"@(#)builddbm.c	1.1 Copyright 1992 Livingston Enterprises Inc";#include	<sys/types.h>#include	<sys/socket.h>#include	<sys/time.h>#include	<sys/file.h>#include	<netinet/in.h>#include	<stdio.h>#include	<netdb.h>#include	<ctype.h>#include	"radius.h"char           *radius_dir;#define FIND_MODE_NAME	0#define FIND_MODE_REPLY	1#define FIND_MODE_SKIP	2#define FIND_MODE_FLUSH	3FILE           *userfd;static int      user_read PROTO((char *, char *));main (argc, argv)int             argc;char           *argv[];{	int             fd;	int             retval;	char           *progname;	char            name[128];	char            content[2048];	datum           named;	datum           contentd;#ifdef	USE_NDBM	DBM            *db;#endif	/* USE_NDBM */	progname = *argv;#ifdef	USE_NDBM	if ((db = dbm_open ("users", O_RDWR | O_CREAT | O_TRUNC, 0600)) == 0)	{		fprintf (stderr, "%s: Couldn't init dbm\n", progname);		exit (-1);	}#else	/* USE_NDBM */	if ((fd = open ("users.pag", O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0)	{		fprintf (stderr, "%s: Couldn't open users.pag for writing\n",			progname);		exit (-1);	}	close (fd);	if ((fd = open ("users.dir", O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0)	{		fprintf (stderr, "%s: Couldn't open users.dir for writing\n",			progname);		exit (-1);	}	close (fd);#endif	/* USE_NDBM */	radius_dir = ".";#ifdef	USE_DBM	if (dbminit ("users") != 0)	{		fprintf (stderr, "%s: Couldn't init dbm\n",			progname);		exit (-1);	}#endif	/* USE_DBM */	while (user_read (name, content) == 0)	{		named.dptr = name;		named.dsize = strlen (name);		contentd.dptr = content;		contentd.dsize = strlen (content);#ifdef	USE_NDBM		if ((retval = dbm_store (db, named, contentd, DBM_INSERT)) != 0)#else	/* USE_NDBM */		if (store (named, contentd) != 0)#endif	/* USE_NDBM */		{			if (retval == 1)			{				fprintf (stderr,					"%s: Duplicate entry for '%s'\n",					progname);			}			else			{				fprintf (stderr, "%s: Couldn't store datum\n",					progname);				exit (-1);			}		}	}#ifdef	USE_NDBM	dbm_close (db);#else	/* USE_NDBM */	dbmclose ();#endif	/* USE_NDBM */	exit (0);} /* end of main () *//************************************************************************* * *	Function: user_read * *	Purpose: Return each user in the database: name is key, content is *		 two strings - check items, and reply items separated by a *		 newline. * *************************************************************************/static intuser_read (name, content)char           *name;char           *content;{	char            buffer[256];	char           *ptr;	int             namelen;	int             mode;	VALUE_PAIR     *check_first;	VALUE_PAIR     *reply_first;	char           *func = "user_name";	/*	 * Open the user table	 */	if (userfd == (FILE *) NULL)	{		sprintf (buffer, "%s/%s", radius_dir, RADIUS_USERS);		if ((userfd = fopen (buffer, "r")) == (FILE *) NULL)		{			fprintf (stderr, "%s: Couldn't open %s for reading\n",				 func, buffer);			exit (-1);		}	}	mode = FIND_MODE_NAME;	while (fgets (buffer, sizeof (buffer), userfd) != (char *) NULL)	{		if (mode == FIND_MODE_NAME)		{			/*			 * Find the entry starting with the users name			 */			if (*buffer != COMMENT &&				*buffer != '\t' && *buffer != '\n')			{				ptr = buffer;				while (*ptr != ' ' && *ptr != '\t' &&						*ptr != '\0')				{					*name++ = *ptr++;				}				*name = '\0';				if (*ptr == '\0')				{					continue;				}				ptr++;				while (*ptr == ' ' || *ptr == '\t')				{					ptr++;				} strcpy (content, ptr);				content += strlen (content);				mode = FIND_MODE_REPLY;			}		}		else		{			if (*buffer == ' ' || *buffer == '\t')			{				ptr = buffer;				while (*ptr == ' ' || *ptr == '\t')				{					ptr++;				}				strcpy (content, ptr);				content += strlen (content);				content -= 2;				while (*content == ' ' || *content == '\t')				{					content--;				}				content++;				*content = '\0';				if (*(content - 1) != ',')				{					return (0);				}			}			else			{				/* We are done */				return (0);			}		}	}	fclose (userfd);	return (-1);} /* end of user_read () */

⌨️ 快捷键说明

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