Changeset 1077


Ignore:
Timestamp:
01/06/06 15:18:02 (13 years ago)
Author:
spascoe
Message:

Implemented full client-server handshake. A version message is now
exchanged client->server then server->client. These messages are logged
in debug mode. Message passing is implemented in Python on the server (at the
moment this is only implemented within test/test_embedded.py).

Location:
TI05-delivery/trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/setup.py

    r1067 r1077  
    55 
    66bbftpd_home = './src/bbftp-server-3.2.0' 
     7# Get the version from ./VERSION 
     8version = open('./VERSION').read() 
     9 
    710 
    811# Not all *.c files are compiled into *.o files in bbftpd 
     
    4346                   define_macros = [('NDG_AUTH', 1), ('LOCAL_SYSLOG_FACILITY', 1), 
    4447                                    ('_LARGEFILE64_SOURCE', 1), 
    45                                     ('NDG_PYTHON_EMBED', 1)], 
     48                                    ('NDG_PYTHON_EMBED', 1), 
     49                                    ('NDG_DELIVERY_VERSION', '"%s"' % version)], 
    4650                   include_dirs = [bbftpd_home+'/includes', bbftpd_home+'/bbftpd'], 
    4751                   libraries = ['crypt', 'crypto'], 
     
    4953 
    5054setup(name = 'bbftp-python', 
    51       version = '0.1', 
     55      version = version, 
    5256      description = 'Embedded bbftp server', 
    5357      author = 'Stephen Pascoe', 
  • TI05-delivery/trunk/src/Makefile

    r1065 r1077  
    11# 
    2 # Top level makefile for the DeliveryService source code. 
     2# Makefile for building bbftp client & server stand alone (without Python API) 
     3# 
    34 
    45PREFIX=$(HOME)/opt/bbftp 
     6# Grab the DeliveryService version from the parent directory. 
     7VERSION:=$(shell cat ../VERSION) 
     8 
     9DEFS="-DNDG_AUTH -DLOCAL_SYSLOG_FACILITY -DNDG_DELIVERY_VERSION=$(VERSION)" 
    510CONFIG_OPTS=--prefix=$(PREFIX) --without-gzip --without-rfio --enable-authentication=private \ 
    6                 CPPFLAGS="-DNDG_AUTH -DLOCAL_SYSLOG_FACILITY" 
     11                CFLAGS=$(DEFS) 
    712 
    813BBFTPD=bbftp-server-3.2.0/bbftpd 
  • TI05-delivery/trunk/src/bbftp-client-3.2.0/bbftpc/bbftp_private_user.c

    r802 r1077  
    3030 
    3131#include <bbftp_private_user.h> 
     32#include <client.h> 
    3233 
    3334/* 
     
    3940*/ 
    4041extern char *privatestr ; 
     42 
     43extern int debug; 
     44 
     45/* From bbftp_util.c */ 
     46void printmessage(FILE *strm , int flag, int errcode, int tok, char *fmt, ...); 
     47 
    4148 
    4249/******************************************************************************* 
     
    118125int bbftp_private_auth(char *logmessage)  
    119126{ 
     127  char msg[NDG_MESSAGE_LEN]; 
     128 
    120129  /* Send version verification message.  */ 
    121   if (bbftp_private_send(NDG_FTP_PROTOCOL, NDG_MESSAGE_LEN, logmessage) == -1) { 
     130  sprintf(msg, "%.*s", NDG_MESSAGE_LEN - 1, NDG_HANDSHAKE); 
     131  if (bbftp_private_send(msg, NDG_MESSAGE_LEN, logmessage) == -1) { 
    122132    return -1; 
     133  } 
     134 
     135  /* Receive response */ 
     136  if (bbftp_private_recv(msg, NDG_MESSAGE_LEN, logmessage) == -1) { 
     137    return -1; 
     138  } 
     139 
     140  if (debug) { 
     141    printmessage(stdout,CASE_NORMAL,0,0,"Received Auth handshake: %s\n", msg) ; 
    123142  } 
    124143 
  • TI05-delivery/trunk/src/bbftp-client-3.2.0/includes/bbftp_private_user.h

    r806 r1077  
    4343 */ 
    4444 
    45 #define NDG_FTP_VERSION "v0.0.1" 
    46 #define NDG_FTP_PROTOCOL ("NDG-bbFTP" NDG_FTP_VERSION) 
     45// Define this in the makefile 
     46// #define NDG_DELIVERY_VERSION "v0.0.1" 
     47#define NDG_STR(s) #s 
     48#define NDG_XSTR(s) NDG_STR(s) 
     49#define NDG_HANDSHAKE ("NDG-Delivery-client " NDG_XSTR(NDG_DELIVERY_VERSION)) 
    4750 
    4851#define NDG_MESSAGE_LEN 256 
     
    5255*/ 
    5356#define NDG_MAX_LOGMESSAGE 1024 
     57 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_user.c

    r1075 r1077  
    3737#include <bbftpd_private_user.h> 
    3838 
     39#ifdef NDG_PYTHON_EMBED 
     40#include <Python.h> 
     41#endif 
     42 
    3943extern char currentusername[MAXLEN] ; 
    4044 
     
    112116 
    113117  char msg[NDG_MESSAGE_LEN]; 
    114   /* Send version verification message.  */ 
     118  /* Receive version verification message.  */ 
    115119  if (bbftpd_private_recv(msg, NDG_MESSAGE_LEN, logmessage) == -1) { 
    116120    return -1; 
     
    118122  else { 
    119123    syslog(LOG_DEBUG, "Received auth message: %s", msg); 
     124  } 
     125 
     126  /* Send response */ 
     127  sprintf(msg, "%.*s", NDG_MESSAGE_LEN - 1, NDG_HANDSHAKE); 
     128  if (bbftpd_private_send(msg, NDG_MESSAGE_LEN, logmessage) == -1) { 
     129    return -1; 
    120130  } 
    121131 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/includes/bbftp_private_user.h

    r773 r1077  
    3838 
    3939**/ 
     40 
     41#ifdef NDG_AUTH 
     42#define NDG_STR(s) #s 
     43#define NDG_XSTR(s) NDG_STR(s) 
     44#define NDG_HANDSHAKE ("NDG-Delivery-server " NDG_XSTR(NDG_DELIVERY_VERSION)) 
     45#endif 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/includes/bbftpd_private_user.h

    r1064 r1077  
    2828*****************************************************************************/ 
    2929 
    30 #include <Python.h> 
    31  
    3230/* 
    3331** This include must contain all global variable to be used for private 
     
    4947#define NDG_MAX_LOGMESSAGE 1024 
    5048#define NDG_MESSAGE_LEN 256 
     49 
     50#define NDG_STR(s) #s 
     51#define NDG_XSTR(s) NDG_STR(s) 
     52#define NDG_HANDSHAKE ("NDG-Delivery-server " NDG_XSTR(NDG_DELIVERY_VERSION)) 
  • TI05-delivery/trunk/test/test_bbftpd.py

    r1064 r1077  
    1111from glob import glob 
    1212import re, tempfile 
     13 
     14 
    1315 
    1416class ExtendedAPITestCase(unittest.TestCase): 
     
    5759        self.assert_(self._findLines(['.*Starting bbftpd in background mode'], lines)) 
    5860 
     61    def testHandshake(self): 
     62        """Connect with client in verbose mode and test Auth handhsake is received. 
     63        """ 
     64 
     65        self._startServer() 
     66        pid = self._getServerPid() 
     67 
     68        fh = self._runClient('dir .', debug=True) 
     69        output = fh.read() 
     70 
     71        self._stopServer(pid) 
     72 
     73        self.assert_(self._findLines(['Received Auth handshake: NDG-Delivery-server %s' % self.VERSION], output)) 
     74 
     75        lines = self._readSyslog() 
     76        self.assert_(self._findLines(['.*Received auth message: NDG-Delivery-client %s.*' % self.VERSION], lines)) 
     77 
     78 
    5979    def testDir(self): 
    6080        """Try connecting the client and listing a directory. 
     
    6484        pid = self._getServerPid() 
    6585 
    66         fh = self._runClient('-e "dir %s"' % self.DATADIR) 
     86        fh = self._runClient('dir %s' % self.DATADIR) 
    6787        output = fh.read() 
    6888 
     
    7494        lines = self._readSyslog() 
    7595        self.assert_(self._findLines(['.*Getting new bbftp connexion.*', 
    76                                       '.*Received auth message: NDG-bbFTP.*', 
    7796                                      r'.*Authz: MSG_LIST_V2 .*/test/data/\*.*', 
    7897                                      r'.*User  disconnected.*'], lines)) 
     
    86105 
    87106        tmp = tempfile.mktemp('test_bbftpd') 
    88         fh = self._runClient('-e "get %s/foo %s"' % (self.DATADIR, tmp)) 
     107        fh = self._runClient('get %s/foo %s' % (self.DATADIR, tmp)) 
    89108 
    90109        # Check the client output 
     
    112131        dest = '%s/new_bar' % (self.DATADIR) 
    113132        os.system('cp %s %s' % (src, dest)) 
    114         fh = self._runClient('-e "put %s %s"' % (src, dest)) 
     133        fh = self._runClient('put %s %s' % (src, dest)) 
    115134 
    116135        # Check the client output 
     
    147166        else: 
    148167            raise RuntimeError, 'Cannot find test data directory' 
     168        self.VERSION = open('%s/VERSION' % self.HOME).read() 
     169 
    149170 
    150171    def _startServer(self): 
     
    192213        return ''.join(filtered_log) 
    193214 
    194     def _runClient(self, *args): 
    195         """Run the client with th -m option and return a file handle of the output. 
    196         """ 
    197         fh = os.popen('%s -m -u testcase %s localhost' % (self.BBFTP, ' '.join(args))) 
     215    def _runClient(self, cmd, debug=False, user="testcase"): 
     216        """Run the client. 
     217        """ 
     218 
     219        if debug: 
     220            f = "-d" 
     221        else: 
     222            f = "-m" 
     223         
     224        fh = os.popen('%s %s -u %s -e %s localhost' % (self.BBFTP, f, user, repr(cmd))) 
    198225        return fh 
    199226 
  • TI05-delivery/trunk/test/test_embedded.py

    r1075 r1077  
    1616BBFTP = glob('%s/src/bbftp-client*/bbftpc/bbftp' % HOME)[0] 
    1717DATADIR = '%s/test/data' % HOME 
     18VERSION = open('%s/VERSION' % HOME).read() 
    1819NDG_MESSAGE_LEN = 256 
     20 
     21NDG_HANDSHAKE = "NDG-Delivery-server %s" % VERSION 
    1922 
    2023sys.path.append(BUILDDIR) 
     
    3639 
    3740        syslog.syslog(syslog.LOG_DEBUG, 'AuthContext received Auth message: %s' % msg) 
    38          
     41 
     42        # Send the response 
     43        msg = NDG_HANDSHAKE + '\0' * (NDG_MESSAGE_LEN - len(NDG_HANDSHAKE)) 
     44        bbftpd.send(msg) 
     45             
    3946        return AuthzContext(msg, "TestCaseUser") 
    4047 
     
    6471 
    6572 
    66         fh = self._runClient('-e "dir %s"' % DATADIR) 
     73        fh = self._runClient("dir %s" % DATADIR) 
    6774        output = fh.read() 
    6875 
     
    7380        lines = self._readSyslog() 
    7481        self.assert_(self._findLines(['.*Getting new bbftp connexion.*', 
    75                                       '.*AuthContext received Auth message: NDG-bbFTP.*', 
     82                                      '.*AuthContext received Auth message: NDG-Delivery-client %s' % VERSION, 
    7683                                      r'.*Authz: MSG_LIST_V2 .*/test/data/\*.*', 
    7784                                      r'.*User TestCaseUser disconnected.*'], lines)) 
     
    8390 
    8491        tmp = tempfile.mktemp('test_bbftpd') 
    85         fh = self._runClient('-e "get %s/foo %s"' % (DATADIR, tmp)) 
     92        fh = self._runClient("get %s/foo %s" % (DATADIR, tmp)) 
    8693 
    8794        # Check the client output 
     
    105112        dest = '%s/new_bar' % (DATADIR) 
    106113        os.system('cp %s %s' % (src, dest)) 
    107         fh = self._runClient('-e "put %s %s"' % (src, dest)) 
     114        fh = self._runClient("put %s %s" % (src, dest)) 
    108115 
    109116        # Check the client output 
     
    134141        syslog.syslog(syslog.LOG_DEBUG, 'Stopping server') 
    135142 
    136     def _runClient(self, *args): 
    137         """Run the client with th -m option and return a file handle of the output. 
     143 
     144    def _runClient(self, cmd, debug=False, user="testcase"): 
     145        """Run the client. 
    138146        """ 
    139         fh = os.popen('%s -m -u testcase %s localhost' % (BBFTP, ' '.join(args))) 
     147 
     148        if debug: 
     149            f = "-d" 
     150        else: 
     151            f = "-m" 
     152         
     153        fh = os.popen('%s %s -u %s -e %s localhost' % (BBFTP, f, user, repr(cmd))) 
    140154        return fh 
     155 
    141156 
    142157    def _readSyslog(self, logfile="/var/log/bbftpd/bbftpd.log"): 
Note: See TracChangeset for help on using the changeset viewer.