Pulled fix from branch_1_1
[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         ATTR_FLAGS      flags;
690
691         if ((argc < 3) || (argc > 4)) {
692                 librad_log("dict_init: %s[%d]: invalid ATTRIBUTE line",
693                         fn, line);
694                 return -1;
695         }
696
697         /*
698          *      Validate all entries
699          */
700         if (!isdigit((int) argv[1][0])) {
701                 librad_log("dict_init: %s[%d]: invalid value", fn, line);
702                 return -1;
703         }
704         sscanf(argv[1], "%i", &value);
705
706         /*
707          *      find the type of the attribute.
708          */
709         type = lrad_str2int(type_table, argv[2], -1);
710         if (type < 0) {
711                 librad_log("dict_init: %s[%d]: invalid type \"%s\"",
712                         fn, line, argv[2]);
713                 return -1;
714         }
715
716         /*
717          *      Only look up the vendor if the string
718          *      is non-empty.
719          */
720         memset(&flags, 0, sizeof(flags));
721         if (argc == 4) {
722                 char *key, *next, *last;
723
724                 key = argv[3];
725                 do {
726                         next = strchr(key, ',');
727                         if (next) *(next++) = '\0';
728
729                         if (strcmp(key, "has_tag") == 0 ||
730                             strcmp(key, "has_tag=1") == 0) {
731                                 /* Boolean flag, means this is a
732                                    tagged attribute */
733                                 flags.has_tag = 1;
734                                 
735                         } else if (strncmp(key, "encrypt=", 8) == 0) {
736                                 /* Encryption method, defaults to 0 (none).
737                                    Currently valid is just type 2,
738                                    Tunnel-Password style, which can only
739                                    be applied to strings. */
740                                 flags.encrypt = strtol(key + 8, &last, 0);
741                                 if (*last) {
742                                         librad_log( "dict_init: %s[%d] invalid option %s",
743                                                     fn, line, key);
744                                         return -1;
745                                 }
746                                 
747                         } else if (strncmp(key, "array", 8) == 0) {
748                                 flags.array = 1;
749                                 
750                                 switch (type) {
751                                         case PW_TYPE_IPADDR:
752                                         case PW_TYPE_BYTE:
753                                         case PW_TYPE_SHORT:
754                                         case PW_TYPE_INTEGER:
755                                         case PW_TYPE_DATE:
756                                                 break;
757
758                                         default:
759                                                 librad_log( "dict_init: %s[%d] Only IP addresses can have the \"array\" flag set.",
760                                                             fn, line);
761                                                 return -1;
762                                 }
763                                 
764                         } else if (block_vendor) {
765                                 librad_log( "dict_init: %s[%d]: unknown option \"%s\"",
766                                             fn, line, key);
767                                 return -1;
768
769                         } else {
770                                 /* Must be a vendor 'flag'... */
771                                 if (strncmp(key, "vendor=", 7) == 0) {
772                                         /* New format */
773                                         key += 7;
774                                 }
775
776                                 vendor = dict_vendorbyname(key);
777                                 if (!vendor) {
778                                         librad_log( "dict_init: %s[%d]: unknown vendor \"%s\"",
779                                                     fn, line, key);
780                                         return -1;
781                                 }
782                                 if (block_vendor && argv[3][0] &&
783                                     (block_vendor != vendor)) {
784                                         librad_log("dict_init: %s[%d]: mismatched vendor %s within BEGIN-VENDOR/END-VENDOR block",
785                                                    fn, line, argv[3]);
786                                         return -1;
787                                 }
788                         }
789
790                         key = next;
791                         if (key && !*key) break;
792                 } while (key);
793         }
794
795         if (block_vendor) vendor = block_vendor;
796
797         /*
798          *      Special checks for tags, they make our life much more
799          *      difficult.
800          */
801         if (flags.has_tag) {
802                 /*
803                  *      Only string, octets, and integer can be tagged.
804                  */
805                 switch (type) {
806                 case PW_TYPE_STRING:
807                 case PW_TYPE_INTEGER:
808                         break;
809
810                 default:
811                         librad_log("dict_init: %s[%d]: Attributes of type %s cannot be tagged.",
812                                    fn, line,
813                                    lrad_int2str(type_table, type, "?Unknown?"));
814                         return -1;
815
816                 }
817         }
818
819         /*
820          *      Add it in.
821          */
822         if (dict_addattr(argv[0], vendor, type, value, flags) < 0) {
823                 librad_log("dict_init: %s[%d]: %s",
824                            fn, line, librad_errstr);
825                 return -1;
826         }
827
828         return 0;
829 }
830
831
832 /*
833  *      Process the VALUE command
834  */
835 static int process_value(const char* fn, const int line, char **argv,
836                          int argc)
837 {
838         int     value;
839
840         if (argc != 3) {
841                 librad_log("dict_init: %s[%d]: invalid VALUE line",
842                         fn, line);
843                 return -1;
844         }
845         /*
846          *      For Compatibility, skip "Server-Config"
847          */
848         if (strcasecmp(argv[0], "Server-Config") == 0)
849                 return 0;
850
851         /*
852          *      Validate all entries
853          */
854         if (!isdigit((int) argv[2][0])) {
855                 librad_log("dict_init: %s[%d]: invalid value",
856                         fn, line);
857                 return -1;
858         }
859         sscanf(argv[2], "%i", &value);
860
861         if (dict_addvalue(argv[1], argv[0], value) < 0) {
862                 librad_log("dict_init: %s[%d]: %s",
863                            fn, line, librad_errstr);
864                 return -1;
865         }
866
867         return 0;
868 }
869
870
871 /*
872  *      Process the VALUE-ALIAS command
873  *
874  *      This allows VALUE mappings to be shared among multiple
875  *      attributes.
876  */
877 static int process_value_alias(const char* fn, const int line, char **argv,
878                                int argc)
879 {
880         DICT_ATTR *my_da, *da;
881         DICT_VALUE *dval;
882
883         if (argc != 2) {
884                 librad_log("dict_init: %s[%d]: invalid VALUE-ALIAS line",
885                         fn, line);
886                 return -1;
887         }
888
889         my_da = dict_attrbyname(argv[0]);
890         if (!my_da) {
891                 librad_log("dict_init: %s[%d]: ATTRIBUTE \"%s\" does not exist",
892                            fn, line, argv[1]);
893                 return -1;
894         }
895
896         if (my_da->flags.has_value) {
897                 librad_log("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" with pre-existing VALUE",
898                            fn, line, argv[0]);
899                 return -1;
900         }
901
902         if (my_da->flags.has_value_alias) {
903                 librad_log("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" with pre-existing VALUE-ALIAS",
904                            fn, line, argv[0]);
905                 return -1;
906         }
907
908         da = dict_attrbyname(argv[1]);
909         if (!da) {
910                 librad_log("dict_init: %s[%d]: Cannot find ATTRIBUTE \"%s\" for alias",
911                            fn, line, argv[1]);
912                 return -1;
913         }
914
915         if (!da->flags.has_value) {
916                 librad_log("dict_init: %s[%d]: VALUE-ALIAS cannot refer to ATTRIBUTE %s: It has no values",
917                            fn, line, argv[1]);
918                 return -1;
919         }
920
921         if (da->flags.has_value_alias) {
922                 librad_log("dict_init: %s[%d]: Cannot add VALUE-ALIAS to ATTRIBUTE \"%s\" which itself has a VALUE-ALIAS",
923                            fn, line, argv[1]);
924                 return -1;
925         }
926
927         if (my_da->type != da->type) {
928                 librad_log("dict_init: %s[%d]: Cannot add VALUE-ALIAS between attributes of differing type",
929                            fn, line);
930                 return -1;
931         }
932
933         if ((dval = malloc(sizeof(*dval))) == NULL) {
934                 librad_log("dict_addvalue: out of memory");
935                 return -1;
936         }
937         memset(dval, 0, sizeof(*dval));
938
939         dval->name[0] = '\0';   /* empty name */
940         dval->attr = my_da->attr;
941         dval->value = da->attr;
942
943         if (!lrad_hash_table_insert(values_byname, dval)) {
944                 librad_log("dict_init: %s[%d]: Error create alias",
945                            fn, line);
946                 free(dval);
947                 return -1;
948         }
949
950         return 0;
951 }
952
953
954 /*
955  *      Process the VENDOR command
956  */
957 static int process_vendor(const char* fn, const int line, char **argv,
958                           int argc)
959 {
960         int     value;
961         const   char *format = NULL;
962
963         if ((argc < 2) || (argc > 3)) {
964                 librad_log( "dict_init: %s[%d] invalid VENDOR entry",
965                             fn, line);
966                 return -1;
967         }
968
969         /*
970          *       Validate all entries
971          */
972         if (!isdigit((int) argv[1][0])) {
973                 librad_log("dict_init: %s[%d]: invalid value",
974                         fn, line);
975                 return -1;
976         }
977         value = atoi(argv[1]);
978
979         /* Create a new VENDOR entry for the list */
980         if (dict_addvendor(argv[0], value) < 0) {
981                 librad_log("dict_init: %s[%d]: %s",
982                            fn, line, librad_errstr);
983                 return -1;
984         }
985
986         /*
987          *      Look for a format statement
988          */
989         if (argc == 3) {
990                 format = argv[2];
991
992         } else if (value == VENDORPEC_USR) { /* catch dictionary screw-ups */
993                 format = "format=4,0";
994
995         } else if (value == VENDORPEC_LUCENT) {
996                 format = "format=2,1";
997
998         } else if (value == VENDORPEC_STARENT) {
999                 format = "format=2,2";
1000
1001         } /* else no fixups to do */
1002
1003         if (format) {
1004                 int type, length;
1005                 const char *p;
1006                 DICT_VENDOR *dv;
1007
1008                 if (strncasecmp(format, "format=", 7) != 0) {
1009                         librad_log("dict_init: %s[%d]: Invalid format for VENDOR.  Expected \"format=\", got \"%s\"",
1010                                    fn, line, format);
1011                         return -1;
1012                 }
1013
1014                 p = format + 7;
1015                 if ((strlen(p) != 3) ||
1016                     !isdigit((int) p[0]) ||
1017                     (p[1] != ',') ||
1018                     !isdigit((int) p[2])) {
1019                         librad_log("dict_init: %s[%d]: Invalid format for VENDOR.  Expected text like \"1,1\", got \"%s\"",
1020                                    fn, line, p);
1021                         return -1;
1022                 }
1023
1024                 type = (int) (p[0] - '0');
1025                 length = (int) (p[2] - '0');
1026
1027                 dv = dict_vendorbyvalue(value);
1028                 if (!dv) {
1029                         librad_log("dict_init: %s[%d]: Failed adding format for VENDOR",
1030                                    fn, line);
1031                         return -1;
1032                 }
1033
1034                 if ((type != 1) && (type != 2) && (type != 4)) {
1035                         librad_log("dict_init: %s[%d]: invalid type value %d for VENDOR",
1036                                    fn, line, type);
1037                         return -1;
1038                 }
1039
1040                 if ((length != 0) && (length != 1) && (length != 2)) {
1041                         librad_log("dict_init: %s[%d]: invalid length value %d for VENDOR",
1042                                    fn, line, length);
1043                         return -1;
1044                 }
1045
1046                 dv->type = type;
1047                 dv->length = length;
1048         }
1049
1050         return 0;
1051 }
1052
1053 /*
1054  *      String split routine.  Splits an input string IN PLACE
1055  *      into pieces, based on spaces.
1056  */
1057 static int str2argv(char *str, char **argv, int max_argc)
1058 {
1059         int argc = 0;
1060
1061         while (*str) {
1062                 if (argc >= max_argc) return argc;
1063
1064                 /*
1065                  *      Chop out comments early.
1066                  */
1067                 if (*str == '#') {
1068                         *str = '\0';
1069                         break;
1070                 }
1071
1072                 while ((*str == ' ') ||
1073                        (*str == '\t') ||
1074                        (*str == '\r') ||
1075                        (*str == '\n')) *(str++) = '\0';
1076
1077                 if (!*str) return argc;
1078
1079                 argv[argc] = str;
1080                 argc++;
1081
1082                 while (*str &&
1083                        (*str != ' ') &&
1084                        (*str != '\t') &&
1085                        (*str != '\r') &&
1086                        (*str != '\n')) str++;
1087         }
1088
1089         return argc;
1090 }
1091
1092 #define MAX_ARGV (16)
1093
1094 /*
1095  *      Initialize the dictionary.
1096  */
1097 static int my_dict_init(const char *dir, const char *fn,
1098                         const char *src_file, int src_line)
1099 {
1100         FILE    *fp;
1101         char    dirtmp[256];
1102         char    buf[256];
1103         char    *p;
1104         int     line = 0;
1105         int     vendor;
1106         int     block_vendor;
1107         struct stat statbuf;
1108         char    *argv[MAX_ARGV];
1109         int     argc;
1110
1111         if (strlen(fn) >= sizeof(dirtmp) / 2 ||
1112             strlen(dir) >= sizeof(dirtmp) / 2) {
1113                 librad_log("dict_init: filename name too long");
1114                 return -1;
1115         }
1116
1117         /*
1118          *      First see if fn is relative to dir. If so, create
1119          *      new filename. If not, remember the absolute dir.
1120          */
1121         if ((p = strrchr(fn, '/')) != NULL) {
1122                 strcpy(dirtmp, fn);
1123                 dirtmp[p - fn] = 0;
1124                 dir = dirtmp;
1125         } else if (dir && dir[0] && strcmp(dir, ".") != 0) {
1126                 snprintf(dirtmp, sizeof(dirtmp), "%s/%s", dir, fn);
1127                 fn = dirtmp;
1128         }
1129
1130         if ((fp = fopen(fn, "r")) == NULL) {
1131                 if (!src_file) {
1132                         librad_log("dict_init: Couldn't open dictionary \"%s\": %s",
1133                                    fn, strerror(errno));
1134                 } else {
1135                         librad_log("dict_init: %s[%d]: Couldn't open dictionary \"%s\": %s",
1136                                    src_file, src_line, fn, strerror(errno));
1137                 }
1138                 return -1;
1139         }
1140
1141         stat(fn, &statbuf); /* fopen() guarantees this will succeed */
1142         if (!S_ISREG(statbuf.st_mode)) {
1143                 fclose(fp);
1144                 librad_log("dict_init: Dictionary \"%s\" is not a regular file",
1145                            fn);
1146                 return -1;
1147         }
1148
1149         /*
1150          *      Globally writable dictionaries means that users can control
1151          *      the server configuration with little difficulty.
1152          */
1153 #ifdef S_IWOTH
1154         if ((statbuf.st_mode & S_IWOTH) != 0) {
1155                 fclose(fp);
1156                 librad_log("dict_init: Dictionary \"%s\" is globally writable.  Refusing to start due to insecure configuration.",
1157                            fn);
1158                 return -1;
1159         }
1160 #endif
1161
1162         dict_stat_add(fn, &statbuf);
1163
1164         /*
1165          *      Seed the random pool with data.
1166          */
1167         lrad_rand_seed(&statbuf, sizeof(statbuf));
1168
1169         block_vendor = 0;
1170
1171         while (fgets(buf, sizeof(buf), fp) != NULL) {
1172                 line++;
1173                 if (buf[0] == '#' || buf[0] == 0 ||
1174                     buf[0] == '\n' || buf[0] == '\r')
1175                         continue;
1176
1177                 /*
1178                  *  Comment characters should NOT be appearing anywhere but
1179                  *  as start of a comment;
1180                  */
1181                 p = strchr(buf, '#');
1182                 if (p) *p = '\0';
1183
1184                 argc = str2argv(buf, argv, MAX_ARGV);
1185                 if (argc == 0) continue;
1186
1187                 if (argc == 1) {
1188                         librad_log( "dict_init: %s[%d] invalid entry",
1189                                     fn, line);
1190                         fclose(fp);
1191                         return -1;
1192                 }
1193
1194                 if (0) {
1195                         int i;
1196
1197                         fprintf(stderr, "ARGC = %d\n",argc);
1198                         for (i = 0; i < argc; i++) {
1199                                 fprintf(stderr, "\t%s\n", argv[i]);
1200                         }
1201                 }
1202
1203                 /*
1204                  *      See if we need to import another dictionary.
1205                  */
1206                 if (strcasecmp(argv[0], "$INCLUDE") == 0) {
1207                         if (my_dict_init(dir, argv[1], fn, line) < 0) {
1208                                 fclose(fp);
1209                                 return -1;
1210                         }
1211                         continue;
1212                 } /* $INCLUDE */
1213
1214                 /*
1215                  *      Perhaps this is an attribute.
1216                  */
1217                 if (strcasecmp(argv[0], "ATTRIBUTE") == 0) {
1218                         if (process_attribute(fn, line, block_vendor,
1219                                               argv + 1, argc - 1) == -1) {
1220                                 fclose(fp);
1221                                 return -1;
1222                         }
1223                         continue;
1224                 }
1225
1226                 /*
1227                  *      Process VALUE lines.
1228                  */
1229                 if (strcasecmp(argv[0], "VALUE") == 0) {
1230                         if (process_value(fn, line,
1231                                           argv + 1, argc - 1) == -1) {
1232                                 fclose(fp);
1233                                 return -1;
1234                         }
1235                         continue;
1236                 }
1237
1238                 if (strcasecmp(argv[0], "VALUE-ALIAS") == 0) {
1239                         if (process_value_alias(fn, line,
1240                                                 argv + 1, argc - 1) == -1) {
1241                                 fclose(fp);
1242                                 return -1;
1243                         }
1244                         continue;
1245                 }
1246
1247                 /*
1248                  *      Process VENDOR lines.
1249                  */
1250                 if (strcasecmp(argv[0], "VENDOR") == 0) {
1251                         if (process_vendor(fn, line,
1252                                            argv + 1, argc - 1) == -1) {
1253                                 fclose(fp);
1254                                 return -1;
1255                         }
1256                         continue;
1257                 }
1258
1259                 if (strcasecmp(argv[0], "BEGIN-VENDOR") == 0) {
1260                         if (argc != 2) {
1261                                 librad_log(
1262                                 "dict_init: %s[%d] invalid BEGIN-VENDOR entry",
1263                                         fn, line);
1264                                 fclose(fp);
1265                                 return -1;
1266                         }
1267
1268                         vendor = dict_vendorbyname(argv[1]);
1269                         if (!vendor) {
1270                                 librad_log(
1271                                         "dict_init: %s[%d]: unknown vendor %s",
1272                                         fn, line, argv[1]);
1273                                 fclose(fp);
1274                                 return -1;
1275                         }
1276                         block_vendor = vendor;
1277                         continue;
1278                 } /* BEGIN-VENDOR */
1279
1280                 if (strcasecmp(argv[0], "END-VENDOR") == 0) {
1281                         if (argc != 2) {
1282                                 librad_log(
1283                                 "dict_init: %s[%d] invalid END-VENDOR entry",
1284                                         fn, line);
1285                                 fclose(fp);
1286                                 return -1;
1287                         }
1288
1289                         vendor = dict_vendorbyname(argv[1]);
1290                         if (!vendor) {
1291                                 librad_log(
1292                                         "dict_init: %s[%d]: unknown vendor %s",
1293                                         fn, line, argv[1]);
1294                                 fclose(fp);
1295                                 return -1;
1296                         }
1297
1298                         if (vendor != block_vendor) {
1299                                 librad_log(
1300                                         "dict_init: %s[%d]: END-VENDOR %s does not match any previous BEGIN-VENDOR",
1301                                         fn, line, argv[1]);
1302                                 fclose(fp);
1303                                 return -1;
1304                         }
1305                         block_vendor = 0;
1306                         continue;
1307                 } /* END-VENDOR */
1308
1309                 /*
1310                  *      Any other string: We don't recognize it.
1311                  */
1312                 librad_log(
1313                         "dict_init: %s[%d] invalid keyword \"%s\"",
1314                         fn, line, argv[0]);
1315                 fclose(fp);
1316                 return -1;
1317         }
1318         fclose(fp);
1319         return 0;
1320 }
1321
1322
1323 /*
1324  *      Empty callback for hash table initialization.
1325  */
1326 static int null_callback(void *ctx, void *data)
1327 {
1328         ctx = ctx;              /* -Wunused */
1329         data = data;            /* -Wunused */
1330
1331         return 0;
1332 }
1333
1334
1335 /*
1336  *      Initialize the directory, then fix the attr member of
1337  *      all attributes.
1338  */
1339 int dict_init(const char *dir, const char *fn)
1340 {
1341         /*
1342          *      Check if we need to change anything.  If not, don't do
1343          *      anything.
1344          */
1345         if (dict_stat_check(dir, fn)) {
1346                 return 0;
1347         }
1348
1349         /*
1350          *      Free the dictionaries, and the stat cache.
1351          */
1352         dict_free();
1353         stat_root_dir = strdup(dir);
1354         stat_root_file = strdup(fn);
1355
1356         /*
1357          *      Create the table of vendor by name.   There MAY NOT
1358          *      be multiple vendors of the same name.
1359          *
1360          *      Each vendor is malloc'd, so the free function is free.
1361          */
1362         vendors_byname = lrad_hash_table_create(dict_vendor_name_hash,
1363                                                 dict_vendor_name_cmp,
1364                                                 free);
1365         if (!vendors_byname) {
1366                 return -1;
1367         }
1368
1369         /*
1370          *      Create the table of vendors by value.  There MAY
1371          *      be vendors of the same value.  If there are, we
1372          *      pick the latest one.
1373          */
1374         vendors_byvalue = lrad_hash_table_create(dict_vendor_value_hash,
1375                                                  dict_vendor_value_cmp,
1376                                                  NULL);
1377         if (!vendors_byvalue) {
1378                 return -1;
1379         }
1380
1381         /*
1382          *      Create the table of attributes by name.   There MAY NOT
1383          *      be multiple attributes of the same name.
1384          *
1385          *      Each attribute is malloc'd, so the free function is free.
1386          */
1387         attributes_byname = lrad_hash_table_create(dict_attr_name_hash,
1388                                                    dict_attr_name_cmp,
1389                                                    free);
1390         if (!attributes_byname) {
1391                 return -1;
1392         }
1393
1394         /*
1395          *      Create the table of attributes by value.  There MAY
1396          *      be attributes of the same value.  If there are, we
1397          *      pick the latest one.
1398          */
1399         attributes_byvalue = lrad_hash_table_create(dict_attr_value_hash,
1400                                                     dict_attr_value_cmp,
1401                                                     NULL);
1402         if (!attributes_byvalue) {
1403                 return -1;
1404         }
1405
1406         values_byname = lrad_hash_table_create(dict_value_name_hash,
1407                                                dict_value_name_cmp,
1408                                                free);
1409         if (!values_byname) {
1410                 return -1;
1411         }
1412
1413         values_byvalue = lrad_hash_table_create(dict_value_value_hash,
1414                                                 dict_value_value_cmp,
1415                                                 NULL);
1416         if (!values_byvalue) {
1417                 return -1;
1418         }
1419
1420         value_fixup = NULL;     /* just to be safe. */
1421
1422         if (my_dict_init(dir, fn, NULL, 0) < 0)
1423                 return -1;
1424
1425         if (value_fixup) {
1426                 DICT_ATTR *a;
1427                 value_fixup_t *this, *next;
1428
1429                 for (this = value_fixup; this != NULL; this = next) {
1430                         next = this->next;
1431
1432                         a = dict_attrbyname(this->attrstr);
1433                         if (!a) {
1434                                 librad_log(
1435                                         "dict_init: No ATTRIBUTE \"%s\" defined for VALUE \"%s\"",
1436                                         this->attrstr, this->dval->name);
1437                                 return -1; /* leak, but they should die... */
1438                         }
1439
1440                         this->dval->attr = a->attr;
1441
1442                         /*
1443                          *      Add the value into the dictionary.
1444                          */
1445                         if (!lrad_hash_table_replace(values_byname,
1446                                                      this->dval)) {
1447                                 librad_log("dict_addvalue: Duplicate value name %s for attribute %s", this->dval->name, a->name);
1448                                 return -1;
1449                         }
1450
1451                         /*
1452                          *      Allow them to use the old name, but
1453                          *      prefer the new name when printing
1454                          *      values.
1455                          */
1456                         if (!lrad_hash_table_finddata(values_byvalue, this->dval)) {
1457                                 lrad_hash_table_replace(values_byvalue,
1458                                                         this->dval);
1459                         }
1460                         free(this);
1461
1462                         /*
1463                          *      Just so we don't lose track of things.
1464                          */
1465                         value_fixup = next;
1466                 }
1467         }
1468
1469         /*
1470          *      Walk over all of the hash tables to ensure they're
1471          *      initialized.  We do this because the threads may perform
1472          *      lookups, and we don't want multi-threaded re-ordering
1473          *      of the table entries.  That would be bad.
1474          */
1475         lrad_hash_table_walk(vendors_byname, null_callback, NULL);
1476         lrad_hash_table_walk(vendors_byvalue, null_callback, NULL);
1477
1478         lrad_hash_table_walk(attributes_byname, null_callback, NULL);
1479         lrad_hash_table_walk(attributes_byvalue, null_callback, NULL);
1480
1481         lrad_hash_table_walk(values_byvalue, null_callback, NULL);
1482         lrad_hash_table_walk(values_byname, null_callback, NULL);
1483
1484         return 0;
1485 }
1486
1487 /*
1488  *      Get an attribute by its numerical value.
1489  */
1490 DICT_ATTR *dict_attrbyvalue(int attr)
1491 {
1492         DICT_ATTR dattr;
1493
1494         if ((attr > 0) && (attr < 256)) return dict_base_attrs[attr];
1495
1496         dattr.attr = attr;
1497         dattr.vendor = VENDOR(attr) & 0x7fff;
1498
1499         return lrad_hash_table_finddata(attributes_byvalue, &dattr);
1500 }
1501
1502 /*
1503  *      Get an attribute by its name.
1504  */
1505 DICT_ATTR *dict_attrbyname(const char *name)
1506 {
1507         DICT_ATTR dattr;
1508
1509         if (!name) return NULL;
1510
1511         strlcpy(dattr.name, name, sizeof(dattr.name));
1512
1513         return lrad_hash_table_finddata(attributes_byname, &dattr);
1514 }
1515
1516 /*
1517  *      Associate a value with an attribute and return it.
1518  */
1519 DICT_VALUE *dict_valbyattr(int attr, int value)
1520 {
1521         DICT_VALUE dval, *dv;
1522
1523         /*
1524          *      First, look up aliases.
1525          */
1526         dval.attr = attr;
1527         dval.name[0] = '\0';
1528
1529         /*
1530          *      Look up the attribute alias target, and use
1531          *      the correct attribute number if found.
1532          */
1533         dv = lrad_hash_table_finddata(values_byname, &dval);
1534         if (dv) dval.attr = dv->value;
1535
1536         dval.value = value;
1537
1538         return lrad_hash_table_finddata(values_byvalue, &dval);
1539 }
1540
1541 /*
1542  *      Get a value by its name, keyed off of an attribute.
1543  */
1544 DICT_VALUE *dict_valbyname(int attr, const char *name)
1545 {
1546         DICT_VALUE *my_dv, *dv;
1547         uint32_t buffer[(sizeof(*my_dv) + DICT_VALUE_MAX_NAME_LEN + 3)/4];
1548
1549         if (!name) return NULL;
1550
1551         my_dv = (DICT_VALUE *) buffer;
1552         my_dv->attr = attr;
1553         my_dv->name[0] = '\0';
1554
1555         /*
1556          *      Look up the attribute alias target, and use
1557          *      the correct attribute number if found.
1558          */
1559         dv = lrad_hash_table_finddata(values_byname, my_dv);
1560         if (dv) my_dv->attr = dv->value;
1561
1562         strlcpy(my_dv->name, name, DICT_VALUE_MAX_NAME_LEN);
1563
1564         return lrad_hash_table_finddata(values_byname, my_dv);
1565 }
1566
1567 /*
1568  *      Get the vendor PEC based on the vendor name
1569  *
1570  *      This is efficient only for small numbers of vendors.
1571  */
1572 int dict_vendorbyname(const char *name)
1573 {
1574         DICT_VENDOR *dv;
1575         uint32_t buffer[(sizeof(*dv) + DICT_VENDOR_MAX_NAME_LEN + 3)/4];
1576
1577         if (!name) return 0;
1578
1579         dv = (DICT_VENDOR *) buffer;
1580         strlcpy(dv->name, name, DICT_VENDOR_MAX_NAME_LEN);
1581
1582         dv = lrad_hash_table_finddata(vendors_byname, dv);
1583         if (!dv) return 0;
1584
1585         return dv->vendorpec;
1586 }
1587
1588 /*
1589  *      Return the vendor struct based on the PEC.
1590  */
1591 DICT_VENDOR *dict_vendorbyvalue(int vendorpec)
1592 {
1593         DICT_VENDOR dv;
1594
1595         dv.vendorpec = vendorpec;
1596
1597         return lrad_hash_table_finddata(vendors_byvalue, &dv);
1598 }