diff options
Diffstat (limited to 'bin/jlogin.in')
-rwxr-xr-x | bin/jlogin.in | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/bin/jlogin.in b/bin/jlogin.in index 28e773b..e0ac844 100755 --- a/bin/jlogin.in +++ b/bin/jlogin.in @@ -47,11 +47,17 @@ set passphrase "" # 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) @@ -184,11 +190,18 @@ 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 + upvar int_$var list if { [info exists list] } { foreach line $list { if { [string match [lindex $line 0] $router ] } { @@ -204,18 +217,12 @@ proc find {var router} { # 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" @@ -400,6 +407,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] |