From 722fb7049d406174d3f4afc963059a2eb71b47f8 Mon Sep 17 00:00:00 2001 From: Tore Anderson Date: Tue, 22 May 2007 16:30:16 +0200 Subject: Fixing Extreme support Hi. I finally got around to fix RANCID so it worked flawlessly with my Extreme devices (I've got switches running both ExtremeWare and XOS): * Identify XOS as a separate platform, this is done by looking for a period before the command number instead of a colon. Fix the prompt match regex in xrancid to recognise both cases. * Always "disable clipaging [session]" to avoid pagination, which earlier caused me to lose a configuration line every 24 or so lines for XOS. Remove comments suggesting such commands isn't available. * XOS doesn't have a marker for the end of the configuration file, so use a prompt match to look for the end too. Also make it so that invalid commands are detected, thus preventing an error message to be mistaken for the complete configuration. * Work around a strange bug in XOS where once in a while the line containing the SSH key will only contain the last seven hundred or so octets (causing spurious diffs to be mailed all the time). If we see a line containing only hex octets, assume we hit the bug and replace it like we would the complete line. * Fix the while loop that's supposed to swallow the SSL privkey for ExtremeWare devices, which earlier caused the next valid configuration line following the key to be swallowed also. * Remove special-casing of the quit/exit command for Extreme products, use "quit" always. This fixes all the bugs I experienced using RANCID with Extreme devices running XOS 11.3.3.7 and EW 7.5e.2.6 / 7.5e.3.8. Hope it's useful to others and that it can be applied to the next alpha release. Regards -- Tore Anderson --- bin/xrancid.in | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'bin/xrancid.in') diff --git a/bin/xrancid.in b/bin/xrancid.in index 96b99ef..4a34fca 100644 --- a/bin/xrancid.in +++ b/bin/xrancid.in @@ -279,9 +279,10 @@ sub WriteTerm { while () { tr/\015//d; - last if(/^$prompt/); + tr/\007//d; next if(/^\s*$/); return(0) if(/^syntax error at token /i); + return(0) if(/^%% Invalid input detected at /i); # the pager can not be disabled per-session on the PIX s/^<-+ More -+>\s*//; return(0) if ($found_end); @@ -317,14 +318,28 @@ sub WriteTerm { ProcessHistory("COMMENTS","keysort","H0","# $1 \n"); next; } - if (/configure ssh2 key/ && $filter_pwds >= 1) { + # XOS (at least version 11.3.3.7) is buggy and sometimees outputs only + # the last 702 octets of the SSH key... make sure to strip it anyway + print STDERR "D \"$_\" D\n"; + if (/^(configure ssh2 key pregenerated|[a-f\d]{2}(:[a-f\d]{2}){700,}\s*$)/ && $filter_pwds >= 1) { + ProcessHistory("COMMENTS","keysort","H0","# configure ssh2 key \n"); + # Only EW has a multiline key (terminated by a blank line) + # XOS has only one line so jump to the next iteration immediately + # to make sure we don't lose the next config statement + next unless /^configure ssh2 key pregenerated$/; + while () { + last if (/^\s*\r?$/); + } + next; + } + # This changes each time the configuration is shown, so remove it + # unconditionally as it is documented in rancid.conf(5). + if (/configure ssl privkey/) { ProcessHistory("COMMENTS","keysort","H0","# $_# \n"); while () { - if (/^(#|enable|conf|disable|unconf)/) { - tr/\015//d; - last; - } + last if (/^\.\r?$/); } + next; } # filter out any RCS/CVS tags to avoid confusing local CVS storage @@ -366,7 +381,7 @@ sub WriteTerm { # catch anything that wasnt match above. ProcessHistory("COMMENTS","keysort","H0","$_"); # end of config - if (/^# End of configuration file/i) { + if (/^($prompt|# End of configuration file)/i) { printf STDERR " End WriteTerm: $_" if ($debug); $found_end = 1; return(0); @@ -462,7 +477,7 @@ TOP: while() { if (!defined($prompt)) { $prompt = ($_ =~ /^([^#]+#)/)[0]; $prompt =~ s/([][}{)(\\])/\\$1/g; - $prompt =~ s/[:.](\d+ ?)#/:\\d+ ?#/; + $prompt =~ s/[:.](\d+ ?)#/[:.]\\d+ ?#/; $prompt =~ s/\*/\\\*/; print STDERR ("PROMPT MATCH: $prompt\n") if ($debug); } -- cgit