Ignore:
Timestamp:
28/09/06 14:06:31 (14 years ago)
Author:
spascoe
Message:

Probably too many changes for one commit :-(.

I've reorganised the auth/authz API to separate interface from
implementation. Some C bug fixes but the example client now segfaults
on exit :-(.

I havn't refactored the test cases to match the new API, so I expect
they fail.

Location:
TI05-delivery/trunk/examples
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/examples/deliveryclient.py

    r1441 r1538  
    77from glob import glob 
    88 
    9 HOME = os.path.abspath(os.getenv('NDG_DELIVERY_HOME', os.curdir)) 
    10 VERSION = open('%s/VERSION' % HOME).read() 
    11 NDG_MESSAGE_LEN = 256 
    12  
    13 NDG_HANDSHAKE = "NDG-Delivery-client %s" % VERSION 
    14  
    159import ndg.delivery.client.pybbftp as DC 
    1610 
    17 class AuthClientHandler(DC.AuthClientHandler): 
    18     def __init__(self, privatestr="none"): 
    19         self.privatestr = privatestr 
    20  
    21     def authenticate(self): 
    22         self.send(NDG_HANDSHAKE) 
    23         resp = self.recv() 
    24  
    25         print "Received Auth handshake: %s" % resp 
    26  
    27         self.send(self.privatestr) 
    28  
    29         return True 
     11from ndg.delivery.auth_plugin import * 
    3012 
    3113def makeClient(username, hostname): 
    32     return DC.connect(AuthClientHandler(), ['-m', '-u', username, '-r', '1', hostname]) 
     14    c = DC.ClientConnector() 
     15    try: 
     16        return DC.connect(AuthClientHandler(c), ['-m', '-u', username, '-r', '1', hostname]) 
     17    except Exception, e: 
     18        if hasattr(e, 'clientMessages'): 
     19            print e.clientMessages 
     20        raise e 
    3321 
    3422def do(cmd): 
  • TI05-delivery/trunk/examples/deliveryd.py

    r1448 r1538  
    99import re, tempfile, getopt 
    1010 
    11 HOME = os.path.abspath(os.getenv('NDG_DELIVERY_HOME', os.curdir)) 
    12 DATADIR = '%s/test/data' % HOME 
    13 VERSION = open('%s/VERSION' % HOME).read() 
    14 NDG_MESSAGE_LEN = 256 
    15  
    16 NDG_HANDSHAKE = "NDG-Delivery-server %s" % VERSION 
    17  
    1811import logging 
    1912logging.basicConfig(level=logging.DEBUG, filename='./bbftpd.log') 
     
    2114 
    2215import ndg.delivery.server.pybbftp as server 
    23  
    24  
    25 class AuthHandler(server.AuthHandler): 
    26      
    27     def authenticate(self): 
    28         msg = self.recv() 
    29         logger.debug('AuthContext received Auth message: %s' % msg) 
    30                  
    31         self.send(NDG_HANDSHAKE) 
    32  
    33         privatestr = self.recv() 
    34         logger.debug("AuthContext received privatestr: %s" % privatestr) 
    35          
    36         return self.makeAuthzHandler(msg, "TestCaseUser") 
    37  
    38     def makeAuthzHandler(self, msg, user): 
    39         return AuthzHandler(msg, "TestCaseUser") 
    40  
    41 class AuthzHandler(server.LiberalAuthzHandler): 
    42     def __init__(self, version, username): 
    43         super(AuthzHandler, self).__init__(username) 
    44         self.version = version 
    45  
    46     def authzControl(self, msgcode, transferopt, path): 
    47         logger.debug('AuthzHandler.authzControl: msgcode = %s' % hex(msgcode)) 
    48         return self.authzPath(path) 
    49  
    50     def authzRetr(self, path): 
    51         return self.authzPath(path) 
    52  
    53     def authzStore(self, path): 
    54         return self.authzPath(path) 
    55  
    56     def authzPath(self, path): 
    57         # For dir commands the path will end with '*' 
    58         if path[-2:] == '/*': 
    59             path = path[:-2] 
    60         mode = stat.S_IMODE(os.stat(path)[stat.ST_MODE]) 
    61         if (mode & 0004): 
    62             logger.debug('AuthzHandler OK') 
    63             return True 
    64         else: 
    65             logger.debug('AuthzHandler FAIL') 
    66             raise server.AuthorisationFailure, "AuthzHandler: no read perms" 
     16from ndg.delivery.auth_plugin import * 
    6717 
    6818 
     
    8030logfile = './bbftpd.log' 
    8131n = len(open(logfile).readlines()) 
    82 pid = server.start(AuthHandler(), ['-l', 'DEBUG']) 
     32c = server.ServerConnector() 
     33pid = server.start(AuthHandler(c), ['-l', 'DEBUG']) 
    8334print 'Server process started at pid = %d' % pid 
    8435print 'Monitoring %s' % logfile 
Note: See TracChangeset for help on using the changeset viewer.