Attachment "ftpd.diff" to
ticket [1720144fff]
added by
andreas_kupries
2007-05-23 03:17:38.
Index: ftpd.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/ftpd/ftpd.tcl,v
retrieving revision 1.26
diff -w -u -r1.26 ftpd.tcl
--- ftpd.tcl 5 Oct 2004 19:15:52 -0000 1.26
+++ ftpd.tcl 22 May 2007 20:16:16 -0000
@@ -534,8 +534,8 @@
switch -exact -- $data(state) {
command {
gets $sock command
- set parts [split $command]
- set cmd [string toupper [lindex $parts 0]]
+ regexp {^([^ ]+) (.*)$} $command -> cmd argument
+ set cmd [string toupper $cmd]
auto_load ::ftpd::command::$cmd
if {($data(access) == 0) && ((![info exists data(user)]) || \
($data(user) == "")) && (![string equal $cmd "USER"])} {
@@ -550,7 +550,7 @@
puts $sock "530 Please login with USER and PASS."
} elseif {[info command ::ftpd::command::$cmd] != ""} {
Log debug $command
- ::ftpd::command::$cmd $sock [lrange $parts 1 end]
+ ::ftpd::command::$cmd $sock $argument
catch {flush $sock}
} else {
Log error "Unknown command: $cmd"
@@ -727,10 +727,9 @@
# The data is copied to from the socket data(sock2) to the
# writable channel to create a file.
-proc ::ftpd::command::APPE {sock list} {
+proc ::ftpd::command::APPE {sock filename} {
upvar #0 ::ftpd::$sock data
- set filename [lindex $list 0]
set path [file join $data(cwd) [string trimleft $filename /]]
if {[::ftpd::hasCallback authFileCmd]} {
set cmd $::ftpd::cfg(authFileCmd)
@@ -791,11 +790,9 @@
# Side Effects:
# Changes the data(cwd) to the appropriate directory.
-proc ::ftpd::command::CWD {sock list} {
+proc ::ftpd::command::CWD {sock relativepath} {
upvar #0 ::ftpd::$sock data
- set relativepath [lindex $list 0]
-
if {[string equal $relativepath .]} {
puts $sock "250 CWD command successful."
return
@@ -826,10 +823,9 @@
# Side Effects:
# The specified file is deleted.
-proc ::ftpd::command::DELE {sock list} {
+proc ::ftpd::command::DELE {sock filename} {
upvar #0 ::ftpd::$sock data
- set filename [lindex $list 0]
set path [file join $data(cwd) [string trimleft $filename /]]
if {[::ftpd::hasCallback authFileCmd]} {
set cmd $::ftpd::cfg(authFileCmd)
@@ -861,11 +857,11 @@
# Side Effects:
# Displays a helpful message.
-proc ::ftpd::command::HELP {sock list} {
+proc ::ftpd::command::HELP {sock command} {
upvar #0 ::ftpd::$sock data
- if {[llength $list] > 0} {
- set command [string toupper [lindex $list 0]]
+ if {$command != ""} {
+ set command [string toupper $command]
if {![info exists ::ftpd::commands($command)]} {
puts $sock "502 Unknown command '$command'."
} elseif {[info commands ::ftpd::command::$command] == ""} {
@@ -913,8 +909,7 @@
# Side Effects:
# A listing of files is written to the socket.
-proc ::ftpd::command::LIST {sock list} {
- set filename [lindex $list 0]
+proc ::ftpd::command::LIST {sock filename} {
::ftpd::List $sock $filename list
return
}
@@ -934,10 +929,9 @@
# Side Effects:
# Prints the modification time of the specified file to the socket.
-proc ::ftpd::command::MDTM {sock list} {
+proc ::ftpd::command::MDTM {sock filename} {
upvar #0 ::ftpd::$sock data
- set filename [lindex $list 0]
set path [file join $data(cwd) [string trimleft $filename /]]
if {[catch {::ftpd::Fs mtime $path $sock} msg]} {
puts $sock "500 MDTM Failed: $path $msg"
@@ -960,10 +954,9 @@
# Side Effects:
# The directory specified by $path (if it exists) is deleted.
-proc ::ftpd::command::MKD {sock list} {
+proc ::ftpd::command::MKD {sock filename} {
upvar #0 ::ftpd::$sock data
- set filename [lindex $list 0]
set path [file join $data(cwd) [string trimleft $filename /]]
if {[::ftpd::hasCallback authFileCmd]} {
@@ -1016,8 +1009,7 @@
# Side Effects:
# A listing of file stats is written to the socket.
-proc ::ftpd::command::NLST {sock list} {
- set filename [lindex $list 0]
+proc ::ftpd::command::NLST {sock filename} {
::ftpd::List $sock $filename nlst
return
}
@@ -1041,14 +1033,14 @@
# The user is accepted, or an error is logged and the user/password is
# denied..
-proc ::ftpd::command::PASS {sock list} {
+proc ::ftpd::command::PASS {sock password} {
upvar #0 ::ftpd::$sock data
- if {[llength $list] == 0} {
+ if {$password == ""} {
puts $sock "530 Please login with USER and PASS."
return
}
- set data(pass) [lindex $list 0]
+ set data(pass) $password
::ftpd::Log debug "pass <$data(pass)>"
@@ -1095,9 +1087,9 @@
# Side Effects:
# A new socket, data(sock2), is opened.
-proc ::ftpd::command::PORT {sock list} {
+proc ::ftpd::command::PORT {sock numbers} {
upvar #0 ::ftpd::$sock data
- set x [split [lindex $list 0] ,]
+ set x [split $numbers ,]
::ftpd::FinishData $sock
@@ -1208,10 +1200,9 @@
# The file specified by $path (if it exists) is copied to the socket
# data(sock2) otherwise a 'Copy Failed' message is output.
-proc ::ftpd::command::RETR {sock list} {
+proc ::ftpd::command::RETR {sock filename} {
upvar #0 ::ftpd::$sock data
- set filename [lindex $list 0]
set path [file join $data(cwd) [string trimleft $filename /]]
if {[::ftpd::hasCallback authFileCmd]} {
@@ -1250,10 +1241,9 @@
# Side Effects:
# The directory specified by $path (if it exists) is deleted.
-proc ::ftpd::command::RMD {sock list} {
+proc ::ftpd::command::RMD {sock filename} {
upvar #0 ::ftpd::$sock data
- set filename [lindex $list 0]
set path [file join $data(cwd) [string trimleft $filename /]]
if {[::ftpd::hasCallback authFileCmd]} {
@@ -1286,10 +1276,9 @@
# If the file specified by $path exists, then store the name and request
# the next name.
-proc ::ftpd::command::RNFR {sock list} {
+proc ::ftpd::command::RNFR {sock filename} {
upvar #0 ::ftpd::$sock data
- set filename [lindex $list 0]
set path [file join $data(cwd) [string trimleft $filename /]]
if {[file exists $path]} {
@@ -1325,13 +1314,13 @@
# Side Effects:
# The specified file is renamed.
-proc ::ftpd::command::RNTO {sock list} {
+proc ::ftpd::command::RNTO {sock filename} {
- if {[llength $list] == 0} {
+ if {$filename == ""} {
puts $sock "500 'RNTO': command not understood."
return
}
- set filename [lindex $list 0]
+
set path [file join $data(cwd) [string trimleft $filename /]]
if {![info exists data(renameFrom)]} {
@@ -1372,10 +1361,9 @@
# Side Effects:
# Prints the size of the specified file to the socket.
-proc ::ftpd::command::SIZE {sock list} {
+proc ::ftpd::command::SIZE {sock filename} {
upvar #0 ::ftpd::$sock data
- set filename [lindex $list 0]
set path [file join $data(cwd) [string trimleft $filename /]]
if {[catch {::ftpd::Fs size $path $sock} msg]} {
puts $sock "500 SIZE Failed: $path $msg"
@@ -1401,10 +1389,9 @@
# The data is copied to from the socket data(sock2) to the
# writable channel to create a file.
-proc ::ftpd::command::STOR {sock list} {
+proc ::ftpd::command::STOR {sock filename} {
upvar #0 ::ftpd::$sock data
- set filename [lindex $list 0]
set path [file join $data(cwd) [string trimleft $filename /]]
if {[::ftpd::hasCallback authFileCmd]} {
set cmd $::ftpd::cfg(authFileCmd)
@@ -1445,10 +1432,9 @@
# The data is copied to from the socket data(sock2) to the
# writable channel to create a file.
-proc ::ftpd::command::STOU {sock list} {
+proc ::ftpd::command::STOU {sock filename} {
upvar #0 ::ftpd::$sock data
- set filename [lindex $list 0]
set path [file join $data(cwd) [string trimleft $filename /]]
if {[::ftpd::hasCallback authFileCmd]} {
set cmd $::ftpd::cfg(authFileCmd)
@@ -1529,9 +1515,9 @@
# The translation mode of the data channel is changed to the appropriate
# mode.
-proc ::ftpd::command::TYPE {sock list} {
+proc ::ftpd::command::TYPE {sock type} {
upvar #0 ::ftpd::$sock data
- set type [lindex $list 0]
+
if {[string compare i [string tolower $type]] == 0} {
set data(mode) binary
} else {
@@ -1560,14 +1546,14 @@
# Side Effects:
# A message is printed asking for the password.
-proc ::ftpd::command::USER {sock list} {
+proc ::ftpd::command::USER {sock username} {
upvar #0 ::ftpd::$sock data
- if {[llength $list] == 0} {
+ if {$username == ""} {
puts $sock "530 Please login with USER and PASS."
return
}
- set data(user) [lindex $list 0]
+ set data(user) $username
puts $sock "331 Password Required"
::ftpd::Log debug "user <$data(user)>"
@@ -1999,7 +1985,7 @@
##
## Implementation of passive command
##
-proc ::ftpd::command::PASV {sock args} {
+proc ::ftpd::command::PASV {sock argument} {
upvar #0 ::ftpd::$sock data
set data(sock2a) [socket -server [list ::ftpd::PasvAccept $sock] 0]