Patch from Kristina Pfaff-Harris <kristina@greatbasin.net>
authoraland <aland>
Wed, 3 Jan 2001 16:42:16 +0000 (16:42 +0000)
committeraland <aland>
Wed, 3 Jan 2001 16:42:16 +0000 (16:42 +0000)
Use attribute number to look up value names.  If this isn't done,
then the named values returned MAY BE associated with another
attribute, and not the one we're interested in.

e.g. Rlogin has one name, but multiple values, which are
per-attribute.

src/include/libradius.h
src/lib/dict.c
src/lib/valuepair.c
src/main/modules.c

index 91dd022..f2eb06f 100644 (file)
@@ -149,7 +149,7 @@ int         dict_init(const char *dir, const char *fn);
 DICT_ATTR      *dict_attrbyvalue(int attr);
 DICT_ATTR      *dict_attrbyname(const char *attr);
 DICT_VALUE     *dict_valbyattr(int attr, int val);
-DICT_VALUE     *dict_valbyname(const char *val);
+DICT_VALUE     *dict_valbyname(int attr, const char *val);
 int            dict_vendorcode(int);
 int            dict_vendorpec(int);
 int            dict_vendorname(const char *name);
index 65bfd41..7537801 100644 (file)
@@ -587,14 +587,20 @@ DICT_VALUE * dict_valbyattr(int attr, int val)
 
 /*
  *     Get a value by its name.
+ *      If you pass an actual attr, it will try to match it.
+ *      If you just want it to return on the first match,
+ *      send it 0 as the attr. I hope this works the way it
+ *      seems to. :) --kph
  */
-DICT_VALUE * dict_valbyname(const char *name)
+DICT_VALUE * dict_valbyname(int attr, const char *name)
 {
        DICT_VALUE      *v;
 
        for (v = dictionary_values; v; v = v->next) {
-               if (DICT_STRCMP(v->name, name) == 0)
-                       return v;
+               if ((attr == 0 || v->attr == attr) &&
+                   DICT_STRCMP(v->name, name) == 0)
+                return v;
+               
        }
 
        return NULL;
index 30aeb20..6ab345d 100644 (file)
@@ -535,8 +535,12 @@ VALUE_PAIR *pairmake(const char *attribute, const char *value, int operator)
                                vp->lvalue = atoi(value);
                                vp->length = 4;
                        }
-                       else if ((dval = dict_valbyname(value)) == NULL) {
-                               free(vp);
+                       /*
+                        *      Look for the named value for the given
+                        *      attribute.
+                        */
+                       else if ((dval = dict_valbyname(da->attr, value)) == NULL) {
+                                       free(vp);
                                librad_log("Unknown value %s for attribute %s",
                                           value, vp->name);
                                return NULL;
index 4f17cbb..5771584 100644 (file)
@@ -168,9 +168,8 @@ static int new_authtype_value(const char *name)
         *  Check to see if it's already defined.
         *  If so, return the old value.
         */
-       old_value = dict_valbyname(name);
-       if (old_value) return old_value->value;
-       
+       old_value = dict_valbyname(PW_AUTHTYPE, name);
+       if (old_value) return old_value->value; 
        /* Look for the predefined Auth-Type value */
        old_value = dict_valbyattr(PW_AUTHTYPE, 0);
        if (!old_value) return 0;       /* something WIERD is happening */