]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix weird issue where it wouldn't update Stripped-User-Name
authorAlan T. DeKok <aland@freeradius.org>
Sun, 16 Oct 2011 03:03:34 +0000 (05:03 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 17 Oct 2011 14:45:00 +0000 (16:45 +0200)
suffix
update request {
       Stripped-User-Name := "%{Stripped-User-Name}@bar.com"
}

would result in Stripped-User-Name being unchanged.
The code was the same as 2.1.x, which worked.

The new code has the benefit of working, and has one less pass
over the input list

src/main/evaluate.c

index c0c5480a354f54b5106fd1c8c33f75f9b90771f2..d5c6929fafd17d317d23c38373561fa60ae4f8b5 100644 (file)
@@ -879,31 +879,6 @@ int radius_evaluate_condition(REQUEST *request, int modreturn, int depth,
 }
 #endif
 
-static void fix_up(REQUEST *request)
-{
-       VALUE_PAIR *vp;
-
-       request->username = NULL;
-       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;
-                       
-               } else if (vp->attribute == PW_STRIPPED_USER_NAME) {
-                       request->username = vp;
-                       
-               } else if (vp->attribute == PW_USER_PASSWORD) {
-                       request->password = vp;
-               }
-
-               if (request->username && request->password) break;
-       }
-}
-
 
 /*
  *     The pairmove() function in src/lib/valuepair.c does all sorts of
@@ -919,6 +894,7 @@ void radius_pairmove(REQUEST *request, VALUE_PAIR **to, VALUE_PAIR *from)
        VALUE_PAIR *vp, *next, **last;
        VALUE_PAIR **from_list, **to_list;
        int *edited = NULL;
+       REQUEST *fixup = NULL;
 
        /*
         *      Set up arrays for editing, to remove some of the
@@ -1155,10 +1131,21 @@ void radius_pairmove(REQUEST *request, VALUE_PAIR **to, VALUE_PAIR *from)
        *to = NULL;
        last = to;
 
+       if (to == &request->packet->vps) {
+               fixup = request;
+       } else if (request->parent && (to == &request->parent->packet->vps)) {
+               fixup = request->parent;
+       }
+       if (fixup) {
+               fixup->username = NULL;
+               fixup->password = NULL;
+       }
+
        for (i = 0; i < tailto; i++) {
                if (!to_list[i]) continue;
                
-               RDEBUG4("::: to[%d] = %s", i, to_list[i]->name);
+               vp = to_list[i];
+               RDEBUG4("::: to[%d] = %s", i, vp->name);
 
                /*
                 *      Mash the operator to a simple '='.  The
@@ -1167,24 +1154,31 @@ void radius_pairmove(REQUEST *request, VALUE_PAIR **to, VALUE_PAIR *from)
                 *      file and debug output, where we don't want to
                 *      see the operators.
                 */
-               to_list[i]->operator = T_OP_EQ;
+               vp->operator = T_OP_EQ;
+
+               /*
+                *      Fix dumb cache issues
+                */
+               if (fixup && (vp->vendor == 0)) {
+                       if ((vp->attribute == PW_USER_NAME) &&
+                           !fixup->username) {
+                               fixup->username = vp;
+
+                       } else if (vp->attribute == PW_STRIPPED_USER_NAME) {
+                               fixup->username = vp;
+
+                       } else if (vp->attribute == PW_USER_PASSWORD) {
+                               fixup->password = vp;
+                       }
+               }
 
-               *last = to_list[i];
+               *last = vp;
                last = &(*last)->next;
        }
 
        rad_assert(request != NULL);
        rad_assert(request->packet != NULL);
 
-       /*
-        *      Fix dumb cache issues
-        */
-       if (to == &request->packet->vps) {
-               fix_up(request);
-       } else if (request->parent && (to == &request->parent->packet->vps)) {
-               fix_up(request->parent);
-       }
-
        free(to_list);
        free(edited);
 }