summaryrefslogtreecommitdiffstats
path: root/bin/flogin.in
diff options
context:
space:
mode:
authorTar Committer <tar@ocjtech.us>2001-02-05 17:47:18 +0000
committerTar Committer <tar@ocjtech.us>2001-02-05 17:47:18 +0000
commitb88919bea4b222a616adbdd2b82fc262a14afc8d (patch)
treea75da71b0e2f905f35d2d7cbfd161df97a3d2c63 /bin/flogin.in
parent25c2b7c2c8a333b276c3499bcce004137d4b4fe0 (diff)
downloadrancid-b88919bea4b222a616adbdd2b82fc262a14afc8d.tar.gz
rancid-b88919bea4b222a616adbdd2b82fc262a14afc8d.tar.xz
rancid-b88919bea4b222a616adbdd2b82fc262a14afc8d.zip
Imported from rancid-2.1.tar.gz.rancid-2.1
Diffstat (limited to 'bin/flogin.in')
-rwxr-xr-xbin/flogin.in66
1 files changed, 40 insertions, 26 deletions
diff --git a/bin/flogin.in b/bin/flogin.in
index a43ddda..6c82594 100755
--- a/bin/flogin.in
+++ b/bin/flogin.in
@@ -55,12 +55,18 @@ 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 -
+ # 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
@@ -211,18 +217,26 @@ 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
@@ -230,18 +244,17 @@ 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
- }
- 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"
- exit 1
- }
+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
+ }
+ file stat $password_file fileinfo
+ if { [expr ($fileinfo(mode) & 007)] != 0000 } {
+ send_user "Error: $password_file must not be world readable/writable\n"
+ exit 1
+ }
if [ catch {source $password_file} reason ] {
send_user "Error: $reason\n"
exit 1
@@ -423,6 +436,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]