From: Alan T. DeKok Date: Sun, 16 Oct 2011 03:03:34 +0000 (+0200) Subject: Fix weird issue where it wouldn't update Stripped-User-Name X-Git-Tag: release_3_0_0_beta0~590 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=604b0987db895f41484ce0c9f5ec6d88afd43023;p=thirdparty%2Ffreeradius-server.git Fix weird issue where it wouldn't update Stripped-User-Name 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 --- diff --git a/src/main/evaluate.c b/src/main/evaluate.c index c0c5480a354..d5c6929fafd 100644 --- a/src/main/evaluate.c +++ b/src/main/evaluate.c @@ -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); }