~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to daemons/poppy-sftp.tac

  • Committer: Julian Edwards
  • Date: 2011-02-23 15:16:38 UTC
  • mfrom: (12392.7.32 twisted-ftp-poppy)
  • mto: This revision was merged to the branch mainline in revision 12470.
  • Revision ID: julian.edwards@canonical.com-20110223151638-8cw0twgnyx2a8c0y
merge parent branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#     twistd -noy sftp.tac
6
6
# or similar.  Refer to the twistd(1) man page for details.
7
7
 
8
 
import os
 
8
import logging
9
9
 
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
23
 
 
24
from lp.poppy import get_poppy_root
25
25
from lp.poppy.twistedftp import (
26
 
    FTPRealm,
27
 
    PoppyAccessCheck,
 
26
    FTPServiceFactory,
28
27
    )
29
28
from lp.poppy.twistedsftp import SFTPServer
30
29
from lp.services.sshserver.auth import (
32
31
from lp.services.sshserver.service import SSHService
33
32
from lp.services.sshserver.session import DoNothingSession
34
33
 
35
 
# XXX: Rename this file to something that doesn't mention poppy. Talk to
36
 
# bigjools.
37
 
 
38
34
 
39
35
def make_portal():
40
36
    """Create and return a `Portal` for the SSH service.
69
65
        return deferred.addCallback(got_user_dict)
70
66
 
71
67
 
72
 
def get_poppy_root():
73
 
    """Return the poppy root to use for this server.
74
 
 
75
 
    If the POPPY_ROOT environment variable is set, use that. If not, use
76
 
    config.poppy.fsroot.
77
 
    """
78
 
    poppy_root = os.environ.get('POPPY_ROOT', None)
79
 
    if poppy_root:
80
 
        return poppy_root
81
 
    return config.poppy.fsroot
82
 
 
83
 
 
84
68
def poppy_sftp_adapter(avatar):
85
69
    return SFTPServer(avatar, get_poppy_root())
86
70
 
87
71
 
 
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)
 
75
 
 
76
 
88
77
components.registerAdapter(
89
78
    poppy_sftp_adapter, LaunchpadAvatar, filetransfer.ISFTPServer)
90
79
 
91
80
components.registerAdapter(DoNothingSession, LaunchpadAvatar, ISession)
92
81
 
93
82
 
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())
100
 
 
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
106
 
 
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
112
 
        self.portno = port
113
 
 
114
 
    @staticmethod
115
 
    def makeFTPService(port=2121):
116
 
        strport = "tcp:%s" % port
117
 
        factory = FTPServiceFactory(port)
118
 
        return strports.service(strport, factory.ftpfactory)
119
 
 
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)
122
85
 
123
86
# Construct an Application that has the Poppy SSH server,
124
87
# and the Poppy FTP server.