From b88919bea4b222a616adbdd2b82fc262a14afc8d Mon Sep 17 00:00:00 2001 From: Tar Committer Date: Mon, 5 Feb 2001 17:47:18 +0000 Subject: Imported from rancid-2.1.tar.gz. --- bin/clogin.in | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'bin/clogin.in') diff --git a/bin/clogin.in b/bin/clogin.in index e239d50..40d0d57 100755 --- a/bin/clogin.in +++ b/bin/clogin.in @@ -53,11 +53,17 @@ set do_enapasswd 1 # Find the user in the ENV, or use the unix userid. if {[ info exists env(CISCO_USER) ] } { set default_user $env(CISCO_USER) +} elseif {[ info exists env(USER) ]} { + set default_user $env(USER) } else { # This uses "id" which I think is portable. At least it has existed # (without options) on all machines/OSes I've been on recently - # unlike whoami or id -nu. - regexp {\(([^)]*)} [exec id] junk default_user + if [ catch {exec id} reason ] { + send_error "Error: could not exec id: $reason\n" + exit 1 + } + regexp {\(([^)]*)} "$reason" junk default_user } # Sometimes routers take awhile to answer (the default is 10 sec) @@ -213,36 +219,39 @@ proc label { host } { # add password sl* pete cow # add password at* steve # add password * hanky-pie -proc add {var args} { global $var ;lappend $var $args} +proc add {var args} { global int_$var ; lappend int_$var $args} +proc include {args} { + global env + regsub -all "(^{|}$)" $args {} args + if { [ regexp "^/" $args ignore ] == 0 } { + set args $env(HOME)/$args + } + source_password_file $args +} + proc find {var router} { - source_password_file - upvar $var list - if { [info exists list] } { - foreach line $list { - if { [string match [lindex $line 0] $router ] } { - return [lrange $line 1 end] - } - } - } - return {} -} + upvar int_$var list + if { [info exists list] } { + foreach line $list { + if { [string match [lindex $line 0] $router ] } { + return [lrange $line 1 end] + } + } + } + return {} +} # Loads the password file. Note that as this file is tcl, and that # it is sourced, the user better know what to put in there, as it # could install more than just password info... I will assume however, # that a "bad guy" could just as easy put such code in the clogin # script, so I will leave .cloginrc as just an extention of that script -proc source_password_file { } { - global env password_file read_password_file - if { [info exists read_password_file] } { return } - if { [info exists password_file] == 0 } { - set password_file $env(HOME)/.cloginrc - } +proc source_password_file { password_file } { + global env if { ! [file exists $password_file] } { send_user "Error: password file ($password_file) does not exist\n" exit 1 } - set read_password_file 1 file stat $password_file fileinfo if { [expr ($fileinfo(mode) & 007)] != 0000 } { send_user "Error: $password_file must not be world readable/writable\n" @@ -458,6 +467,7 @@ proc run_commands { prompt command } { # # For each router... (this is main loop) # +source_password_file $password_file set in_proc 0 foreach router [lrange $argv $i end] { set router [string tolower $router] @@ -530,7 +540,7 @@ foreach router [lrange $argv $i end] { # Figure out prompts set u_prompt [find userprompt $router] - if { "$u_prompt" == "" } { set u_prompt "(Username|login):" } + if { "$u_prompt" == "" } { set u_prompt "(Username|login|user name):" } set p_prompt [find passprompt $router] if { "$p_prompt" == "" } { set p_prompt "(\[Pp]assword|passwd):" } set e_prompt [find enableprompt $router] @@ -573,6 +583,7 @@ foreach router [lrange $argv $i end] { send "term length 0\r" } else { send "set length 0\r" + send "set logging session disable\r" } expect $prompt {} source $sfile -- cgit