Ignore:
Timestamp:
01/06/06 16:50:32 (14 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.