~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/poppy/server.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2005-03-16 15:03:49 UTC
  • mfrom: (unknown (missing))
  • Revision ID: Arch-1:rocketfuel@canonical.com%launchpad--devel--0--patch-1443
GPGV movement, initial poppy-upload and clean up ftpserver signon
Patches applied:

 * daniel.silverstone@canonical.com--desktop/launchpad--upload-and-queue--0--patch-2
   manual merge of rocketfuel patches 1376-1420

 * daniel.silverstone@canonical.com--desktop/launchpad--upload-and-queue--0--patch-3
   Merge from rocketfuel@canonical.com/launchpad--devel--0

 * daniel.silverstone@canonical.com--desktop/launchpad--upload-and-queue--0--patch-4
   Shift around the GPGV errors a bit and test that NoPublicKeyError gets a keyid

 * daniel.silverstone@canonical.com--desktop/launchpad--upload-and-queue--0--patch-5
   star-merge from rocketfuel@canonical.com/launchpad--devel--0

 * daniel.silverstone@canonical.com--desktop/launchpad--upload-and-queue--0--patch-6
   Initial poppy-upload.py daemon with Lucille integration

 * daniel.silverstone@canonical.com--desktop/launchpad--upload-and-queue--0--patch-7
   Tidy the ftpserver signon a little

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
class Channel(FTPServerChannel):
24
24
 
25
 
    jdub_sez = "yo yo pants off"
26
 
 
27
25
    def __init__(self, server, conn, addr, adj=None):
28
26
        # Work around a zope3 bug where the status messages dict is copied by
29
27
        # reference, not by value.
30
28
        self.status_messages = dict(self.status_messages)
31
29
        self.status_messages['SERVER_READY'] = (
32
 
            '220 %%s FTP server (%s) ready.' % self.jdub_sez)
 
30
            '220 %s Canonical FTP server ready.')
33
31
 
34
32
        FTPServerChannel.__init__(self, server, conn, addr, adj=None)
35
33
        self.peername = self.socket.getpeername()
36
34
        self.uploadfilesystem, self.fsroot = server.newClient(self)
 
35
        self.hook = server.auth_verify_hook
37
36
 
38
37
    def close(self):
39
38
        FTPServerChannel.close(self)
60
59
        self.authenticated = 0
61
60
        password = args
62
61
        credentials = (self.username, password)
63
 
        self.credentials = credentials
64
 
        self.authenticated = 1
65
 
        self.reply('LOGIN_SUCCESS')
 
62
        okay = True
 
63
        if self.hook:
 
64
            try:
 
65
                if not self.hook(self.fsroot, self.username, password):
 
66
                    okay = False
 
67
            except:
 
68
                okay = False
 
69
        if not okay:
 
70
            self.reply('LOGIN_MISMATCH')
 
71
            self.close_when_done()
 
72
        else:
 
73
            self.credentials = credentials
 
74
            self.authenticated = 1
 
75
            self.reply('LOGIN_SUCCESS')
66
76
 
67
77
    def cmd_stor(self, args, write_mode='w'):
68
78
        'See IFTPCommandHandler'
98
108
    channel_class = Channel
99
109
 
100
110
    def __init__(self, ip, port, root, startcount,
101
 
                 new_client_hook, client_done_hook,
 
111
                 new_client_hook, client_done_hook, auth_verify_hook,
102
112
                 *args, **kw):
103
113
        ServerBase.__init__(self, ip, port, *args, **kw)
104
114
        self.clientcount = startcount
105
115
        self.rootpath = root
106
116
        self.new_client_hook = new_client_hook
107
117
        self.client_done_hook = client_done_hook
 
118
        self.auth_verify_hook = auth_verify_hook
108
119
 
109
120
    def newClient(self, channel):
110
121
        root = '/'  # sentinel
132
143
 
133
144
 
134
145
def run_server(rootdir, host, port, ident, numthreads,
135
 
               new_client_hook, client_done_hook):
 
146
               new_client_hook, client_done_hook, auth_verify_hook = None):
136
147
    task_dispatcher = ThreadedTaskDispatcher()
137
148
    task_dispatcher.setThreadCount(numthreads)
138
149
    server = Server(host, port, rootdir, 0,
139
 
                    new_client_hook, client_done_hook,
 
150
                    new_client_hook, client_done_hook, auth_verify_hook,
140
151
                    task_dispatcher=task_dispatcher)
141
152
    server.SERVER_IDENT = ident
142
153
    try:
169
180
    def client_done_hook(fsroot, host, port):
170
181
        print "client done:", fsroot, host, port
171
182
 
 
183
    def auth_verify_hook(fsroot, user,passw):
 
184
        print "Auth Verification hook:", fsroot, user, passw
 
185
        return True
172
186
 
173
187
    run_server(root, host, int(port), ident, numthreads,
174
 
               new_client_hook, client_done_hook)
 
188
               new_client_hook, client_done_hook,
 
189
               auth_verify_hook)
175
190
    return 0
176
191
 
177
192
if __name__ == '__main__':