📄 dict.c
字号:
(attr->type == PW_TYPE_IPADDR)) { if (good_ipaddr (ptr) == 0) /* IP address */ { value = ntohl(inet_addr (ptr)); } else /* was not dotted quad notation */ { value = strtol (ptr, &dummy, 0); } } else /* normal integer value */ { /* Value as integer */ value = strtol (ptr, &dummy, 0); } dprintf(4, (LOG_DAEMON, LOG_DEBUG, "%s: dict line %d, value %s = %lu [0x%08X], attr %s, type = %d", func, line_no, namestr, value, value, attrstr, attr ? attr->type : -1)); /* Create a new VALUE entry for the list */ if ((dval = (DICT_VALUE *) calloc (1, sizeof (DICT_VALUE))) == (DICT_VALUE *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: FATAL out of memory", func); abort (); } dval->attrname = add_string (attrstr, ASIS); dval->name = add_string (namestr, ASIS); dval->dv_value = value; dval->vendor_ptr = vep; dval->next = (DICT_VALUE *) NULL; dval->vnext = (DICT_VALUE *) NULL; /* Insert it into the list */ *dval_last = dval; dval_last = &dval->next; break; /* from case attorval */ default: logit (LOG_DAEMON, LOG_ALERT, "%s: Invalid line %d in dictionary", func, line_no); return (-1); } /* end of switch */ } /* end of while */ fclose (dictfd); return vend_verify (); /* Set up and verify vendor info */} /* end of dict_init () *//************************************************************************* * * Function: dict_attrget * * Purpose: Return the full attribute structure based on the * attribute id number. * *************************************************************************/DICT_ATTR *dict_attrget (attribute, vid)int attribute;UINT4 vid;{ VENDOR *vep; DICT_ATTR *attr; if ((vep = find_vendor_by_id (vid)) == (VENDOR *) NULL) { return (DICT_ATTR *) NULL; } for (attr = vep->attrs; attr; attr = attr->vnext) { if (attr->value == attribute) { break; } } return attr;} /* end of dict_attrget () *//************************************************************************* * * Function: dict_attrfind * * Purpose: Return the full attribute structure based on the * attribute name. * *************************************************************************/DICT_ATTR *dict_attrfind (attrname)char *attrname;{ char *ptr; DICT_ATTR *attr; VENDOR *vep; static char *func = "dict_attrfind"; if ((ptr = parse_for_vendor (attrname, &vep)) == (char *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: invalid vendor name in attribute name '%s'", func, attrname); return (DICT_ATTR *) NULL; } /* Look on global list if vendor not known */ if (ptr == attrname) { for (attr = dictionary_attributes; attr; attr = attr->next) { if (strcasecmp (attr->name, ptr) == 0) { break; } } return attr; } for (attr = vep->attrs; attr; attr = attr->vnext) { if (strcasecmp (attr->name, ptr) == 0) { break; } } return attr;} /* end of dict_attrfind () *//************************************************************************* * * Function: dict_find_value * * Purpose: Return the full value structure based on the * actual value and the associated attribute. * * Returns: Pointer to DICT_VALUE object found, * or, NULL, if failed. * *************************************************************************/DICT_VALUE *dict_find_value (value, attr)UINT4 value;DICT_ATTR *attr;{ DICT_VALUE *val; static char *func = "dict_find_value"; for (val = attr->vendor_ptr->values; val; val = val->vnext) { if (val->dv_value == value && val->attrnum == attr->value) { break; } } return val;} /* end of dict_find_value () *//************************************************************************* * * Function: dict_valfind * * Purpose: Return the full value structure based on the * value name. * *************************************************************************/DICT_VALUE *dict_valfind (value, attrname)char *value;char *attrname;{ DICT_VALUE *val; DICT_ATTR *attr; static char *func = "dict_valfind"; if (attrname == (char *) NULL) { /* No attrname given; Find first match on global list */ for (val = dictionary_values; val; val = val->next) { if (strcasecmp (val->name, value) == 0) { break; } } return val; } /* Search vendor list of values for match */ if ((attr = dict_attrfind (attrname)) == (DICT_ATTR *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: invalid attribute name '%s'", func, attrname); return (DICT_VALUE *) NULL; } for (val = attr->vendor_ptr->values; val; val = val->vnext) { if (strcasecmp (val->name, value) == 0 && val->attrnum == attr->value) { break; } } return val;} /* end of dict_valfind () *//************************************************************************* * * Function: dict_valget * * Purpose: Return the full value structure based on the * actual value and the associated attribute name. * *************************************************************************/DICT_VALUE *dict_valget (value, attrname)UINT4 value;char *attrname;{ DICT_ATTR *attr; static char *func = "dict_valget"; if ((attr = dict_attrfind (attrname)) == (DICT_ATTR *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: invalid attribute name '%s'", func, attrname); return (DICT_VALUE *) NULL; } return dict_find_value (value, attr);} /* end of dict_valget () *//***************************************************************************** * * Function: find_vendor_by_id * * Purpose: Returns VENDOR data structure for vendor with given id * *****************************************************************************/VENDOR *find_vendor_by_id (vendor_id)UINT4 vendor_id;{ VENDOR *vend_ptr; for (vend_ptr = vendors; vend_ptr; vend_ptr = vend_ptr->next) { if (vend_ptr->id == vendor_id) { break; } } return vend_ptr;} /* end of find_vendor_by_id () *//***************************************************************************** * * Function: find_vendor_by_name * * Purpose: Returns VENDOR data structure for vendor with given name * *****************************************************************************/VENDOR *find_vendor_by_name (vendor_name)char *vendor_name;{ VENDOR *vend_ptr; for (vend_ptr = vendors; vend_ptr; vend_ptr = vend_ptr->next) { if (strcasecmp (vend_ptr->name, vendor_name) == 0) { break; } } return vend_ptr;} /* end of find_vendor_by_name () *//************************************************************************* * * Function: free_vendor_list * * Purpose: Free all VENDOR_LIST entries and count results. * *************************************************************************/intfree_vendor_list (veps)VENDOR_LIST *veps;{ int count = 0; VENDOR_LIST *next; static char *func = "free_vendor_list"; while (veps != (VENDOR_LIST *) NULL) { next = veps->next; free (veps); veps = next; count++; vendor_list_mf.f++; } return count;} /* end free_vendor_list () *//************************************************************************* * * Function: parse_flags * * Purpose: Return the attribute flags value specified in dictionary. * * Remarks: parses the following syntax: * * "(" <tail> * <tail> ::= "config" * "1," <nak_tail> * "*," <nak_tail> * "0," <nak_tail> * "," <nak_tail> * * <nak_tail> ::= "1" [ "," <etc_tail> ] * "0" [ "," <etc_tail> ] * "*" [ "," <etc_tail> ] * [ "," <etc_tail> ] * * <etc_tail> ::= "must" | "may" | "nolog" | "encaps" | "noencaps" * *************************************************************************/static intparse_flags (flags)int *flags;{ enum { FIND_LP, /* Look for leading "(" */ FIND_AF, FIND_CO1, FIND_NF, FIND_CO2, FIND_ETC, FIND_END } mode; char *ptr; static char *func = "parse_flags"; /* Set up default values, in case nothing was specified. */ *flags = ATTR_ACK_NONE | ATTR_NAK_NONE | ATTR_ENCAPS; if ((ptr = strtok (NULL, ")")) == (char *) NULL) { return 0; } mode = FIND_LP; while (*ptr != '\0') { if (isspace(*ptr)) { ptr++; continue; } switch (mode) { case FIND_LP: if (*ptr++ != '(') { return (0); } mode = FIND_AF; break; case FIND_AF: if (strcasecmp (ptr, "config") == 0) { *flags = ATTR_CONFIG; mode = FIND_END; ptr += 6; return (0); } mode = FIND_CO1; switch (*ptr++) { case '1': *flags |= ATTR_ACK_ONE; /****FALLTHROUGH****/ case '*': *flags &= ~ATTR_ACK_NONE; break; case '0': break; case ',': /* Nothing - Assume default */ mode = FIND_NF; break; default: logit (LOG_DAEMON, LOG_ERR, "%s: Junk in col one, '%s'", func, ptr); return (-1); } break; case FIND_CO1: if (*ptr++ != ',') { return (-1); } mode = FIND_NF; break; case FIND_NF: mode = FIND_CO2; switch (*ptr++) { case '1': *flags |= ATTR_NAK_ONE; /****FALLTHROUGH****/ case '*': *flags &= ~ATTR_NAK_NONE; break; case '0': break; case ',': /* Nothing - use default */ mode = FIND_ETC; break; default: logit (LOG_DAEMON, LOG_ERR, "%s: Junk after column two, '%s'", func, ptr); return (-1); } break; case FIND_CO2: if (*ptr++ != ',') { return (-1); } mode = FIND_ETC; break; case FIND_ETC: /* Look for Version 2 MAY/MUST indicator */ if (strncasecmp (ptr, "MUST", 4) == 0) { *flags |= ATTR_MUST; ptr += 4; } else if (strncasecmp (ptr, "MAY", 3) == 0) { if (*flags & ATTR_MUST) { return (-1); } ptr += 3; } else if (strncasecmp (ptr, "NOLOG", 5) == 0) { *flags |= ATTR_NOLOG; ptr += 5; } else if (strncasecmp (ptr, "ENCAPSULATE", 11) == 0) { *flags |= ATTR_ENCAPS; ptr += 11; } else if (strncasecmp (ptr, "ENCAPS", 6) == 0) { *flags |= ATTR_ENCAPS; ptr += 6; } else if (strncasecmp (ptr, "NOENCAPS", 6) == 0) { *flags &= ~ATTR_ENCAPS; ptr += 8; } else { logit (LOG_DAEMON, LOG_ERR, "%s: Invalid flags text in dictionary, '%s'", func, ptr); return (-1); } while (isspace(*ptr)) { ptr++; } if (*ptr == '\0') { return 0; } if (*ptr != ',') { logit (LOG_DAEMON, LOG_ERR, "%s: Invalid trailing text '%s'", func, ptr); return (-1); } ptr++; break; case FIND_END: logit (LOG_DAEMON, LOG_ERR, "%s: Shouldn't reach here with '%s'", func, ptr); return (-1); /* What is this stuff at end? */ } /* end of switch */ } /* end of while */ return 0;} /* end of parse_flags *//***************************************************************************** * * Function: parse_for_vendor * * Purpose: Checks for <vendor>:<attrname> and returns vendor ID * *****************************************************************************/static char *parse_for_vendor (name, vendor)char *name;VENDOR **vendor;{ char *ptr; static char *func = "parse_for_vendor"; if ((ptr = strchr (name, ':')) == (char *) NULL) { if (DEFAULT_VENDOR_ID == 0) { *vendor = (VENDOR *) NULL; } else { *vendor = find_vendor_by_id (DEFAULT_VENDOR_ID); } return name; } *ptr = '\0'; /* Check to see if there is a "none" vendor. */ if (strcasecmp (name, "none") == 0) { *vendor = (VENDOR *) NULL; } else { if ((*vendor = find_vendor_by_name (name)) == (VENDOR *) NULL) { logit (LOG_DAEMON, LOG_ALERT, "%s: Cannot find vendor named '%s'", func, name); *ptr = ':'; return (char *) NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -