source: TI05-delivery/trunk/lib/python/ndg/delivery/server/pybbftp.py @ 1539

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/lib/python/ndg/delivery/server/pybbftp.py@1539
Revision 1539, 3.7 KB checked in by spascoe, 13 years ago (diff)

Some bug fixes to auth/authz API.

test_embedded.py now passes (except for the usual testStartup problem).

Line 
1"""
2Start a bbftp server process and define python callbacks for authentication and authorisation.
3
4Interface to the BBftp server.
5
6@copyright Copyright (C) 2006 CCLRC & NERC
7@license This software may be distributed under the terms of the Q Public Licence, version 1.0 or later.
8
9@author Stephen Pascoe
10"""
11
12#!NOTE: Importing bbftpd and bbftpc together is dangerous and will cause stange errors.
13#       However if the module is being scanned by epydoc allow the import (This is a hack!)
14import sys
15if sys.modules.has_key('ndg.delivery.client.pybbftp.bbftpc') and not sys.modules.has_key('epydoc'):
16    raise ImportError, "ndg.delivery.client.pybbftp.bbftpc extension already loaded.  You cannot use both client and server extensions together"
17
18import bbftpd
19
20class TROPT:
21    """Static class containing constants used by bbftp in the transferoption parameter.
22
23    TROPT.X always corresponds to TROPT_X as defined in bbftpd/structures.h.
24    Options that aren't likely to be used for the delivery service are not
25    included (e.g. TROPT_RFIO).
26
27    @cvar TMP always use temporary name.
28    @cvar ACC keep access and modification time.
29    @cvar MODE keep mode.
30    @cvar DIR create all dirs in path.
31    """
32    TMP = bbftpd.TROPT_TMP
33    ACC = bbftpd.TROPT_ACC
34    MODE = bbftpd.TROPT_MODE
35    DIR = bbftpd.TROPT_DIR
36
37class MSG:
38    """Static class containing message codes used by bbftp.
39
40    MSG.X corresponds to MSG_X or MSG_X_V2 as defined in bbftpd/structures.h.
41    Message codes not returned by the auth/authz interface are not included.
42
43    @cvar CHDIR a chdir request.
44    @cvar LIST a ls/dir request.
45    @cvar MKDIR a mkdir request.
46    @cvar RM a rm request.
47    @cvar STAT a stat request.
48    @cvar DF a statfs request.
49    """
50    CHDIR = bbftpd.MSG_CHDIR_V2
51    LIST = bbftpd.MSG_LIST_V2
52    MKDIR = bbftpd.MSG_MKDIR_V2
53    RM = bbftpd.MSG_RM
54    STAT = bbftpd.MSG_STAT
55    DF = bbftpd.MSG_DF
56   
57
58# Import all LOG_* levels from syslog.
59import syslog
60for x in dir(syslog):
61    if x[:4] == 'LOG_':
62        globals()[x] = getattr(syslog, x)
63
64#--------------------------------------------------------------------------------------------------------------
65
66def start(authHandler, args):
67    """Start the bbftp server.
68
69    The server performs a fork() during initialisation, the child process remains in
70    the server's main loop and the parent returns from this function.  The server process
71    calls authHandler.authorise() on each connection to do authentication/authorisation.
72
73    @note because the server process forks, authHandler will not see any changes to the python
74        interpreter following the call to start().
75
76    @param authHandler an instance of AuthHandler.
77    @param args a list of command line arguments.
78    @return the PID of the server process.
79    """
80   
81    return bbftpd.run(authHandler, args)
82
83
84
85class ServerConnector(object):
86    def send(self, buffer):
87        """Send a message to the client during authentication
88
89        This method must only be used from within auth.AuthHandler.authenticate() which has been called
90        from the bbftp server process started by start().
91
92        @param buffer a string containing the message to send.
93        """
94   
95        return bbftpd.send(buffer)
96
97    def recv(self):
98        """Receive a message from the client during authentication
99
100        This method must only be used from within auth.AuthHandler.authenticate() which has been called
101        from the bbftp server process started by start().
102
103        @return a string containing the message received.
104        """
105
106        return bbftpd.recv()
107
108    def log(self, priority, msg):
109        """Send a message to the bbftpd logger.
110
111        @param priority one of server.LOG_*
112        @param msg the message to log
113        """
114        bbftpd.log(priority, msg)
115
116
117   
Note: See TracBrowser for help on using the repository browser.