Fix typos in previous commit
[freeradius.git] / src / main / evaluate.c
index 96283da..10aeac4 100644 (file)
@@ -162,7 +162,7 @@ static FR_TOKEN getregex(const char **ptr, char *buffer, size_t buflen,
 
                        default:
                                if ((p[1] >= '0') && (p[1] <= '9') &&
-                                   (sscanf(p, "%3o", &x) == 1)) {
+                                   (sscanf(p + 1, "%3o", &x) == 1)) {
                                        *q++ = x;
                                        p += 2;
                                } else {
@@ -289,7 +289,7 @@ int radius_get_vp(REQUEST *request, const char *name, VALUE_PAIR **vp_p)
        /*
         *      May not may not be found, but it *is* a known name.
         */
-       *vp_p = pairfind(vps, da->attr);
+       *vp_p = pairfind(vps, da->attr, da->vendor);
        return TRUE;
 }
 
@@ -303,7 +303,7 @@ static int radius_do_cmp(REQUEST *request, int *presult,
                         int cflags, int modreturn)
 {
        int result;
-       int lint, rint;
+       uint32_t lint, rint;
        VALUE_PAIR *vp = NULL;
 #ifdef HAVE_REGEX_H
        char buffer[1024];
@@ -355,7 +355,7 @@ static int radius_do_cmp(REQUEST *request, int *presult,
                                 *      If so, try looking for it.
                                 */
                                da = dict_attrbyname(pleft);
-                               if (da && radius_find_compare(da->attr)) {
+                               if (da && (da->vendor == 0) && radius_find_compare(da->attr)) {
                                        VALUE_PAIR *check = pairmake(pleft, pright, token);
                                        *presult = (radius_callback_compare(request, NULL, check, NULL, NULL) == 0);
                                        RDEBUG3("  Callback returns %d",
@@ -366,7 +366,8 @@ static int radius_do_cmp(REQUEST *request, int *presult,
                                
                                RDEBUG2("    (Attribute %s was not found)",
                                       pleft);
-                               return FALSE;
+                               *presult = 0;
+                               return TRUE;
                        }
 
 #ifdef HAVE_REGEX_H
@@ -408,12 +409,12 @@ static int radius_do_cmp(REQUEST *request, int *presult,
                        RDEBUG2("    (Right field is not a number at: %s)", pright);
                        return FALSE;
                }
-               rint = atoi(pright);
+               rint = strtoul(pright, NULL, 0);
                if (!all_digits(pleft)) {
                        RDEBUG2("    (Left field is not a number at: %s)", pleft);
                        return FALSE;
                }
-               lint = atoi(pleft);
+               lint = strtoul(pleft, NULL, 0);
                break;
                
        default:
@@ -427,7 +428,7 @@ static int radius_do_cmp(REQUEST *request, int *presult,
                 *      Check for truth or falsehood.
                 */
                if (all_digits(pleft)) {
-                       lint = atoi(pleft);
+                       lint = strtoul(pleft, NULL, 0);
                        result = (lint != 0);
                        
                } else {
@@ -881,6 +882,8 @@ static void fix_up(REQUEST *request)
        request->password = NULL;
        
        for (vp = request->packet->vps; vp != NULL; vp = vp->next) {
+               if (vp->vendor != 0) continue;
+
                if ((vp->attribute == PW_USER_NAME) &&
                    !request->username) {
                        request->username = vp;
@@ -891,6 +894,8 @@ static void fix_up(REQUEST *request)
                } else if (vp->attribute == PW_USER_PASSWORD) {
                        request->password = vp;
                }
+
+               if (request->username && request->password) break;
        }
 }
 
@@ -979,12 +984,13 @@ void radius_pairmove(REQUEST *request, VALUE_PAIR **to, VALUE_PAIR *from)
 
                found = FALSE;
                for (j = 0; j < to_count; j++) {
-                       if (edited[j] || !to_list[j]) continue;
+                       if (edited[j] || !to_list[j] || !from_list[i]) continue;
 
                        /*
                         *      Attributes aren't the same, skip them.
                         */
-                       if (from_list[i]->attribute != to_list[j]->attribute) {
+                       if ((from_list[i]->attribute != to_list[j]->attribute) ||
+                           (from_list[i]->vendor != to_list[j]->vendor)) {
                                continue;
                        }
 
@@ -1316,6 +1322,13 @@ int radius_update_attrlist(REQUEST *request, CONF_SECTION *cs,
 
                cp = cf_itemtopair(ci);
 
+#ifndef NDEBUG
+               if (debug_flag && (vp->vendor == 0) &&
+                   radius_find_compare(vp->attribute)) {
+                       DEBUG("WARNING: You are modifying the value of virtual attribute %s.  This is not supported.", vp->name);
+               }
+#endif
+
                /*
                 *      The VP && CF lists should be in sync.  If they're
                 *      not, panic.