Changeset 1075


Ignore:
Timestamp:
31/05/06 17:03:55 (13 years ago)
Author:
spascoe
Message:

Python code can read an authorisation message from the client.

Test cases confirm message passing client->server->python is working.

Location:
TI05-delivery/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_user.c

    r1074 r1075  
    9797int bbftpd_private_auth(char *logmessage) 
    9898{ 
     99 
     100#ifdef NDG_PYTHON_EMBED 
    99101  char *username; 
     102 
     103  if (bbftpd_private_auth_callback(logmessage) == -1) { 
     104    return -1; 
     105  } 
     106  if ((username = bbftpd_private_auth_getusername(logmessage)) == NULL) { 
     107    return -1; 
     108  } 
     109    
     110  sprintf(currentusername, "%.*s", MAXLEN, username); 
     111#else 
    100112 
    101113  char msg[NDG_MESSAGE_LEN]; 
     
    108120  } 
    109121 
    110 #ifdef NDG_PYTHON_EMBED 
    111   if (bbftpd_private_auth_callback(logmessage) == -1) { 
    112     return -1; 
    113   } 
    114   if ((username = bbftpd_private_auth_getusername(logmessage)) == NULL) { 
    115     return -1; 
    116   } 
    117     
    118   sprintf(currentusername, "%.*s", MAXLEN, username); 
    119122#endif 
    120123 
  • TI05-delivery/trunk/src/python_ext/bbftpd.c

    r1073 r1075  
    1414extern char **environ; 
    1515/* 
    16  * variables and prototypes from bbftpd.c 
     16 * variables and prototypes from bbftpd source 
    1717 */ 
    1818 
     
    2121 
    2222int bbftpd_main(int argc, char **argv, char **envp); 
     23int bbftpd_private_send(char *buffertosend, int buffertosendlength, char *logmessage) ; 
     24int bbftpd_private_recv(char *buffertorecv, int lengthtorecv, char *logmessage) ; 
    2325 
    2426/* 
     
    100102 * 
    101103 */ 
     104 
     105/* send(string) */ 
     106static PyObject *bbftpd_send(PyObject *self, PyObject *args) { 
     107  char *buffer, logmessage[1024]; 
     108  int len; 
     109 
     110  if (!PyArg_ParseTuple(args, "s#", &buffer, &len)) { 
     111    return NULL; 
     112  } 
     113 
     114  if (authContext == NULL) { 
     115    PyErr_SetString(PyExc_RuntimeError, "Must be called within a bbftpd callback"); 
     116    return NULL; 
     117  } 
     118 
     119  if (bbftpd_private_send(buffer, len, logmessage) == -1) { 
     120    PyErr_SetString(PyExc_IOError, logmessage); 
     121    return NULL; 
     122  } 
     123 
     124  Py_RETURN_NONE; 
     125} 
     126 
     127/* recv(length) -> string */ 
     128static PyObject *bbftpd_recv(PyObject *self, PyObject *args) { 
     129  char *buffer, logmessage[1024]; 
     130  int len; 
     131 
     132  if (!PyArg_ParseTuple(args, "i", &len)) { 
     133    return NULL; 
     134  } 
     135 
     136  if (authContext == NULL) { 
     137    PyErr_SetString(PyExc_RuntimeError, "Must be called within a bbftpd callback"); 
     138    return NULL; 
     139  } 
     140  if ((buffer = (char*)malloc(len*sizeof(char))) == NULL) { 
     141    PyErr_NoMemory(); 
     142    return NULL; 
     143  } 
     144 
     145  if (bbftpd_private_recv(buffer, len, logmessage) == -1) { 
     146    PyErr_SetString(PyExc_IOError, logmessage); 
     147    free(buffer); 
     148    return NULL; 
     149  } 
     150 
     151  return Py_BuildValue("s#", buffer, len); 
     152} 
     153 
    102154 
    103155/** 
     
    174226    "@return: the PID of the server process\n" 
    175227  }, 
     228  { 
     229    "send", bbftpd_send, METH_VARARGS, 
     230    "Send an authentication message to the client.\n" 
     231    "\n" 
     232    "Equivilent to bbftpd_private_send() C call.\n" 
     233    "\n" 
     234    "@param buffer: A string containing the message\n" 
     235    "@raise IOError: if bbftpd_private_send() call fails\n" 
     236  }, 
     237  { 
     238    "recv", bbftpd_recv, METH_VARARGS, 
     239    "Receive an authentication message from the client.\n" 
     240    "\n" 
     241    "Equivilent to bbftpd_private_recv() C call.\n" 
     242    "\n" 
     243    "@param len: The length of message to expect\n" 
     244    "@return: A string containing the message\n" 
     245    "@raise IOError: if bbftpd_private_recv() call fails\n" 
     246  }, 
    176247  {NULL, NULL, 0, NULL} 
    177248}; 
  • TI05-delivery/trunk/test/test_embedded.py

    r1074 r1075  
    1616BBFTP = glob('%s/src/bbftp-client*/bbftpc/bbftp' % HOME)[0] 
    1717DATADIR = '%s/test/data' % HOME 
     18NDG_MESSAGE_LEN = 256 
     19 
    1820sys.path.append(BUILDDIR) 
    1921import bbftpd 
    2022         
    21 class AuthContext(object): 
     23class AuthzContext: 
     24    def __init__(self, version_msg, user): 
     25        self.version = version_msg 
     26        self.username = user 
     27 
     28class AuthContext: 
    2229    def authorise(self): 
    23         # Return a dummy authzContext 
    24         return AuthzContext("JoeBloggs") 
     30        # Read the auth version message 
     31        msg = bbftpd.recv(NDG_MESSAGE_LEN) 
     32        # Trim to first '\0' 
     33        x = msg.find('\0') 
     34        if x: 
     35            msg = msg[:x] 
    2536 
    26 class AuthzContext(object): 
    27     def __init__(self, username): 
    28         self.username = username 
     37        syslog.syslog(syslog.LOG_DEBUG, 'AuthContext received Auth message: %s' % msg) 
     38         
     39        return AuthzContext(msg, "TestCaseUser") 
    2940 
    3041class EmbeddedServerTestCase(unittest.TestCase): 
     
    6273        lines = self._readSyslog() 
    6374        self.assert_(self._findLines(['.*Getting new bbftp connexion.*', 
    64                                       '.*Received auth message: NDG-bbFTP.*', 
     75                                      '.*AuthContext received Auth message: NDG-bbFTP.*', 
    6576                                      r'.*Authz: MSG_LIST_V2 .*/test/data/\*.*', 
    66                                       r'.*User JoeBloggs disconnected.*'], lines)) 
     77                                      r'.*User TestCaseUser disconnected.*'], lines)) 
    6778 
    6879 
     
    8495        # Check syslog 
    8596        lines = self._readSyslog() 
    86         self.assert_(self._findLines(['.*Authz: RETR .*/foo', '.*GET JoeBloggs .*/foo.*'], lines)) 
     97        self.assert_(self._findLines(['.*Authz: RETR .*/foo', '.*GET TestCaseUser .*/foo.*'], lines)) 
    8798 
    8899    def testStore(self): 
     
    107118        # Check syslog 
    108119        lines = self._readSyslog() 
    109         self.assert_(self._findLines(['.*Authz: STORE .*/new_bar', '.*PUT JoeBloggs .*/new_bar.*'], lines)) 
     120        self.assert_(self._findLines(['.*Authz: STORE .*/new_bar', '.*PUT TestCaseUser .*/new_bar.*'], lines)) 
    110121 
    111122 
Note: See TracChangeset for help on using the changeset viewer.