- unsigned int netint[2];
-
- assert(SIZEOF(netint) == 8);
-
- switch (net_read(fd, &netint, SIZEOF(netint), timeout)) {
- case -1:
- if (errmsg)
- *errmsg = newvstrallocf(*errmsg, _("recv error: %s"), strerror(errno));
- auth_debug(1, _("tcpm_recv_token: A return(-1)\n"));
- return (-1);
- case 0:
- *size = 0;
- *handle = H_EOF;
- *errmsg = newvstrallocf(*errmsg, _("SOCKET_EOF"));
- auth_debug(1, _("tcpm_recv_token: A return(0)\n"));
- return (0);
- default:
- break;
- }
-
- *size = (ssize_t)ntohl(netint[0]);
- *handle = (int)ntohl(netint[1]);
- /* amanda protocol packet can be above NETWORK_BLOCK_BYTES */
- if (*size > 128*NETWORK_BLOCK_BYTES || *size < 0) {
- if (isprint((int)(*size ) & 0xFF) &&
- isprint((int)(*size >> 8 ) & 0xFF) &&
- isprint((int)(*size >> 16) & 0xFF) &&
- isprint((int)(*size >> 24) & 0xFF) &&
- isprint((*handle ) & 0xFF) &&
- isprint((*handle >> 8 ) & 0xFF) &&
- isprint((*handle >> 16) & 0xFF) &&
- isprint((*handle >> 24) & 0xFF)) {
- char s[101];
- int i;
- s[0] = ((int)(*size) >> 24) & 0xFF;
- s[1] = ((int)(*size) >> 16) & 0xFF;
- s[2] = ((int)(*size) >> 8) & 0xFF;
- s[3] = ((int)(*size) ) & 0xFF;
- s[4] = (*handle >> 24) & 0xFF;
- s[5] = (*handle >> 16) & 0xFF;
- s[6] = (*handle >> 8 ) & 0xFF;
- s[7] = (*handle ) & 0xFF;
- i = 8; s[i] = ' ';
- while(i<100 && isprint((int)s[i]) && s[i] != '\n') {
- switch(net_read(fd, &s[i], 1, 0)) {
- case -1: s[i] = '\0'; break;
- case 0: s[i] = '\0'; break;
- default:
+ ssize_t rval;
+
+ assert(SIZEOF(rc->netint) == 8);
+ if (rc->size_header_read < (ssize_t)SIZEOF(rc->netint)) {
+ rval = read(fd, ((char *)&rc->netint) + rc->size_header_read,
+ SIZEOF(rc->netint) - rc->size_header_read);
+ if (rval == -1) {
+ if (errmsg)
+ *errmsg = newvstrallocf(*errmsg, _("recv error: %s"),
+ strerror(errno));
+ auth_debug(1, _("tcpm_recv_token: A return(-1)\n"));
+ return(-1);
+ } else if (rval == 0) {
+ *size = 0;
+ *handle = H_EOF;
+ *errmsg = newvstrallocf(*errmsg, _("SOCKET_EOF"));
+ auth_debug(1, _("tcpm_recv_token: A return(0)\n"));
+ return(0);
+ } else if (rval < (ssize_t)SIZEOF(rc->netint) - rc->size_header_read) {
+ rc->size_header_read += rval;
+ return(-2);
+ }
+ rc->size_header_read += rval;
+ amfree(rc->buffer);
+ *size = (ssize_t)ntohl(rc->netint[0]);
+ *handle = (int)ntohl(rc->netint[1]);
+ rc->buffer = NULL;
+ rc->size_buffer_read = 0;
+
+ /* amanda protocol packet can be above NETWORK_BLOCK_BYTES */
+ if (*size > 128*NETWORK_BLOCK_BYTES || *size < 0) {
+ if (isprint((int)(*size ) & 0xFF) &&
+ isprint((int)(*size >> 8 ) & 0xFF) &&
+ isprint((int)(*size >> 16) & 0xFF) &&
+ isprint((int)(*size >> 24) & 0xFF) &&
+ isprint((*handle ) & 0xFF) &&
+ isprint((*handle >> 8 ) & 0xFF) &&
+ isprint((*handle >> 16) & 0xFF) &&
+ isprint((*handle >> 24) & 0xFF)) {
+ char s[201];
+ char *s1;
+ int i;
+ s[0] = ((int)(*size) >> 24) & 0xFF;
+ s[1] = ((int)(*size) >> 16) & 0xFF;
+ s[2] = ((int)(*size) >> 8) & 0xFF;
+ s[3] = ((int)(*size) ) & 0xFF;
+ s[4] = (*handle >> 24) & 0xFF;
+ s[5] = (*handle >> 16) & 0xFF;
+ s[6] = (*handle >> 8 ) & 0xFF;
+ s[7] = (*handle ) & 0xFF;
+ i = 8; s[i] = ' ';
+ while(i<200 && isprint((int)s[i]) && s[i] != '\n') {
+ switch(net_read(fd, &s[i], 1, 0)) {
+ case -1: s[i] = '\0'; break;
+ case 0: s[i] = '\0'; break;
+ default: