[rancid] Error with 10 character prompts

heasley heas at shrubbery.net
Sun Mar 1 16:18:41 UTC 2015


Sat, Feb 28, 2015 at 12:18:17AM +0000, Michael Newton:
> 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().

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
     }



More information about the Rancid-discuss mailing list