Index is not an integer

Franks Andy (IT Technical Architecture Manager) Andy.Franks at sath.nhs.uk
Tue Dec 15 15:20:42 CET 2015


Hi Alan,
  Had an earlier attempt was to break it down, guess I might have come at it from the wrong angle, i.e. trying "%{xlat:%{control:Tmp-Integer-0}}". I imagined that piece to be expanded first into and integer, in the way bracketed things work inside -> out.

  "%{Control:Tmp-Integer-0}" is fine, gives the correct number, no great surprise there.

  I can't test "%{control:Tmp-String-3[%{control:Tmp-Integer-0}]}" as the server won't start up since it doesn't see control:Tmp-Integer-0 as an actual integer.

Arran's suggestion does allow the server to start, but gives an empty output in debugging mode:

Variables going in :
(1)         control:Tmp-string-1 += 4685a44565edf4d8aae476f8ed3b0ab9
(1)         control:Tmp-string-2 += 000E0000009C
(1)         control:Tmp-string-3 += 20b399f37010
(1)         control:Tmp-string-4 += radacct_lan0
(1)         control:Tmp-string-1 += 4ae6bd20c2955bdbc7a61703bd811c5b
(1)         control:Tmp-string-2 += 000E0000004B
(1)         control:Tmp-string-3 += 20b399f37010
(1)         control:Tmp-string-4 += radacct_lant

.. but not coming out:
(1)        update control {
(1)           Tmp-Integer-0 := 0
(1)         } # update control (noop)
(1)         foreach &control:Tmp-String-1 {
(1)         foreach &control:Tmp-String-1
(1)         # Foreach-Variable-0 = "4685a44565edf4d8aae476f8ed3b0ab9"
(1)           update control {
(1)             CoA-Failure-Reason !* ANY
(1)             EXPAND Foreach-Variable-0
(1)                --> 4685a44565edf4d8aae476f8ed3b0ab9
(1)             EXPAND %{Foreach-Variable-0}
(1)                --> 4685a44565edf4d8aae476f8ed3b0ab9
(1)             CoA-Acct-Unique-Session-Id := "4685a44565edf4d8aae476f8ed3b0ab9"
(1)             EXPAND %{xlat:%%{control:Tmp-String-2[%{control:Tmp-Integer-0}]%}}
(1)                -->
(1)             CoA-Acct-Session-Id := ""
(1)             EXPAND %{xlat:%%{control:Tmp-String-3[%{control:Tmp-Integer-0}]%}}
(1)                -->
(1)             CoA-User-Name := ""

.. based on a bit of trial code:

  update control {
    Tmp-Integer-0 !* ANY
    Tmp-String-0 !* ANY
    Tmp-String-1 !* ANY
    Tmp-String-2 !* ANY
    Tmp-String-0 := "call get_active_sessions_for_switchport ('%{NAS-IP-Address}', '%{NAS-Port}', ${policy.MaxClientAge})"
  }

  # map - get back one or more devices.
  map sql_SP_rsh-radius-lant &control:Tmp-String-0 {
    control:Tmp-string-1 += acctuniqueid
    control:Tmp-string-2 += acctsessionid
    control:Tmp-string-3 += username
    control:Tmp-string-4 += accounttable
  }

  if (&control:Tmp-String-1) {
    update control {
      Tmp-Integer-0 := 0
    }
    foreach &control:Tmp-String-1 {
      # send the disconnect
      update control {
        CoA-Failure-Reason !* ANY
        CoA-Acct-Unique-Session-Id := "%{Foreach-Variable-0}"
        CoA-Acct-Session-Id := "%{xlat:%%{control:Tmp-String-2[%{control:Tmp-Integer-0}]%}}"
        CoA-User-Name := "%{xlat:%%{control:Tmp-String-3[%{control:Tmp-Integer-0}]%}}"
      }
    }
   }

As you can see I'm trying to disconnect some switch sessions via CoA in an effort to get around a really annoying issue with phones we have of hanging onto mac addresses for ages after they've been removed.
If I can't do it, no worries, it seems to me the most efficient way, but as with all things I.T. there are other ways of doing it, presumably some that still make the sql map stuff useful.

Thank you! I'm sure all this will be useful for other people searching!
Andy

-----Original Message-----
From: Freeradius-Users [mailto:freeradius-users-bounces+andy.franks=sath.nhs.uk at lists.freeradius.org] On Behalf Of Alan DeKok
Sent: 15 December 2015 14:03
To: FreeRadius users mailing list
Subject: Re: Index is not an integer

On Dec 15, 2015, at 8:54 AM, Franks Andy (IT Technical Architecture Manager) <Andy.Franks at sath.nhs.uk> wrote:
> 
> Hi Alan,
>  First of all thanks for the reply, that helps me understand "xlat's place".
> 
> My real struggle was with what Arran provided yesterday, can't get it to work:

  As with most things, break it down in pieces.

> "%{xlat:%%{control:Tmp-String-3[%{control:Tmp-Integer-0}]%}}"

  Hmm... I'm not sure that works.  The problem is that this is complicated and not simple...

> It use is to refer to the index of Tmp-String-3 via the dynamic integer Tmp-Integer-0. Trouble is, it comes back with an empty string.

  It comes back with a lot more than that.  PLEASE run the server in debugging mode to see what the inputs and outputs are for each stage of expansion.  Honestly, this should be the *first step*.  And you should post it here, too.

  Ignoring the debug output means you will *never* get the problem solved.

> Is it because of what you mentioned ; that 
> 
> control:Tmp-String-3[%{3}] != control:Tmp-String-3[3]

  No.  %{xlat:3} is the same as %{3}.  %{xlat:foo-3} is the same as %{foo-3}, not %{foo-%{3}}.  There's no magical expansion in the middle of a string.

> Do I need to do some regex matching and plug the integer value into the corresponding group by building, for example, a delimited string? Would that work?

  No.  I'd break it down into pieces.  The question is, what does each piece produce?  Build it up in sequence.

	%{control:Tmp-Integer-0}  is...

	%{control:Tmp-String-3[%{control:Tmp-Integer-0}] is ...

  My guess is that won't work, because the normal case is to *not* do xlat expansions on the array offsets.  You might need to build up multiple layers of xlat expansions.

> The apparent downside to that would be to only match a preset number of groups my expression contained, and, if possible, I'd like to match any number of previous "things", within reason. I'm guessing I'm on the edge of what should maybe done in perl / python / whatever, it just seems the tricky bit has been done with the import of mapped sql stuff, can't get over how useful that is, and now I just want to iterate over things in turn, literally the last thing to be done.

  Yup.

  Alan DeKok.


-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html



More information about the Freeradius-Users mailing list