recv_bin_buffer() returns the converted errno on errors.
So there's no point in having a paraslash error number for recv errors.
if (ret < 0)
goto out;
if (ret != sizeof(int)) {
- ret = -E_RECV;
+ ret = -E_AFS_SHORT_READ;
goto out;
}
ret = *(int *) buf;
/* We can't use send_buffer here since buf may contain null bytes */
ret = send_bin_buffer(fd,(char *) crypt_buf, numbytes);
if (ret < 0)
- goto err_out;
+ goto net_err;
/* recv decrypted number */
ret = recv_buffer(fd, buf, sizeof(buf));
if (ret < 0)
- goto err_out;
+ goto net_err;
numbytes = ret;
ret = -E_AUTH;
if (!numbytes)
- goto err_out;
+ goto net_err;
if (sscanf(buf, CHALLENGE_RESPONSE_MSG "%lu", &chall_response) < 1
|| chall_response != challenge_nr)
goto err_out;
numbytes = strlen(buf);
ret = send_bin_buffer(fd, buf, numbytes);
if (ret < 0)
- goto err_out;
+ goto net_err;
if (use_rc4)
enable_crypt(fd, rc4_recv, rc4_send, NULL);
ret = read_command(fd, &command);
- if (ret < 0)
+ if (ret == -E_COMMAND_SYNTAX)
goto err_out;
+ if (ret < 0)
+ goto net_err;
ret = -E_BAD_CMD;
cmd = parse_cmd(command);
if (!cmd)
goto out;
}
err_out:
+ send_va_buffer(fd, "%s\n", PARA_STRERROR(-ret));
+net_err:
PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-ret));
- if (ret != -E_SEND && ret != -E_RECV)
- send_va_buffer(fd, "%s\n", PARA_STRERROR(-ret));
ret = EXIT_FAILURE;
out:
free(command);
PARA_ERROR(AFS_SIGNAL, "afs caught deadly signal"), \
PARA_ERROR(AFS_SOCKET, "afs socket not writable"), \
PARA_ERROR(AFS_PARENT_DIED, "fatal: server process terminated"), \
+ PARA_ERROR(AFS_SHORT_READ, "short read from afs socket"), \
#define MOOD_ERRORS \
#define NET_ERRORS \
PARA_ERROR(SEND, "send error"), \
- PARA_ERROR(RECV, "receive error"), \
PARA_ERROR(SOCKET, "socket error"), \
PARA_ERROR(CONNECT, "connect error"), \
PARA_ERROR(ACCEPT, "accept error"), \
* \param buf the buffer to write the decrypted data to
* \param size the size of \a buf
*
- * Receive at most \a size bytes from filedescriptor fd. If encryption is
+ * Receive at most \a size bytes from file descriptor \a fd. If encryption is
* available, decrypt the received buffer.
*
- * \return The number of bytes received on success. On receive errors, -E_RECV
- * is returned. On crypt errors, the corresponding crypt error number is
- * returned.
+ * \return The number of bytes received on success, negative on errors.
*
* \sa recv(2)
*/
{
int n;
- if (!size)
- return -E_RECV;
+ assert(size);
n = recv_bin_buffer(fd, buf, size - 1);
if (n >= 0)
buf[n] = '\0';