[rancid] reason for autoenable?
john heasley
heas at shrubbery.net
Fri Aug 27 00:07:49 UTC 2010
Thu, Aug 19, 2010 at 03:04:25PM -0400, Lee:
> ... more newbie questions
>
> If the userid automatically gets priv level 15 at login and you forget
> to set the autoenable flag the clogin script times out waiting for the
> ">" prompt. Why was the autoenable flag added instead of changing the
> expect script to look for # or >? It seems nicer not to require a
> flag...
i'll blame Hank again. autoenable just simplifies the code by moving the
burden.
I have a patch to remove it, but it still wants to enable. i'd like poeple
to test before its is committed. see attached.
-------------- next part --------------
Index: bin/clogin.in
===================================================================
--- bin/clogin.in (revision 2244)
+++ bin/clogin.in (working copy)
@@ -312,7 +312,7 @@
# returns: 0 on success, 1 on failure, -1 if rsh was used successfully
proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
global command spawn_id in_proc do_command do_script platform
- global prompt u_prompt p_prompt e_prompt sshcmd
+ global prompt prompt_match u_prompt p_prompt e_prompt sshcmd
set in_proc 1
set uprompt_seen 0
@@ -542,7 +542,10 @@
}
exp_continue
}
- -re "$prompt" { break; }
+ -re "$prompt" {
+ set prompt_match $expect_out(0,string);
+ break;
+ }
"Login invalid" {
send_user "\nError: Invalid login: $router\n";
catch {close}; catch {wait}; return 1
@@ -719,6 +722,8 @@
source_password_file $password_file
set in_proc 0
set exitval 0
+set prompt_match ""
+set enable 0
foreach router [lrange $argv $i end] {
set router [string tolower $router]
# attempt at platform switching.
@@ -731,26 +736,8 @@
set timeout $timeoutdflt
}
- # Figure out the prompt.
- # autoenable is off by default. If we have it defined, it was done
- # on the command line. If it is not specifically set on the command
- # line, check the password file.
- if $avautoenable {
- set autoenable 1
- set enable 0
- set prompt "(#| \\(enable\\))"
- } else {
- set ae [find autoenable $router]
- if { "$ae" == "1" } {
- set autoenable 1
- set enable 0
- set prompt "(#| \\(enable\\))"
- } else {
- set autoenable 0
- set enable $avenable
- set prompt ">"
- }
- }
+ # Default prompt.
+ set prompt "(>|#| \\(enable\\))"
# look for noenable option in .cloginrc
if { [find noenable $router] != "" } {
@@ -845,6 +832,22 @@
# if login failed or rsh was unsuccessful, move on to the next device
continue
}
+ # Figure out the prompt.
+ if { [regexp -- "(#| \\(enable\\))" $prompt_match junk] == 1 } {
+ set enable 0
+ } else {
+ if { $avenable == 0 } {
+ set enable 0
+ } else {
+ set ne [find noenable $router]
+ set ae [find autoenable $router]
+ if { "$ne" == "1" || "$ae" == "1" || $avautoenable } {
+ set enable 0
+ } else {
+ set enable 1
+ }
+ }
+ }
if { $enable } {
if {[do_enable $enauser $enapasswd]} {
if { $do_command || $do_script } {
More information about the Rancid-discuss
mailing list