Discussion:
[rancid] Error with 10 character prompts
Michael Newton
2015-02-28 00:18:17 UTC
Permalink
I’ve come across a bit of an odd problem in clogin, I believe it shows up
with prompts that are ten characters long, and the tenth character would
need escaping if it were put in a regex.

I modified clogin to show me what it was building for a prompt and this is
what I saw:

(ThisLong) #
reprompt is \(ThisLong\([^#>\r\n]+)?[#>](\([^)\r\n]+\))?

(ThisIsLonger) #
reprompt is \(ThisIsLon([^#>\r\n]+)?[#>](\([^)\r\n]+\))?

Notice on the shorter prompt, the parenthesis in the regex ends up being
escaped, I suspect because the prompt is being escaped and then trimmed.
The problem code is right near the top of run_commands().

Mike
heasley
2015-03-01 16:18:41 UTC
Permalink
I’ve come across a bit of an odd problem in clogin, I believe it shows up
with prompts that are ten characters long, and the tenth character would
need escaping if it were put in a regex.
I modified clogin to show me what it was building for a prompt and this is
(ThisLong) #
reprompt is \(ThisLong\([^#>\r\n]+)?[#>](\([^)\r\n]+\))?
(ThisIsLonger) #
reprompt is \(ThisIsLon([^#>\r\n]+)?[#>](\([^)\r\n]+\))?
Notice on the shorter prompt, the parenthesis in the regex ends up being
escaped, I suspect because the prompt is being escaped and then trimmed.
The problem code is right near the top of run_commands().
indeed. This should fix it:

Index: clogin.in
===================================================================
--- clogin.in (revision 3045)
+++ clogin.in (working copy)
@@ -636,7 +636,9 @@
if { [string compare "extreme" "$platform"] } {
# match cisco config mode prompts too, such as router(config-if)#,
# but catalyst does not change in this fashion.
- regsub -all {^(.{1,11}).*([#>])$} $prompt {\1([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?} reprompt
+ regsub -lineanchor -- {^(.{1,11}).*([#>])$} $prompt {\1} junk
+ regsub -all -- {[\\]$} $junk {} reprompt
+ append reprompt {([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?}
} else {
set reprompt $prompt
}

Loading...