📄 resources.c
字号:
#ifdef USR_CCA/* * * Copyright (c) 1996 U.S. Robotics, Access Corp. * 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. * * If providing code not subject to a copyright please indicate that the * code has been dedicated to the public. * *//* * 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: resources.c,v 1.1.1.1 2001/08/10 20:49:29 bonze Exp $";/****************************************************************************** * * resources.c * * This file contains the functions required for managing resources * *****************************************************************************/#include <sys/param.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <sys/ioctl.h>#include <sys/file.h>#include <sys/time.h>#include <sys/file.h>#include <sys/wait.h>#include <sys/stat.h>#include <net/if.h>#include <stdio.h>#include <stdlib.h>#include <netdb.h>#include <fcntl.h>#include <errno.h>#include <signal.h>#include <syslog.h>#include "radius.h"extern int debug_flag;static void put_in_pool PROTO((ADDR_POOL *, ADDR_POOL **));static int range_ok PROTO((UINT4, UINT4, int));static char pool_overlap PROTO((ADDR_POOL **, char *, UINT4));/***************************************************************************** * * Function: add_to_addr_pool * * Purpose: Parse the given string and get the base IP address and range * for this address pool. Then link this pool into the global * list of address pools by calling put_in_pool(). * *****************************************************************************/intadd_to_addr_pool (pool, string, line_nbr)ADDR_POOL **pool;char *string;int line_nbr; /* Current users file line */{ char *store; ADDR_POOL *addrptr; char *temp; UINT4 first_host; char error = 0; char *name; static char *func = "add_to_addr_pool"; dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: entered", func)); if ((name = strtok (string, " \t\n\r")) == NULL) { logit (LOG_DAEMON, LOG_ERR, "%s: users file, line %d - Invalid Assigned IP Address Pool.", func, line_nbr); return (-1); } if ((store = strtok (NULL, " \t\n\r")) == NULL) { logit (LOG_DAEMON, LOG_ERR, "%s: users file, line %d - Assigned IP Address Pool - Missing base address", func, line_nbr); return (-1); } if (good_ipaddr (store) != 0) { logit (LOG_DAEMON, LOG_ERR, "%s: users file, line %d - Assigned IP Address Pool - Bad base address", func, line_nbr); return (-1); } if (strcmp (store, "0.0.0.0") == 0) { logit (LOG_DAEMON, LOG_ERR, "%s: users file, line %d - Assigned IP Address Pool - Base address is 0.0.0.0", func, line_nbr); return (-1); } /* Base address is okay. */ if (pool_overlap (pool, name, ntohl(inet_addr (store)))) { logit (LOG_DAEMON, LOG_ALERT,"%s: users file, line %d - Address Pool - Name repeated, or base address overlaps with another pool", func, line_nbr); return (-1); } if ((addrptr = (ADDR_POOL *) malloc (sizeof (ADDR_POOL))) == NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: users file, line %d - Couldn't allocate ADDR_POOL storage", func, line_nbr); abort (); return (-1); } addrptr->name = add_string (name, ASIS); addrptr->ip_address = ntohl(inet_addr (store)); addrptr->count = 0; addrptr->user_q = (ASSIGNED_IP *) NULL; addrptr->next = (ADDR_POOL *) NULL; if ((store = strtok (NULL, " \t\n\r")) == NULL) { logit (LOG_DAEMON, LOG_ERR,"%s: users file, line %d - Missing Assigned IP Address Pool netmask and range.", func, line_nbr); free (addrptr); return (-1); } if (good_ipaddr (store) != 0) { logit (LOG_DAEMON, LOG_ERR, "%s: users file, line %d - Invalid Assigned IP Address Pool netmask.", func, line_nbr); free (addrptr); return (-1); } addrptr->netmask = ntohl(inet_addr (store)); addrptr->network = addrptr->ip_address & addrptr->netmask; if ((store = strtok (NULL, " \t\n\r")) == NULL) { /* * logit (LOG_DAEMON, LOG_ERR, "%s: users file, line %d - * Missing Assigned IP Address Pool range.", func, line_nbr); */ free (addrptr); return (-1); } for (temp = store; *temp != '\0'; temp++) { if (!isdigit(*temp)) { error = 1; break; } } if (error == 1 || ((addrptr->range = atoi (store)) <= 0)) { /* * logit (LOG_DAEMON, LOG_ERR, "%s: users file, line %d - * Invalid Assigned IP Address Pool range.", func, line_nbr); */ free (addrptr); return (-1); }/* Now check the supplied address, netmask, range, etc. */ if (addrptr->netmask == 0xffffffff) { if (IN_CLASSA (addrptr->ip_address) && (((first_host = addrptr->ip_address & IN_CLASSA_HOST) == 0) || first_host == IN_CLASSA_HOST)) { /* * logit (LOG_DAEMON, LOG_ERR, "%s: users file, line * %d - Class A address with host part all zeros or * broadcast", func, line_nbr); */ free (addrptr); return (-1); } if (IN_CLASSB (addrptr->ip_address) && (((first_host = addrptr->ip_address & IN_CLASSB_HOST) == 0) || first_host == IN_CLASSB_HOST)) { /* * logit (LOG_DAEMON, LOG_ERR, "%s: users file, line * %d - Class B address with host part all zeros or * broadcast", func, line_nbr); */ free (addrptr); return (-1); } if (IN_CLASSC (addrptr->ip_address) && (((first_host = addrptr->ip_address & IN_CLASSC_HOST) == 0) || first_host == IN_CLASSC_HOST)) { /* * logit (LOG_DAEMON, LOG_ERR, "%s: users file, line * %d - Class C address with host part all zeros or * broadcast", func, line_nbr); */ free (addrptr); return (-1); } if (IN_CLASSD (addrptr->ip_address) || IN_EXPERIMENTAL (addrptr->ip_address)) { /* * logit (LOG_DAEMON, LOG_ERR, "%s: users file, line * %d - Class D or Class E address specified", func, * line_nbr); */ free (addrptr); return (-1); } } /* Checking if host part is zero. */ if (((addrptr->ip_address & (~addrptr->netmask)) == 0) && (addrptr->netmask != 0xffffffff)) { /* * Host part of base address is zero and the base address * is not host specific; set host part to one. */ addrptr->ip_address += 1; } if (!range_ok (addrptr->ip_address, addrptr->netmask, addrptr->range)) { /* * logit (LOG_DAEMON, LOG_ERR, "%s: users file, line %d - * Range too large for given base IP address.", func, * line_nbr); */ free (addrptr); return (-1); } put_in_pool (addrptr, pool); return 0;} /* end of add_to_addr_pool () *//***************************************************************************** * * Function: put_in_pool * * Purpose: Attach the given address pool to the global list of address * pools. * *****************************************************************************/static voidput_in_pool (addrptr, pool)ADDR_POOL *addrptr;ADDR_POOL **pool; /* pool to put this address pool in */{ ADDR_POOL *aptr; static char *func = "put_in_pool"; dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: entered", func)); if (*pool == (ADDR_POOL *) NULL) { *pool = addrptr; } else { for (aptr = *pool; aptr->next; aptr = aptr->next) { ; /* continue */ } aptr->next = addrptr; }} /* end of put_in_pool () *//************************************************************************* * * Function: free_pool_ent * * Purpose: Free all components of an ADDR_POOL structure. Delete * all the ASSIGNED_IP structures hanging from the ADDR_POOL * structure. * ************************************************************************/voidfree_pool_ent (pool_ent)ADDR_POOL *pool_ent;{ ASSIGNED_IP *assign_ent; if (pool_ent->user_q == (ASSIGNED_IP *) NULL) { free (pool_ent); return; } for (assign_ent = pool_ent->user_q; assign_ent; assign_ent = pool_ent->user_q) { pool_ent->user_q = assign_ent->next; free (assign_ent); } return;} /* end of free_pool_ent () *//***************************************************************************** *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -