📄 dict.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 * *//* * * Public entry points in this file: * * attr_check * attr_check_by_dict * attr_check_by_name * attr_check_clear * dict_attrfind * dict_attrget * dict_find_value * dict_init * dict_valfind * dict_valget * free_vendor_list * parse_for_vendor_list * vendor_list_toa * */static char sccsid[] = "@(#)dict.c 1.2 Copyright 1992 Livingston Enterprises Inc";static char rcsid[] = "$Id: dict.c,v 1.1.1.1 2001/08/10 20:49:28 bonze Exp $";#include <sys/types.h>#include <netinet/in.h>#include <arpa/inet.h>#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <syslog.h>#include "radius.h"extern int debug_flag;extern char *radius_dir;extern MF_ENT vendor_mf;extern MF_ENT vendor_list_mf;extern int dumpcore;static int parse_flags PROTO((int *));static char *parse_for_vendor PROTO((char *, VENDOR **));static int vend_init PROTO((void));static int vend_verify PROTO((void));static DICT_ATTR *dictionary_attributes = (DICT_ATTR *) NULL;static DICT_VALUE *dictionary_values = (DICT_VALUE *) NULL;static have_vendors = 0;static VENDOR *vendors = (VENDOR *) NULL;char *dict_id = (char *) NULL;char *vend_id = (char *) NULL;/************************************************************************* * * Function: attr_check * * Purpose: Used to specify what kind of attribute/value pair * to check. * * Returns: success or failure code (0 == success, -1 == failure) * *************************************************************************/intattr_check (p_list, attr, vend_id)DICT_ATTR_LIST **p_list;int attr;UINT4 vend_id;{ DICT_ATTR *ap = dict_attrget (attr, vend_id); static char *func = "attr_check"; if (ap == (DICT_ATTR *) NULL) { logit (LOG_DAEMON, LOG_ERR, "%s: No such attribute:vendor (%d:%d)", func, attr, vend_id); return (-1); } return attr_check_by_dict (p_list, ap);} /* end of attr_check () *//************************************************************************* * * Function: attr_check_by_dict * * Purpose: Used to specify what kind of attribute/value pair * to check. * * Returns: success or failure code (0 == success, -1 == failure) * *************************************************************************/intattr_check_by_dict (p_list, ap)DICT_ATTR_LIST **p_list;DICT_ATTR *ap;{ DICT_ATTR_LIST *new; static char *func = "attr_check_by_dict"; if (ap == (DICT_ATTR *) NULL) { logit (LOG_DAEMON, LOG_ERR, "%s: No dictionary entry", func); return (-1); } if (p_list == (DICT_ATTR_LIST **) NULL) { logit (LOG_DAEMON, LOG_ERR, "%s: No list to add dictionary entry '%s' to", func, ap->name); return (-1); } /* * Check to see if it's in the check-list already. If so, * then don't add it again (but treat this as successful.) */ for (new = *p_list; new != (DICT_ATTR_LIST *) NULL; new = new->next) { if (new->ap == ap) { return (0); /* Already found. */ } } if ((new = (DICT_ATTR_LIST *) calloc(1, sizeof(DICT_ATTR_LIST))) == (DICT_ATTR_LIST *) NULL) { logit(LOG_DAEMON, LOG_ERR, "%s: FATAL -- out of memory", func); dumpcore = 0; abort (); } new->ap = ap; new->next = *p_list; *p_list = new; return (0);} /* end of attr_check_by_dict () *//************************************************************************* * * Function: attr_check_by_name * * Purpose: Used to specify what kind of attribute/value pair * to check. * * Returns: success or failure code (0 == success, -1 == failure) * *************************************************************************/intattr_check_by_name (p_list, name)DICT_ATTR_LIST **p_list;char *name;{ DICT_ATTR *ap = dict_attrfind (name); static char *func = "attr_check_by_name"; if (ap == (DICT_ATTR *) NULL) { logit (LOG_DAEMON, LOG_ERR, "%s: No such dictionary entry, '%s'", func, name); return (-1); } return attr_check_by_dict (p_list, ap);} /* end of attr_check_by_name () *//************************************************************************* * * Function: attr_check_clear * * Purpose: Used to specify what kind of attribute/value pair * to check. * * Returns: success or failure code (0 == success, -1 == failure) * *************************************************************************/intattr_check_clear (p_list)DICT_ATTR_LIST **p_list;{ int count = 0; DICT_ATTR_LIST *link; static char *func = "attr_check_clear"; if (p_list == (DICT_ATTR_LIST **) NULL) { return (-1); } while (*p_list != (DICT_ATTR_LIST *) NULL) { link = *p_list; *p_list =link->next; free (link); count++; } return (count);} /* end of attr_check_clear () *//************************************************************************* * * Function: dict_init * * Purpose: Initialize the dictionary. Read all ATTRIBUTES into * the dictionary_attributes list. Read all VALUES into * the dictionary_values list. * *************************************************************************/intdict_init (){ int attorval; int flags; int j; int line_no; int type; UINT4 value; FILE *dictfd; char *attrstr; char *dummy; char *namestr; char *ptr; DICT_ATTR *attr; DICT_ATTR **attr_last; DICT_VALUE *dval; DICT_VALUE **dval_last; VENDOR *attr_vep; VENDOR *vep; char buffer[256]; static char *func = "dict_init";#define ATTRIBUTE 1 /* Used by dict_init() */#define VALUE 2 /* Used by dict_init() */ dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: entered", func)); if (vend_init () != 0) { logit (LOG_DAEMON, LOG_ALERT, "%s: vend_init() failed", func); return (-1); } sprintf (buffer, "%s/%s", radius_dir, RADIUS_DICTIONARY); if ((dictfd = fopen (buffer, "r")) == (FILE *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Couldn't open dictionary: %s", func, buffer); return (-1); } attr_last = &dictionary_attributes; dval_last = &dictionary_values; line_no = 0; while (fgets (buffer, sizeof (buffer), dictfd) != (char *) NULL) { line_no++; /* Skip empty space */ if (*buffer == COMMENT || *buffer == '\0' || *buffer == '\n') { continue; } /* Check for DICT_ID, etc. */ if (*buffer == '%') { if ((ptr = strtok (buffer, " \t\n\r")) != (char *) NULL) { if (strcasecmp (ptr, "%DICTID") == 0) { if ((ptr = strtok (NULL, "\n\r")) != (char *) NULL) { if (dict_id != (char *) NULL) { free (dict_id); } j = strlen (ptr); if (j > MAX_DICTID_LEN) { ptr[MAX_DICTID_LEN] = '\0'; } dict_id = rad_strdup (ptr); } } } continue; /* treat as a comment. */ } /* Parse the regular dictionary */ attorval = 0; /* assume the worst */ if ((ptr = strtok (buffer, " \t\n\r")) != (char *) NULL) { for (vep = vendors; vep; vep = vep->next) { if (strcasecmp (vep->attr_name, buffer) == 0) { attorval = ATTRIBUTE; break; } if (strcasecmp (vep->value_name, buffer) == 0) { attorval = VALUE; break; } } } else /* Must have been a "blank" line (?) */ { continue; } switch (attorval) { case ATTRIBUTE: /* Read the ATTRIBUTE name */ if ((attrstr = strtok (NULL, " \t\n\r")) == (char *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid attribute on line %d of dictionary", func, line_no); return (-1); } ptr = parse_for_vendor (attrstr, &attr_vep); if (ptr == (char *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Missing vendor on line %d of dictionary", func, line_no); if (have_vendors == 0) { logit (LOG_DAEMON, LOG_ALERT, "%s: Vendors file is required for this dictionary", func); } return (-1); } if (ptr != attrstr) { vep = attr_vep; attrstr = ptr; } if ((ptr = strtok (NULL, " \t\n\r")) == (char *) NULL || !isdigit(*ptr)) { logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid value on line %d of dictionary", func, line_no); return (-1); } /* Attribute index value */ value = strtol (ptr, &dummy, 0); if ((ptr = strtok (NULL, " \t\n\r")) == (char *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid type on line %d of dictionary", func, line_no); return (-1); } if (strcmp (ptr, "string") == 0) { type = PW_TYPE_STRING; }#ifdef PW_TYPE_FILTER_BINARY else if (strcmp (ptr, "abinary") == 0) { type = PW_TYPE_FILTER_BINARY; }#endif /* PW_TYPE_FILTER_BINARY */ else if (strcmp (ptr, "integer") == 0) { type = PW_TYPE_INTEGER; } else if (strcmp (ptr, "short") == 0) { type = PW_TYPE_SHORT; } else if (strcmp (ptr, "octet") == 0) { type = PW_TYPE_OCTET; } else if (strcmp (ptr, "ipaddr") == 0) { type = PW_TYPE_IPADDR; } else if (strcmp (ptr, "date") == 0) { type = PW_TYPE_DATE; } else if (strcmp (ptr, "octets") == 0) { type = PW_TYPE_OCTETS; } else if (strcmp (ptr, "vendor") == 0) { type = PW_TYPE_VENDOR; } else if (strcmp (ptr, "tag-int") == 0) { type = PW_TYPE_TAG_INT; } else if (strcmp (ptr, "tag-str") == 0) { type = PW_TYPE_TAG_STR; } else { logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid type on line %d of dictionary", func, line_no); return (-1); } if (parse_flags (&flags) == -1) { logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid flags on line %d of dictionary", func, line_no); return (-1); } /* Create a new attribute for the list */ if ((attr = (DICT_ATTR *) calloc (1, sizeof (DICT_ATTR))) == (DICT_ATTR *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: FATAL out of memory", func); abort (); } attr->name = add_string (attrstr, ASIS); attr->value = value; attr->type = type; attr->vendor_id = vep->id; attr->vendor_ptr = vep; attr->flags = flags; attr->next = (DICT_ATTR *) NULL; attr->vnext = (DICT_ATTR *) NULL; /* Insert it at end of list */ *attr_last = attr; attr_last = &attr->next; dprintf(3, (LOG_DAEMON, LOG_DEBUG,"%s: dict line %d, attr %s, type = %d, val %d [0x%08X], vend %d, flags 0x%08X", func, line_no, attrstr, type, value, value, vep->id, flags)); break; /* from case attorval */ case VALUE: /* Read the ATTRIBUTE name */ if ((attrstr = strtok (NULL, " \t\n\r")) == (char *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid VALUE on line %d of dictionary", func, line_no); return (-1); } if ((namestr = strtok (NULL, " \t\n\r")) == (char *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid VALUE on line %d of dictionary", func, line_no); return (-1); } if ((ptr = parse_for_vendor (attrstr, &attr_vep)) != attrstr) { vep = attr_vep; attrstr = ptr; } if ((ptr = strtok (NULL, " \t\n\r")) == (char *) NULL || (!isdigit(*ptr) && *ptr != '-')) { logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid value on line %d of dictionary", func, line_no); return (-1); } if (((attr = dict_attrfind (attrstr)) != (DICT_ATTR *) NULL) &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -