Ignore:
Timestamp:
08/06/06 15:28:07 (14 years ago)
Author:
spascoe
Message:

Authorisation in python is confirmed as working with 2 test cases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/src/python_ext/bbftpd.c

    r1141 r1144  
    9191  } 
    9292 
     93  /** @todo exceptions of type delivery.server.AuthenticationFailure should be logged as 
     94   *      failure rather than error. 
     95   */ 
    9396  if ((authzHandler = PyObject_CallMethod(authHandler, "authorise", "")) == NULL) { 
    9497    ndg_pyerr_to_logmessage(logmessage, "ndg_auth"); 
     
    9699  } 
    97100 
    98   /* If authHandler.authorise() returned None then authorisation failed.  */ 
    99   if (authzHandler == Py_None) { 
     101  /* Authorisation is considered failed if the return value isn't True.  */ 
     102  if (!PyObject_IsTrue(authzHandler)) { 
    100103    sprintf(logmessage, "ndg_auth: python authorisation failed"); 
    101104    return -1; 
     
    143146int ndg_authz_control(int msgcode, int transferoption, char *path, char *logmessage) { 
    144147  PyObject *ret_obj; 
    145   int ret; 
    146148 
    147149  if (authzHandler == NULL) { 
     
    155157  } 
    156158   
    157   if (!PyInt_Check(ret_obj)) { 
     159  /* Authorisation fails if ret_obj is false. */ 
     160  if (!PyObject_IsTrue(ret_obj)) { 
    158161    ndg_pyerr_to_logmessage(logmessage, "ndg_authz_control"); 
    159162    Py_DECREF(ret_obj); 
     
    161164  } 
    162165 
    163   ret = (int)PyInt_AsLong(ret_obj); 
    164   Py_DECREF(ret_obj); 
    165   return ret; 
     166  return 0; 
    166167} 
    167168 
     
    169170 * Make a callback to do authorisation of a retr command. 
    170171 * 
    171  * @see bbftpd_private_authz_store() 
     172 * @see bbftpd_private_authz_retr() 
    172173 */ 
    173174int ndg_authz_retr(char *path, char *logmessage) { 
    174175  PyObject *ret_obj; 
    175   int ret; 
    176176 
    177177  if (authzHandler == NULL) { 
     
    185185  } 
    186186   
    187   if (!PyInt_Check(ret_obj)) { 
     187  /* Authorisation fails if ret_obj is false. */ 
     188  if (!PyObject_IsTrue(ret_obj)) { 
    188189    ndg_pyerr_to_logmessage(logmessage, "ndg_authz_retr"); 
    189190    Py_DECREF(ret_obj); 
     
    191192  } 
    192193 
    193   ret = (int)PyInt_AsLong(ret_obj); 
    194   Py_DECREF(ret_obj); 
    195   return ret; 
     194  return 0; 
    196195} 
    197196 
     
    204203int ndg_authz_store(char *path, char *logmessage) { 
    205204  PyObject *ret_obj; 
    206   int ret; 
    207205 
    208206  if (authzHandler == NULL) { 
     
    216214  } 
    217215   
    218   if (!PyInt_Check(ret_obj)) { 
     216  /* Authorisation fails if ret_obj is false. */ 
     217  if (!PyObject_IsTrue(ret_obj)) { 
    219218    ndg_pyerr_to_logmessage(logmessage, "ndg_authz_store"); 
    220219    Py_DECREF(ret_obj); 
     
    222221  } 
    223222 
    224   ret = (int)PyInt_AsLong(ret_obj); 
    225   Py_DECREF(ret_obj); 
    226   return ret; 
     223  return 0; 
    227224} 
    228225  
Note: See TracChangeset for help on using the changeset viewer.