Rev 69: Backport chmod too. in file:///net/bigmamac/Volumes/home/vila/.bazaar/plugins/local_test_server/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Mar 18 14:36:03 GMT 2009
At file:///net/bigmamac/Volumes/home/vila/.bazaar/plugins/local_test_server/
------------------------------------------------------------
revno: 69
revision-id: v.ladeuil+lp at free.fr-20090318143602-2y1utx8t1w8bvemo
parent: v.ladeuil+lp at free.fr-20090318105612-k891u1n5the4x7sq
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: local_test_server
timestamp: Wed 2009-03-18 15:36:02 +0100
message:
Backport chmod too.
* bin/pyftpdlib:
(BzrConformingFS): Needed at least for chmod called by ftp_SITE_CHMOD.
(FTPHandler.ftp_SITE_CHMOD): Implement chmod.
-------------- next part --------------
=== modified file 'bin/pyftpdlib'
--- a/bin/pyftpdlib 2009-03-18 10:56:12 +0000
+++ b/bin/pyftpdlib 2009-03-18 14:36:02 +0000
@@ -7,11 +7,10 @@
absolutely useless when running as a separate process is still a complete
mystery :-/
"""
+import os
import sys
from pyftpdlib import ftpserver
-# An empty password is valid, hence the arg is neither mandatory not forbidden
-ftpserver.proto_cmds['PASS'].arg_needed = None
class AnonymousWithWriteAccessAuthorizer(ftpserver.DummyAuthorizer):
@@ -23,8 +22,16 @@
raise ftpserver.AuthorizerError('No such permission "%s"' %p)
+class BzrConformingFS(ftpserver.AbstractedFS):
+
+ def chmod(self, path, mode):
+ return os.chmod(path, mode)
+
+
class BZRConformingFTPHandler(ftpserver.FTPHandler):
+ abstracted_fs = BzrConformingFS
+
def __init__(self, conn, server):
ftpserver.FTPHandler.__init__(self, conn, server)
self.authorizer = server.authorizer
@@ -51,6 +58,39 @@
else:
ftpserver.FTPHandler.ftp_NLST(self, path)
+ def ftp_SITE_CHMOD(self, line):
+ try:
+ mode, path = line.split(None, 1)
+ mode = int(mode, 8)
+ except ValueError:
+ # We catch both malformed line and malformed mode with the same
+ # ValueError.
+ self.respond("500 'SITE CHMOD %s': command not understood."
+ % line)
+ self.log('FAIL SITE CHMOD ' % line)
+ return
+ ftp_path = self.fs.fs2ftp(path)
+ try:
+ self.run_as_current_user(self.fs.chmod, self.fs.ftp2fs(path), mode)
+ except OSError, err:
+ why = ftpserver._strerror(err)
+ self.log('FAIL SITE CHMOD 0%03o "%s". %s.' % (mode, ftp_path, why))
+ self.respond('550 %s.' % why)
+ else:
+ self.log('OK SITE CHMOD 0%03o "%s".' % (mode, ftp_path))
+ self.respond('200 SITE CHMOD succesful.')
+
+
+# pyftpdlib says to define SITE commands by declaring ftp_SITE_<CMD> methods,
+# but fails to recognize them.
+ftpserver.proto_cmds['SITE CHMOD'] = ftpserver._CommandProperty(
+ perm='w', # Best fit choice even if not exactly right (can be d, f or m too)
+ auth_needed=True, arg_needed=True, check_path=False,
+ help='Syntax: SITE CHMOD <SP> octal_mode_bits file-name (chmod file)',
+ )
+# An empty password is valid, hence the arg is neither mandatory not forbidden
+ftpserver.proto_cmds['PASS'].arg_needed = None
+
class ftp_server(ftpserver.FTPServer):
More information about the bazaar-commits
mailing list