Ignore:
Timestamp:
30/05/06 16:49:09 (14 years ago)
Author:
spascoe
Message:

A python module which provides a function to start the daemon can be
built using the setup.py script. This method of invoking the server
has been briefly tested but no test cases yet.

I've taken out the initialisation/finalisation hooks from the auth API because
we shouldn't need them now. They were written assuming the python interpretter
was going to be embedded within bbftpd, but I've inverted the embedding by
wrapping bbftpd.c:main in a python extension function.

Location:
TI05-delivery/trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/src/Makefile

    r999 r1064  
    99BBFTPC=bbftp-client-3.2.0/bbftpc 
    1010 
    11 all: 
     11all: server client 
     12 
     13server: 
     14        make -C $(BBFTPD) 
     15 
     16client: 
    1217        make -C $(BBFTPC) 
    13         make -C $(BBFTPD) 
    1418 
    1519# Configure and build bbftp 
     
    2327 
    2428clean: 
    25         make -C $(BBFTPC) clean 
    26         make -C $(BBFTPD) clean 
     29        -rm $(BBFTPD)/*.o $(BBFTPD)/bbftpd 
     30        -rm $(BBFTPC)/*.o $(BBFTPC)/bbftp 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd.c

    r973 r1064  
    116116#define OPTIONS    "bd:e:fl:m:R:suvw:" 
    117117#endif 
     118 
     119#ifdef NDG_PYTHON_EMBED 
     120#include <Python.h> 
     121extern char **environ; 
     122 
     123#endif // NDG_PYTHON_EMBED 
     124 
    118125/* 
    119126** Common variables for BBFTP protocole version 1 and 2 
     
    383390struct  timeval  tstart; 
    384391 
     392#ifdef NDG_PYTHON_EMBED 
     393bbftpd_main (argc, argv, envp) 
     394#else 
    385395main (argc,argv,envp) 
     396#endif //NDG_PYTHON_EMBED 
    386397    int     argc ; 
    387398    char    **argv ; 
     
    790801    } 
    791802#endif 
    792 #ifdef NDG_AUTH 
    793     if ( bbftpd_private_initialise(logmessage) == -1) {       
    794       syslog(BBFTPD_ERR, "bbftpd_private_init failure: %s", logmessage); 
    795       //!TODO: Should I write to stderr in all daemon modes (be_daemon)? 
    796       fprintf(stderr, "bbftpd_private_init failure: %s", logmessage); 
    797       exit(1); 
    798     } 
    799 #endif // NDG_AUTH 
    800803    if ( be_daemon == 2 ) { 
    801804        /* 
     
    10841087                state = S_PROTWAIT ; 
    10851088                sprintf(logmessage,"bbftpd version %s : OK",VERSION) ; 
     1089                syslog(BBFTPD_DEBUG, "Lets send the auth reply ..."); 
    10861090                reply(MSG_OK,logmessage) ; 
    10871091            } else { 
     
    14021406#endif 
    14031407 
     1408#ifdef NDG_PYTHON_EMBED 
     1409/* 
     1410  When embedding in python main is replaced by a simple python function call. 
     1411*/ 
     1412static PyObject *bbftpd_run(PyObject *self, PyObject *args) { 
     1413  int argc, i; 
     1414  char **argv, **arg_p; 
     1415 
     1416  /* 
     1417   * Convert arguments into a standard argv sequence. 
     1418   */ 
     1419  argc = PyTuple_GET_SIZE(args); 
     1420  if ((argv = (char*)malloc(argc*sizeof(char*))) == NULL) { 
     1421    PyErr_SetString(PyExc_MemoryError, "malloc failed"); 
     1422    return NULL; 
     1423  } 
     1424 
     1425  arg_p = argv; 
     1426  for (i==0; i<argc; i++) { 
     1427    if ((*arg_p = PyString_AsString(PyTuple_GET_ITEM(args, i))) == NULL) { 
     1428      free(argv); 
     1429      return NULL; 
     1430    } 
     1431    arg_p++; 
     1432  } 
     1433 
     1434  bbftpd_main(argc, argv, environ); 
     1435 
     1436  // I'm not sure we ever get here. 
     1437  free(argv); 
     1438  Py_RETURN_NONE; 
     1439} 
     1440 
     1441static PyMethodDef BbftpdMethods[] = { 
     1442  {"run", bbftpd_run, METH_VARARGS, "Execute the bbftpd server"}, 
     1443  {NULL, NULL, 0, NULL} 
     1444}; 
     1445 
     1446PyMODINIT_FUNC initbbftpd(void) { 
     1447  (void) Py_InitModule("bbftpd", BbftpdMethods); 
     1448} 
     1449 
     1450#endif // NDG_PYTHON_EMBED 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private.c

    r975 r1064  
    179179    ** Now give hand to user routine 
    180180    */ 
     181 
    181182    if ( bbftpd_private_auth(logmessage) < 0 ) { 
    182183        syslog(BBFTPD_ERR,"bbftpd_private_auth failed : %s",logmessage) ; 
     
    184185        return -1 ; 
    185186    } 
    186 #ifdef NDG_AUTH 
    187     ndg_atexit_status = NDG_INCHILD; 
    188 #endif // NDG_AUTH 
    189187 
    190188    return 0 ; 
     
    352350} 
    353351 
    354  
    355 #ifdef NDG_AUTH 
    356 /* 
    357 ** bbftpd_private_initialise : 
    358 ** 
    359 **      Routine to initialise the private authentication infrastructure. 
    360 **      This function is mainly a wrapper around bbftpd_private_init(), 
    361 **      except that it also sets up an atexit function. 
    362 */ 
    363 int bbftpd_private_initialise(char *logmessage) { 
    364   struct sigaction sga; 
    365  
    366   /* Set signal handlers for the daemon. 
    367    */ 
    368   sga.sa_handler = bbftpd_private_sigaction ; 
    369   sigemptyset(&(sga.sa_mask)); 
    370   sga.sa_flags = 0  ; 
    371   if ( sigaction(SIGTERM,&sga,0) < 0 ) { 
    372     syslog(BBFTPD_ERR,"Error sigaction SIGCTERM : %s",strerror(errno)) ; 
    373     return -1; 
    374   } 
    375  
    376  
    377   if (atexit(bbftpd_private_atexit) != 0) { 
    378     sprintf(logmessage, "atexit failure"); 
    379     return -1; 
    380   } 
    381   ndg_atexit_status = NDG_INFATHER; 
    382   return bbftpd_private_init(logmessage); 
    383 } 
    384  
    385 /* 
    386 ** bbftpd_private_sigaction(int sig) 
    387 ** 
    388 **      Routine to exit gracefully if SIGTERM is sent.  The daemon process 
    389 **      will not call any atexit() functions on receipt of SIGTERM by default. 
    390 **      This function is a signal handler to change this behaviour. 
    391 */ 
    392 void bbftpd_private_sigaction(int sig) 
    393 { 
    394   // Hopefully calling atexit() handlers. 
    395   exit(0); 
    396 } 
    397  
    398  
    399 /* 
    400 ** bbftpd_private_atexit : 
    401 ** 
    402 **      Routine to be registered with atexit() for cleaning up the private authentication 
    403 **      infrastructure.  This function must know whether the server is in a connected or 
    404 **      unconnected state, therefore the global variable ndg_atexit_status is used. 
    405 */ 
    406 void bbftpd_private_atexit(void) 
    407 { 
    408   if (ndg_atexit_status == NDG_INFATHER) { 
    409     bbftpd_private_finalise(); 
    410   } 
    411   else if (ndg_atexit_status == NDG_INCHILD) { 
    412     bbftpd_private_auth_finalise(); 
    413   } 
    414   else { 
    415     syslog(BBFTPD_ERR, "ndg_atexit_status unrecognised: %d", ndg_atexit_status); 
    416     fprintf(stderr, "ndg_atexit_status unrecognised: %d", ndg_atexit_status); 
    417   } 
    418 } 
    419 #endif // NDG_AUTH 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_user.c

    r1003 r1064  
    3939extern char currentusername[MAXLEN] ; 
    4040 
     41 
     42 
    4143/******************************************************************************* 
    4244** bbftpd_private_auth :                                                       * 
     
    109111 
    110112/* 
    111  * bbftpd_private_init : 
    112  * 
    113  *     Routine to initialise private authentication.  This function will be 
    114  *     called before bbftpd begins listening for connections and therefore 
    115  *     before the fork() that occurs when a client connects. 
    116  * 
    117  *     OUTPUT variable : 
    118  *          logmessage :  to write the error message in case of error 
    119  * 
    120  *     RETURN: 
    121  *         -1  Unrecoverable error 
    122  *          0  OK 
    123  * 
    124  */ 
    125  
    126 int bbftpd_private_init(char *logmessage) 
    127 { 
    128   syslog(LOG_DEBUG, "initialising private authentication"); 
    129   return 0; 
    130 } 
    131  
    132 /* 
    133  * bbftpd_private_finalise : 
    134  * 
    135  *     Routine to clean up the private authentication infrastructure when the 
    136  *     daemon exits.  This function is the counterpart of bbftpd_private_init and 
    137  *     will be called from the daemon process during exit.  NOTE: it will not 
    138  *     be aware of any actions of child processes. 
    139  * 
    140  */ 
    141  
    142 void bbftpd_private_finalise(void) 
    143 { 
    144   syslog(LOG_DEBUG, "finalising private authentication in server"); 
    145   return; 
    146 } 
    147  
    148 /* 
    149  * bbftpd_private_auth_finalise : 
    150  * 
    151  *     Routine to clean up the private authentication infrastructure for each child. 
    152  *     This function is the counterpart of bbftpd_private_auth and will be called from 
    153  *     each child of the daemon during exit. 
    154  * 
    155  */ 
    156  
    157 void bbftpd_private_auth_finalise(void) 
    158 { 
    159   syslog(LOG_DEBUG, "finalising private authentication in connection"); 
    160   return; 
    161 } 
    162  
    163 /* 
    164113** bbftpd_private_authz_control : 
    165114** 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/includes/bbftpd_private.h

    r973 r1064  
    4141RSA     *hisrsa ; 
    4242 
    43 #ifdef NDG_AUTH 
    44 /* 
    45 ** NDG authentication global variables. 
    46 */ 
    47 #define NDG_INFATHER 1 
    48 #define NDG_INCHILD 2 
    49 int ndg_atexit_status ; 
    50 #endif // NDG_AUTH 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/includes/bbftpd_private_user.h

    r802 r1064  
    2828*****************************************************************************/ 
    2929 
     30#include <Python.h> 
     31 
    3032/* 
    3133** This include must contain all global variable to be used for private 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/includes/daemon_proto.h

    r988 r1064  
    6363int bbftpd_private_send(char *buffertosend, int buffertosendlength, char *logmessage) ; 
    6464int bbftpd_private_recv(char *buffertorecv, int lengthtorecv, char *logmessage) ; 
    65 #ifdef NDG_AUTH 
    66 int bbftpd_private_initialise(char *logmessage); 
    67 void bbftpd_private_sigaction(int sig); 
    68 void bbftpd_private_atexit(void); 
    69 #endif // NDG_AUTH 
    7065/* 
    7166** Prototype for user private authentication routines 
     
    7368int bbftpd_private_auth(char *logmessage) ; 
    7469#ifdef NDG_AUTH 
    75 int bbftpd_private_init(char *logmessage); 
    76 void bbftpd_private_finalise(void); 
    77 void bbftpd_private_auth_finalise(void); 
    7870int bbftpd_private_authz_control(int msgcode, int transferoption, char *path, char *logmessage); 
    7971int bbftpd_private_authz_retr(char *path, char *logmessage); 
Note: See TracChangeset for help on using the changeset viewer.