5
5
# twistd -noy sftp.tac
6
6
# or similar. Refer to the twistd(1) man page for details.
10
from twisted.application import service, strports
10
from twisted.application import service
11
11
from twisted.conch.interfaces import ISession
12
12
from twisted.conch.ssh import filetransfer
13
13
from twisted.cred.portal import IRealm, Portal
14
from twisted.protocols import ftp
15
14
from twisted.protocols.policies import TimeoutFactory
16
15
from twisted.python import components
17
16
from twisted.web.xmlrpc import Proxy
22
21
from canonical.launchpad.daemons import readyservice
23
22
from canonical.launchpad.scripts import execute_zcml_for_scripts
24
from lp.poppy import get_poppy_root
25
25
from lp.poppy.twistedftp import (
29
28
from lp.poppy.twistedsftp import SFTPServer
30
29
from lp.services.sshserver.auth import (
69
65
return deferred.addCallback(got_user_dict)
73
"""Return the poppy root to use for this server.
75
If the POPPY_ROOT environment variable is set, use that. If not, use
78
poppy_root = os.environ.get('POPPY_ROOT', None)
81
return config.poppy.fsroot
84
68
def poppy_sftp_adapter(avatar):
85
69
return SFTPServer(avatar, get_poppy_root())
72
# Connect Python logging to Twisted's logging.
73
from lp.services.twistedsupport.loggingsupport import set_up_tacfile_logging
74
set_up_tacfile_logging("poppy-sftp", logging.INFO)
88
77
components.registerAdapter(
89
78
poppy_sftp_adapter, LaunchpadAvatar, filetransfer.ISFTPServer)
91
80
components.registerAdapter(DoNothingSession, LaunchpadAvatar, ISession)
94
class FTPServiceFactory(service.Service):
95
def __init__(self, port):
96
factory = ftp.FTPFactory()
97
realm = FTPRealm(get_poppy_root())
98
portal = Portal(realm)
99
portal.registerChecker(PoppyAccessCheck())
101
factory.tld = get_poppy_root()
102
factory.portal = portal
103
factory.protocol = ftp.FTP
104
factory.welcomeMessage = "Launchpad upload server"
105
factory.timeOut = config.poppy.idle_timeout
107
# Setting this works around the fact that the twistd FTP server
108
# invokes a special restricted shell when someone logs in as
109
# "anonymous" which is the default for 'dput'.
110
factory.userAnonymous = "userthatwillneverhappen"
111
self.ftpfactory = factory
115
def makeFTPService(port=2121):
116
strport = "tcp:%s" % port
117
factory = FTPServiceFactory(port)
118
return strports.service(strport, factory.ftpfactory)
120
83
# ftpport defaults to 2121 in schema-lazr.conf
121
ftpservice = FTPServiceFactory.makeFTPService(port=config.poppy.ftpport)
84
ftpservice = FTPServiceFactory.makeFTPService(port=config.poppy.ftp_port)
123
86
# Construct an Application that has the Poppy SSH server,
124
87
# and the Poppy FTP server.