Changeset 1078


Ignore:
Timestamp:
01/06/06 16:50:32 (13 years ago)
Author:
spascoe
Message:

Implemented higher level auth message passing (the receiver doesn't
need to know the message length). The client will use this mechanism to
send the private string. This is working with stand alone bbftp client/server.

Embedded bbftpd is broken until I make corresponding
changes to the python API.

Location:
TI05-delivery/trunk
Files:
4 edited

Legend:

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

    r1077 r1078  
    77VERSION:=$(shell cat ../VERSION) 
    88 
    9 DEFS="-DNDG_AUTH -DLOCAL_SYSLOG_FACILITY -DNDG_DELIVERY_VERSION=$(VERSION)" 
     9DEFS="-DNDG_AUTH -DLOCAL_SYSLOG_FACILITY -DNDG_DELIVERY_VERSION=$(VERSION) -g" 
    1010CONFIG_OPTS=--prefix=$(PREFIX) --without-gzip --without-rfio --enable-authentication=private \ 
    1111                CFLAGS=$(DEFS) 
  • TI05-delivery/trunk/src/bbftp-client-3.2.0/bbftpc/bbftp_private_user.c

    r1077 r1078  
    4646void printmessage(FILE *strm , int flag, int errcode, int tok, char *fmt, ...); 
    4747 
     48 
     49/* prototypes */ 
     50static int ndg_message_recv(char **buffer, int *length, char *logmessage); 
     51static int ndg_message_send(char *buffer, int length, char *logmessage); 
    4852 
    4953/******************************************************************************* 
     
    126130{ 
    127131  char msg[NDG_MESSAGE_LEN]; 
    128  
     132  char default_privatestr[] = "none"; 
     133   
    129134  /* Send version verification message.  */ 
    130135  sprintf(msg, "%.*s", NDG_MESSAGE_LEN - 1, NDG_HANDSHAKE); 
     
    142147  } 
    143148 
     149  /* Send the privatestr */ 
     150  // If there is no private string, send default 
     151  if (privatestr == NULL) { 
     152    privatestr = default_privatestr; 
     153  } 
     154 
     155  if (ndg_message_send(privatestr, strlen(privatestr) + 1, logmessage) == -1) { 
     156    return -1; 
     157  } 
     158 
    144159  return  0 ; 
    145160} 
     161 
     162/* 
     163 * Higher level message transfer functions. 
     164 * 
     165 */ 
     166 
     167/** 
     168 * Send a message, declaring it's length to the client. 
     169 * 
     170 * @param buffer a pointer to the message buffer 
     171 * @param length the number of bytes to send 
     172 * @param[out] loggmessage is filled with the error message on error 
     173 * @return 0 if OK, -1 if error 
     174 */ 
     175static int ndg_message_send(char *buffer, int length, char *logmessage) { 
     176  char ctrl[NDG_MESSAGE_LEN]; 
     177 
     178  sprintf(ctrl, "NDG-msg: %i", length); 
     179  if (bbftp_private_send(ctrl, NDG_MESSAGE_LEN, logmessage) == -1) { 
     180    return -1; 
     181  } 
     182 
     183  if (bbftp_private_send(buffer, length, logmessage) == -1) { 
     184    return -1; 
     185  } 
     186 
     187  return 0; 
     188} 
     189 
     190/** 
     191 * Receive a message of variable length 
     192 * 
     193 * @param[out] buffer is set to newly allocated message buffer 
     194 * @param[out] length is set to the length of the message 
     195 * @param[out] logmessage is filled with the logmessage on error 
     196 * @return 0 if OK, -1 if error 
     197 */ 
     198static int ndg_message_recv(char **buffer, int *length, char *logmessage) { 
     199  char ctrl[NDG_MESSAGE_LEN]; 
     200 
     201  if (bbftp_private_recv(ctrl, NDG_MESSAGE_LEN, logmessage) == -1) { 
     202    return -1; 
     203  } 
     204  if (sscanf(ctrl, "NDG-msg: %i", length) != 1) { 
     205    sprintf(logmessage, "ndg_message_recv ctrl error: %40s", ctrl); 
     206    return -1; 
     207  } 
     208 
     209  if ((*buffer = (char *)malloc(*length * sizeof(char))) == NULL) { 
     210    sprintf(logmessage, "ngd_message_recv malloc error"); 
     211    return -1; 
     212  } 
     213 
     214  if (bbftp_private_recv(buffer, *length, logmessage) == -1) { 
     215    free(*buffer); *buffer = NULL; 
     216    return -1; 
     217  } 
     218 
     219  return 0; 
     220} 
     221   
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_user.c

    r1077 r1078  
    4545#ifdef NDG_PYTHON_EMBED 
    4646int bbftpd_private_auth_callback(char *logmessage); 
     47 
    4748#endif 
     49 
     50/* prototypes */ 
     51static int ndg_message_recv(char **buffer, int *length, char *logmessage); 
     52static int ndg_message_send(char *buffer, int length, char *logmessage); 
     53 
     54 
    4855 
    4956/******************************************************************************* 
     
    114121  sprintf(currentusername, "%.*s", MAXLEN, username); 
    115122#else 
     123  char *privatestr; 
     124  int privatestr_len; 
    116125 
    117126  char msg[NDG_MESSAGE_LEN]; 
     
    129138    return -1; 
    130139  } 
     140 
     141  /* Receive the privatestr */ 
     142  if (ndg_message_recv(&privatestr, &privatestr_len, logmessage) == -1) { 
     143    return -1; 
     144  } 
     145 
     146  syslog(LOG_INFO, "Private string: %s", privatestr); 
    131147 
    132148#endif 
     
    232248  return 0; 
    233249} 
     250 
     251 
     252/* 
     253 * Higher level message transfer functions. 
     254 * 
     255 */ 
     256 
     257/** 
     258 * Send a message, declaring it's length to the client. 
     259 * 
     260 * @param buffer a pointer to the message buffer 
     261 * @param length the number of bytes to send 
     262 * @param[out] loggmessage is filled with the error message on error 
     263 * @return 0 if OK, -1 if error 
     264 */ 
     265static int ndg_message_send(char *buffer, int length, char *logmessage) { 
     266  char ctrl[NDG_MESSAGE_LEN]; 
     267 
     268  sprintf(ctrl, "NDG-msg: %i", length); 
     269  if (bbftpd_private_send(ctrl, NDG_MESSAGE_LEN, logmessage) == -1) { 
     270    return -1; 
     271  } 
     272 
     273  if (bbftpd_private_send(buffer, length, logmessage) == -1) { 
     274    return -1; 
     275  } 
     276 
     277  return 0; 
     278} 
     279 
     280/** 
     281 * Receive a message of variable length 
     282 * 
     283 * @param[out] buffer is set to newly allocated message buffer 
     284 * @param[out] length is set to the length of the message 
     285 * @param[out] logmessage is filled with the logmessage on error 
     286 * @return 0 if OK, -1 if error 
     287 */ 
     288static int ndg_message_recv(char **buffer, int *length, char *logmessage) { 
     289  char ctrl[NDG_MESSAGE_LEN]; 
     290 
     291  if (bbftpd_private_recv(ctrl, NDG_MESSAGE_LEN, logmessage) == -1) { 
     292    return -1; 
     293  } 
     294  if (sscanf(ctrl, "NDG-msg: %i", length) != 1) { 
     295    sprintf(logmessage, "ndg_message_recv ctrl error: %40s", ctrl); 
     296    return -1; 
     297  } 
     298 
     299  if ((*buffer = (char *)malloc(*length * sizeof(char))) == NULL) { 
     300    sprintf(logmessage, "ngd_message_recv malloc error"); 
     301    return -1; 
     302  } 
     303 
     304  if (bbftpd_private_recv(*buffer, *length, logmessage) == -1) { 
     305    free(*buffer); *buffer = NULL; 
     306    return -1; 
     307  } 
     308 
     309  return 0; 
     310} 
     311   
     312 
     313 
     314 
    234315#endif // NDG_AUTH 
  • TI05-delivery/trunk/test/test_bbftpd.py

    r1077 r1078  
    7171        self._stopServer(pid) 
    7272 
    73         self.assert_(self._findLines(['Received Auth handshake: NDG-Delivery-server %s' % self.VERSION], output)) 
     73        self.assert_(self._findLines(['Received Auth handshake: NDG-Delivery-server %s.*' % self.VERSION], output)) 
    7474 
    7575        lines = self._readSyslog() 
    7676        self.assert_(self._findLines(['.*Received auth message: NDG-Delivery-client %s.*' % self.VERSION], lines)) 
    7777 
     78    def testPrivateStr(self): 
     79        """Connect with a private string.  Check syslog for string value. 
     80        """ 
     81 
     82        self._startServer() 
     83        pid = self._getServerPid() 
     84 
     85        fh = self._runClient('dir .', privatestr="Tester calling") 
     86        output = fh.read() 
     87 
     88        self._stopServer(pid) 
     89 
     90        lines = self._readSyslog() 
     91        self.assert_(self._findLines(['.*Private string: Tester calling.*'], lines)) 
    7892 
    7993    def testDir(self): 
     
    213227        return ''.join(filtered_log) 
    214228 
    215     def _runClient(self, cmd, debug=False, user="testcase"): 
     229    def _runClient(self, cmd, debug=False, user="testcase", privatestr=None): 
    216230        """Run the client. 
    217231        """ 
     
    221235        else: 
    222236            f = "-m" 
    223          
    224         fh = os.popen('%s %s -u %s -e %s localhost' % (self.BBFTP, f, user, repr(cmd))) 
     237 
     238        if privatestr: 
     239            p = '-P %s' % repr(privatestr) 
     240        else: 
     241            p = '' 
     242         
     243        fh = os.popen('%s %s -u %s %s -e %s localhost' % (self.BBFTP, f, user, p, repr(cmd))) 
    225244        return fh 
    226245 
Note: See TracChangeset for help on using the changeset viewer.