Commit c3526c9b authored by Amos Latteier's avatar Amos Latteier

First cut at cookie support for ZServer FTP server. This is needed for things...

First cut at cookie support for ZServer FTP server. This is needed for things like FTP authentication via UserDB.
parent 9dd04960
...@@ -104,7 +104,11 @@ class FTPRequest(HTTPRequest): ...@@ -104,7 +104,11 @@ class FTPRequest(HTTPRequest):
stdin=StringIO() stdin=StringIO()
env=self._get_env(path, command, channel, stdin) env=self._get_env(path, command, channel, stdin)
HTTPRequest.__init__(self, stdin, env, response, clean=1) HTTPRequest.__init__(self, stdin, env, response, clean=1)
self.cookies=channel.cookies
for k,v in self.cookies.items():
if not self.other.has_key(k):
self.other[k]=v
def _get_env(self, path, command, channel, stdin): def _get_env(self, path, command, channel, stdin):
"Returns a CGI style environment" "Returns a CGI style environment"
env={} env={}
......
...@@ -133,8 +133,9 @@ class CallbackPipe: ...@@ -133,8 +133,9 @@ class CallbackPipe:
return result return result
def make_response(callback,*args): def make_response(channel, callback, *args):
# XXX should this be the FTPResponse constructor instead? # XXX should this be the FTPResponse constructor instead?
r=FTPResponse(stdout=CallbackPipe(callback, args), stderr=StringIO()) r=FTPResponse(stdout=CallbackPipe(callback, args), stderr=StringIO())
r.setHeader('content-type','text/plain') r.setHeader('content-type','text/plain')
r.cookies=channel.cookies
return r return r
...@@ -163,6 +163,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -163,6 +163,7 @@ class zope_ftp_channel(ftp_channel):
self.userid='' self.userid=''
self.password='' self.password=''
self.path='/' self.path='/'
self.cookies={}
def _join_paths(self,*args): def _join_paths(self,*args):
path=apply(os.path.join,args) path=apply(os.path.join,args)
...@@ -218,7 +219,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -218,7 +219,7 @@ class zope_ftp_channel(ftp_channel):
self.listdir(dir, long) self.listdir(dir, long)
def listdir (self, path, long=0): def listdir (self, path, long=0):
response=make_response(self.listdir_completion, long) response=make_response(self, self.listdir_completion, long)
request=FTPRequest(path, 'LST', self, response) request=FTPRequest(path, 'LST', self, response)
handle(self.module, request, response) handle(self.module, request, response)
...@@ -252,7 +253,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -252,7 +253,7 @@ class zope_ftp_channel(ftp_channel):
def cmd_cwd (self, line): def cmd_cwd (self, line):
'change working directory' 'change working directory'
response=make_response(self.cwd_completion, response=make_response(self, self.cwd_completion,
self._join_paths(self.path,line[1])) self._join_paths(self.path,line[1]))
request=FTPRequest(line[1],'CWD',self,response) request=FTPRequest(line[1],'CWD',self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -297,7 +298,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -297,7 +298,7 @@ class zope_ftp_channel(ftp_channel):
if len (line) != 2: if len (line) != 2:
self.command.not_understood (string.join (line)) self.command.not_understood (string.join (line))
return return
response=make_response(self.mdtm_completion) response=make_response(self, self.mdtm_completion)
request=FTPRequest(line[1],'MDTM',self,response) request=FTPRequest(line[1],'MDTM',self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -324,7 +325,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -324,7 +325,7 @@ class zope_ftp_channel(ftp_channel):
if len (line) != 2: if len (line) != 2:
self.command.not_understood (string.join (line)) self.command.not_understood (string.join (line))
return return
response=make_response(self.size_completion) response=make_response(self, self.size_completion)
request=FTPRequest(line[1],'SIZE',self,response) request=FTPRequest(line[1],'SIZE',self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -343,7 +344,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -343,7 +344,7 @@ class zope_ftp_channel(ftp_channel):
if len(line) < 2: if len(line) < 2:
self.command_not_understood (string.join (line)) self.command_not_understood (string.join (line))
return return
response=make_response(self.retr_completion,line[1]) response=make_response(self, self.retr_completion, line[1])
request=FTPRequest(line[1],'RETR',self,response) request=FTPRequest(line[1],'RETR',self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -388,7 +389,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -388,7 +389,7 @@ class zope_ftp_channel(ftp_channel):
def stor_callback(self,path,data): def stor_callback(self,path,data):
'callback to do the STOR, after we have the input' 'callback to do the STOR, after we have the input'
response=make_response(self.stor_completion) response=make_response(self, self.stor_completion)
request=FTPRequest(path,'STOR',self,response,stdin=data) request=FTPRequest(path,'STOR',self,response,stdin=data)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -407,7 +408,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -407,7 +408,7 @@ class zope_ftp_channel(ftp_channel):
self.command.not_understood (string.join (line)) self.command.not_understood (string.join (line))
return return
path,id=os.path.split(line[1]) path,id=os.path.split(line[1])
response=make_response(self.dele_completion) response=make_response(self, self.dele_completion)
request=FTPRequest(path,('DELE',id),self,response) request=FTPRequest(path,('DELE',id),self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -425,7 +426,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -425,7 +426,7 @@ class zope_ftp_channel(ftp_channel):
self.command.not_understood (string.join (line)) self.command.not_understood (string.join (line))
return return
path,id=os.path.split(line[1]) path,id=os.path.split(line[1])
response=make_response(self.mkd_completion) response=make_response(self, self.mkd_completion)
request=FTPRequest(path,('MKD',id),self,response) request=FTPRequest(path,('MKD',id),self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -447,7 +448,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -447,7 +448,7 @@ class zope_ftp_channel(ftp_channel):
self.command.not_understood (string.join (line)) self.command.not_understood (string.join (line))
return return
path,id=os.path.split(line[1]) path,id=os.path.split(line[1])
response=make_response(self.rmd_completion) response=make_response(self, self.rmd_completion)
request=FTPRequest(path,('RMD',id),self,response) request=FTPRequest(path,('RMD',id),self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -491,7 +492,8 @@ class zope_ftp_channel(ftp_channel): ...@@ -491,7 +492,8 @@ class zope_ftp_channel(ftp_channel):
path=self.userid[i+1:] path=self.userid[i+1:]
self.userid=self.userid[:i] self.userid=self.userid[:i]
self.anonymous=None self.anonymous=None
response=make_response(self.pass_completion, self._join_paths('/',path)) response=make_response(self, self.pass_completion,
self._join_paths('/',path))
request=FTPRequest(path,'PASS',self,response) request=FTPRequest(path,'PASS',self,response)
handle(self.module,request,response) handle(self.module,request,response)
......
...@@ -104,7 +104,11 @@ class FTPRequest(HTTPRequest): ...@@ -104,7 +104,11 @@ class FTPRequest(HTTPRequest):
stdin=StringIO() stdin=StringIO()
env=self._get_env(path, command, channel, stdin) env=self._get_env(path, command, channel, stdin)
HTTPRequest.__init__(self, stdin, env, response, clean=1) HTTPRequest.__init__(self, stdin, env, response, clean=1)
self.cookies=channel.cookies
for k,v in self.cookies.items():
if not self.other.has_key(k):
self.other[k]=v
def _get_env(self, path, command, channel, stdin): def _get_env(self, path, command, channel, stdin):
"Returns a CGI style environment" "Returns a CGI style environment"
env={} env={}
......
...@@ -133,8 +133,9 @@ class CallbackPipe: ...@@ -133,8 +133,9 @@ class CallbackPipe:
return result return result
def make_response(callback,*args): def make_response(channel, callback, *args):
# XXX should this be the FTPResponse constructor instead? # XXX should this be the FTPResponse constructor instead?
r=FTPResponse(stdout=CallbackPipe(callback, args), stderr=StringIO()) r=FTPResponse(stdout=CallbackPipe(callback, args), stderr=StringIO())
r.setHeader('content-type','text/plain') r.setHeader('content-type','text/plain')
r.cookies=channel.cookies
return r return r
...@@ -163,6 +163,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -163,6 +163,7 @@ class zope_ftp_channel(ftp_channel):
self.userid='' self.userid=''
self.password='' self.password=''
self.path='/' self.path='/'
self.cookies={}
def _join_paths(self,*args): def _join_paths(self,*args):
path=apply(os.path.join,args) path=apply(os.path.join,args)
...@@ -218,7 +219,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -218,7 +219,7 @@ class zope_ftp_channel(ftp_channel):
self.listdir(dir, long) self.listdir(dir, long)
def listdir (self, path, long=0): def listdir (self, path, long=0):
response=make_response(self.listdir_completion, long) response=make_response(self, self.listdir_completion, long)
request=FTPRequest(path, 'LST', self, response) request=FTPRequest(path, 'LST', self, response)
handle(self.module, request, response) handle(self.module, request, response)
...@@ -252,7 +253,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -252,7 +253,7 @@ class zope_ftp_channel(ftp_channel):
def cmd_cwd (self, line): def cmd_cwd (self, line):
'change working directory' 'change working directory'
response=make_response(self.cwd_completion, response=make_response(self, self.cwd_completion,
self._join_paths(self.path,line[1])) self._join_paths(self.path,line[1]))
request=FTPRequest(line[1],'CWD',self,response) request=FTPRequest(line[1],'CWD',self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -297,7 +298,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -297,7 +298,7 @@ class zope_ftp_channel(ftp_channel):
if len (line) != 2: if len (line) != 2:
self.command.not_understood (string.join (line)) self.command.not_understood (string.join (line))
return return
response=make_response(self.mdtm_completion) response=make_response(self, self.mdtm_completion)
request=FTPRequest(line[1],'MDTM',self,response) request=FTPRequest(line[1],'MDTM',self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -324,7 +325,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -324,7 +325,7 @@ class zope_ftp_channel(ftp_channel):
if len (line) != 2: if len (line) != 2:
self.command.not_understood (string.join (line)) self.command.not_understood (string.join (line))
return return
response=make_response(self.size_completion) response=make_response(self, self.size_completion)
request=FTPRequest(line[1],'SIZE',self,response) request=FTPRequest(line[1],'SIZE',self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -343,7 +344,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -343,7 +344,7 @@ class zope_ftp_channel(ftp_channel):
if len(line) < 2: if len(line) < 2:
self.command_not_understood (string.join (line)) self.command_not_understood (string.join (line))
return return
response=make_response(self.retr_completion,line[1]) response=make_response(self, self.retr_completion, line[1])
request=FTPRequest(line[1],'RETR',self,response) request=FTPRequest(line[1],'RETR',self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -388,7 +389,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -388,7 +389,7 @@ class zope_ftp_channel(ftp_channel):
def stor_callback(self,path,data): def stor_callback(self,path,data):
'callback to do the STOR, after we have the input' 'callback to do the STOR, after we have the input'
response=make_response(self.stor_completion) response=make_response(self, self.stor_completion)
request=FTPRequest(path,'STOR',self,response,stdin=data) request=FTPRequest(path,'STOR',self,response,stdin=data)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -407,7 +408,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -407,7 +408,7 @@ class zope_ftp_channel(ftp_channel):
self.command.not_understood (string.join (line)) self.command.not_understood (string.join (line))
return return
path,id=os.path.split(line[1]) path,id=os.path.split(line[1])
response=make_response(self.dele_completion) response=make_response(self, self.dele_completion)
request=FTPRequest(path,('DELE',id),self,response) request=FTPRequest(path,('DELE',id),self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -425,7 +426,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -425,7 +426,7 @@ class zope_ftp_channel(ftp_channel):
self.command.not_understood (string.join (line)) self.command.not_understood (string.join (line))
return return
path,id=os.path.split(line[1]) path,id=os.path.split(line[1])
response=make_response(self.mkd_completion) response=make_response(self, self.mkd_completion)
request=FTPRequest(path,('MKD',id),self,response) request=FTPRequest(path,('MKD',id),self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -447,7 +448,7 @@ class zope_ftp_channel(ftp_channel): ...@@ -447,7 +448,7 @@ class zope_ftp_channel(ftp_channel):
self.command.not_understood (string.join (line)) self.command.not_understood (string.join (line))
return return
path,id=os.path.split(line[1]) path,id=os.path.split(line[1])
response=make_response(self.rmd_completion) response=make_response(self, self.rmd_completion)
request=FTPRequest(path,('RMD',id),self,response) request=FTPRequest(path,('RMD',id),self,response)
handle(self.module,request,response) handle(self.module,request,response)
...@@ -491,7 +492,8 @@ class zope_ftp_channel(ftp_channel): ...@@ -491,7 +492,8 @@ class zope_ftp_channel(ftp_channel):
path=self.userid[i+1:] path=self.userid[i+1:]
self.userid=self.userid[:i] self.userid=self.userid[:i]
self.anonymous=None self.anonymous=None
response=make_response(self.pass_completion, self._join_paths('/',path)) response=make_response(self, self.pass_completion,
self._join_paths('/',path))
request=FTPRequest(path,'PASS',self,response) request=FTPRequest(path,'PASS',self,response)
handle(self.module,request,response) handle(self.module,request,response)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment