📄 dict.c
字号:
} } *ptr++ = ':'; return ptr;} /* end of parse_for_vendor () *//***************************************************************************** * * Function: parse_for_vendor_list * * Purpose: Checks for <vendor>[+<vendor>...]:<attrname> and * returns list of vendor ids. * *****************************************************************************/char *parse_for_vendor_list (name, vep_list)char *name;VENDOR_LIST **vep_list;{ char *each; char *next; char *ptr; VENDOR *vendor; VENDOR_LIST *new; static char *func = "parse_for_vendor_list"; (void) free_vendor_list (*vep_list); *vep_list = (VENDOR_LIST *) NULL; if ((ptr = strchr (name, ':')) == (char *) NULL) { if (DEFAULT_VENDOR_ID != 0) { *vep_list = (VENDOR_LIST *) calloc (1, sizeof (VENDOR_LIST)); if (*vep_list == (VENDOR_LIST *) NULL) { logit (LOG_DAEMON, LOG_CRIT, "%s: FATAL, calloc(1, %d) for VENDOR_LIST", func, sizeof (VENDOR_LIST)); abort (); } vendor_list_mf.m++; (*vep_list)->vep = find_vendor_by_id (DEFAULT_VENDOR_ID); (*vep_list)->next = (VENDOR_LIST *) NULL; } return name; } *ptr = '\0'; /* Check to see if there is a "none" vendor. */ if (strcasecmp (name, "none") != 0) { for (each = name, next = strchr (each, '+'); each != NULL; each = next, next = strchr (each, '+')) { /* If not end of list, mark off this vendor... */ if (next != NULL) { *next = '\0'; /* Terminate vendor name */ next++; /* Ready for next... */ } if ((vendor = find_vendor_by_name (each)) == (VENDOR *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Cannot find vendor named '%s'", func, each); *ptr = ':'; return (char *) NULL; } new = (VENDOR_LIST *) calloc (1, sizeof (VENDOR_LIST)); if (new == (VENDOR_LIST *) NULL) { logit (LOG_DAEMON, LOG_CRIT, "%s: FATAL, calloc(1, %d) for VENDOR_LIST", func, sizeof (VENDOR_LIST)); abort (); } vendor_list_mf.m++; new->vep = vendor; new->next = (VENDOR_LIST *) NULL; *vep_list = new; vep_list = &(new->next); /* Short circut test above. */ if (next == NULL) { break; } } } /* end of if "none" */ *ptr++ = ':'; return ptr;} /* end of parse_for_vendor_list () */#define PARSE_VENDOR 1#define PARSE_MAP 2/****************************************************************************** * * Function: vend_init * * Purpose: Initialize the vendors list * *****************************************************************************/static intvend_init (){ int j; int line_no; int mode = PARSE_VENDOR; UINT4 s_attr; UINT4 s_attr2; UINT4 v_attr; UINT4 vendor_id; char *attrstr; char *dummy; char *valstr; char *ptr; char *vend_name; FILE *vendor_fd; VENDOR *vend_tmp; VENDOR *vend_last; VENDOR_MAP *map_ent; char buffer[256]; static char *func = "vend_init"; dprintf(2, (LOG_AUTH, LOG_DEBUG, "%s: entered", func)); /* Create dummy vendor entry for RADIUS */ if ((vend_tmp = (VENDOR *) calloc (1, sizeof (VENDOR))) == (VENDOR *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: FATAL out of memory", func); abort (); } vendor_mf.m++; vend_tmp->attr_name = add_string ("ATTRIBUTE", ASIS); vend_tmp->value_name = add_string ("VALUE", ASIS); vend_tmp->name = add_string ("RADIUS", ASIS); vend_tmp->id = 0; vend_tmp->map = (VENDOR_MAP *) NULL; vend_tmp->attrs = (DICT_ATTR *) NULL; vend_tmp->values = (DICT_VALUE *) NULL; vend_tmp->next = (VENDOR *) NULL; vendors = vend_tmp; /* Put it on the list. */ vend_last = vend_tmp; sprintf (buffer, "%s/%s", radius_dir, RADIUS_VENDORS); if ((vendor_fd = fopen (buffer, "r")) == (FILE *) NULL) { dprintf(1, (LOG_DAEMON, LOG_ALERT, "%s: Assuming no Vendor Specific attributes defined", func)); logit (LOG_DAEMON, LOG_ALERT, "%s: No vendors file found", func); return 0; } have_vendors = 1; line_no = 0; while (fgets (buffer, sizeof (buffer), vendor_fd) != (char *) NULL) { line_no++; /* Skip empty space */ if (*buffer == COMMENT || *buffer == '\0' || *buffer == '\n') { continue; } /* Check for VEND_ID, etc. */ if (*buffer == '%') { if ((ptr = strtok (buffer, " \t\n\r")) != (char *) NULL) { if (strcasecmp (ptr, "%VENDORSID") == 0) { if ((ptr = strtok (NULL, "\n\r")) != (char *) NULL) { if (vend_id != (char *) NULL) { free (vend_id); } j = strlen (ptr); if (j > MAX_VENDID_LEN) { ptr[MAX_VENDID_LEN] = '\0'; } vend_id = rad_strdup (ptr); } } } continue; /* treat as a comment. */ } /* See if we're reading attribute mapping table */ if (mode == PARSE_MAP) { /* Check if we're to return to parsing vendor info */ if (*buffer == ')') { mode = PARSE_VENDOR; continue; } if ((map_ent = vend_tmp->map) == (VENDOR_MAP *) NULL) { if ((map_ent = (VENDOR_MAP *) calloc (1, sizeof (VENDOR_MAP))) == (VENDOR_MAP *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: FATAL out of memory", func); abort (); } map_ent->vid = vend_tmp->id; vend_tmp->map = map_ent; } /* Assume bad values */ s_attr = -1; s_attr2 = -1; v_attr = -1; if ((ptr = strtok (buffer, " \t\n\r")) != (char *) NULL) { if (isdigit(*ptr)) { s_attr = strtol (ptr, &dummy, 0); s_attr2 = strtol (ptr, &dummy, 0); } } if ((ptr = strtok (NULL, " \t\n\r")) != (char *) NULL) { if (isdigit(*ptr)) { v_attr = strtol (ptr, &dummy, 0); } } if ((ptr = strtok (NULL, " \t\n\r")) != (char *) NULL) { if (isdigit(*ptr)) { s_attr2 = v_attr; v_attr = strtol (ptr, &dummy, 0); } } if (s_attr > 255 || s_attr2 > 255 || v_attr > 255 || s_attr > s_attr2) { logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid line %d in vendors", func, line_no); fclose (vendor_fd); return (-1); } while (s_attr <= s_attr2) { /* Request map */ map_ent->s_attr[s_attr] = v_attr; /* Reply map */ map_ent->v_attr[v_attr] = s_attr; s_attr++; v_attr++; } continue; } /* Check if attribute mapping table supplied */ if (*buffer == '(' && vend_tmp) { mode = PARSE_MAP; continue; } valstr = (char *) NULL; /* Can have vendor number _OR_ attribute string here */ if ((attrstr = strtok (buffer, " \t\n\r")) == (char *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid line %d in vendors", func, line_no); fclose (vendor_fd); return (-1); } if (!isdigit(*attrstr)) /* was ASCII attribute string */ { if ((valstr = strtok (NULL, " \t\n\r")) == (char *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Missing/invalid Vendor Value name on line %d of vendors", func, line_no); fclose (vendor_fd); return (-1); } if ((ptr = strtok (NULL, " \t\n\r")) == (char *) NULL || !isdigit(*ptr)) { logit (LOG_DAEMON, LOG_ALERT, "%s: Missing Vendor number on line %d of vendors", func, line_no); fclose (vendor_fd); return (-1); } } else /* was numeric vendor code */ { ptr = attrstr; attrstr = (char *) NULL; } /* Obtain numeric vendor code. */ vendor_id = atol (ptr); vend_name = strtok (NULL, " \t\n\r"); for (vend_tmp = vendors; vend_tmp != (VENDOR *) NULL; vend_tmp = vend_tmp->next) { if ((attrstr != (char *) NULL) && (strcasecmp ("ATTRIBUTE", attrstr) != 0) && (strcasecmp (vend_tmp->attr_name, attrstr) == 0 || strcasecmp (vend_tmp->value_name, attrstr) == 0)) { logit (LOG_DAEMON, LOG_ALERT, "%s: Duplicate Vendor Attribute Identifier on line %d of vendors", func, line_no); fclose (vendor_fd); return (-1); } if ((valstr != (char *) NULL) && (strcasecmp ("VALUE", valstr) != 0) && (strcasecmp (vend_tmp->value_name, valstr) == 0 || strcasecmp (vend_tmp->attr_name, valstr) == 0)) { logit (LOG_DAEMON, LOG_ALERT, "%s: Duplicate Vendor Value Identifier on line %d of vendors", func, line_no); fclose (vendor_fd); return (-1); } if (vendor_id == vend_tmp->id) { logit (LOG_DAEMON, LOG_ALERT, "%s: Duplicate Vendor ID on line %d of vendors", func, line_no); fclose (vendor_fd); return (-1); } if (vend_name != (char *) NULL && *vend_name) { if (strcasecmp (vend_name, vend_tmp->name) == 0) { logit (LOG_DAEMON, LOG_ALERT, "%s: Duplicate Vendor name on line %d of vendors", func, line_no); fclose (vendor_fd); return (-1); } } } if ((vend_tmp = (VENDOR *) calloc (1, sizeof (VENDOR))) == (VENDOR *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: FATAL out of memory", func); abort (); } vendor_mf.m++; vend_tmp->attr_name = add_string (attrstr, ASIS); vend_tmp->value_name = add_string (valstr, ASIS); vend_tmp->name = add_string (vend_name, ASIS); vend_tmp->id = vendor_id; vend_tmp->map = (VENDOR_MAP *) NULL; vend_tmp->attrs = (DICT_ATTR *) NULL; vend_tmp->values = (DICT_VALUE *) NULL; vend_tmp->next = (VENDOR *) NULL; vend_last->next = vend_tmp; vend_last = vend_tmp; } /* end of while loop */ fclose (vendor_fd); return 0;} /* end of vend_init () *//****************************************************************************** * * Function: vend_verify * * Purpose: Verify any attribute mapping tables that we read in. * *****************************************************************************/static intvend_verify (){ int i; int result = 0; VENDOR *vep; VENDOR_MAP *vmp; DICT_ATTR *attr; DICT_ATTR *da; DICT_ATTR **da_prev; DICT_VALUE *value; DICT_VALUE *dv; DICT_VALUE **dv_prev; static char *func = "vend_verify"; /* * Check all attribute and values read in for duplicates or * inconsistencies. Build up lists of attrs. and values rooted in * the appropriate vendor structures. This is to speed up access. * Note that there is a vendor structure for OID zero, the standard * RADIUS attributes and values. */ for (attr = dictionary_attributes; attr; attr = attr->next) { for (da_prev = &attr->vendor_ptr->attrs; (da = *da_prev) != (DICT_ATTR *) NULL; da_prev = &da->vnext) { if (strcasecmp (da->name, attr->name) == 0) { logit (LOG_DAEMON, LOG_ALERT, "%s: %s Attr. %s is multiply defined", func, attr->vendor_ptr->name, attr->name); result = -1; continue; } if (da->value == attr->value && da->type != attr->type) { logit (LOG_DAEMON, LOG_ALERT, "%s: %s Attrs. %s and %s have type confict", func, attr->vendor_ptr->name, attr->name, da->name); result = -1; continue; } } attr->vnext = (DICT_ATTR *) NULL; *da_prev = attr; } for (value = dictionary_values; value; value = value->next) { for (attr = value->vendor_ptr->attrs; attr; attr = attr->vnext) { if (strcasecmp (attr->name, value->attrname) == 0) { break; } } if (attr != (DICT_ATTR *) NULL) { value->attrnum = attr->value; } else if (strcasecmp (value->attrname, "Server-Config") == 0) { /* Special name for configuration attribute */ value->attrnum = -1; } else { logit (LOG_DAEMON, LOG_ALERT, "%s: %s Value %s refers to non-existent attr %s", func, value->vendor_ptr->name, value->name, value->attrname); result = -1; continue; } for (dv_prev = &value->vendor_ptr->values; (dv = *dv_prev) != (DICT_VALUE *) NULL; dv_prev = &dv->vnext) { if (strcasecmp (dv->name, value->name) == 0 && dv->attrnum == value->attrnum) { logit (LOG_DAEMON, LOG_ALERT, "%s: %s Value %s is multiply defined", func, value->vendor_ptr->name, value->name); result = -1; continue; } } value->vnext = (DICT_VALUE *) NULL; *dv_prev = value; } /* Now check any vendor attribute maps */ for (vep = vendors; vep; vep = vep->next) { if ((vmp = vep->map) == (VENDOR_MAP *) NULL) { continue; } for (i = 0; i < 256; i++) { if (vmp->s_attr[i] == 0) { continue; } if (dict_attrget (vmp->s_attr[i], vep->id) == (DICT_ATTR *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Vendor Attr. %d in %s map is undefined ", func, vmp->s_attr[i], vep->name);/* Just log for now result = -1; */ } } } return result;} /* end of vend_verify () *//************************************************************************* * * Function: vendor_list_toa * * Purpose: Produce an ASCII list of vendor names. * *************************************************************************/char *vendor_list_toa (veps)VENDOR_LIST *veps;{ static char buffers[20][40]; static int pos = 0; char *buff = buffers[pos]; static char *func = "vendor_list_toa"; if (veps == (VENDOR_LIST *) NULL) { return "none"; } else { if (veps->next == (VENDOR_LIST *) NULL) { return veps->vep->name; } } /* Print out concatenated list. */ *buff = '\0'; for ( ; veps != (VENDOR_LIST *) NULL ; veps = veps->next) { strcat (buff, veps->vep->name); if (veps->next) { strcat (buff, "+"); } } pos++; if (pos >= 20) { pos = 0; } return buff;} /* end of vendor_list_toa () */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -