Space after exec module - is it a bug?
Hello. I've encountered a weird problem. Tested on the newest stable (2.1.3) too. Well it's not a problem anymore since I found out a way to make my unlangish things work but: I wanted to check some things in post-auth. I am passing some arguments to my script and I want to do something based on the script's output switch "%{exec:/script %{User-Name} %{outer.request:Calling-Station-Id}" { case 0 { update reply { Tunnel-Private-Group-Id := "2000" } } case "1" { update reply { Tunnel-Private-Group-Id := "1999" } } case "2 " { update reply { Tunnel-Private-Group-Id := "999" } } } As you can see it's not a rocket science. script prints a number 0, 1 or 2 and exits. What's weird is that only the last case example will work. Is this intentional that there has to be a space in case expression? The same applies to this situation: if ("%{Calling-Station-Id} " == "%{exec:/script2 %{Calling-Station-Id}") { $do_anything } when script2 only prints the argument. Why there is a need for a space? It won't work with this expression: if ("%{Calling-Station-Id}" == "%{exec:/script2 %{Calling-Station-Id}") { $never_here } Kind regards, PS script2 looks like this: #!/usr/bin/python import sys if __name__ == "__main__": print sys.argv[1] -- Lech Karol Pawłaszek <ike> "You will never see me fall from grace" [KoRn]
Lech Karol Pawłaszek wrote:
Hello.
I've encountered a weird problem. Tested on the newest stable (2.1.3) too. Well it's not a problem anymore since I found out a way to make my unlangish things work but:
I wanted to check some things in post-auth. I am passing some arguments to my script and I want to do something based on the script's output
switch "%{exec:/script %{User-Name} %{outer.request:Calling-Station-Id}" {
You're missing a closing } I suspect this is adding a trailing " " to the output
case 0 { update reply { Tunnel-Private-Group-Id := "2000" } } case "1" { update reply { Tunnel-Private-Group-Id := "1999" } } case "2 " { update reply { Tunnel-Private-Group-Id := "999" } } }
As you can see it's not a rocket science. script prints a number 0, 1 or 2 and exits. What's weird is that only the last case example will work. Is this intentional that there has to be a space in case expression?
The same applies to this situation:
if ("%{Calling-Station-Id} " == "%{exec:/script2 %{Calling-Station-Id}") { $do_anything }
Ditto missing } on the %{exec}
when script2 only prints the argument. Why there is a need for a space? It won't work with this expression:
if ("%{Calling-Station-Id}" == "%{exec:/script2 %{Calling-Station-Id}") { $never_here }
Kind regards,
PS script2 looks like this:
#!/usr/bin/python import sys
if __name__ == "__main__": print sys.argv[1]
Phil Mayers wrote:
Lech Karol Pawłaszek wrote: [...]
switch "%{exec:/script %{User-Name} %{outer.request:Calling-Station-Id}" {
You're missing a closing }
I suspect this is adding a trailing " " to the output [...]
if ("%{Calling-Station-Id} " == "%{exec:/script2 %{Calling-Station-Id}") { $do_anything }
Ditto missing } on the %{exec}
Argh! True. However I still have the same symptoms even if I'll put the missing brace like this: switch "%{exec:/script %{User-Name} %{outer.request:Calling-Station-Id}}" [...] Some logs: The case when there is no space: Mon Dec 15 12:51:38 2008 : Auth: Login OK: [test/<via Auth-Type = EAP>] (from client localhost port 0 via TLS tunnel) Mon Dec 15 12:51:38 2008 : Info: +- entering group post-auth {...} Mon Dec 15 12:51:38 2008 : Info: Executing /root/test.py %{User-Name} %{outer.request:Calling-Station-Id} Mon Dec 15 12:51:38 2008 : Info: expand: %{User-Name} -> test Mon Dec 15 12:51:38 2008 : Info: expand: %{outer.request:Calling-Station-Id} -> 02-00-00-00-00-01 Mon Dec 15 12:51:38 2008 : Debug: Exec-Program output: 1 Mon Dec 15 12:51:38 2008 : Debug: Exec-Program-Wait: plaintext: 1 Mon Dec 15 12:51:38 2008 : Debug: Exec-Program: returned: 0 Mon Dec 15 12:51:38 2008 : Info: result 0 Mon Dec 15 12:51:38 2008 : Info: expand: %{exec:/root/test.py %{User-Name} %{outer.request:Calling-Station-Id}} -> 1 Mon Dec 15 12:51:38 2008 : Info: ++- entering switch %{exec:/root/test.py %{User-Name} %{outer.request:Calling-Station-Id}} {...} Mon Dec 15 12:51:38 2008 : Info: +++- switch %{exec:/root/test.py %{User-Name} %{outer.request:Calling-Station-Id}} returns noop Mon Dec 15 12:51:38 2008 : Info: ++- group post-auth returns noop } # server inner-tunnel Mon Dec 15 12:51:38 2008 : Info: [peap] Got tunneled reply code 2 Tunnel-Private-Group-Id:0 = "2000" (Tunnel-Private-Group-Id = "2000" is the default. It sould be 1999 here because /root/test.py returned 1) The case when there is a space: Mon Dec 15 12:53:04 2008 : Auth: Login OK: [test/<via Auth-Type = EAP>] (from client localhost port 0 via TLS tunnel) Mon Dec 15 12:53:04 2008 : Info: +- entering group post-auth {...} Mon Dec 15 12:53:04 2008 : Info: Executing /root/test.py %{User-Name} %{outer.request:Calling-Station-Id} Mon Dec 15 12:53:04 2008 : Info: expand: %{User-Name} -> test Mon Dec 15 12:53:04 2008 : Info: expand: %{outer.request:Calling-Station-Id} -> 02-00-00-00-00-01 Mon Dec 15 12:53:04 2008 : Debug: Exec-Program output: 2 Mon Dec 15 12:53:04 2008 : Debug: Exec-Program-Wait: plaintext: 2 Mon Dec 15 12:53:04 2008 : Debug: Exec-Program: returned: 0 Mon Dec 15 12:53:04 2008 : Info: result 0 Mon Dec 15 12:53:04 2008 : Info: expand: %{exec:/root/test.py %{User-Name} %{outer.request:Calling-Station-Id}} -> 2 Mon Dec 15 12:53:04 2008 : Info: ++- entering switch %{exec:/root/test.py %{User-Name} %{outer.request:Calling-Station-Id}} {...} Mon Dec 15 12:53:04 2008 : Info: +++- entering case 2 {...} Mon Dec 15 12:53:04 2008 : Info: ++++[reply] returns noop Mon Dec 15 12:53:04 2008 : Info: +++- case 2 returns noop Mon Dec 15 12:53:04 2008 : Info: ++- switch %{exec:/root/test.py %{User-Name} %{outer.request:Calling-Station-Id}} returns noop } # server inner-tunnel Mon Dec 15 12:53:04 2008 : Info: [peap] Got tunneled reply code 2 Tunnel-Private-Group-Id:0 = "999" Kind regards, -- Lech Karol Pawłaszek <ike> "You will never see me fall from grace" [KoRn]
Lech Karol Pawłaszek wrote:
Argh! True. However I still have the same symptoms even if I'll put the missing brace like this:
The "exec" module converts all carriage returns to spaces. This is likely what's happening here. Maybe it should do that for all carriage returns *except* for the last one. Alan DeKok.
participants (3)
-
Alan DeKok -
Lech Karol Pawłaszek -
Phil Mayers