Update Stripped-User-Name, too.
authorAlan T. DeKok <aland@freeradius.org>
Tue, 28 Oct 2014 18:59:45 +0000 (14:59 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 28 Oct 2014 19:00:21 +0000 (15:00 -0400)
And do one loop, rather than 3.  It's a bit more efficient.

src/main/map.c

index 9ce6c17..194ab4d 100644 (file)
@@ -1160,9 +1160,40 @@ int map_to_request(REQUEST *request, value_pair_map_t const *map, radius_map_get
 finish:
        rad_assert(!head);
 
+       /*
+        *      Update the cached username && password.  This is code
+        *      we execute on EVERY update (sigh) so that SOME modules
+        *      MIGHT NOT have to do the search themselves.
+        *
+        *      TBH, we should probably make each module just do the
+        *      search themselves.
+        */
        if (map->lhs->tmpl_list == PAIR_LIST_REQUEST) {
-               context->username = pairfind(*list, PW_USER_NAME, 0, TAG_ANY);
-               context->password = pairfind(*list, PW_USER_PASSWORD, 0, TAG_ANY);
+               context->username = NULL;
+               context->password = NULL;
+
+               for (vp = fr_cursor_init(&src_list, list);
+                    vp;
+                    vp = fr_cursor_next(&src_list)) {
+
+                       if (vp->da->vendor != 0) continue;
+                       if (vp->da->flags.has_tag) continue;
+
+                       if (!context->username && (vp->da->attr == PW_USER_NAME)) {
+                               context->username = vp;
+                               continue;
+                       }
+
+                       if (vp->da->attr == PW_STRIPPED_USER_NAME) {
+                               context->username = vp;
+                               continue;
+                       }
+
+                       if (vp->da->attr == PW_USER_PASSWORD) {
+                               context->password = vp;
+                               continue;
+                       }
+               }
        }
        return 0;
 }