diff options
author | Tar Committer <tar@ocjtech.us> | 2001-02-05 17:47:18 +0000 |
---|---|---|
committer | Tar Committer <tar@ocjtech.us> | 2001-02-05 17:47:18 +0000 |
commit | b88919bea4b222a616adbdd2b82fc262a14afc8d (patch) | |
tree | a75da71b0e2f905f35d2d7cbfd161df97a3d2c63 /bin/elogin.in | |
parent | 25c2b7c2c8a333b276c3499bcce004137d4b4fe0 (diff) | |
download | rancid-2.1.tar.gz rancid-2.1.tar.xz rancid-2.1.zip |
Imported from rancid-2.1.tar.gz.rancid-2.1
Diffstat (limited to 'bin/elogin.in')
-rwxr-xr-x | bin/elogin.in | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/bin/elogin.in b/bin/elogin.in index 5ef908b..89f7a99 100755 --- a/bin/elogin.in +++ b/bin/elogin.in @@ -47,12 +47,18 @@ set do_passwd 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) set timeout 45 @@ -199,36 +205,40 @@ 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] - } + upvar int_$var list + if { [info exists list] } { + foreach line $list { + if { [string match [lindex $line 0] $router ] } { + return [lrange $line 1 end] + } + } } - } - return {} + 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" @@ -240,6 +250,7 @@ proc source_password_file { } { } } + # Log into the router. proc login { router user userpswd passwd prompt cyphertype } { global spawn_id in_proc do_command do_script @@ -372,6 +383,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] |