Skip to content

Commit

Permalink
Return string 0 for &Attr[#] where no attributes exist
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Nov 5, 2014
1 parent 521fffd commit 513fd1d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/xlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ static ssize_t xlat_tokenize_request(REQUEST *request, char const *fmt, xlat_exp
static char *xlat_getvp(TALLOC_CTX *ctx, REQUEST *request, pair_lists_t list, DICT_ATTR const *da,
int8_t tag, int num, bool return_null)
{
VALUE_PAIR *vp, *vps = NULL, *myvp = NULL;
VALUE_PAIR *vp = NULL, *vps = NULL, *myvp = NULL;
RADIUS_PACKET *packet = NULL;
DICT_VALUE *dv;
char *ret = NULL;
Expand Down Expand Up @@ -1650,6 +1650,11 @@ static char *xlat_getvp(TALLOC_CTX *ctx, REQUEST *request, pair_lists_t list, DI
#endif
}

/*
* Counting attributes doesn't require us to search for them
*/
if (!da->flags.virtual && (num == NUM_COUNT)) goto do_print;

/*
* Now we have the list, check to see if we have an attribute in
* the request, if we do, it takes precedence over the virtual
Expand Down Expand Up @@ -1846,10 +1851,9 @@ static char *xlat_getvp(TALLOC_CTX *ctx, REQUEST *request, pair_lists_t list, DI
* Return a count of the VPs.
*/
case NUM_COUNT:
fr_cursor_init(&cursor, &vp);
while (fr_cursor_next_by_da(&cursor, da, tag) != NULL) {
count++;
}
fr_cursor_init(&cursor, &vps);
while (fr_cursor_next_by_da(&cursor, da, tag) != NULL) count++;

return talloc_typed_asprintf(ctx, "%d", count);

/*
Expand All @@ -1859,7 +1863,7 @@ static char *xlat_getvp(TALLOC_CTX *ctx, REQUEST *request, pair_lists_t list, DI
{
char *p, *q;

(void) fr_cursor_init(&cursor, &vp);
(void) fr_cursor_init(&cursor, &vps);
vp = fr_cursor_next_by_da(&cursor, da, tag);
if (!vp) return NULL;

Expand All @@ -1876,7 +1880,7 @@ static char *xlat_getvp(TALLOC_CTX *ctx, REQUEST *request, pair_lists_t list, DI
}

default:
fr_cursor_init(&cursor, &vp);
fr_cursor_init(&cursor, &vps);
while ((vp = fr_cursor_next_by_da(&cursor, da, tag)) != NULL) {
if (count++ == num) break;
}
Expand Down

0 comments on commit 513fd1d

Please sign in to comment.