Now that we do VMPS, support ethernet types natively.
[freeradius.git] / src / lib / dict.c
1 /*
2  * dict.c       Routines to read the dictionary file.
3  *
4  * Version:     $Id$
5  *
6  *   This library is free software; you can redistribute it and/or
7  *   modify it under the terms of the GNU Lesser General Public
8  *   License as published by the Free Software Foundation; either
9  *   version 2.1 of the License, or (at your option) any later version.
10  *
11  *   This library is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  *   Lesser General Public License for more details.
15  *
16  *   You should have received a copy of the GNU Lesser General Public
17  *   License along with this library; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 2000,2006  The FreeRADIUS server project
21  */
22
23 #include        <freeradius-devel/ident.h>
24 RCSID("$Id$")
25
26 #include        <freeradius-devel/libradius.h>
27
28 #include        <ctype.h>
29
30 #ifdef HAVE_MALLOC_H
31 #include        <malloc.h>
32 #endif
33
34 #ifdef HAVE_SYS_STAT_H
35 #include        <sys/stat.h>
36 #endif
37
38 #define DICT_VALUE_MAX_NAME_LEN (128)
39 #define DICT_VENDOR_MAX_NAME_LEN (128)
40
41 static lrad_hash_table_t *vendors_byname = NULL;
42 static lrad_hash_table_t *vendors_byvalue = NULL;
43
44 static lrad_hash_table_t *attributes_byname = NULL;
45 static lrad_hash_table_t *attributes_byvalue = NULL;
46
47 static lrad_hash_table_t *values_byvalue = NULL;
48 static lrad_hash_table_t *values_byname = NULL;
49
50 static DICT_ATTR *dict_base_attrs[256];
51
52 /*
53  *      For faster HUP's, we cache the stat information for
54  *      files we've $INCLUDEd
55  */
56 typedef struct dict_stat_t {
57         struct dict_stat_t *next;
58         char               *name;
59         time_t             mtime;
60 } dict_stat_t;
61
62 static char *stat_root_dir = NULL;
63 static char *stat_root_file = NULL;
64
65 static dict_stat_t *stat_head = NULL;
66 static dict_stat_t *stat_tail = NULL;
67
68 typedef struct value_fixup_t {
69         char            attrstr[40];
70         DICT_VALUE      *dval;
71         struct value_fixup_t *next;
72 } value_fixup_t;
73
74
75 /*
76  *      So VALUEs in the dictionary can have forward references.
77  */
78 static value_fixup_t *value_fixup = NULL;
79
80 static const LRAD_NAME_NUMBER type_table[] = {
81         { "string",     PW_TYPE_STRING },
82         { "integer",    PW_TYPE_INTEGER },
83         { "ipaddr",     PW_TYPE_IPADDR },
84         { "date",       PW_TYPE_DATE },
85         { "abinary",    PW_TYPE_ABINARY },
86         { "octets",     PW_TYPE_OCTETS },
87         { "ifid",       PW_TYPE_IFID },
88         { "ipv6addr",   PW_TYPE_IPV6ADDR },
89         { "ipv6prefix", PW_TYPE_IPV6PREFIX },
90         { "byte",       PW_TYPE_BYTE },
91         { "short",      PW_TYPE_SHORT },
92         { "ether",      PW_TYPE_ETHERNET },
93         { NULL, 0 }
94 };
95
96
97 /*
98  *      Create the hash of the name.
99  *
100  *      We copy the hash function here because it's substantially faster.
101  */
102 #define FNV_MAGIC_INIT (0x811c9dc5)
103 #define FNV_MAGIC_PRIME (0x01000193)
104
105 static uint32_t dict_hashname(const char *name)
106 {
107         uint32_t hash = FNV_MAGIC_INIT;
108         const char *p;
109
110         for (p = name; *p != '\0'; p++) {
111                 int c = *(const unsigned char *) p;
112                 if (isalpha(c)) c = tolower(c);
113
114                 hash *= FNV_MAGIC_PRIME;
115                 hash ^= (uint32_t ) (c & 0xff);
116         }
117
118         return hash;
119 }
120
121
122 /*
123  *      Hash callback functions.
124  */
125 static uint32_t dict_attr_name_hash(const void *data)
126 {
127         return dict_hashname(((const DICT_ATTR *)data)->name);
128 }
129
130 static int dict_attr_name_cmp(const void *one, const void *two)
131 {
132         const DICT_ATTR *a = one;
133         const DICT_ATTR *b = two;
134
135         return strcasecmp(a->name, b->name);
136 }
137
138 static uint32_t dict_attr_value_hash(const void *data)
139 {
140         uint32_t hash;
141         const DICT_ATTR *attr = data;
142
143         hash = lrad_hash(&attr->vendor, sizeof(attr->vendor));
144         return lrad_hash_update(&attr->attr, sizeof(attr->attr), hash);
145 }
146
147 static int dict_attr_value_cmp(const void *one, const void *two)
148 {
149         const DICT_ATTR *a = one;
150         const DICT_ATTR *b = two;
151
152         if (a->vendor < b->vendor) return -1;
153         if (a->vendor > b->vendor) return +1;
154
155         return a->attr - b->attr;
156 }
157
158 static uint32_t dict_vendor_name_hash(const void *data)
159 {
160         return dict_hashname(((const DICT_VENDOR *)data)->name);
161 }
162
163 static int dict_vendor_name_cmp(const void *one, const void *two)
164 {
165         const DICT_VENDOR *a = one;
166         const DICT_VENDOR *b = two;
167
168         return strcasecmp(a->name, b->name);
169 }
170
171 static uint32_t dict_vendor_value_hash(const void *data)
172 {
173         return lrad_hash(&(((const DICT_VENDOR *)data)->vendorpec),
174                          sizeof(((const DICT_VENDOR *)data)->vendorpec));
175 }
176
177 static int dict_vendor_value_cmp(const void *one, const void *two)
178 {
179         const DICT_VENDOR *a = one;
180         const DICT_VENDOR *b = two;
181
182         return a->vendorpec - b->vendorpec;
183 }
184
185 static uint32_t dict_value_name_hash(const void *data)
186 {
187         uint32_t hash;
188         const DICT_VALUE *dval = data;
189
190         hash = dict_hashname(dval->name);
191         return lrad_hash_update(&dval->attr, sizeof(dval->attr), hash);
192 }
193
194 static int dict_value_name_cmp(const void *one, const void *two)
195 {
196         int rcode;
197         const DICT_VALUE *a = one;
198         const DICT_VALUE *b = two;
199
200         rcode = a->attr - b->attr;
201         if (rcode != 0) return rcode;
202
203         return strcasecmp(a->name, b->name);
204 }
205
206 static uint32_t dict_value_value_hash(const void *data)
207 {
208         uint32_t hash;
209         const DICT_VALUE *dval = data;
210
211         hash = lrad_hash(&dval->attr, sizeof(dval->attr));
212         return lrad_hash_update(&dval->value, sizeof(dval->value), hash);
213 }
214
215 static int dict_value_value_cmp(const void *one, const void *two)
216 {
217         int rcode;
218         const DICT_VALUE *a = one;
219         const DICT_VALUE *b = two;
220
221         rcode = a->attr - b->attr;
222         if (rcode != 0) return rcode;
223
224         return a->value - b->value;
225 }
226
227
228 /*
229  *      Free the list of stat buffers
230  */
231 static void dict_stat_free(void)
232 {
233         dict_stat_t *this, *next;
234
235         free(stat_root_dir);
236         stat_root_dir = NULL;
237         free(stat_root_file);
238         stat_root_file = NULL;
239
240         if (!stat_head) {
241                 stat_tail = NULL;
242                 return;
243         }
244
245         for (this = stat_head; this != NULL; this = next) {
246                 next = this->next;
247                 free(this->name);
248                 free(this);
249         }
250
251         stat_head = stat_tail = NULL;
252 }
253
254
255 /*
256  *      Add an entry to the list of stat buffers.
257  */
258 static void dict_stat_add(const char *name, const struct stat *stat_buf)
259 {
260         dict_stat_t *this;
261
262         this = malloc(sizeof(*this));
263         if (!this) return;
264         memset(this, 0, sizeof(*this));
265
266         this->name = strdup(name);
267         this->mtime = stat_buf->st_mtime;
268
269         if (!stat_head) {
270                 stat_head = stat_tail = this;
271         } else {
272                 stat_tail->next = this;
273                 stat_tail = this;
274         }
275 }
276
277
278 /*
279  *      See if any dictionaries have changed.  If not, don't
280  *      do anything.
281  */
282 static int dict_stat_check(const char *root_dir, const char *root_file)
283 {
284         struct stat buf;
285         dict_stat_t *this;
286
287         if (!stat_root_dir) return 0;
288         if (!stat_root_file) return 0;
289
290         if (strcmp(root_dir, stat_root_dir) != 0) return 0;
291         if (strcmp(root_file, stat_root_file) != 0) return 0;
292
293         if (!stat_head) return 0; /* changed, reload */
294
295         for (this = stat_head; this != NULL; this = this->next) {
296                 if (stat(this->name, &buf) < 0) return 0;
297
298                 if (buf.st_mtime != this->mtime) return 0;
299         }
300
301         return 1;
302 }
303
304
305 /*
306  *      Free the dictionary_attributes and dictionary_values lists.
307  */
308 void dict_free(void)
309 {
310         /*
311          *      Free the tables
312          */
313         lrad_hash_table_free(vendors_byname);
314         lrad_hash_table_free(vendors_byvalue);
315         vendors_byname = NULL;
316         vendors_byvalue = NULL;
317
318         lrad_hash_table_free(attributes_byname);
319         lrad_hash_table_free(attributes_byvalue);
320         attributes_byname = NULL;
321         attributes_byvalue = NULL;
322
323         lrad_hash_table_free(values_byname);
324         lrad_hash_table_free(values_byvalue);
325         values_byname = NULL;
326         values_byvalue = NULL;
327
328         memset(dict_base_attrs, 0, sizeof(dict_base_attrs));
329
330         dict_stat_free();
331 }
332
333
334 /*
335  *      Add vendor to the list.
336  */
337 int dict_addvendor(const char *name, int value)
338 {
339         size_t length;
340         DICT_VENDOR *dv;
341
342         if (value >= 32767) {
343                 librad_log("dict_addvendor: Cannot handle vendor ID larger than 65535");
344                 return -1;
345         }
346
347         if ((length = strlen(name)) >= DICT_VENDOR_MAX_NAME_LEN) {
348                 librad_log("dict_addvendor: vendor name too long");
349                 return -1;
350         }
351
352         if ((dv = malloc(sizeof(*dv) + length)) == NULL) {
353                 librad_log("dict_addvendor: out of memory");
354                 return -1;
355         }
356
357         strcpy(dv->name, name);
358         dv->vendorpec  = value;
359         dv->type = dv->length = 1; /* defaults */
360
361         if (!lrad_hash_table_insert(vendors_byname, dv)) {
362                 DICT_VENDOR *old_dv;
363
364                 old_dv = lrad_hash_table_finddata(vendors_byname, dv);
365                 if (!old_dv) {
366                         librad_log("dict_addvendor: Failed inserting vendor name %s", name);
367                         return -1;
368                 }
369                 if (old_dv->vendorpec != dv->vendorpec) {
370                         librad_log("dict_addvendor: Duplicate vendor name %s", name);
371                         return -1;
372                 }
373
374                 /*
375                  *      Already inserted.  Discard the duplicate entry.
376                  */
377                 free(dv);
378                 return 0;
379         }
380
381         /*
382          *      Insert the SAME pointer (not free'd when this table is
383          *      deleted), into another table.
384          *
385          *      We want this behaviour because we want OLD names for
386          *      the attributes to be read from the configuration
387          *      files, but when we're printing them, (and looking up
388          *      by value) we want to use the NEW name.
389          */
390         if (!lrad_hash_table_replace(vendors_byvalue, dv)) {
391                 librad_log("dict_addvendor: Failed inserting vendor %s",
392                            name);
393                 return -1;
394         }
395
396         return 0;
397 }
398
399 /*
400  *      Add an attribute to the dictionary.
401  */
402 int dict_addattr(const char *name, int vendor, int type, int value,
403                  ATTR_FLAGS flags)
404 {
405         static int      max_attr = 0;
406         DICT_ATTR       *attr;
407
408         if (strlen(name) > (sizeof(attr->name) -1)) {
409                 librad_log("dict_addattr: attribute name too long");
410                 return -1;
411         }
412
413         /*
414          *      If the value is '-1', that means use a pre-existing
415          *      one (if it already exists).  If one does NOT already exist,
416          *      then create a new attribute, with a non-conflicting value,
417          *      and use that.
418          */
419         if (value == -1) {
420                 if (dict_attrbyname(name)) {
421                         return 0; /* exists, don't add it again */
422                 }
423
424                 value = ++max_attr;
425
426         } else if (vendor == 0) {
427                 /*
428                  *  Update 'max_attr'
429                  */
430                 if (value > max_attr) {
431                         max_attr = value;
432                 }
433         }
434
435         if (value < 0) {
436                 librad_log("dict_addattr: ATTRIBUTE has invalid number (less than zero)");
437                 return -1;
438         }
439
440         if (value >= 65536) {
441                 librad_log("dict_addattr: ATTRIBUTE has invalid number (larger than 65535).");
442                 return -1;
443         }
444
445         if (vendor) {
446                 DICT_VENDOR *dv = dict_vendorbyvalue(vendor);
447
448                 /*
449                  *      If the vendor isn't defined, die/
450                  */
451                 if (!dv) {
452                         librad_log("dict_addattr: Unknown vendor");
453                         return -1;
454                 }
455
456                 /*
457                  *      FIXME: Switch over dv->type, and limit things
458                  *      properly.
459                  */
460                 if ((dv->type == 1) && (value >= 256)) {
461                         librad_log("dict_addattr: ATTRIBUTE has invalid number (larger than 255).");
462                         return -1;
463                 } /* else 256..65535 are allowed */
464         }
465
466         /*
467          *      Create a new attribute for the list
468          */
469         if ((attr = malloc(sizeof(*attr))) == NULL) {
470                 librad_log("dict_addattr: out of memory");
471                 return -1;
472         }
473
474         strcpy(attr->name, name);
475         attr->attr = value;
476         attr->attr |= (vendor << 16); /* FIXME: hack */
477         attr->vendor = vendor;
478         attr->type = type;
479         attr->flags = flags;
480         attr->vendor = vendor;
481
482         /*
483          *      Insert the attribute, only if it's not a duplicate.
484          */
485         if (!lrad_hash_table_insert(attributes_byname, attr)) {
486                 DICT_ATTR       *a;
487
488                 /*
489                  *      If the attribute has identical number, then
490                  *      ignore the duplicate.
491                  */
492                 a = lrad_hash_table_finddata(attributes_byname, attr);
493                 if (a && (strcasecmp(a->name, attr->name) == 0)) {
494                         if (a->attr != attr->attr) {
495                                 librad_log("dict_addattr: Duplicate attribute name %s", name);
496                                 free(attr);
497                                 return -1;
498                         }
499
500                         /*
501                          *      Same name, same vendor, same attr,
502                          *      maybe the flags and/or type is
503                          *      different.  Let the new value
504                          *      over-ride the old one.
505                          */
506                 }
507
508
509                 lrad_hash_table_delete(attributes_byvalue, a);
510
511                 if (!lrad_hash_table_replace(attributes_byname, attr)) {
512                         librad_log("dict_addattr: Internal error storing attribute %s", name);
513                         free(attr);
514                         return -1;
515                 }
516         }
517
518         /*
519          *      Insert the SAME pointer (not free'd when this entry is
520          *      deleted), into another table.
521          *
522          *      We want this behaviour because we want OLD names for
523          *      the attributes to be read from the configuration
524          *      files, but when we're printing them, (and looking up
525          *      by value) we want to use the NEW name.
526          */
527         if (!lrad_hash_table_replace(attributes_byvalue, attr)) {
528                 librad_log("dict_addattr: Failed inserting attribute name %s", name);
529                 return -1;
530         }
531
532         if (!vendor && (value > 0) && (value < 256)) {
533                  dict_base_attrs[value] = attr;
534         }
535
536         return 0;
537 }
538
539
540 /*
541  *      Add a value for an attribute to the dictionary.
542  */
543 int dict_addvalue(const char *namestr, const char *attrstr, int value)
544 {
545         size_t          length;
546         DICT_ATTR       *dattr;
547         DICT_VALUE      *dval;
548
549         if (!*namestr) {
550                 librad_log("dict_addvalue: empty names are not permitted");
551                 return -1;
552         }
553
554         if ((length = strlen(namestr)) >= DICT_VALUE_MAX_NAME_LEN) {
555                 librad_log("dict_addvalue: value name too long");
556                 return -1;
557         }
558
559         if ((dval = malloc(sizeof(*dval) + length)) == NULL) {
560                 librad_log("dict_addvalue: out of memory");
561                 return -1;
562         }
563         memset(dval, 0, sizeof(*dval));
564
565         strcpy(dval->name, namestr);
566         dval->value = value;
567
568         /*
569          *      Remember which attribute is associated with this
570          *      value, if possible.
571          */
572         dattr = dict_attrbyname(attrstr);
573         if (dattr) {
574                 if (dattr->flags.has_value_alias) {
575                         librad_log("dict_addvalue: Cannot add VALUE for ATTRIBUTE \"%s\": It already has a VALUE-ALIAS", attrstr);
576                         return -1;
577                 }
578
579                 dval->attr = dattr->attr;
580
581                 /*
582                  *      Enforce valid values
583                  *
584                  *      Don't worry about fixups...
585                  */
586                 switch (dattr->type) {
587                         case PW_TYPE_BYTE:
588                                 if (value > 255) {
589                                         free(dval);
590                                         librad_log("dict_addvalue: ATTRIBUTEs of type 'byte' cannot have VALUEs larger than 255");
591                                         return -1;
592                                 }
593                                 break;
594                         case PW_TYPE_SHORT:
595                                 if (value > 65535) {
596                                         free(dval);
597                                         librad_log("dict_addvalue: ATTRIBUTEs of type 'short' cannot have VALUEs larger than 65535");
598                                         return -1;
599                                 }
600                                 break;
601
602                                 /*
603                                  *      Allow octets for now, because
604                                  *      of dictionary.cablelabs
605                                  */
606                         case PW_TYPE_OCTETS:
607
608                         case PW_TYPE_INTEGER:
609                                 break;
610
611                         default:
612                                 free(dval);
613                                 librad_log("dict_addvalue: VALUEs cannot be defined for attributes of type '%s'",
614                                            lrad_int2str(type_table, dattr->type, "?Unknown?"));
615                                 return -1;
616                 }
617
618                 dattr->flags.has_value = 1;
619         } else {
620                 value_fixup_t *fixup;
621
622                 fixup = (value_fixup_t *) malloc(sizeof(*fixup));
623                 if (!fixup) {
624                         free(dval);
625                         librad_log("dict_addvalue: out of memory");
626                         return -1;
627                 }
628                 memset(fixup, 0, sizeof(*fixup));
629
630                 strlcpy(fixup->attrstr, attrstr, sizeof(fixup->attrstr));
631                 fixup->dval = dval;
632
633                 /*
634                  *      Insert to the head of the list.
635                  */
636                 fixup->next = value_fixup;
637                 value_fixup = fixup;
638
639                 return 0;
640         }
641
642         /*
643          *      Add the value into the dictionary.
644          */
645         if (!lrad_hash_table_insert(values_byname, dval)) {
646                 if (dattr) {
647                         DICT_VALUE *old;
648
649                         /*
650                          *      Suppress duplicates with the same
651                          *      name and value.  There are lots in
652                          *      dictionary.ascend.
653                          */
654                         old = dict_valbyname(dattr->attr, namestr);
655                         if (old && (old->value == dval->value)) {
656                                 free(dval);
657                                 return 0;
658                         }
659                 }
660
661                 free(dval);
662                 librad_log("dict_addvalue: Duplicate value name %s for attribute %s", namestr, attrstr);
663                 return -1;
664         }
665
666         /*
667          *      There are multiple VALUE's, keyed by attribute, so we
668          *      take care of that here.
669          */
670         if (!lrad_hash_table_replace(values_byvalue, dval)) {
671                 librad_log("dict_addvalue: Failed inserting value %s",
672                            namestr);
673                 return -1;
674         }
675
676         return 0;
677 }
678
679 /*
680  *      Process the ATTRIBUTE command
681  */
682 static int process_attribute(const char* fn, const int line,
683                              const int block_vendor, char **argv,
684                              int argc)
685 {
686         int             vendor = 0;
687         int             value;
688         int             type;
689         char            *s, *c;
690         ATTR_FLAGS      flags;
691
692         if ((argc < 3) || (argc > 4)) {
693                 librad_log("dict_init: %s[%d]: invalid ATTRIBUTE line",
694                         fn, line);
695                 return -1;
696         }
697
698         /*
699          *      Validate all entries
700          */
701         if (!isdigit((int) argv[1][0])) {
702                 librad_log("dict_init: %s[%d]: invalid value", fn, line);
703                 return -1;
704         }
705         sscanf(argv[1], "%i", &value);
706
707         /*
708          *      find the type of the attribute.
709          */
710         type = lrad_str2int(type_table, argv[2], -1);
711         if (type < 0) {
712                 librad_log("dict_init: %s[%d]: invalid type \"%s\"",
713                         fn, line, argv[2]);
714                 return -1;
715         }
716
717         /*
718          *      Only look up the vendor if the string
719          *      is non-empty.
720          */
721         memset(&flags, 0, sizeof(flags));
722         if (argc == 4) {
723                 /*
724                  *      FIXME: replace strtok with str2argv
725                  */
726                 s = strtok(argv[3], ",");
727                 while (s) {
728                         if (strcmp(s, "has_tag") == 0 ||
729                             strcmp(s, "has_tag=1") == 0) {
730                                 /* Boolean flag, means this is a
731                                    tagged attribute */
732                                 flags.has_tag = 1;
733
734                         } else if (strncmp(s, "encrypt=", 8) == 0) {
735                                 /* Encryption method, defaults to 0 (none).
736                                    Currently valid is just type 2,
737                                    Tunnel-Password style, which can only
738                                    be applied to strings. */
739                                 flags.encrypt = strtol(s + 8, &c, 0);
740                                 if (*c) {
741                                         librad_log( "dict_init: %s[%d] invalid option %s",
742                                                     fn, line, s);
743                                         return -1;
744                                 }
745
746                         } else if (strncmp(s, "array", 8) == 0) {
747                                 flags.array = 1;
748
749                                 switch (type) {
750                                         case PW_TYPE_IPADDR:
751                                         case PW_TYPE_BYTE:
752                                         case PW_TYPE_SHORT:
753                                         case PW_TYPE_INTEGER:
754                                         case PW_TYPE_DATE:
755                                                 break;
756
757                                         default:
758                                                 librad_log( "dict_init: %s[%d] Only IP addresses can have the \"array\" flag set.",
759                                                             fn, line);
760                                                 return -1;
761                                 }
762
763                         } else if (block_vendor) {
764                                 librad_log( "dict_init: %s[%d]: unknown option \"%s\"",
765                                             fn, line, s);
766                                 return -1;
767
768                         } else {
769                                 /* Must be a vendor 'flag'... */
770                                 if (strncmp(s, "vendor=", 7) == 0) {
771                                         /* New format */
772                                         s += 7;
773                                 }
774
775                                 vendor = dict_vendorbyname(s);
776                                 if (!vendor) {
777                                         librad_log( "dict_init: %s[%d]: unknown vendor \"%s\"",
778                                                     fn, line, s);
779                                         return -1;
780                                 }
781                                 if (block_vendor && argv[3][0] &&
782                                     (block_vendor != vendor)) {
783                                         librad_log("dict_init: %s[%d]: mismatched vendor %s within BEGIN-VENDOR/END-VENDOR block",
784                                                    fn, line, argv[3]);
785                                         return -1;
786                                 }
787                         }
788                         s = strtok(NULL, ",");
789                 }
790         }
791
792         if (block_vendor) vendor = block_vendor;
793
794         /*
795          *      Special checks for tags, they make our life much more
796          *      difficult.
797          */
798         if (flags.has_tag) {
799                 /*
800                  *      Only string, octets, and integer can be tagged.
801                  */
802                 switch (type) {
803                 case PW_TYPE_STRING:
804                 case PW_TYPE_INTEGER:
805                         break;
806
807                 default:
808                         librad_log("dict_init: %s[%d]: Attributes of type %s cannot be tagged.",
809                                    fn, line,
810                                    lrad_int2str(type_table, type, "?Unknown?"));
811                         return -1;
812
813                 }
814         }
815
816         /*
817          *      Add it in.
818          */
819         if (dict_addattr(argv[0], vendor, type, value, flags) < 0) {
820                 librad_log("dict_init: %s[%d]: %s",
821                            fn, line, librad_errstr);
822                 return -1;
823         }
824
825         return 0;
826 }
827
828
829 /*
830  *      Process the VALUE command
831  */
832 static int process_value(const char* fn, const int line, char **argv,
833                          int argc)
834 {
835         int     value;
836
837         if (argc != 3) {
838                 librad_log("dict_init: %s[%d]: invalid VALUE line",
839                         fn, line);
840                 return -1;
841         }
842         /*
843          *      For Compatibility, skip "Server-Config"
844          */
845         if (strcasecmp(argv[0], "Server-Config") == 0)
846                 return 0;
847
848         /*
849          *      Validate all entries
850          */
851         if (!isdigit((int) argv[2][0])) {
852                 librad_log("dict_init: %s[%d]: invalid value",
853                         fn, line);
854                 return -1;
855         }
856         sscanf(argv[2], "%i", &value);
857
858         if (dict_addvalue(argv[1], argv[0], value) < 0) {
859                 librad_log("dict_init: %s[%d]: %s",
860                            fn, line, librad_errstr);
861                 return -1;
862         }
863
864         return 0;
865 }
866
867
868 /*
869  *      Process the VALUE-ALIAS command
870  *
871  *      This allows VALUE mappings to be shared among multiple
872  *      attributes.
873  */
874 static int process_value_alias(const char* fn, const int line, char **argv,
875                                int argc)
876 {
877         DICT_ATTR *my_da, *da;
878         DICT_VALUE *dval;
879
880         if (argc != 2) {
881                 librad_log("dict_init: %s[%d]: invalid VALUE-ALIAS line",
882                         fn, line);
883                 return -1;
884         }
885
886         my_da = dict_attrbyname(argv[0]);
887         if (!my_da) {
888                 librad_log("dict_init: %s[%d]: ATTRIBUTE \"%s\" does not exist",
889                            fn, line, argv[1]);
890                 return -1;
891         }
892
893         if (my_da->flags.has_value) {
894                 librad_log("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" with pre-existing VALUE",
895                            fn, line, argv[0]);
896                 return -1;
897         }
898
899         if (my_da->flags.has_value_alias) {
900                 librad_log("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" with pre-existing VALUE-ALIAS",
901                            fn, line, argv[0]);
902                 return -1;
903         }
904
905         da = dict_attrbyname(argv[1]);
906         if (!da) {
907                 librad_log("dict_init: %s[%d]: Cannot find ATTRIBUTE \"%s\" for alias",
908                            fn, line, argv[1]);
909                 return -1;
910         }
911
912         if (!da->flags.has_value) {
913                 librad_log("dict_init: %s[%d]: VALUE-ALIAS cannot refer to ATTRIBUTE %s: It has no values",
914                            fn, line, argv[1]);
915                 return -1;
916         }
917
918         if (da->flags.has_value_alias) {
919                 librad_log("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" which itself has a VALUE-ALIAS",
920                            fn, line, argv[1]);
921                 return -1;
922         }
923
924         if (my_da->type != da->type) {
925                 librad_log("dict_init: %s[%d]: Cannot add VALUE-ALIAS between attributes of differing type",
926                            fn, line);
927                 return -1;
928         }
929
930         if ((dval = malloc(sizeof(*dval))) == NULL) {
931                 librad_log("dict_addvalue: out of memory");
932                 return -1;
933         }
934         memset(dval, 0, sizeof(*dval));
935
936         dval->name[0] = '\0';   /* empty name */
937         dval->attr = my_da->attr;
938         dval->value = da->attr;
939
940         if (!lrad_hash_table_insert(values_byname, dval)) {
941                 librad_log("dict_init: %s[%d]: Error create alias",
942                            fn, line);
943                 free(dval);
944                 return -1;
945         }
946
947         return 0;
948 }
949
950
951 /*
952  *      Process the VENDOR command
953  */
954 static int process_vendor(const char* fn, const int line, char **argv,
955                           int argc)
956 {
957         int     value;
958         const   char *format = NULL;
959
960         if ((argc < 2) || (argc > 3)) {
961                 librad_log( "dict_init: %s[%d] invalid VENDOR entry",
962                             fn, line);
963                 return -1;
964         }
965
966         /*
967          *       Validate all entries
968          */
969         if (!isdigit((int) argv[1][0])) {
970                 librad_log("dict_init: %s[%d]: invalid value",
971                         fn, line);
972                 return -1;
973         }
974         value = atoi(argv[1]);
975
976         /* Create a new VENDOR entry for the list */
977         if (dict_addvendor(argv[0], value) < 0) {
978                 librad_log("dict_init: %s[%d]: %s",
979                            fn, line, librad_errstr);
980                 return -1;
981         }
982
983         /*
984          *      Look for a format statement
985          */
986         if (argc == 3) {
987                 format = argv[2];
988
989         } else if (value == VENDORPEC_USR) { /* catch dictionary screw-ups */
990                 format = "format=4,0";
991
992         } else if (value == VENDORPEC_LUCENT) {
993                 format = "format=2,1";
994
995         } else if (value == VENDORPEC_STARENT) {
996                 format = "format=2,2";
997
998         } /* else no fixups to do */
999
1000         if (format) {
1001                 int type, length;
1002                 const char *p;
1003                 DICT_VENDOR *dv;
1004
1005                 if (strncasecmp(format, "format=", 7) != 0) {
1006                         librad_log("dict_init: %s[%d]: Invalid format for VENDOR.  Expected \"format=\", got \"%s\"",
1007                                    fn, line, format);
1008                         return -1;
1009                 }
1010
1011                 p = format + 7;
1012                 if ((strlen(p) != 3) ||
1013                     !isdigit((int) p[0]) ||
1014                     (p[1] != ',') ||
1015                     !isdigit((int) p[2])) {
1016                         librad_log("dict_init: %s[%d]: Invalid format for VENDOR.  Expected text like \"1,1\", got \"%s\"",
1017                                    fn, line, p);
1018                         return -1;
1019                 }
1020
1021                 type = (int) (p[0] - '0');
1022                 length = (int) (p[2] - '0');
1023
1024                 dv = dict_vendorbyvalue(value);
1025                 if (!dv) {
1026                         librad_log("dict_init: %s[%d]: Failed adding format for VENDOR",
1027                                    fn, line);
1028                         return -1;
1029                 }
1030
1031                 if ((type != 1) && (type != 2) && (type != 4)) {
1032                         librad_log("dict_init: %s[%d]: invalid type value %d for VENDOR",
1033                                    fn, line, type);
1034                         return -1;
1035                 }
1036
1037                 if ((length != 0) && (length != 1) && (length != 2)) {
1038                         librad_log("dict_init: %s[%d]: invalid length value %d for VENDOR",
1039                                    fn, line, length);
1040                         return -1;
1041                 }
1042
1043                 dv->type = type;
1044                 dv->length = length;
1045         }
1046
1047         return 0;
1048 }
1049
1050 /*
1051  *      String split routine.  Splits an input string IN PLACE
1052  *      into pieces, based on spaces.
1053  */
1054 static int str2argv(char *str, char **argv, int max_argc)
1055 {
1056         int argc = 0;
1057
1058         while (*str) {
1059                 if (argc >= max_argc) return argc;
1060
1061                 /*
1062                  *      Chop out comments early.
1063                  */
1064                 if (*str == '#') {
1065                         *str = '\0';
1066                         break;
1067                 }
1068
1069                 while ((*str == ' ') ||
1070                        (*str == '\t') ||
1071                        (*str == '\r') ||
1072                        (*str == '\n')) *(str++) = '\0';
1073
1074                 if (!*str) return argc;
1075
1076                 argv[argc] = str;
1077                 argc++;
1078
1079                 while (*str &&
1080                        (*str != ' ') &&
1081                        (*str != '\t') &&
1082                        (*str != '\r') &&
1083                        (*str != '\n')) str++;
1084         }
1085
1086         return argc;
1087 }
1088
1089 #define MAX_ARGV (16)
1090
1091 /*
1092  *      Initialize the dictionary.
1093  */
1094 static int my_dict_init(const char *dir, const char *fn,
1095                         const char *src_file, int src_line)
1096 {
1097         FILE    *fp;
1098         char    dirtmp[256];
1099         char    buf[256];
1100         char    *p;
1101         int     line = 0;
1102         int     vendor;
1103         int     block_vendor;
1104         struct stat statbuf;
1105         char    *argv[MAX_ARGV];
1106         int     argc;
1107
1108         if (strlen(fn) >= sizeof(dirtmp) / 2 ||
1109             strlen(dir) >= sizeof(dirtmp) / 2) {
1110                 librad_log("dict_init: filename name too long");
1111                 return -1;
1112         }
1113
1114         /*
1115          *      First see if fn is relative to dir. If so, create
1116          *      new filename. If not, remember the absolute dir.
1117          */
1118         if ((p = strrchr(fn, '/')) != NULL) {
1119                 strcpy(dirtmp, fn);
1120                 dirtmp[p - fn] = 0;
1121                 dir = dirtmp;
1122         } else if (dir && dir[0] && strcmp(dir, ".") != 0) {
1123                 snprintf(dirtmp, sizeof(dirtmp), "%s/%s", dir, fn);
1124                 fn = dirtmp;
1125         }
1126
1127         if ((fp = fopen(fn, "r")) == NULL) {
1128                 if (!src_file) {
1129                         librad_log("dict_init: Couldn't open dictionary \"%s\": %s",
1130                                    fn, strerror(errno));
1131                 } else {
1132                         librad_log("dict_init: %s[%d]: Couldn't open dictionary \"%s\": %s",
1133                                    src_file, src_line, fn, strerror(errno));
1134                 }
1135                 return -1;
1136         }
1137
1138         stat(fn, &statbuf); /* fopen() guarantees this will succeed */
1139         if (!S_ISREG(statbuf.st_mode)) {
1140                 fclose(fp);
1141                 librad_log("dict_init: Dictionary \"%s\" is not a regular file",
1142                            fn);
1143                 return -1;
1144         }
1145
1146         /*
1147          *      Globally writable dictionaries means that users can control
1148          *      the server configuration with little difficulty.
1149          */
1150 #ifdef S_IWOTH
1151         if ((statbuf.st_mode & S_IWOTH) != 0) {
1152                 fclose(fp);
1153                 librad_log("dict_init: Dictionary \"%s\" is globally writable.  Refusing to start due to insecure configuration.",
1154                            fn);
1155                 return -1;
1156         }
1157 #endif
1158
1159         dict_stat_add(fn, &statbuf);
1160
1161         /*
1162          *      Seed the random pool with data.
1163          */
1164         lrad_rand_seed(&statbuf, sizeof(statbuf));
1165
1166         block_vendor = 0;
1167
1168         while (fgets(buf, sizeof(buf), fp) != NULL) {
1169                 line++;
1170                 if (buf[0] == '#' || buf[0] == 0 ||
1171                     buf[0] == '\n' || buf[0] == '\r')
1172                         continue;
1173
1174                 /*
1175                  *  Comment characters should NOT be appearing anywhere but
1176                  *  as start of a comment;
1177                  */
1178                 p = strchr(buf, '#');
1179                 if (p) *p = '\0';
1180
1181                 argc = str2argv(buf, argv, MAX_ARGV);
1182                 if (argc == 0) continue;
1183
1184                 if (argc == 1) {
1185                         librad_log( "dict_init: %s[%d] invalid entry",
1186                                     fn, line);
1187                         fclose(fp);
1188                         return -1;
1189                 }
1190
1191                 if (0) {
1192                         int i;
1193
1194                         fprintf(stderr, "ARGC = %d\n",argc);
1195                         for (i = 0; i < argc; i++) {
1196                                 fprintf(stderr, "\t%s\n", argv[i]);
1197                         }
1198                 }
1199
1200                 /*
1201                  *      See if we need to import another dictionary.
1202                  */
1203                 if (strcasecmp(argv[0], "$INCLUDE") == 0) {
1204                         if (my_dict_init(dir, argv[1], fn, line) < 0) {
1205                                 fclose(fp);
1206                                 return -1;
1207                         }
1208                         continue;
1209                 } /* $INCLUDE */
1210
1211                 /*
1212                  *      Perhaps this is an attribute.
1213                  */
1214                 if (strcasecmp(argv[0], "ATTRIBUTE") == 0) {
1215                         if (process_attribute(fn, line, block_vendor,
1216                                               argv + 1, argc - 1) == -1) {
1217                                 fclose(fp);
1218                                 return -1;
1219                         }
1220                         continue;
1221                 }
1222
1223                 /*
1224                  *      Process VALUE lines.
1225                  */
1226                 if (strcasecmp(argv[0], "VALUE") == 0) {
1227                         if (process_value(fn, line,
1228                                           argv + 1, argc - 1) == -1) {
1229                                 fclose(fp);
1230                                 return -1;
1231                         }
1232                         continue;
1233                 }
1234
1235                 if (strcasecmp(argv[0], "VALUE-ALIAS") == 0) {
1236                         if (process_value_alias(fn, line,
1237                                                 argv + 1, argc - 1) == -1) {
1238                                 fclose(fp);
1239                                 return -1;
1240                         }
1241                         continue;
1242                 }
1243
1244                 /*
1245                  *      Process VENDOR lines.
1246                  */
1247                 if (strcasecmp(argv[0], "VENDOR") == 0) {
1248                         if (process_vendor(fn, line,
1249                                            argv + 1, argc - 1) == -1) {
1250                                 fclose(fp);
1251                                 return -1;
1252                         }
1253                         continue;
1254                 }
1255
1256                 if (strcasecmp(argv[0], "BEGIN-VENDOR") == 0) {
1257                         if (argc != 2) {
1258                                 librad_log(
1259                                 "dict_init: %s[%d] invalid BEGIN-VENDOR entry",
1260                                         fn, line);
1261                                 fclose(fp);
1262                                 return -1;
1263                         }
1264
1265                         vendor = dict_vendorbyname(argv[1]);
1266                         if (!vendor) {
1267                                 librad_log(
1268                                         "dict_init: %s[%d]: unknown vendor %s",
1269                                         fn, line, argv[1]);
1270                                 fclose(fp);
1271                                 return -1;
1272                         }
1273                         block_vendor = vendor;
1274                         continue;
1275                 } /* BEGIN-VENDOR */
1276
1277                 if (strcasecmp(argv[0], "END-VENDOR") == 0) {
1278                         if (argc != 2) {
1279                                 librad_log(
1280                                 "dict_init: %s[%d] invalid END-VENDOR entry",
1281                                         fn, line);
1282                                 fclose(fp);
1283                                 return -1;
1284                         }
1285
1286                         vendor = dict_vendorbyname(argv[1]);
1287                         if (!vendor) {
1288                                 librad_log(
1289                                         "dict_init: %s[%d]: unknown vendor %s",
1290                                         fn, line, argv[1]);
1291                                 fclose(fp);
1292                                 return -1;
1293                         }
1294
1295                         if (vendor != block_vendor) {
1296                                 librad_log(
1297                                         "dict_init: %s[%d]: END-VENDOR %s does not match any previous BEGIN-VENDOR",
1298                                         fn, line, argv[1]);
1299                                 fclose(fp);
1300                                 return -1;
1301                         }
1302                         block_vendor = 0;
1303                         continue;
1304                 } /* END-VENDOR */
1305
1306                 /*
1307                  *      Any other string: We don't recognize it.
1308                  */
1309                 librad_log(
1310                         "dict_init: %s[%d] invalid keyword \"%s\"",
1311                         fn, line, argv[0]);
1312                 fclose(fp);
1313                 return -1;
1314         }
1315         fclose(fp);
1316         return 0;
1317 }
1318
1319
1320 /*
1321  *      Empty callback for hash table initialization.
1322  */
1323 static int null_callback(void *ctx, void *data)
1324 {
1325         ctx = ctx;              /* -Wunused */
1326         data = data;            /* -Wunused */
1327
1328         return 0;
1329 }
1330
1331
1332 /*
1333  *      Initialize the directory, then fix the attr member of
1334  *      all attributes.
1335  */
1336 int dict_init(const char *dir, const char *fn)
1337 {
1338         /*
1339          *      Check if we need to change anything.  If not, don't do
1340          *      anything.
1341          */
1342         if (dict_stat_check(dir, fn)) {
1343                 return 0;
1344         }
1345
1346         /*
1347          *      Free the dictionaries, and the stat cache.
1348          */
1349         dict_free();
1350         stat_root_dir = strdup(dir);
1351         stat_root_file = strdup(fn);
1352
1353         /*
1354          *      Create the table of vendor by name.   There MAY NOT
1355          *      be multiple vendors of the same name.
1356          *
1357          *      Each vendor is malloc'd, so the free function is free.
1358          */
1359         vendors_byname = lrad_hash_table_create(dict_vendor_name_hash,
1360                                                 dict_vendor_name_cmp,
1361                                                 free);
1362         if (!vendors_byname) {
1363                 return -1;
1364         }
1365
1366         /*
1367          *      Create the table of vendors by value.  There MAY
1368          *      be vendors of the same value.  If there are, we
1369          *      pick the latest one.
1370          */
1371         vendors_byvalue = lrad_hash_table_create(dict_vendor_value_hash,
1372                                                  dict_vendor_value_cmp,
1373                                                  NULL);
1374         if (!vendors_byvalue) {
1375                 return -1;
1376         }
1377
1378         /*
1379          *      Create the table of attributes by name.   There MAY NOT
1380          *      be multiple attributes of the same name.
1381          *
1382          *      Each attribute is malloc'd, so the free function is free.
1383          */
1384         attributes_byname = lrad_hash_table_create(dict_attr_name_hash,
1385                                                    dict_attr_name_cmp,
1386                                                    free);
1387         if (!attributes_byname) {
1388                 return -1;
1389         }
1390
1391         /*
1392          *      Create the table of attributes by value.  There MAY
1393          *      be attributes of the same value.  If there are, we
1394          *      pick the latest one.
1395          */
1396         attributes_byvalue = lrad_hash_table_create(dict_attr_value_hash,
1397                                                     dict_attr_value_cmp,
1398                                                     NULL);
1399         if (!attributes_byvalue) {
1400                 return -1;
1401         }
1402
1403         values_byname = lrad_hash_table_create(dict_value_name_hash,
1404                                                dict_value_name_cmp,
1405                                                free);
1406         if (!values_byname) {
1407                 return -1;
1408         }
1409
1410         values_byvalue = lrad_hash_table_create(dict_value_value_hash,
1411                                                 dict_value_value_cmp,
1412                                                 NULL);
1413         if (!values_byvalue) {
1414                 return -1;
1415         }
1416
1417         value_fixup = NULL;     /* just to be safe. */
1418
1419         if (my_dict_init(dir, fn, NULL, 0) < 0)
1420                 return -1;
1421
1422         if (value_fixup) {
1423                 DICT_ATTR *a;
1424                 value_fixup_t *this, *next;
1425
1426                 for (this = value_fixup; this != NULL; this = next) {
1427                         next = this->next;
1428
1429                         a = dict_attrbyname(this->attrstr);
1430                         if (!a) {
1431                                 librad_log(
1432                                         "dict_init: No ATTRIBUTE \"%s\" defined for VALUE \"%s\"",
1433                                         this->attrstr, this->dval->name);
1434                                 return -1; /* leak, but they should die... */
1435                         }
1436
1437                         this->dval->attr = a->attr;
1438
1439                         /*
1440                          *      Add the value into the dictionary.
1441                          */
1442                         if (!lrad_hash_table_replace(values_byname,
1443                                                      this->dval)) {
1444                                 librad_log("dict_addvalue: Duplicate value name %s for attribute %s", this->dval->name, a->name);
1445                                 return -1;
1446                         }
1447
1448                         /*
1449                          *      Allow them to use the old name, but
1450                          *      prefer the new name when printing
1451                          *      values.
1452                          */
1453                         if (!lrad_hash_table_finddata(values_byvalue, this->dval)) {
1454                                 lrad_hash_table_replace(values_byvalue,
1455                                                         this->dval);
1456                         }
1457                         free(this);
1458
1459                         /*
1460                          *      Just so we don't lose track of things.
1461                          */
1462                         value_fixup = next;
1463                 }
1464         }
1465
1466         /*
1467          *      Walk over all of the hash tables to ensure they're
1468          *      initialized.  We do this because the threads may perform
1469          *      lookups, and we don't want multi-threaded re-ordering
1470          *      of the table entries.  That would be bad.
1471          */
1472         lrad_hash_table_walk(vendors_byname, null_callback, NULL);
1473         lrad_hash_table_walk(vendors_byvalue, null_callback, NULL);
1474
1475         lrad_hash_table_walk(attributes_byname, null_callback, NULL);
1476         lrad_hash_table_walk(attributes_byvalue, null_callback, NULL);
1477
1478         lrad_hash_table_walk(values_byvalue, null_callback, NULL);
1479         lrad_hash_table_walk(values_byname, null_callback, NULL);
1480
1481         return 0;
1482 }
1483
1484 /*
1485  *      Get an attribute by its numerical value.
1486  */
1487 DICT_ATTR *dict_attrbyvalue(int attr)
1488 {
1489         DICT_ATTR dattr;
1490
1491         if ((attr > 0) && (attr < 256)) return dict_base_attrs[attr];
1492
1493         dattr.attr = attr;
1494         dattr.vendor = VENDOR(attr) & 0x7fff;
1495
1496         return lrad_hash_table_finddata(attributes_byvalue, &dattr);
1497 }
1498
1499 /*
1500  *      Get an attribute by its name.
1501  */
1502 DICT_ATTR *dict_attrbyname(const char *name)
1503 {
1504         DICT_ATTR dattr;
1505
1506         if (!name) return NULL;
1507
1508         strlcpy(dattr.name, name, sizeof(dattr.name));
1509
1510         return lrad_hash_table_finddata(attributes_byname, &dattr);
1511 }
1512
1513 /*
1514  *      Associate a value with an attribute and return it.
1515  */
1516 DICT_VALUE *dict_valbyattr(int attr, int value)
1517 {
1518         DICT_VALUE dval, *dv;
1519
1520         /*
1521          *      First, look up aliases.
1522          */
1523         dval.attr = attr;
1524         dval.name[0] = '\0';
1525
1526         /*
1527          *      Look up the attribute alias target, and use
1528          *      the correct attribute number if found.
1529          */
1530         dv = lrad_hash_table_finddata(values_byname, &dval);
1531         if (dv) dval.attr = dv->value;
1532
1533         dval.value = value;
1534
1535         return lrad_hash_table_finddata(values_byvalue, &dval);
1536 }
1537
1538 /*
1539  *      Get a value by its name, keyed off of an attribute.
1540  */
1541 DICT_VALUE *dict_valbyname(int attr, const char *name)
1542 {
1543         DICT_VALUE *my_dv, *dv;
1544         uint32_t buffer[(sizeof(*my_dv) + DICT_VALUE_MAX_NAME_LEN + 3)/4];
1545
1546         if (!name) return NULL;
1547
1548         my_dv = (DICT_VALUE *) buffer;
1549         my_dv->attr = attr;
1550         my_dv->name[0] = '\0';
1551
1552         /*
1553          *      Look up the attribute alias target, and use
1554          *      the correct attribute number if found.
1555          */
1556         dv = lrad_hash_table_finddata(values_byname, my_dv);
1557         if (dv) my_dv->attr = dv->value;
1558
1559         strlcpy(my_dv->name, name, DICT_VALUE_MAX_NAME_LEN);
1560
1561         return lrad_hash_table_finddata(values_byname, my_dv);
1562 }
1563
1564 /*
1565  *      Get the vendor PEC based on the vendor name
1566  *
1567  *      This is efficient only for small numbers of vendors.
1568  */
1569 int dict_vendorbyname(const char *name)
1570 {
1571         DICT_VENDOR *dv;
1572         uint32_t buffer[(sizeof(*dv) + DICT_VENDOR_MAX_NAME_LEN + 3)/4];
1573
1574         if (!name) return 0;
1575
1576         dv = (DICT_VENDOR *) buffer;
1577         strlcpy(dv->name, name, DICT_VENDOR_MAX_NAME_LEN);
1578
1579         dv = lrad_hash_table_finddata(vendors_byname, dv);
1580         if (!dv) return 0;
1581
1582         return dv->vendorpec;
1583 }
1584
1585 /*
1586  *      Return the vendor struct based on the PEC.
1587  */
1588 DICT_VENDOR *dict_vendorbyvalue(int vendorpec)
1589 {
1590         DICT_VENDOR dv;
1591
1592         dv.vendorpec = vendorpec;
1593
1594         return lrad_hash_table_finddata(vendors_byvalue, &dv);
1595 }